"unconfirmed" -> "unverified"

This commit is contained in:
Aditya Kulkarni 2020-08-07 10:11:55 -07:00
parent 6187156936
commit 06a268c2bd
3 changed files with 15 additions and 11 deletions

View File

@ -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::<Vec<JsonValue>>();
@ -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,

View File

@ -976,7 +976,7 @@ impl LightWallet {
.sum::<u64>()
}
pub fn unconfirmed_zbalance(&self, addr: Option<String>) -> u64 {
pub fn unverified_zbalance(&self, addr: Option<String>) -> 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(

View File

@ -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);
}