Skip to content

Commit f75831a

Browse files
committed
wrap wallet in a mutex
1 parent 01eb57a commit f75831a

File tree

7 files changed

+86
-65
lines changed

7 files changed

+86
-65
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ multicore = ["zcash_proofs/multicore", "zcash_primitives/multicore", "zcash_clie
3838
# WASM specific features
3939
wasm = ["console_error_panic_hook", "dep:tracing-web", "zcash_client_backend/wasm-bindgen"]
4040
wasm-parallel = ["wasm", "wasm-bindgen-rayon", "multicore"]
41-
native = ["dep:tokio", "tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots"]
41+
native = ["tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots", "tokio/macros", "tokio/rt", "tokio/rt-multi-thread"]
4242
sqlite-db = ["dep:zcash_client_sqlite"]
4343
console_error_panic_hook = ["dep:console_error_panic_hook"]
4444
no-bundler = ["wasm-bindgen-rayon?/no-bundler"]
@@ -90,7 +90,7 @@ tonic = { version = "0.12", default-features = false, features = [
9090

9191

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

9696
getrandom = { version = "0.2", features = ["js"] }

examples/message-board-sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ async fn main() {
8080

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

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

examples/simple-sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async fn main() {
8686

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

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

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

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

src/bindgen/wallet.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl WebWallet {
4747
}
4848
}
4949

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

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

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

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

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

142142
///

0 commit comments

Comments
 (0)