mod.rs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. pub mod memory;
  2. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  3. pub mod redb_store;
  4. use std::collections::HashMap;
  5. use async_trait::async_trait;
  6. use cashu::nuts::nut02::mint::KeySet;
  7. use cashu::nuts::{CurrencyUnit, Id, MintInfo, Proof, PublicKey};
  8. use cashu::secret::Secret;
  9. use cashu::types::{MeltQuote, MintQuote};
  10. pub use memory::MemoryLocalStore;
  11. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  12. pub use redb_store::RedbLocalStore;
  13. use thiserror::Error;
  14. #[derive(Debug, Error)]
  15. pub enum Error {
  16. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  17. #[error("`{0}`")]
  18. Redb(#[from] redb::Error),
  19. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  20. #[error("`{0}`")]
  21. Database(#[from] redb::DatabaseError),
  22. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  23. #[error("`{0}`")]
  24. Transaction(#[from] redb::TransactionError),
  25. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  26. #[error("`{0}`")]
  27. Commit(#[from] redb::CommitError),
  28. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  29. #[error("`{0}`")]
  30. Table(#[from] redb::TableError),
  31. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  32. #[error("`{0}`")]
  33. Storage(#[from] redb::StorageError),
  34. #[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
  35. #[error("`{0}`")]
  36. Serde(#[from] serde_json::Error),
  37. #[error("Unknown Mint Info")]
  38. UnknownMintInfo,
  39. #[error("`{0}`")]
  40. Cashu(#[from] cashu::error::Error),
  41. #[error("`{0}`")]
  42. CashuNut02(#[from] cashu::nuts::nut02::Error),
  43. #[error("`{0}`")]
  44. Secret(#[from] cashu::secret::Error),
  45. }
  46. #[async_trait]
  47. pub trait LocalStore {
  48. async fn set_mint_info(&self, mint_info: &MintInfo) -> Result<(), Error>;
  49. async fn get_mint_info(&self) -> Result<MintInfo, Error>;
  50. async fn add_active_keyset(&self, unit: CurrencyUnit, id: Id) -> Result<(), Error>;
  51. async fn get_active_keyset_id(&self, unit: &CurrencyUnit) -> Result<Option<Id>, Error>;
  52. async fn get_active_keysets(&self) -> Result<HashMap<CurrencyUnit, Id>, Error>;
  53. async fn add_mint_quote(&self, quote: MintQuote) -> Result<(), Error>;
  54. async fn get_mint_quote(&self, quote_id: &str) -> Result<Option<MintQuote>, Error>;
  55. async fn get_mint_quotes(&self) -> Result<Vec<MintQuote>, Error>;
  56. async fn remove_mint_quote(&self, quote_id: &str) -> Result<(), Error>;
  57. async fn add_melt_quote(&self, quote: MeltQuote) -> Result<(), Error>;
  58. async fn get_melt_quote(&self, quote_id: &str) -> Result<Option<MeltQuote>, Error>;
  59. async fn get_melt_quotes(&self) -> Result<Vec<MeltQuote>, Error>;
  60. async fn remove_melt_quote(&self, quote_id: &str) -> Result<(), Error>;
  61. async fn add_keyset(&self, keyset: KeySet) -> Result<(), Error>;
  62. async fn get_keyset(&self, id: &Id) -> Result<Option<KeySet>, Error>;
  63. async fn get_keysets(&self) -> Result<Vec<KeySet>, Error>;
  64. async fn add_spent_proof(&self, proof: Proof) -> Result<(), Error>;
  65. async fn get_spent_proof_by_secret(&self, secret: &Secret) -> Result<Option<Proof>, Error>;
  66. async fn get_spent_proof_by_y(&self, y: &PublicKey) -> Result<Option<Proof>, Error>;
  67. async fn add_pending_proof(&self, proof: Proof) -> Result<(), Error>;
  68. async fn get_pending_proof_by_secret(&self, secret: &Secret) -> Result<Option<Proof>, Error>;
  69. async fn get_pending_proof_by_y(&self, y: &PublicKey) -> Result<Option<Proof>, Error>;
  70. async fn remove_pending_proof(&self, secret: &Secret) -> Result<(), Error>;
  71. }