Sfoglia il codice sorgente

refactor: redb as feature

thesimplekid 1 anno fa
parent
commit
a4b409ee87

+ 2 - 1
crates/cashu-sdk/Cargo.toml

@@ -17,6 +17,7 @@ gloo = ["dep:gloo"]
 all-nuts = ["nut07", "nut08"]
 nut07 = ["cashu/nut07"]
 nut08 = ["cashu/nut08"]
+redb = ["dep:redb"]
 
 
 [dependencies]
@@ -35,7 +36,7 @@ gloo = { version = "0.10.0", optional = true, features = ["net"] }
 [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
 tokio = { workspace = true, features = ["rt-multi-thread", "time", "macros", "sync"] }
 minreq = { version = "2.7.0", optional = true, features = ["json-using-serde", "https"] }
-redb = "1.4.0"
+redb = { version = "1.4.0", optional = true }
 
 [target.'cfg(target_arch = "wasm32")'.dependencies]
 tokio = { workspace = true, features = ["rt", "macros", "sync", "time"] }

+ 1 - 1
crates/cashu-sdk/src/lib.rs

@@ -20,7 +20,7 @@ pub mod wallet;
 
 pub use bip39::Mnemonic;
 pub use cashu::{self, *};
-#[cfg(not(target_arch = "wasm32"))]
+#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
 pub use localstore::redb_store::RedbLocalStore;
 
 #[cfg(feature = "blocking")]

+ 8 - 1
crates/cashu-sdk/src/localstore/mod.rs

@@ -1,6 +1,6 @@
 mod memory;
 
-#[cfg(not(target_arch = "wasm32"))]
+#[cfg(all(not(target_arch = "wasm32"), feature = "redb"))]
 pub mod redb_store;
 
 use std::collections::HashMap;
@@ -13,18 +13,25 @@ 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),
 }