//! CDK Database use std::collections::HashMap; use std::fmt::Debug; use async_trait::async_trait; use cashu::KeySet; use super::Error; use crate::common::ProofInfo; use crate::mint_url::MintUrl; use crate::nuts::{ CurrencyUnit, Id, KeySetInfo, Keys, MintInfo, PublicKey, SpendingConditions, State, }; use crate::wallet::{ self, MintQuote as WalletMintQuote, Transaction, TransactionDirection, TransactionId, }; /// Wallet Database trait #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait Database: Debug { /// Wallet Database Error type Err: Into + From; /// Add Mint to storage async fn add_mint( &self, mint_url: MintUrl, mint_info: Option, ) -> Result<(), Self::Err>; /// Remove Mint from storage async fn remove_mint(&self, mint_url: MintUrl) -> Result<(), Self::Err>; /// Get mint from storage async fn get_mint(&self, mint_url: MintUrl) -> Result, Self::Err>; /// Get all mints from storage async fn get_mints(&self) -> Result>, Self::Err>; /// Update mint url async fn update_mint_url( &self, old_mint_url: MintUrl, new_mint_url: MintUrl, ) -> Result<(), Self::Err>; /// Add mint keyset to storage async fn add_mint_keysets( &self, mint_url: MintUrl, keysets: Vec, ) -> Result<(), Self::Err>; /// Get mint keysets for mint url async fn get_mint_keysets( &self, mint_url: MintUrl, ) -> Result>, Self::Err>; /// Get mint keyset by id async fn get_keyset_by_id(&self, keyset_id: &Id) -> Result, Self::Err>; /// Add mint quote to storage async fn add_mint_quote(&self, quote: WalletMintQuote) -> Result<(), Self::Err>; /// Get mint quote from storage async fn get_mint_quote(&self, quote_id: &str) -> Result, Self::Err>; /// Get mint quotes from storage async fn get_mint_quotes(&self) -> Result, Self::Err>; /// Remove mint quote from storage async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Self::Err>; /// Add melt quote to storage async fn add_melt_quote(&self, quote: wallet::MeltQuote) -> Result<(), Self::Err>; /// Get melt quote from storage async fn get_melt_quote(&self, quote_id: &str) -> Result, Self::Err>; /// Get melt quotes from storage async fn get_melt_quotes(&self) -> Result, Self::Err>; /// Remove melt quote from storage async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Self::Err>; /// Add [`Keys`] to storage async fn add_keys(&self, keyset: KeySet) -> Result<(), Self::Err>; /// Get [`Keys`] from storage async fn get_keys(&self, id: &Id) -> Result, Self::Err>; /// Remove [`Keys`] from storage async fn remove_keys(&self, id: &Id) -> Result<(), Self::Err>; /// Update the proofs in storage by adding new proofs or removing proofs by /// their Y value. async fn update_proofs( &self, added: Vec, removed_ys: Vec, ) -> Result<(), Self::Err>; /// Get proofs from storage async fn get_proofs( &self, mint_url: Option, unit: Option, state: Option>, spending_conditions: Option>, ) -> Result, Self::Err>; /// Update proofs state in storage async fn update_proofs_state(&self, ys: Vec, state: State) -> Result<(), Self::Err>; /// Atomically increment Keyset counter and return new value async fn increment_keyset_counter(&self, keyset_id: &Id, count: u32) -> Result; /// Add transaction to storage async fn add_transaction(&self, transaction: Transaction) -> Result<(), Self::Err>; /// Get transaction from storage async fn get_transaction( &self, transaction_id: TransactionId, ) -> Result, Self::Err>; /// List transactions from storage async fn list_transactions( &self, mint_url: Option, direction: Option, unit: Option, ) -> Result, Self::Err>; /// Remove transaction from storage async fn remove_transaction(&self, transaction_id: TransactionId) -> Result<(), Self::Err>; }