From 08a2fded8807ba505afa99675c08d8166473f366 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Mon, 21 Oct 2019 14:05:33 -0700 Subject: [PATCH] Fix issue where t addresses weren't scanned when locked --- lib/src/lightwallet.rs | 24 +++++++++--------------- lib/src/lightwallet/bugs.rs | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/src/lightwallet.rs b/lib/src/lightwallet.rs index 9a3e0f8..568ba64 100644 --- a/lib/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -842,15 +842,11 @@ impl LightWallet { } } - // Scan the full Tx and update memos for incoming shielded transactions + // Scan the full Tx and update memos for incoming shielded transactions. pub fn scan_full_tx(&self, tx: &Transaction, height: i32, datetime: u64) { - // Scan all the inputs to see if we spent any transparent funds in this tx - - // TODO: Save this object - let secp = secp256k1::Secp256k1::new(); - let mut total_transparent_spend: u64 = 0; + // Scan all the inputs to see if we spent any transparent funds in this tx for vin in tx.vin.iter() { // Find the txid in the list of utxos that we have. let txid = TxId {0: vin.prevout.hash}; @@ -890,19 +886,15 @@ impl LightWallet { .total_transparent_value_spent = total_transparent_spend; } - // TODO: Iterate over all transparent addresses. This is currently looking only at - // the first one. // Scan for t outputs - let all_pubkeys = self.tkeys.read().unwrap().iter() - .map(|sk| - secp256k1::PublicKey::from_secret_key(&secp, sk).serialize() - ) - .collect::>(); - for pubkey in all_pubkeys { + let all_taddresses = self.taddresses.read().unwrap().iter() + .map(|a| a.clone()) + .collect::>(); + for address in all_taddresses { for (n, vout) in tx.vout.iter().enumerate() { match vout.script_pubkey.address() { Some(TransparentAddress::PublicKey(hash)) => { - if hash[..] == ripemd160::Ripemd160::digest(&Sha256::digest(&pubkey))[..] { + if address == hash.to_base58check(&self.config.base58_pubkey_address(), &[]) { // This is our address. Add this as an output to the txid self.add_toutput_to_wtx(height, datetime, &tx.txid(), &vout, n as u64); } @@ -1316,6 +1308,8 @@ impl LightWallet { let total_value = tos.iter().map(|to| to.1).sum::(); + // TODO: Check for duplicates in destination addresses + println!( "0: Creating transaction sending {} ztoshis to {} addresses", total_value, tos.len() diff --git a/lib/src/lightwallet/bugs.rs b/lib/src/lightwallet/bugs.rs index 0e9c925..8a88170 100644 --- a/lib/src/lightwallet/bugs.rs +++ b/lib/src/lightwallet/bugs.rs @@ -74,13 +74,13 @@ impl BugBip39Derivation { // Tranfer money // 1. The desination is z address #0 - println!("Sending funds to ourself."); let zaddr = client.do_address()["z_addresses"][0].as_str().unwrap().to_string(); let balance_json = client.do_balance(); let amount: u64 = balance_json["zbalance"].as_u64().unwrap() + balance_json["tbalance"].as_u64().unwrap(); let txid = if amount > 0 { + println!("Sending funds to ourself."); let fee: u64 = DEFAULT_FEE.try_into().unwrap(); match client.do_send(vec![(&zaddr, amount-fee, None)]) { Ok(txid) => txid,