diff --git a/Cargo.lock b/Cargo.lock index d9a0144..f84c00a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3850,8 +3850,7 @@ dependencies = [ [[package]] name = "pepper-sync" version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3b3c82be25cab357957856b2eacef69a51530616240f6fd5ba21cf9896b3bf" +source = "git+https://github.com/zingolabs/zingolib.git?rev=a9b66315b853c9084008d51e149d2572954aba8e#a9b66315b853c9084008d51e149d2572954aba8e" dependencies = [ "bip32 0.6.0-pre.1", "byteorder", @@ -4803,6 +4802,40 @@ dependencies = [ "time", ] +[[package]] +name = "rust-embed" +version = "6.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a36224c3276f8c4ebc8c20f158eca7ca4359c8db89991c4925132aaaf6702661" +dependencies = [ + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "6.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b94b81e5b2c284684141a2fb9e2a31be90638caf040bf9afbc5a0416afe1ac" +dependencies = [ + "proc-macro2", + "quote", + "rust-embed-utils", + "syn 2.0.101", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "7.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d38ff6bf570dc3bb7100fce9f7b60c33fa71d80e88da3f2580df4ff2bdded74" +dependencies = [ + "sha2 0.10.9", + "walkdir", +] + [[package]] name = "rust_decimal" version = "1.37.1" @@ -8370,13 +8403,13 @@ dependencies = [ "zcash_primitives 0.20.1", "zingolabs-zewif", "zingolib", + "zip32 0.2.0", ] [[package]] name = "zingo-memo" version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c2c655174c0bff41505d5c0d45b0fea09d458e62324206b27fb2888f92a6293" +source = "git+https://github.com/zingolabs/zingolib.git?rev=a9b66315b853c9084008d51e149d2572954aba8e#a9b66315b853c9084008d51e149d2572954aba8e" dependencies = [ "zcash_address 0.7.1", "zcash_client_backend 0.18.0", @@ -8388,8 +8421,7 @@ dependencies = [ [[package]] name = "zingo-netutils" version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a19585976d02b6ccb84e7a51433ce1cc7e76d9061b993f58598fb73a1d07a27" +source = "git+https://github.com/zingolabs/zingolib.git?rev=a9b66315b853c9084008d51e149d2572954aba8e#a9b66315b853c9084008d51e149d2572954aba8e" dependencies = [ "http", "http-body", @@ -8409,8 +8441,7 @@ dependencies = [ [[package]] name = "zingo-price" version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11878e7124006314820d39666fd417e0f269c6de7e9402e6e186c6f389512cbf" +source = "git+https://github.com/zingolabs/zingolib.git?rev=a9b66315b853c9084008d51e149d2572954aba8e#a9b66315b853c9084008d51e149d2572954aba8e" dependencies = [ "byteorder", "reqwest", @@ -8426,8 +8457,7 @@ dependencies = [ [[package]] name = "zingo-status" version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66709d62607750781993ae49bebd96b3e5823fda5b46adca5dcf618dfdc3dc17" +source = "git+https://github.com/zingolabs/zingolib.git?rev=a9b66315b853c9084008d51e149d2572954aba8e#a9b66315b853c9084008d51e149d2572954aba8e" dependencies = [ "byteorder", "zcash_primitives 0.22.0", @@ -8451,8 +8481,7 @@ dependencies = [ [[package]] name = "zingolib" version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a9668c4a4884e0f5408e553f424db5c28ba4b6f03a9a2e998f1677bba308e9c" +source = "git+https://github.com/zingolabs/zingolib.git?rev=a9b66315b853c9084008d51e149d2572954aba8e#a9b66315b853c9084008d51e149d2572954aba8e" dependencies = [ "append-only-vec", "bech32 0.11.0", @@ -8462,7 +8491,7 @@ dependencies = [ "byteorder", "bytes", "chrono", - "dirs 5.0.1", + "dirs 6.0.0", "futures", "hex", "http", @@ -8479,6 +8508,7 @@ dependencies = [ "prost", "rand 0.8.5", "ring 0.17.14", + "rust-embed", "rustls 0.23.27", "sapling-crypto 0.5.0", "secp256k1 0.29.1", diff --git a/Cargo.toml b/Cargo.toml index 705b77a..6276415 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,5 +34,5 @@ orchard_new = "0.10.1" orchard_old = "=0.3.0" sapling = { version = "0.3", default-features = false } zewif = { version = "0.0.2", package = "zingolabs-zewif" } -zingolib = { version = "0.0.1" } -pepper-sync = { version = "0.0.1" } +zingolib = { git = "https://github.com/zingolabs/zingolib.git", rev = "a9b66315b853c9084008d51e149d2572954aba8e" } +pepper-sync = { git = "https://github.com/zingolabs/zingolib.git", rev = "a9b66315b853c9084008d51e149d2572954aba8e", package = "pepper-sync" } diff --git a/zexcavator-tui/Cargo.toml b/zexcavator-tui/Cargo.toml index e1ae911..d80c28d 100644 --- a/zexcavator-tui/Cargo.toml +++ b/zexcavator-tui/Cargo.toml @@ -53,3 +53,4 @@ prost = { workspace = true } incrementalmerkletree = { workspace = true } orchard_old = { package = "orchard", version = "=0.3.0" } orchard_new = { package = "orchard", version = "0.10.1" } +zip32 = "0.2.0" diff --git a/zexcavator-tui/src/main.rs b/zexcavator-tui/src/main.rs index f3980c5..6748a8e 100644 --- a/zexcavator-tui/src/main.rs +++ b/zexcavator-tui/src/main.rs @@ -16,7 +16,7 @@ mod components; mod views; mod walletparsers; use app::model::Model; -use zingolib::lightclient::PoolBalances; +use zingolib::wallet::balance::AccountBalance; mod constants; #[derive(Debug, PartialEq)] @@ -39,7 +39,7 @@ pub enum Msg { FromPathSubmit, GoToResult, InitializeLightClient, - BalanceReady(PoolBalances), + BalanceReady(AccountBalance), FetchBalance, None, } diff --git a/zexcavator-tui/src/views/export.rs b/zexcavator-tui/src/views/export.rs index 832434d..c6a3934 100644 --- a/zexcavator-tui/src/views/export.rs +++ b/zexcavator-tui/src/views/export.rs @@ -2,9 +2,11 @@ pub mod send; pub mod zewif; pub mod zingolib; +use std::num::NonZero; use std::sync::Arc; -use ::zingolib::lightclient::{LightClient, PoolBalances}; +use ::zingolib::lightclient::LightClient; +use ::zingolib::wallet::balance::AccountBalance; use tokio::sync::RwLock; use tuirealm::command::CmdResult; use tuirealm::ratatui::layout::{Constraint, Direction, Layout}; @@ -46,7 +48,7 @@ impl MenuOptions for ExportOptions { #[derive(Debug, Clone)] pub struct ExportView { pub light_client: Arc>>, - pub balance: Arc>>, + pub balance: Arc>>, pub menu: Menu, } @@ -59,10 +61,16 @@ impl ExportView { } } - pub async fn load_balance(&self) -> Option { + pub async fn load_balance(&self) -> Option { let mut client_guard = self.light_client.write().await; let client = client_guard.as_mut()?; - let b = client.do_balance().await; + let b = client + .wallet + .lock() + .await + .account_balance(zip32::AccountId::try_from(0).unwrap()) + .await + .unwrap(); self.balance.try_write().unwrap().replace(b.clone()); drop(client_guard); Some(b) @@ -84,10 +92,12 @@ impl MockComponent for ExportView { balance = balance_guard.clone().unwrap(); } - let total_balance = balance.confirmed_transparent_balance.unwrap_or(0) - + balance.verified_sapling_balance.unwrap_or(0) - + balance.verified_orchard_balance.unwrap_or(0); - let text = format!("Total ZEC found: {:}", total_balance); + let final_balance = balance.total_transparent_balance.unwrap() + + balance.total_sapling_balance.unwrap() + + balance.total_orchard_balance.unwrap(); + let balance_in_zec = final_balance.unwrap() / NonZero::new(10u64.pow(8)).unwrap(); + + let text = format!("Total ZEC found: {:}", balance_in_zec.into_u64()); let para = Paragraph::new(text).block(Block::default().borders(Borders::ALL).title("Balance")); frame.render_widget(para, chunks[0]); diff --git a/zexcavator-tui/src/views/export/send.rs b/zexcavator-tui/src/views/export/send.rs index bf955c6..98aa7f7 100644 --- a/zexcavator-tui/src/views/export/send.rs +++ b/zexcavator-tui/src/views/export/send.rs @@ -5,47 +5,23 @@ use tuirealm::event::{Key, KeyEvent}; use tuirealm::ratatui::layout::{Constraint, Direction, Layout}; use tuirealm::ratatui::widgets::{Block, Borders, Paragraph}; use tuirealm::{Component, Frame, MockComponent, NoUserEvent, State}; -use zingolib::lightclient::{LightClient, PoolBalances}; +use zingolib::lightclient::LightClient; +use zingolib::wallet::balance::AccountBalance; use crate::Msg; use crate::app::model::HasScreenAndQuit; use crate::components::HandleMessage; -// #[derive(Debug, Clone, Copy, PartialEq, Eq)] -// pub enum ExportOptions { -// ZeWIF, -// Send, -// } - -// impl MenuOptions for ExportOptions { -// fn all() -> Vec -// where -// Self: Sized, -// { -// vec![Self::ZeWIF, Self::Send] -// } - -// fn label(&self) -> &'static str { -// match self { -// Self::ZeWIF => "ZeWIF", -// Self::Send => "Send", -// } -// } -// } - #[derive(Debug, Clone)] pub struct ExportSendView { // pub light_client: Arc>>, - pub balance: Arc>>, - // pub menu: Menu, + pub balance: Arc>>, } impl ExportSendView { pub fn new(_light_client: Arc>>) -> Self { Self { - // light_client, balance: Arc::new(RwLock::new(None)), - // menu: Menu::new("Choose an export option"), } } } @@ -64,8 +40,6 @@ impl MockComponent for ExportSendView { Paragraph::new(text).block(Block::default().borders(Borders::ALL).title("Balance")); frame.render_widget(para, chunks[0]); } - - // self.menu.view(frame, chunks[1]); } fn query(&self, _attr: tuirealm::Attribute) -> Option { diff --git a/zexcavator-tui/src/views/export/zewif.rs b/zexcavator-tui/src/views/export/zewif.rs index 9b44716..069372f 100644 --- a/zexcavator-tui/src/views/export/zewif.rs +++ b/zexcavator-tui/src/views/export/zewif.rs @@ -45,7 +45,7 @@ impl ExportZewifView { let export_height = get_latest_block(lc.get_server_uri()).await.unwrap().height as u32; drop(guard); - let (m, _) = mnemonic.unwrap(); + let m = mnemonic.unwrap(); let path = ExportZewifView::export_to_zewif(Some(m), export_height); diff --git a/zexcavator-tui/src/views/export/zingolib.rs b/zexcavator-tui/src/views/export/zingolib.rs index ac1ae2b..0603e3a 100644 --- a/zexcavator-tui/src/views/export/zingolib.rs +++ b/zexcavator-tui/src/views/export/zingolib.rs @@ -39,7 +39,6 @@ impl ExportZingolibView { let network = lw_guard.network; lw_guard .write(&mut buf, &network) - .await .context("failed to serialize LightWallet")?; } diff --git a/zexcavator-tui/src/views/sync.rs b/zexcavator-tui/src/views/sync.rs index a36c088..285f54b 100644 --- a/zexcavator-tui/src/views/sync.rs +++ b/zexcavator-tui/src/views/sync.rs @@ -1,3 +1,4 @@ +use std::num::NonZero; use std::path::PathBuf; use std::str::FromStr; use std::sync::{Arc, Mutex}; @@ -47,6 +48,7 @@ impl SyncView { let seed = wallet_parser.parser.get_wallet_seed(); let bd = wallet_parser.parser.get_birthday(); + let wallet_version = wallet_parser.parser.get_wallet_version(); if let Err(e) = rustls::crypto::ring::default_provider().install_default() { self.log_buffer @@ -64,13 +66,17 @@ impl SyncView { transparent_address_discovery: TransparentAddressDiscovery::recovery(), }, }, + NonZero::new(1).unwrap(), ) .unwrap(); let initial_bh: u32 = bd.try_into().unwrap(); let lw = LightWallet::new( ChainType::Mainnet, - WalletBase::SeedBytes(seed), + WalletBase::Mnemonic { + mnemonic: Mnemonic::from_entropy(seed).unwrap(), + no_of_accounts: NonZero::new(1).unwrap(), + }, initial_bh.into(), WalletSettings { sync_config: SyncConfig { @@ -91,7 +97,12 @@ impl SyncView { self.log_buffer .lock() .unwrap() - .push(format!("Mnemonic: {}", mnemonic.unwrap().0)); + .push(format!("=== WALLET VERSION: {} ===", wallet_version)); + + self.log_buffer + .lock() + .unwrap() + .push(format!("Mnemonic: {}", mnemonic.unwrap().to_string())); self.log_buffer .lock() .unwrap() @@ -135,15 +146,22 @@ impl SyncView { .lock() .unwrap() .push(format!("Sync result: {:?}", sync_result)); - let balances = light_client.do_balance().await; - let final_balance = balances.confirmed_transparent_balance.unwrap() - + balances.verified_sapling_balance.unwrap() - + balances.verified_orchard_balance.unwrap(); - let balance_in_zec = final_balance / 10u64.pow(8); + let balances = light_client + .wallet + .lock() + .await + .account_balance(zip32::AccountId::try_from(0).unwrap()) + .await + .unwrap(); + let final_balance = balances.total_transparent_balance.unwrap() + + balances.total_sapling_balance.unwrap() + + balances.total_orchard_balance.unwrap(); + let balance_in_zec = + final_balance.unwrap() / NonZero::new(10u64.pow(8)).unwrap(); self.log_buffer .lock() .unwrap() - .push(format!("Total ZEC found: {}", balance_in_zec)); + .push(format!("Total ZEC found: {}", balance_in_zec.into_u64())); *self.sync_complete.lock().unwrap() = true; @@ -206,6 +224,7 @@ impl SyncView { transparent_address_discovery: TransparentAddressDiscovery::recovery(), }, }, + NonZero::new(1).unwrap(), ) .unwrap(); @@ -215,7 +234,10 @@ impl SyncView { let lw = LightWallet::new( ChainType::Mainnet, - WalletBase::Mnemonic(mnemonic), + WalletBase::Mnemonic { + mnemonic: mnemonic, + no_of_accounts: NonZero::new(1).unwrap(), + }, birthday.into(), WalletSettings { sync_config: SyncConfig { @@ -270,16 +292,22 @@ impl SyncView { .lock() .unwrap() .push(format!("Sync result: {:?}", sync_result)); - let balances = light_client.do_balance().await; - - let final_balance = balances.confirmed_transparent_balance.unwrap() - + balances.verified_sapling_balance.unwrap() - + balances.verified_orchard_balance.unwrap(); - let balance_in_zec = final_balance / 10u64.pow(8); + let balances = light_client + .wallet + .lock() + .await + .account_balance(zip32::AccountId::try_from(0).unwrap()) + .await + .unwrap(); + let final_balance = balances.total_transparent_balance.unwrap() + + balances.total_sapling_balance.unwrap() + + balances.total_orchard_balance.unwrap(); + let balance_in_zec = + final_balance.unwrap() / NonZero::new(10u64.pow(8)).unwrap(); self.log_buffer .lock() .unwrap() - .push(format!("Total ZEC found: {}", balance_in_zec)); + .push(format!("Total ZEC found: {}", balance_in_zec.into_u64())); *self.sync_complete.lock().unwrap() = true; break; @@ -394,13 +422,22 @@ mod tests { vec.mnemonic, vec.birthday ); - let balances = client.do_balance().await; - let total = balances.confirmed_transparent_balance.unwrap_or(0) - + balances.verified_sapling_balance.unwrap_or(0) - + balances.verified_orchard_balance.unwrap_or(0); - let zec = total / 10u64.pow(8); - - println!("Vector {i} passed! Found balance: {} ZEC", zec); + let balances = client + .wallet + .lock() + .await + .account_balance(zip32::AccountId::try_from(0).unwrap()) + .await + .unwrap(); + let final_balance = balances.total_transparent_balance.unwrap() + + balances.total_sapling_balance.unwrap() + + balances.total_orchard_balance.unwrap(); + let balance_in_zec = final_balance.unwrap() / NonZero::new(10u64.pow(8)).unwrap(); + + println!( + "Vector {i} passed! Found balance: {} ZEC", + balance_in_zec.into_u64() + ); } } }