1use std::collections::HashMap;
4
5use async_trait::async_trait;
6use cashu::MintInfo;
7use uuid::Uuid;
8
9use super::Error;
10use crate::common::{LnKey, QuoteTTL};
11use crate::mint::{self, MintKeySetInfo, MintQuote as MintMintQuote};
12use crate::nuts::{
13 BlindSignature, CurrencyUnit, Id, MeltBolt11Request, MeltQuoteState, MintQuoteState, Proof,
14 Proofs, PublicKey, State,
15};
16
17#[async_trait]
19pub trait Database {
20 type Err: Into<Error> + From<Error>;
22
23 async fn set_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err>;
25 async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Self::Err>;
27 async fn get_active_keysets(&self) -> Result<HashMap<CurrencyUnit, Id>, Self::Err>;
29
30 async fn add_mint_quote(&self, quote: MintMintQuote) -> Result<(), Self::Err>;
32 async fn get_mint_quote(&self, quote_id: &Uuid) -> Result<Option<MintMintQuote>, Self::Err>;
34 async fn update_mint_quote_state(
36 &self,
37 quote_id: &Uuid,
38 state: MintQuoteState,
39 ) -> Result<MintQuoteState, Self::Err>;
40 async fn get_mint_quote_by_request(
42 &self,
43 request: &str,
44 ) -> Result<Option<MintMintQuote>, Self::Err>;
45 async fn get_mint_quote_by_request_lookup_id(
47 &self,
48 request_lookup_id: &str,
49 ) -> Result<Option<MintMintQuote>, Self::Err>;
50 async fn get_mint_quotes(&self) -> Result<Vec<MintMintQuote>, Self::Err>;
52 async fn get_mint_quotes_with_state(
54 &self,
55 state: MintQuoteState,
56 ) -> Result<Vec<MintMintQuote>, Self::Err>;
57 async fn remove_mint_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
59
60 async fn add_melt_quote(&self, quote: mint::MeltQuote) -> Result<(), Self::Err>;
62 async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err>;
64 async fn update_melt_quote_state(
66 &self,
67 quote_id: &Uuid,
68 state: MeltQuoteState,
69 ) -> Result<MeltQuoteState, Self::Err>;
70 async fn get_melt_quotes(&self) -> Result<Vec<mint::MeltQuote>, Self::Err>;
72 async fn remove_melt_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
74
75 async fn add_melt_request(
77 &self,
78 melt_request: MeltBolt11Request<Uuid>,
79 ln_key: LnKey,
80 ) -> Result<(), Self::Err>;
81 async fn get_melt_request(
83 &self,
84 quote_id: &Uuid,
85 ) -> Result<Option<(MeltBolt11Request<Uuid>, LnKey)>, Self::Err>;
86
87 async fn add_keyset_info(&self, keyset: MintKeySetInfo) -> Result<(), Self::Err>;
89 async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
91 async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
93
94 async fn add_proofs(&self, proof: Proofs, quote_id: Option<Uuid>) -> Result<(), Self::Err>;
96 async fn remove_proofs(
98 &self,
99 ys: &[PublicKey],
100 quote_id: Option<Uuid>,
101 ) -> Result<(), Self::Err>;
102 async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err>;
104 async fn get_proof_ys_by_quote_id(&self, quote_id: &Uuid) -> Result<Vec<PublicKey>, Self::Err>;
106 async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
108 async fn update_proofs_states(
110 &self,
111 ys: &[PublicKey],
112 proofs_state: State,
113 ) -> Result<Vec<Option<State>>, Self::Err>;
114 async fn get_proofs_by_keyset_id(
116 &self,
117 keyset_id: &Id,
118 ) -> Result<(Proofs, Vec<Option<State>>), Self::Err>;
119
120 async fn add_blind_signatures(
122 &self,
123 blinded_messages: &[PublicKey],
124 blind_signatures: &[BlindSignature],
125 quote_id: Option<Uuid>,
126 ) -> Result<(), Self::Err>;
127 async fn get_blind_signatures(
129 &self,
130 blinded_messages: &[PublicKey],
131 ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
132 async fn get_blind_signatures_for_keyset(
134 &self,
135 keyset_id: &Id,
136 ) -> Result<Vec<BlindSignature>, Self::Err>;
137 async fn get_blind_signatures_for_quote(
139 &self,
140 quote_id: &Uuid,
141 ) -> Result<Vec<BlindSignature>, Self::Err>;
142
143 async fn set_mint_info(&self, mint_info: MintInfo) -> Result<(), Self::Err>;
145 async fn get_mint_info(&self) -> Result<MintInfo, Self::Err>;
147
148 async fn set_quote_ttl(&self, quote_ttl: QuoteTTL) -> Result<(), Self::Err>;
150 async fn get_quote_ttl(&self) -> Result<QuoteTTL, Self::Err>;
152}