cdk_common/database/
mint.rs

1//! CDK Database
2
3use 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/// Mint Database trait
18#[async_trait]
19pub trait Database {
20    /// Mint Database Error
21    type Err: Into<Error> + From<Error>;
22
23    /// Add Active Keyset
24    async fn set_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Self::Err>;
25    /// Get Active Keyset
26    async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Self::Err>;
27    /// Get all Active Keyset
28    async fn get_active_keysets(&self) -> Result<HashMap<CurrencyUnit, Id>, Self::Err>;
29
30    /// Add [`MintMintQuote`]
31    async fn add_mint_quote(&self, quote: MintMintQuote) -> Result<(), Self::Err>;
32    /// Get [`MintMintQuote`]
33    async fn get_mint_quote(&self, quote_id: &Uuid) -> Result<Option<MintMintQuote>, Self::Err>;
34    /// Update state of [`MintMintQuote`]
35    async fn update_mint_quote_state(
36        &self,
37        quote_id: &Uuid,
38        state: MintQuoteState,
39    ) -> Result<MintQuoteState, Self::Err>;
40    /// Get all [`MintMintQuote`]s
41    async fn get_mint_quote_by_request(
42        &self,
43        request: &str,
44    ) -> Result<Option<MintMintQuote>, Self::Err>;
45    /// Get all [`MintMintQuote`]s
46    async fn get_mint_quote_by_request_lookup_id(
47        &self,
48        request_lookup_id: &str,
49    ) -> Result<Option<MintMintQuote>, Self::Err>;
50    /// Get Mint Quotes
51    async fn get_mint_quotes(&self) -> Result<Vec<MintMintQuote>, Self::Err>;
52    /// Get Mint Quotes with state
53    async fn get_mint_quotes_with_state(
54        &self,
55        state: MintQuoteState,
56    ) -> Result<Vec<MintMintQuote>, Self::Err>;
57    /// Remove [`MintMintQuote`]
58    async fn remove_mint_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
59
60    /// Add [`mint::MeltQuote`]
61    async fn add_melt_quote(&self, quote: mint::MeltQuote) -> Result<(), Self::Err>;
62    /// Get [`mint::MeltQuote`]
63    async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err>;
64    /// Update [`mint::MeltQuote`] state
65    async fn update_melt_quote_state(
66        &self,
67        quote_id: &Uuid,
68        state: MeltQuoteState,
69    ) -> Result<MeltQuoteState, Self::Err>;
70    /// Get all [`mint::MeltQuote`]s
71    async fn get_melt_quotes(&self) -> Result<Vec<mint::MeltQuote>, Self::Err>;
72    /// Remove [`mint::MeltQuote`]
73    async fn remove_melt_quote(&self, quote_id: &Uuid) -> Result<(), Self::Err>;
74
75    /// Add melt request
76    async fn add_melt_request(
77        &self,
78        melt_request: MeltBolt11Request<Uuid>,
79        ln_key: LnKey,
80    ) -> Result<(), Self::Err>;
81    /// Get melt request
82    async fn get_melt_request(
83        &self,
84        quote_id: &Uuid,
85    ) -> Result<Option<(MeltBolt11Request<Uuid>, LnKey)>, Self::Err>;
86
87    /// Add [`MintKeySetInfo`]
88    async fn add_keyset_info(&self, keyset: MintKeySetInfo) -> Result<(), Self::Err>;
89    /// Get [`MintKeySetInfo`]
90    async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
91    /// Get [`MintKeySetInfo`]s
92    async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
93
94    /// Add  [`Proofs`]
95    async fn add_proofs(&self, proof: Proofs, quote_id: Option<Uuid>) -> Result<(), Self::Err>;
96    /// Remove [`Proofs`]
97    async fn remove_proofs(
98        &self,
99        ys: &[PublicKey],
100        quote_id: Option<Uuid>,
101    ) -> Result<(), Self::Err>;
102    /// Get [`Proofs`] by ys
103    async fn get_proofs_by_ys(&self, ys: &[PublicKey]) -> Result<Vec<Option<Proof>>, Self::Err>;
104    /// Get ys by quote id
105    async fn get_proof_ys_by_quote_id(&self, quote_id: &Uuid) -> Result<Vec<PublicKey>, Self::Err>;
106    /// Get [`Proofs`] state
107    async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
108    /// Get [`Proofs`] state
109    async fn update_proofs_states(
110        &self,
111        ys: &[PublicKey],
112        proofs_state: State,
113    ) -> Result<Vec<Option<State>>, Self::Err>;
114    /// Get [`Proofs`] by state
115    async fn get_proofs_by_keyset_id(
116        &self,
117        keyset_id: &Id,
118    ) -> Result<(Proofs, Vec<Option<State>>), Self::Err>;
119
120    /// Add [`BlindSignature`]
121    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    /// Get [`BlindSignature`]s
128    async fn get_blind_signatures(
129        &self,
130        blinded_messages: &[PublicKey],
131    ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
132    /// Get [`BlindSignature`]s for keyset_id
133    async fn get_blind_signatures_for_keyset(
134        &self,
135        keyset_id: &Id,
136    ) -> Result<Vec<BlindSignature>, Self::Err>;
137    /// Get [`BlindSignature`]s for quote
138    async fn get_blind_signatures_for_quote(
139        &self,
140        quote_id: &Uuid,
141    ) -> Result<Vec<BlindSignature>, Self::Err>;
142
143    /// Set [`MintInfo`]
144    async fn set_mint_info(&self, mint_info: MintInfo) -> Result<(), Self::Err>;
145    /// Get [`MintInfo`]
146    async fn get_mint_info(&self) -> Result<MintInfo, Self::Err>;
147
148    /// Set [`QuoteTTL`]
149    async fn set_quote_ttl(&self, quote_ttl: QuoteTTL) -> Result<(), Self::Err>;
150    /// Get [`QuoteTTL`]
151    async fn get_quote_ttl(&self) -> Result<QuoteTTL, Self::Err>;
152}