diff --git a/justfile b/justfile index 432eb12..ad95223 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,9 @@ default: just --list + + + build: wasm-pack build -t web --release --out-dir ./packages/webz-core -Z --no-default-features --features="wasm-parallel,no-bundler" build-std="panic_abort,std" @@ -10,5 +13,13 @@ test-web: test-native: cargo test -r -- --nocapture +alias c := check + check: cargo check + +alias cw := check-wasm + +check-wasm: + cargo check --no-default-features --features="wasm-parallel,no-bundler" --target=wasm32-unknown-unknown + diff --git a/src/wallet.rs b/src/wallet.rs index 6a5f4e4..4b56572 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -1,16 +1,16 @@ use std::num::NonZeroU32; use bip0039::{English, Mnemonic}; -use futures_util::{StreamExt, TryStreamExt}; +use futures_util::{Stream, StreamExt, TryStreamExt}; use nonempty::NonEmpty; use secrecy::{ExposeSecret, SecretVec, Zeroize}; use tonic::{ client::GrpcService, codegen::{Body, Bytes, StdError}, + Status, }; use zcash_address::ZcashAddress; -use zcash_client_backend::data_api::scanning::ScanRange; use zcash_client_backend::data_api::wallet::{ create_proposed_transactions, input_selection::GreedyInputSelector, propose_transfer, }; @@ -26,6 +26,7 @@ use zcash_client_backend::scanning::{scan_block, Nullifiers, ScanningKeys}; use zcash_client_backend::wallet::OvkPolicy; use zcash_client_backend::zip321::{Payment, TransactionRequest}; use zcash_client_backend::ShieldedProtocol; +use zcash_client_backend::{data_api::scanning::ScanRange, proto::compact_formats::CompactBlock}; use zcash_client_memory::MemoryWalletDb; use zcash_keys::keys::UnifiedSpendingKey; use zcash_primitives::consensus::{self, BlockHeight, Network}; @@ -200,6 +201,27 @@ where Ok(()) } + async fn fetch_blocks( + &mut self, + start: u32, + end: u32, + ) -> Result>, Error> { + let range = service::BlockRange { + start: Some(service::BlockId { + height: start.into(), + ..Default::default() + }), + end: Some(service::BlockId { + height: end.into(), + ..Default::default() + }), + }; + + let blocks = self.client.get_block_range(range).await?.into_inner(); + + Ok(blocks) + } + /// Download and process all blocks in the given range async fn fetch_and_scan_range(&mut self, start: u32, end: u32) -> Result<(), Error> { // get the chainstate prior to the range @@ -222,24 +244,11 @@ where self.db.get_orchard_nullifiers(NullifierQuery::Unspent)?, ); - let range = service::BlockRange { - start: Some(service::BlockId { - height: start.into(), - ..Default::default() - }), - end: Some(service::BlockId { - height: (end - 1).into(), - ..Default::default() - }), - }; - tracing::info!("Scanning block range: {:?} to {:?}", start, end); let scanned_blocks = self - .client - .get_block_range(range) + .fetch_blocks(start, end) .await? - .into_inner() .map(|compact_block| { scan_block( &self.network, @@ -401,7 +410,7 @@ where }) .unwrap(); - tracing::info!("Transaction hex: 0x{}", hex::encode(&raw_tx.data)); + // tracing::info!("Transaction hex: 0x{}", hex::encode(&raw_tx.data)); let response = self.client.send_transaction(raw_tx).await?.into_inner(); diff --git a/tests/tests.rs b/tests/tests.rs index 0e027d3..54aa372 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -19,7 +19,6 @@ static INIT: Once = Once::new(); // Required to initialize the logger and panic hooks only once use std::{num::NonZeroU32, sync::Once}; pub fn initialize() { - console_log!("Calling initialize"); INIT.call_once(|| { webz_core::init::start(); }); @@ -29,7 +28,8 @@ async fn init_threadpool(threads: usize) -> wasm_bindgen_futures::JsFuture { console_log!("Initializing thread pool with {} threads", threads); wasm_bindgen_futures::JsFuture::from(wasm_bindgen_rayon::init_thread_pool(threads)) } - +fn is_sync() {} +fn is_send() {} #[wasm_bindgen_test] async fn test_get_and_scan_range() { initialize(); @@ -38,11 +38,14 @@ async fn test_get_and_scan_range() { init_threadpool(THREADS).await; let mut w = WebWallet::new("test", "https://zcash-testnet.chainsafe.dev", 1).unwrap(); - + is_sync::(); + is_send::(); let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap(); tracing::info!("Created account with id: {}", id); tracing::info!("Syncing wallet"); + // Note to self: js_sys::Function is NOT send or sync + // TODO: Find a better way to do this... Perhaps passing a Stream or something instead? w.sync(&js_sys::Function::new_with_args( "scanned_to, tip", "console.log('Scanned: ', scanned_to, '/', tip)",