1use std::collections::HashMap;
4use std::fmt::Debug;
5
6use async_trait::async_trait;
7use cashu::KeySet;
8
9use super::Error;
10use crate::common::ProofInfo;
11use crate::mint_url::MintUrl;
12use crate::nuts::{
13 CurrencyUnit, Id, KeySetInfo, Keys, MintInfo, PublicKey, SpendingConditions, State,
14};
15use crate::wallet::{
16 self, MintQuote as WalletMintQuote, Transaction, TransactionDirection, TransactionId,
17};
18
19#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
21#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
22pub trait Database: Debug {
23 type Err: Into<Error> + From<Error>;
25
26 async fn add_mint(
28 &self,
29 mint_url: MintUrl,
30 mint_info: Option<MintInfo>,
31 ) -> Result<(), Self::Err>;
32 async fn remove_mint(&self, mint_url: MintUrl) -> Result<(), Self::Err>;
34 async fn get_mint(&self, mint_url: MintUrl) -> Result<Option<MintInfo>, Self::Err>;
36 async fn get_mints(&self) -> Result<HashMap<MintUrl, Option<MintInfo>>, Self::Err>;
38 async fn update_mint_url(
40 &self,
41 old_mint_url: MintUrl,
42 new_mint_url: MintUrl,
43 ) -> Result<(), Self::Err>;
44
45 async fn add_mint_keysets(
47 &self,
48 mint_url: MintUrl,
49 keysets: Vec<KeySetInfo>,
50 ) -> Result<(), Self::Err>;
51 async fn get_mint_keysets(
53 &self,
54 mint_url: MintUrl,
55 ) -> Result<Option<Vec<KeySetInfo>>, Self::Err>;
56 async fn get_keyset_by_id(&self, keyset_id: &Id) -> Result<Option<KeySetInfo>, Self::Err>;
58
59 async fn add_mint_quote(&self, quote: WalletMintQuote) -> Result<(), Self::Err>;
61 async fn get_mint_quote(&self, quote_id: &str) -> Result<Option<WalletMintQuote>, Self::Err>;
63 async fn get_mint_quotes(&self) -> Result<Vec<WalletMintQuote>, Self::Err>;
65 async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Self::Err>;
67
68 async fn add_melt_quote(&self, quote: wallet::MeltQuote) -> Result<(), Self::Err>;
70 async fn get_melt_quote(&self, quote_id: &str) -> Result<Option<wallet::MeltQuote>, Self::Err>;
72 async fn get_melt_quotes(&self) -> Result<Vec<wallet::MeltQuote>, Self::Err>;
74 async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Self::Err>;
76
77 async fn add_keys(&self, keyset: KeySet) -> Result<(), Self::Err>;
79 async fn get_keys(&self, id: &Id) -> Result<Option<Keys>, Self::Err>;
81 async fn remove_keys(&self, id: &Id) -> Result<(), Self::Err>;
83
84 async fn update_proofs(
87 &self,
88 added: Vec<ProofInfo>,
89 removed_ys: Vec<PublicKey>,
90 ) -> Result<(), Self::Err>;
91 async fn get_proofs(
93 &self,
94 mint_url: Option<MintUrl>,
95 unit: Option<CurrencyUnit>,
96 state: Option<Vec<State>>,
97 spending_conditions: Option<Vec<SpendingConditions>>,
98 ) -> Result<Vec<ProofInfo>, Self::Err>;
99 async fn update_proofs_state(&self, ys: Vec<PublicKey>, state: State) -> Result<(), Self::Err>;
101
102 async fn increment_keyset_counter(&self, keyset_id: &Id, count: u32) -> Result<u32, Self::Err>;
104
105 async fn add_transaction(&self, transaction: Transaction) -> Result<(), Self::Err>;
107 async fn get_transaction(
109 &self,
110 transaction_id: TransactionId,
111 ) -> Result<Option<Transaction>, Self::Err>;
112 async fn list_transactions(
114 &self,
115 mint_url: Option<MintUrl>,
116 direction: Option<TransactionDirection>,
117 unit: Option<CurrencyUnit>,
118 ) -> Result<Vec<Transaction>, Self::Err>;
119 async fn remove_transaction(&self, transaction_id: TransactionId) -> Result<(), Self::Err>;
121}