1use std::collections::HashMap;
4use std::fmt::Debug;
5
6use async_trait::async_trait;
7
8use super::Error;
9use crate::common::ProofInfo;
10use crate::mint_url::MintUrl;
11use crate::nuts::{
12 CurrencyUnit, Id, KeySetInfo, Keys, MintInfo, PublicKey, SpendingConditions, State,
13};
14use crate::wallet::{
15 self, MintQuote as WalletMintQuote, Transaction, TransactionDirection, TransactionId,
16};
17
18#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
20#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
21pub trait Database: Debug {
22 type Err: Into<Error> + From<Error>;
24
25 async fn add_mint(
27 &self,
28 mint_url: MintUrl,
29 mint_info: Option<MintInfo>,
30 ) -> Result<(), Self::Err>;
31 async fn remove_mint(&self, mint_url: MintUrl) -> Result<(), Self::Err>;
33 async fn get_mint(&self, mint_url: MintUrl) -> Result<Option<MintInfo>, Self::Err>;
35 async fn get_mints(&self) -> Result<HashMap<MintUrl, Option<MintInfo>>, Self::Err>;
37 async fn update_mint_url(
39 &self,
40 old_mint_url: MintUrl,
41 new_mint_url: MintUrl,
42 ) -> Result<(), Self::Err>;
43
44 async fn add_mint_keysets(
46 &self,
47 mint_url: MintUrl,
48 keysets: Vec<KeySetInfo>,
49 ) -> Result<(), Self::Err>;
50 async fn get_mint_keysets(
52 &self,
53 mint_url: MintUrl,
54 ) -> Result<Option<Vec<KeySetInfo>>, Self::Err>;
55 async fn get_keyset_by_id(&self, keyset_id: &Id) -> Result<Option<KeySetInfo>, Self::Err>;
57
58 async fn add_mint_quote(&self, quote: WalletMintQuote) -> Result<(), Self::Err>;
60 async fn get_mint_quote(&self, quote_id: &str) -> Result<Option<WalletMintQuote>, Self::Err>;
62 async fn get_mint_quotes(&self) -> Result<Vec<WalletMintQuote>, Self::Err>;
64 async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Self::Err>;
66
67 async fn add_melt_quote(&self, quote: wallet::MeltQuote) -> Result<(), Self::Err>;
69 async fn get_melt_quote(&self, quote_id: &str) -> Result<Option<wallet::MeltQuote>, Self::Err>;
71 async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Self::Err>;
73
74 async fn add_keys(&self, keys: Keys) -> Result<(), Self::Err>;
76 async fn get_keys(&self, id: &Id) -> Result<Option<Keys>, Self::Err>;
78 async fn remove_keys(&self, id: &Id) -> Result<(), Self::Err>;
80
81 async fn update_proofs(
84 &self,
85 added: Vec<ProofInfo>,
86 removed_ys: Vec<PublicKey>,
87 ) -> Result<(), Self::Err>;
88 async fn get_proofs(
90 &self,
91 mint_url: Option<MintUrl>,
92 unit: Option<CurrencyUnit>,
93 state: Option<Vec<State>>,
94 spending_conditions: Option<Vec<SpendingConditions>>,
95 ) -> Result<Vec<ProofInfo>, Self::Err>;
96 async fn update_proofs_state(&self, ys: Vec<PublicKey>, state: State) -> Result<(), Self::Err>;
98
99 async fn increment_keyset_counter(&self, keyset_id: &Id, count: u32) -> Result<(), Self::Err>;
101 async fn get_keyset_counter(&self, keyset_id: &Id) -> Result<Option<u32>, Self::Err>;
103
104 async fn add_transaction(&self, transaction: Transaction) -> Result<(), Self::Err>;
106 async fn get_transaction(
108 &self,
109 transaction_id: TransactionId,
110 ) -> Result<Option<Transaction>, Self::Err>;
111 async fn list_transactions(
113 &self,
114 mint_url: Option<MintUrl>,
115 direction: Option<TransactionDirection>,
116 unit: Option<CurrencyUnit>,
117 ) -> Result<Vec<Transaction>, Self::Err>;
118 async fn remove_transaction(&self, transaction_id: TransactionId) -> Result<(), Self::Err>;
120}