From 06a268c2bd6412283100acd81c8f012608154c5d Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Fri, 7 Aug 2020 10:11:55 -0700 Subject: [PATCH] "unconfirmed" -> "unverified" --- lib/src/lightclient.rs | 4 ++-- lib/src/lightwallet.rs | 6 +++++- lib/src/lightwallet/tests.rs | 16 ++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index f166e60..e669d45 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -681,7 +681,7 @@ impl LightClient { "zbalance" => wallet.zbalance(Some(zaddress.clone())), "verified_zbalance" => wallet.verified_zbalance(Some(zaddress.clone())), "spendable_zbalance" => wallet.spendable_zbalance(Some(zaddress.clone())), - "unconfirmed_zbalance" => wallet.unconfirmed_zbalance(Some(zaddress.clone())) + "unverified_zbalance" => wallet.unverified_zbalance(Some(zaddress.clone())) } }).collect::>(); @@ -700,7 +700,7 @@ impl LightClient { "zbalance" => wallet.zbalance(None), "verified_zbalance" => wallet.verified_zbalance(None), "spendable_zbalance" => wallet.spendable_zbalance(None), - "unconfirmed_zbalance" => wallet.unconfirmed_zbalance(None), + "unverified_zbalance" => wallet.unverified_zbalance(None), "tbalance" => wallet.tbalance(None), "z_addresses" => z_addresses, "t_addresses" => t_addresses, diff --git a/lib/src/lightwallet.rs b/lib/src/lightwallet.rs index e4976aa..bc0b339 100644 --- a/lib/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -976,7 +976,7 @@ impl LightWallet { .sum::() } - pub fn unconfirmed_zbalance(&self, addr: Option) -> u64 { + pub fn unverified_zbalance(&self, addr: Option) -> u64 { let anchor_height = match self.get_target_height_and_anchor_offset() { Some((height, anchor_offset)) => height - anchor_offset as u32 - 1, None => return 0, @@ -990,6 +990,10 @@ impl LightWallet { tx.notes .iter() .filter(|nd| nd.spent.is_none() && nd.unconfirmed_spent.is_none()) + .filter(|nd| { + // Check to see if we have this note's spending key. + self.have_spendingkey_for_extfvk(&nd.extfvk) + }) .filter(|nd| { // TODO, this whole section is shared with verified_balance. Refactor it. match addr.clone() { Some(a) => a == encode_payment_address( diff --git a/lib/src/lightwallet/tests.rs b/lib/src/lightwallet/tests.rs index 77e69e2..986b909 100644 --- a/lib/src/lightwallet/tests.rs +++ b/lib/src/lightwallet/tests.rs @@ -699,7 +699,7 @@ fn get_test_wallet(amount: u64) -> (LightWallet, TxId, BlockHash) { } assert_eq!(wallet.verified_zbalance(None), amount); - assert_eq!(wallet.unconfirmed_zbalance(None), 0); + assert_eq!(wallet.unverified_zbalance(None), 0); // Create a new block so that the note is now verified to be spent let cb2 = FakeCompactBlock::new(1, cb1.hash()); @@ -738,7 +738,7 @@ fn test_unconfirmed_txns() { // Make sure the starting balances are correct assert_eq!(wallet.verified_zbalance(None), amount); - assert_eq!(wallet.unconfirmed_zbalance(None), 0); + assert_eq!(wallet.unverified_zbalance(None), 0); // Now spend some of the money, paying our own address let zaddr1 = encode_payment_address(wallet.config.hrp_sapling_address(), &wallet.zkeys.read().unwrap().get(0).unwrap().zaddress); @@ -754,15 +754,15 @@ fn test_unconfirmed_txns() { wallet.scan_block(&block.as_bytes()).unwrap(); // pending tx - assert_eq!(wallet.unconfirmed_zbalance(Some(zaddr1.clone())), amount - AMOUNT_SENT - fee); + assert_eq!(wallet.unverified_zbalance(Some(zaddr1.clone())), amount - AMOUNT_SENT - fee); assert_eq!(wallet.verified_zbalance(Some(zaddr1.clone())), 0); assert_eq!(wallet.spendable_zbalance(Some(zaddr1.clone())), 0); - assert_eq!(wallet.unconfirmed_zbalance(None), amount - fee); + assert_eq!(wallet.unverified_zbalance(None), amount - fee); assert_eq!(wallet.verified_zbalance(None), 0); assert_eq!(wallet.spendable_zbalance(None), 0); - assert_eq!(wallet.unconfirmed_zbalance(Some(zaddr2.clone())), AMOUNT_SENT); + assert_eq!(wallet.unverified_zbalance(Some(zaddr2.clone())), AMOUNT_SENT); assert_eq!(wallet.verified_zbalance(Some(zaddr2.clone())), 0); assert_eq!(wallet.spendable_zbalance(Some(zaddr2.clone())), 0); @@ -771,15 +771,15 @@ fn test_unconfirmed_txns() { block = FakeCompactBlock::new(7+i, block.hash()); wallet.scan_block(&block.as_bytes()).unwrap(); } - assert_eq!(wallet.unconfirmed_zbalance(Some(zaddr1.clone())), 0); + assert_eq!(wallet.unverified_zbalance(Some(zaddr1.clone())), 0); assert_eq!(wallet.verified_zbalance(Some(zaddr1.clone())), amount - AMOUNT_SENT - fee); assert_eq!(wallet.spendable_zbalance(Some(zaddr1.clone())), amount - AMOUNT_SENT - fee); - assert_eq!(wallet.unconfirmed_zbalance(None), 0); + assert_eq!(wallet.unverified_zbalance(None), 0); assert_eq!(wallet.verified_zbalance(None), amount - fee); assert_eq!(wallet.spendable_zbalance(None), amount - fee); - assert_eq!(wallet.unconfirmed_zbalance(Some(zaddr2.clone())), 0); + assert_eq!(wallet.unverified_zbalance(Some(zaddr2.clone())), 0); assert_eq!(wallet.verified_zbalance(Some(zaddr2.clone())), AMOUNT_SENT); assert_eq!(wallet.spendable_zbalance(Some(zaddr2.clone())), AMOUNT_SENT); }