mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-05 21:26:13 +01:00
feat: get_pubkeys
This commit is contained in:
@@ -94,6 +94,10 @@ impl LocalStore for MemoryLocalStore {
|
||||
Ok(self.mint_quotes.lock().await.get(quote_id).cloned())
|
||||
}
|
||||
|
||||
async fn get_mint_quotes(&self) -> Result<Vec<MintQuote>, Error> {
|
||||
Ok(self.mint_quotes.lock().await.values().cloned().collect())
|
||||
}
|
||||
|
||||
async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Error> {
|
||||
self.mint_quotes.lock().await.remove(quote_id);
|
||||
|
||||
@@ -112,6 +116,10 @@ impl LocalStore for MemoryLocalStore {
|
||||
Ok(self.melt_quotes.lock().await.get(quote_id).cloned())
|
||||
}
|
||||
|
||||
async fn get_melt_quotes(&self) -> Result<Vec<MeltQuote>, Error> {
|
||||
Ok(self.melt_quotes.lock().await.values().cloned().collect())
|
||||
}
|
||||
|
||||
async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Error> {
|
||||
self.melt_quotes.lock().await.remove(quote_id);
|
||||
|
||||
|
||||
@@ -47,10 +47,12 @@ pub trait LocalStore {
|
||||
|
||||
async fn add_mint_quote(&self, quote: MintQuote) -> Result<(), Error>;
|
||||
async fn get_mint_quote(&self, quote_id: &str) -> Result<Option<MintQuote>, Error>;
|
||||
async fn get_mint_quotes(&self) -> Result<Vec<MintQuote>, Error>;
|
||||
async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Error>;
|
||||
|
||||
async fn add_melt_quote(&self, quote: MeltQuote) -> Result<(), Error>;
|
||||
async fn get_melt_quote(&self, quote_id: &str) -> Result<Option<MeltQuote>, Error>;
|
||||
async fn get_melt_quotes(&self) -> Result<Vec<MeltQuote>, Error>;
|
||||
async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Error>;
|
||||
|
||||
async fn add_keyset(&self, keyset: KeySet) -> Result<(), Error>;
|
||||
|
||||
@@ -156,6 +156,22 @@ impl LocalStore for RedbLocalStore {
|
||||
Ok(quote.map(|q| serde_json::from_str(q.value()).unwrap()))
|
||||
}
|
||||
|
||||
async fn get_mint_quotes(&self) -> Result<Vec<MintQuote>, Error> {
|
||||
let db = self.db.lock().await;
|
||||
let read_txn = db.begin_read()?;
|
||||
let table = read_txn.open_table(MINT_QUOTES_TABLE)?;
|
||||
|
||||
let mut quotes = Vec::new();
|
||||
|
||||
for (_id, quote) in (table.iter()?).flatten() {
|
||||
let quote = serde_json::from_str(quote.value())?;
|
||||
|
||||
quotes.push(quote)
|
||||
}
|
||||
|
||||
Ok(quotes)
|
||||
}
|
||||
|
||||
async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Error> {
|
||||
let db = self.db.lock().await;
|
||||
|
||||
@@ -194,6 +210,22 @@ impl LocalStore for RedbLocalStore {
|
||||
Ok(quote.map(|q| serde_json::from_str(q.value()).unwrap()))
|
||||
}
|
||||
|
||||
async fn get_melt_quotes(&self) -> Result<Vec<MeltQuote>, Error> {
|
||||
let db = self.db.lock().await;
|
||||
let read_txn = db.begin_read()?;
|
||||
let table = read_txn.open_table(MELT_QUOTES_TABLE)?;
|
||||
|
||||
let mut quotes = Vec::new();
|
||||
|
||||
for (_id, quote) in (table.iter()?).flatten() {
|
||||
let quote = serde_json::from_str(quote.value())?;
|
||||
|
||||
quotes.push(quote)
|
||||
}
|
||||
|
||||
Ok(quotes)
|
||||
}
|
||||
|
||||
async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Error> {
|
||||
let db = self.db.lock().await;
|
||||
|
||||
|
||||
@@ -19,10 +19,9 @@ use tracing::{debug, info};
|
||||
use crate::Mnemonic;
|
||||
|
||||
mod localstore;
|
||||
use localstore::LocalStore;
|
||||
pub use localstore::MemoryLocalStore;
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
|
||||
pub use localstore::RedbLocalStore;
|
||||
pub use localstore::{LocalStore, MemoryLocalStore};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
@@ -58,7 +57,7 @@ pub struct Mint<L: LocalStore> {
|
||||
// pub pubkey: PublicKey
|
||||
mnemonic: Mnemonic,
|
||||
pub fee_reserve: FeeReserve,
|
||||
localstore: L,
|
||||
pub localstore: L,
|
||||
}
|
||||
|
||||
impl<L: LocalStore> Mint<L> {
|
||||
@@ -142,6 +141,16 @@ impl<L: LocalStore> Mint<L> {
|
||||
}))
|
||||
}
|
||||
|
||||
/// Retrieve the public keys of the active keyset for distribution to
|
||||
/// wallet clients
|
||||
pub async fn pubkeys(&self) -> Result<KeysResponse, Error> {
|
||||
let keysets = self.localstore.get_keysets().await?;
|
||||
|
||||
Ok(KeysResponse {
|
||||
keysets: keysets.into_iter().map(|k| k.into()).collect(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Return a list of all supported keysets
|
||||
pub async fn keysets(&self) -> Result<KeysetResponse, Error> {
|
||||
let keysets = self.localstore.get_keysets().await?;
|
||||
|
||||
Reference in New Issue
Block a user