mod.rs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. mod memory;
  2. use async_trait::async_trait;
  3. use cashu::nuts::nut02::mint::KeySet;
  4. use cashu::nuts::{CurrencyUnit, Id, Proof};
  5. use cashu::secret::Secret;
  6. use cashu::types::{MeltQuote, MintQuote};
  7. use thiserror::Error;
  8. #[derive(Debug, Error)]
  9. pub enum Error {
  10. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  11. #[error("`{0}`")]
  12. Redb(#[from] redb::Error),
  13. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  14. #[error("`{0}`")]
  15. Database(#[from] redb::DatabaseError),
  16. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  17. #[error("`{0}`")]
  18. Transaction(#[from] redb::TransactionError),
  19. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  20. #[error("`{0}`")]
  21. Commit(#[from] redb::CommitError),
  22. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  23. #[error("`{0}`")]
  24. Table(#[from] redb::TableError),
  25. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  26. #[error("`{0}`")]
  27. Storage(#[from] redb::StorageError),
  28. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  29. #[error("`{0}`")]
  30. Serde(#[from] serde_json::Error),
  31. }
  32. #[async_trait(?Send)]
  33. pub trait LocalStore {
  34. async fn add_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Error>;
  35. async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Error>;
  36. async fn add_mint_quote(&self, quote: MintQuote) -> Result<(), Error>;
  37. async fn get_mint_quote(&self, quote_id: &str) -> Result<Option<MintQuote>, Error>;
  38. async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Error>;
  39. async fn add_melt_quote(&self, quote: MeltQuote) -> Result<(), Error>;
  40. async fn get_melt_quote(&self, quote_id: &str) -> Result<Option<MeltQuote>, Error>;
  41. async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Error>;
  42. async fn add_keyset(&self, keyset: KeySet) -> Result<(), Error>;
  43. async fn get_keyset(&self, id: &Id) -> Result<Option<KeySet>, Error>;
  44. async fn add_spent_proof(&self, secret: Secret, proof: Proof) -> Result<(), Error>;
  45. async fn get_spent_proof(&self, secret: &Secret) -> Result<Option<Proof>, Error>;
  46. async fn add_pending_proof(&self, secret: Secret, proof: Proof) -> Result<(), Error>;
  47. async fn get_pending_proof(&self, secret: &Secret) -> Result<Option<Proof>, Error>;
  48. async fn remove_pending_proof(&self, secret: &Secret) -> Result<(), Error>;
  49. }