Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap wallet in a mutex #23

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
402 changes: 374 additions & 28 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 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 @@ -78,7 +78,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 All @@ -99,12 +99,16 @@ wasm_thread = { git = "https://github.com/WilsonGramer/wasm_thread.git", rev = "

wasm_sync = "0.1.2"
http = { version = "1.1.0", default-features = false }
serde = { version = "1", features = ["derive"], default-features = false }

postcard = { version = "1.0.10", features = ["alloc"] }
ec2 marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
wasm-bindgen-test = "0.3.43"
tempfile = "3.12"
# Used in Native tests
tokio = { version = "1.0", features = ["rt", "macros"] }
byte-unit = { version = "5.1.4", features = ["byte"] }


[patch.crates-io]
Expand Down
18 changes: 16 additions & 2 deletions examples/message-board-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn main() {
.unwrap();

let ufvk = UnifiedFullViewingKey::from_sapling_extended_full_viewing_key(s).unwrap();
let id = w.import_ufvk(&ufvk, Some(2477329)).await.unwrap();
let id = w.import_ufvk(&ufvk, Some(2277329)).await.unwrap();
tracing::info!("Created account with id: {}", id);

#[cfg(not(feature = "sync2"))]
Expand All @@ -80,6 +80,20 @@ 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);

#[cfg(not(feature = "sqlite-db"))]
{
tracing::info!("Serializing wallet");
let serialized_wallet = w.to_vec_postcard().await;
let byte_count = byte_unit::Byte::from_u64(serialized_wallet.len() as u64);

tracing::info!(
"Wallet serialized: {}",
byte_count
.get_adjusted_unit(byte_unit::Unit::MB)
.to_string()
)
}
}
18 changes: 16 additions & 2 deletions examples/simple-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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 @@ -93,6 +93,20 @@ 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);

#[cfg(not(feature = "sqlite-db"))]
{
tracing::info!("Serializing wallet");
let serialized_wallet = w.to_vec_postcard().await;
let byte_count = byte_unit::Byte::from_u64(serialized_wallet.len() as u64);

tracing::info!(
"Wallet serialized: {}",
byte_count
.get_adjusted_unit(byte_unit::Unit::MB)
.to_string()
)
}
}
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
Loading