diff --git a/zingo-testutils/test_binaries/bins/README.md b/zingo-testutils/test_binaries/bins/README.md new file mode 100644 index 000000000..05cf14793 --- /dev/null +++ b/zingo-testutils/test_binaries/bins/README.md @@ -0,0 +1 @@ +This repo exists to stash test binaries in. diff --git a/zingolib/src/lightclient.rs b/zingolib/src/lightclient.rs index da1cdff9a..4a74ac9e8 100644 --- a/zingolib/src/lightclient.rs +++ b/zingolib/src/lightclient.rs @@ -15,7 +15,9 @@ use crate::{ keys::{address_from_pubkeyhash, unified::ReceiverSelection}, message::Message, notes::ShieldedNoteInterface, - now, LightWallet, Pool, SendProgress, WalletBase, + now, + utils::get_price, + LightWallet, Pool, SendProgress, WalletBase, }, }; use futures::future::join_all; @@ -1308,7 +1310,7 @@ impl LightClient { transaction, status, now() as u32, - TransactionRecord::get_price(now(), &price), + get_price(now(), &price), ) .await; } @@ -2214,6 +2216,70 @@ async fn get_recent_median_price_from_gemini() -> Result { Ok(trades[5]) } +#[cfg(test)] +mod tests { + use tokio::runtime::Runtime; + use zingo_testvectors::seeds::CHIMNEY_BETTER_SEED; + use zingoconfig::{ChainType, ZingoConfig}; + + use crate::{lightclient::LightClient, wallet::WalletBase}; + + #[test] + fn new_wallet_from_phrase() { + let temp_dir = tempfile::Builder::new().prefix("test").tempdir().unwrap(); + let data_dir = temp_dir + .into_path() + .canonicalize() + .expect("This path is available."); + + let wallet_name = data_dir.join("zingo-wallet.dat"); + let config = ZingoConfig::build(ChainType::FakeMainnet) + .set_wallet_dir(data_dir) + .create(); + let lc = LightClient::create_from_wallet_base( + WalletBase::MnemonicPhrase(CHIMNEY_BETTER_SEED.to_string()), + &config, + 0, + false, + ) + .unwrap(); + assert_eq!( + format!( + "{:?}", + LightClient::create_from_wallet_base( + WalletBase::MnemonicPhrase(CHIMNEY_BETTER_SEED.to_string()), + &config, + 0, + false + ) + .err() + .unwrap() + ), + format!( + "{:?}", + std::io::Error::new( + std::io::ErrorKind::AlreadyExists, + format!("Cannot create a new wallet from seed, because a wallet already exists at:\n{:?}", wallet_name), + ) + ) + ); + + // The first t address and z address should be derived + Runtime::new().unwrap().block_on(async move { + let addresses = lc.do_addresses().await; + assert_eq!( + "zs1q6xk3q783t5k92kjqt2rkuuww8pdw2euzy5rk6jytw97enx8fhpazdv3th4xe7vsk6e9sfpawfg" + .to_string(), + addresses[0]["receivers"]["sapling"] + ); + assert_eq!( + "t1eQ63fwkQ4n4Eo5uCrPGaAV8FWB2tmx7ui", + addresses[0]["receivers"]["transparent"] + ); + }); + } +} + #[cfg(feature = "lightclient-deprecated")] mod deprecated; #[cfg(feature = "test-features")] diff --git a/zingolib/src/lightclient/deprecated.rs b/zingolib/src/lightclient/deprecated.rs index cba15c33b..0108d9d1a 100644 --- a/zingolib/src/lightclient/deprecated.rs +++ b/zingolib/src/lightclient/deprecated.rs @@ -204,66 +204,3 @@ impl LightClient { JsonValue::Array(consumer_ui_notes) } } -#[cfg(test)] -mod tests { - use tokio::runtime::Runtime; - use zingo_testvectors::seeds::CHIMNEY_BETTER_SEED; - use zingoconfig::{ChainType, ZingoConfig}; - - use crate::{lightclient::LightClient, wallet::WalletBase}; - - #[test] - fn new_wallet_from_phrase() { - let temp_dir = tempfile::Builder::new().prefix("test").tempdir().unwrap(); - let data_dir = temp_dir - .into_path() - .canonicalize() - .expect("This path is available."); - - let wallet_name = data_dir.join("zingo-wallet.dat"); - let config = ZingoConfig::build(ChainType::FakeMainnet) - .set_wallet_dir(data_dir) - .create(); - let lc = LightClient::create_from_wallet_base( - WalletBase::MnemonicPhrase(CHIMNEY_BETTER_SEED.to_string()), - &config, - 0, - false, - ) - .unwrap(); - assert_eq!( - format!( - "{:?}", - LightClient::create_from_wallet_base( - WalletBase::MnemonicPhrase(CHIMNEY_BETTER_SEED.to_string()), - &config, - 0, - false - ) - .err() - .unwrap() - ), - format!( - "{:?}", - std::io::Error::new( - std::io::ErrorKind::AlreadyExists, - format!("Cannot create a new wallet from seed, because a wallet already exists at:\n{:?}", wallet_name), - ) - ) - ); - - // The first t address and z address should be derived - Runtime::new().unwrap().block_on(async move { - let addresses = lc.do_addresses().await; - assert_eq!( - "zs1q6xk3q783t5k92kjqt2rkuuww8pdw2euzy5rk6jytw97enx8fhpazdv3th4xe7vsk6e9sfpawfg" - .to_string(), - addresses[0]["receivers"]["sapling"] - ); - assert_eq!( - "t1eQ63fwkQ4n4Eo5uCrPGaAV8FWB2tmx7ui", - addresses[0]["receivers"]["transparent"] - ); - }); - } -} diff --git a/zingolib/src/wallet.rs b/zingolib/src/wallet.rs index 912f8607e..d5d1a7ff5 100644 --- a/zingolib/src/wallet.rs +++ b/zingolib/src/wallet.rs @@ -54,6 +54,7 @@ use self::data::{SpendableOrchardNote, WitnessTrees, COMMITMENT_TREE_LEVELS, MAX use self::keys::unified::{Capability, WalletCapability}; use self::traits::Recipient; use self::traits::{DomainWalletExt, SpendableNote}; +use self::utils::get_price; use self::{ data::{BlockData, WalletZecPriceInfo}, message::Message, @@ -1432,12 +1433,7 @@ impl LightWallet { let status = ConfirmationStatus::Broadcast(submission_height); self.transaction_context - .scan_full_tx( - transaction, - status, - now() as u32, - TransactionRecord::get_price(now(), &price), - ) + .scan_full_tx(transaction, status, now() as u32, get_price(now(), &price)) .await; } diff --git a/zingolib/src/wallet/transaction_record.rs b/zingolib/src/wallet/transaction_record.rs index 2801dda2f..5e5767a2a 100644 --- a/zingolib/src/wallet/transaction_record.rs +++ b/zingolib/src/wallet/transaction_record.rs @@ -49,9 +49,6 @@ pub struct TransactionRecord { // All outgoing sends pub outgoing_tx_data: Vec, - // Whether this TxID was downloaded from the server and scanned for Memos - pub full_tx_scanned: bool, - // Price of Zec when this Tx was created pub price: Option, } @@ -72,7 +69,6 @@ impl TransactionRecord { total_sapling_value_spent: 0, total_orchard_value_spent: 0, outgoing_tx_data: vec![], - full_tx_scanned: false, price: None, } } @@ -175,21 +171,6 @@ impl TransactionRecord { self.total_orchard_value_spent, ] } - pub fn get_price(datetime: u64, price: &WalletZecPriceInfo) -> Option { - match price.zec_price { - None => None, - Some((t, p)) => { - // If the price was fetched within 24 hours of this Tx, we use the "current" price - // else, we mark it as None, for the historical price fetcher to get - // TODO: Investigate the state of "the historical price fetcher". - if (t as i64 - datetime as i64).abs() < 24 * 60 * 60 { - Some(p) - } else { - None - } - } - } - } } // read/write impl TransactionRecord { @@ -254,7 +235,7 @@ impl TransactionRecord { // Outgoing metadata was only added in version 2 let outgoing_metadata = Vector::read(&mut reader, |r| OutgoingTxData::read(r))?; - let full_tx_scanned = reader.read_u8()? > 0; + let _full_tx_scanned = reader.read_u8()? > 0; let zec_price = if version <= 4 { None @@ -295,7 +276,6 @@ impl TransactionRecord { total_transparent_value_spent, total_orchard_value_spent, outgoing_tx_data: outgoing_metadata, - full_tx_scanned, price: zec_price, }) } @@ -327,7 +307,7 @@ impl TransactionRecord { // Write the outgoing metadata Vector::write(&mut writer, &self.outgoing_tx_data, |w, om| om.write(w))?; - writer.write_u8(if self.full_tx_scanned { 1 } else { 0 })?; + writer.write_u8(0)?; Optional::write(&mut writer, self.price, |w, p| { w.write_f64::(p) diff --git a/zingolib/src/wallet/utils.rs b/zingolib/src/wallet/utils.rs index 879e15d7f..cf376521f 100644 --- a/zingolib/src/wallet/utils.rs +++ b/zingolib/src/wallet/utils.rs @@ -2,6 +2,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::io::{self, Read, Write}; use zcash_primitives::{memo::MemoBytes, transaction::TxId}; +use super::data::WalletZecPriceInfo; + pub fn read_string(mut reader: R) -> io::Result { // Strings are written as len + bytes let str_len = reader.read_u64::()?; @@ -41,3 +43,18 @@ pub fn txid_from_slice(txid: &[u8]) -> TxId { txid_bytes.copy_from_slice(txid); TxId::from_bytes(txid_bytes) } +pub fn get_price(datetime: u64, price: &WalletZecPriceInfo) -> Option { + match price.zec_price { + None => None, + Some((t, p)) => { + // If the price was fetched within 24 hours of this Tx, we use the "current" price + // else, we mark it as None, for the historical price fetcher to get + // TODO: Investigate the state of "the historical price fetcher". + if (t as i64 - datetime as i64).abs() < 24 * 60 * 60 { + Some(p) + } else { + None + } + } + } +}