pub mod memory; #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))] pub mod redb_store; use std::collections::HashMap; use async_trait::async_trait; use cashu::nuts::nut02::mint::KeySet; use cashu::nuts::{CurrencyUnit, Id, MintInfo, Proof, PublicKey}; use cashu::secret::Secret; use cashu::types::{MeltQuote, MintQuote}; pub use memory::MemoryLocalStore; #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))] pub use redb_store::RedbLocalStore; use thiserror::Error; #[derive(Debug, Error)] pub enum Error { #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))] #[error("`{0}`")] Redb(#[from] redb::Error), #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))] #[error("`{0}`")] Database(#[from] redb::DatabaseError), #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))] #[error("`{0}`")] Transaction(#[from] redb::TransactionError), #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))] #[error("`{0}`")] Commit(#[from] redb::CommitError), #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))] #[error("`{0}`")] Table(#[from] redb::TableError), #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))] #[error("`{0}`")] Storage(#[from] redb::StorageError), #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))] #[error("`{0}`")] Serde(#[from] serde_json::Error), #[error("Unknown Mint Info")] UnknownMintInfo, #[error("`{0}`")] Cashu(#[from] cashu::error::Error), #[error("`{0}`")] CashuNut02(#[from] cashu::nuts::nut02::Error), #[error("`{0}`")] Secret(#[from] cashu::secret::Error), } #[async_trait] pub trait LocalStore { async fn set_mint_info(&self, mint_info: &MintInfo) -> Result<(), Error>; async fn get_mint_info(&self) -> Result; async fn add_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Error>; async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result, Error>; async fn get_active_keysets(&self) -> Result, Error>; async fn add_mint_quote(&self, quote: MintQuote) -> Result<(), Error>; async fn get_mint_quote(&self, quote_id: &str) -> Result, Error>; async fn get_mint_quotes(&self) -> Result, 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, Error>; async fn get_melt_quotes(&self) -> Result, Error>; async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Error>; async fn add_keyset(&self, keyset: KeySet) -> Result<(), Error>; async fn get_keyset(&self, id: &Id) -> Result, Error>; async fn get_keysets(&self) -> Result, Error>; async fn add_spent_proof(&self, proof: Proof) -> Result<(), Error>; async fn get_spent_proof_by_secret(&self, secret: &Secret) -> Result, Error>; async fn get_spent_proof_by_y(&self, y: &PublicKey) -> Result, Error>; async fn add_pending_proof(&self, proof: Proof) -> Result<(), Error>; async fn get_pending_proof_by_secret(&self, secret: &Secret) -> Result, Error>; async fn get_pending_proof_by_y(&self, y: &PublicKey) -> Result, Error>; async fn remove_pending_proof(&self, secret: &Secret) -> Result<(), Error>; }