diff --git a/crates/cashu-sdk/Cargo.toml b/crates/cashu-sdk/Cargo.toml index 446af03e..0bce5376 100644 --- a/crates/cashu-sdk/Cargo.toml +++ b/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"] } diff --git a/crates/cashu-sdk/src/lib.rs b/crates/cashu-sdk/src/lib.rs index e8f80948..77678f67 100644 --- a/crates/cashu-sdk/src/lib.rs +++ b/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")] diff --git a/crates/cashu-sdk/src/localstore/mod.rs b/crates/cashu-sdk/src/localstore/mod.rs index 08f5af5f..8458fc70 100644 --- a/crates/cashu-sdk/src/localstore/mod.rs +++ b/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), }