Skip to content

Commit

Permalink
wrap wallet in a mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
ec2 committed Sep 20, 2024
1 parent 01eb57a commit f75831a
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 65 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ multicore = ["zcash_proofs/multicore", "zcash_primitives/multicore", "zcash_clie
# WASM specific features
wasm = ["console_error_panic_hook", "dep:tracing-web", "zcash_client_backend/wasm-bindgen"]
wasm-parallel = ["wasm", "wasm-bindgen-rayon", "multicore"]
native = ["dep:tokio", "tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots"]
native = ["tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots", "tokio/macros", "tokio/rt", "tokio/rt-multi-thread"]
sqlite-db = ["dep:zcash_client_sqlite"]
console_error_panic_hook = ["dep:console_error_panic_hook"]
no-bundler = ["wasm-bindgen-rayon?/no-bundler"]
Expand Down Expand Up @@ -90,7 +90,7 @@ tonic = { version = "0.12", default-features = false, features = [


# Used in Native tests
tokio = { version = "1.0", features = ["rt", "macros", "rt-multi-thread"], optional = true }
tokio = { version = "1.0" }
zcash_client_sqlite = { git = "https://github.com/ChainSafe/librustzcash", rev = "0fdd2fbb992a6f84eba45f488ee74a75d08d449b", default-features = false, features = ["unstable", "orchard"], optional = true }

getrandom = { version = "0.2", features = ["js"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/message-board-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ async fn main() {

tracing::info!("Syncing complete :)");

let summary = w.get_wallet_summary().unwrap();
let summary = w.get_wallet_summary().await.unwrap();
tracing::info!("Wallet summary: {:?}", summary);
}
4 changes: 2 additions & 2 deletions examples/simple-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async fn main() {

tracing::info!("Syncing complete :)");

let summary = w.get_wallet_summary().unwrap();
let summary = w.get_wallet_summary().await.unwrap();
tracing::info!("Wallet summary: {:?}", summary);

tracing::info!("Proposing a transaction");
Expand All @@ -95,6 +95,6 @@ async fn main() {
w.transfer(SEED, 0, addr.unwrap(), 1000).await.unwrap();
tracing::info!("Transaction proposed");

let summary = w.get_wallet_summary().unwrap();
let summary = w.get_wallet_summary().await.unwrap();
tracing::info!("Wallet summary: {:?}", summary);
}
12 changes: 6 additions & 6 deletions src/bindgen/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl WebWallet {
}
}

pub fn client(&mut self) -> &mut CompactTxStreamerClient<tonic_web_wasm_client::Client> {
self.inner.client()
pub fn client(&self) -> CompactTxStreamerClient<tonic_web_wasm_client::Client> {
self.inner.client.clone()
}

pub fn inner_mut(&mut self) -> &mut MemoryWallet<tonic_web_wasm_client::Client> {
Expand Down Expand Up @@ -109,8 +109,8 @@ impl WebWallet {
self.inner.import_ufvk(&ufvk, birthday_height).await
}

pub fn suggest_scan_ranges(&self) -> Result<Vec<BlockRange>, Error> {
self.inner.suggest_scan_ranges()
pub async fn suggest_scan_ranges(&self) -> Result<Vec<BlockRange>, Error> {
self.inner.suggest_scan_ranges().await
}

/// Synchronize the wallet with the blockchain up to the tip
Expand All @@ -135,8 +135,8 @@ impl WebWallet {
self.inner.sync2().await
}

pub fn get_wallet_summary(&self) -> Result<Option<WalletSummary>, Error> {
Ok(self.inner.get_wallet_summary()?.map(Into::into))
pub async fn get_wallet_summary(&self) -> Result<Option<WalletSummary>, Error> {
Ok(self.inner.get_wallet_summary().await?.map(Into::into))
}

///
Expand Down
Loading

0 comments on commit f75831a

Please sign in to comment.