cdk_common/database/
wallet.rs1use 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;
15use crate::wallet::MintQuote as WalletMintQuote;
16
17#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
19#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
20pub trait Database: Debug {
21 type Err: Into<Error> + From<Error>;
23
24 async fn add_mint(
26 &self,
27 mint_url: MintUrl,
28 mint_info: Option<MintInfo>,
29 ) -> Result<(), Self::Err>;
30 async fn remove_mint(&self, mint_url: MintUrl) -> Result<(), Self::Err>;
32 async fn get_mint(&self, mint_url: MintUrl) -> Result<Option<MintInfo>, Self::Err>;
34 async fn get_mints(&self) -> Result<HashMap<MintUrl, Option<MintInfo>>, Self::Err>;
36 async fn update_mint_url(
38 &self,
39 old_mint_url: MintUrl,
40 new_mint_url: MintUrl,
41 ) -> Result<(), Self::Err>;
42
43 async fn add_mint_keysets(
45 &self,
46 mint_url: MintUrl,
47 keysets: Vec<KeySetInfo>,
48 ) -> Result<(), Self::Err>;
49 async fn get_mint_keysets(
51 &self,
52 mint_url: MintUrl,
53 ) -> Result<Option<Vec<KeySetInfo>>, Self::Err>;
54 async fn get_keyset_by_id(&self, keyset_id: &Id) -> Result<Option<KeySetInfo>, Self::Err>;
56
57 async fn add_mint_quote(&self, quote: WalletMintQuote) -> Result<(), Self::Err>;
59 async fn get_mint_quote(&self, quote_id: &str) -> Result<Option<WalletMintQuote>, Self::Err>;
61 async fn get_mint_quotes(&self) -> Result<Vec<WalletMintQuote>, Self::Err>;
63 async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Self::Err>;
65
66 async fn add_melt_quote(&self, quote: wallet::MeltQuote) -> Result<(), Self::Err>;
68 async fn get_melt_quote(&self, quote_id: &str) -> Result<Option<wallet::MeltQuote>, Self::Err>;
70 async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Self::Err>;
72
73 async fn add_keys(&self, keys: Keys) -> Result<(), Self::Err>;
75 async fn get_keys(&self, id: &Id) -> Result<Option<Keys>, Self::Err>;
77 async fn remove_keys(&self, id: &Id) -> Result<(), Self::Err>;
79
80 async fn update_proofs(
83 &self,
84 added: Vec<ProofInfo>,
85 removed_ys: Vec<PublicKey>,
86 ) -> Result<(), Self::Err>;
87 async fn set_pending_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
90 async fn reserve_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
92 async fn set_unspent_proofs(&self, ys: Vec<PublicKey>) -> Result<(), Self::Err>;
95 async fn get_proofs(
97 &self,
98 mint_url: Option<MintUrl>,
99 unit: Option<CurrencyUnit>,
100 state: Option<Vec<State>>,
101 spending_conditions: Option<Vec<SpendingConditions>>,
102 ) -> Result<Vec<ProofInfo>, Self::Err>;
103
104 async fn increment_keyset_counter(&self, keyset_id: &Id, count: u32) -> Result<(), Self::Err>;
106 async fn get_keyset_counter(&self, keyset_id: &Id) -> Result<Option<u32>, Self::Err>;
108
109 async fn get_nostr_last_checked(
111 &self,
112 verifying_key: &PublicKey,
113 ) -> Result<Option<u32>, Self::Err>;
114 async fn add_nostr_last_checked(
116 &self,
117 verifying_key: PublicKey,
118 last_checked: u32,
119 ) -> Result<(), Self::Err>;
120}