Rename get_verified_balance -> get_balance_at

This commit is contained in:
Kris Nuttycombe 2021-01-15 12:00:14 -07:00
parent c70a9ed81f
commit 8e8ed2bb4f
8 changed files with 36 additions and 29 deletions

View File

@ -123,7 +123,7 @@ pub trait WalletRead {
/// implementation for efficiency.
fn get_balance(&self, account: AccountId) -> Result<Amount, Self::Error> {
if let Some((_, tip)) = self.block_height_extrema()? {
self.get_verified_balance(account, tip)
self.get_balance_at(account, tip)
} else {
Ok(Amount::zero())
}
@ -134,7 +134,7 @@ pub trait WalletRead {
///
/// This may be used to obtain a balance that ignores notes that have been
/// received so recently that they are not yet deemed spendable.
fn get_verified_balance(
fn get_balance_at(
&self,
account: AccountId,
anchor_height: BlockHeight,
@ -210,6 +210,10 @@ pub trait WalletWrite: WalletRead {
/// a chain reorg might invalidate some stored state, this method must be
/// implemented in order to allow users of this API to "reset" the data store
/// to correctly represent chainstate as of a specified block height.
///
/// After calling this method, the block at the given height will be the
/// most recent block and all other operations will treat this block
/// as the chain tip for balance determination purposes.
fn rewind_to_height(&mut self, block_height: BlockHeight) -> Result<(), Self::Error>;
/// Add wallet-relevant metadata for a specific transaction to the data
@ -439,7 +443,7 @@ pub mod testing {
Ok(false)
}
fn get_verified_balance(
fn get_balance_at(
&self,
_account: AccountId,
_anchor_height: BlockHeight,

View File

@ -259,7 +259,10 @@ where
// Fetch the ExtendedFullViewingKeys we are tracking
let extfvks = data.get_extended_full_viewing_keys()?;
let ivks: Vec<_> = extfvks.iter().map(|(a, extfvk)| (*a, extfvk.fvk.vk.ivk())).collect();
let ivks: Vec<_> = extfvks
.iter()
.map(|(a, extfvk)| (*a, extfvk.fvk.vk.ivk()))
.collect();
// Get the most recent CommitmentTree
let mut tree = data
@ -340,17 +343,17 @@ where
for output in tx.shielded_outputs {
if let Some(extfvk) = &extfvks.get(&output.account) {
let nf = output
.note
.nf(&extfvk.fvk.vk, output.witness.position() as u64);
let nf = output
.note
.nf(&extfvk.fvk.vk, output.witness.position() as u64);
let note_id = up.put_received_note(&output, &Some(nf), tx_row)?;
let note_id = up.put_received_note(&output, &Some(nf), tx_row)?;
// Save witness for note.
witnesses.push((note_id, output.witness));
// Save witness for note.
witnesses.push((note_id, output.witness));
// Cache nullifier for note (to detect subsequent spends in this scan).
nullifiers.push((output.account, nf));
// Cache nullifier for note (to detect subsequent spends in this scan).
nullifiers.push((output.account, nf));
}
}
}

View File

@ -1,7 +1,7 @@
//! Structs representing transaction data scanned from the block chain by a wallet or
//! light client.
use subtle::{ConditionallySelectable, Choice};
use subtle::{Choice, ConditionallySelectable};
use zcash_primitives::{
keys::OutgoingViewingKey,

View File

@ -115,8 +115,8 @@ pub fn scan_block<P: consensus::Parameters>(
.iter()
.map(|&(account, nf)| CtOption::new(account, nf.ct_eq(&spend_nf)))
.fold(
CtOption::new(AccountId::default(), 0.into()),
|first, next| CtOption::conditional_select(&next, &first, first.is_some())
CtOption::new(AccountId::default(), 0.into()),
|first, next| CtOption::conditional_select(&next, &first, first.is_some()),
)
.map(|account| WalletShieldedSpend {
index,

View File

@ -196,12 +196,12 @@ impl<P: consensus::Parameters> WalletRead for WalletDB<P> {
wallet::get_balance(self, account)
}
fn get_verified_balance(
fn get_balance_at(
&self,
account: AccountId,
anchor_height: BlockHeight,
) -> Result<Amount, Self::Error> {
wallet::get_verified_balance(self, account, anchor_height)
wallet::get_balance_at(self, account, anchor_height)
}
fn get_received_memo_as_utf8(
@ -315,12 +315,12 @@ impl<'a, P: consensus::Parameters> WalletRead for DataConnStmtCache<'a, P> {
self.wallet_db.get_balance(account)
}
fn get_verified_balance(
fn get_balance_at(
&self,
account: AccountId,
anchor_height: BlockHeight,
) -> Result<Amount, Self::Error> {
self.wallet_db.get_verified_balance(account, anchor_height)
self.wallet_db.get_balance_at(account, anchor_height)
}
fn get_received_memo_as_utf8(

View File

@ -121,7 +121,7 @@ pub fn is_valid_account_extfvk<P: consensus::Parameters>(
///
/// WARNING: This balance is potentially unreliable, as mined notes may become unmined due
/// to chain reorgs. You should generally not show this balance to users without some
/// caveat. Use [`get_verified_balance`] where you need a more reliable indication of the
/// caveat. Use [`get_balance_at`] where you need a more reliable indication of the
/// wallet balance.
///
/// # Examples
@ -168,14 +168,14 @@ pub fn get_balance<P>(wdb: &WalletDB<P>, account: AccountId) -> Result<Amount, S
/// use zcash_client_backend::wallet::AccountId;
/// use zcash_client_sqlite::{
/// WalletDB,
/// wallet::get_verified_balance,
/// wallet::get_balance_at,
/// };
///
/// let data_file = NamedTempFile::new().unwrap();
/// let db = WalletDB::for_path(data_file, Network::TestNetwork).unwrap();
/// let addr = get_verified_balance(&db, AccountId(0), BlockHeight::from_u32(0));
/// let addr = get_balance_at(&db, AccountId(0), BlockHeight::from_u32(0));
/// ```
pub fn get_verified_balance<P>(
pub fn get_balance_at<P>(
wdb: &WalletDB<P>,
account: AccountId,
anchor_height: BlockHeight,

View File

@ -171,7 +171,7 @@ mod tests {
chain::init::init_cache_database,
tests::{self, fake_compact_block, insert_into_cache, sapling_activation_height},
wallet::{
get_balance, get_verified_balance,
get_balance, get_balance_at,
init::{init_accounts_table, init_blocks_table, init_wallet_db},
},
AccountId, BlockDB, DataConnStmtCache, WalletDB,
@ -340,7 +340,7 @@ mod tests {
let (_, anchor_height) = (&db_data).get_target_and_anchor_heights().unwrap().unwrap();
assert_eq!(get_balance(&db_data, AccountId(0)).unwrap(), value);
assert_eq!(
get_verified_balance(&db_data, AccountId(0), anchor_height).unwrap(),
get_balance_at(&db_data, AccountId(0), anchor_height).unwrap(),
value
);
@ -358,7 +358,7 @@ mod tests {
let (_, anchor_height2) = (&db_data).get_target_and_anchor_heights().unwrap().unwrap();
assert_eq!(get_balance(&db_data, AccountId(0)).unwrap(), value + value);
assert_eq!(
get_verified_balance(&db_data, AccountId(0), anchor_height2).unwrap(),
get_balance_at(&db_data, AccountId(0), anchor_height2).unwrap(),
value
);

View File

@ -4,7 +4,7 @@ use ff::PrimeField;
use group::{Curve, Group, GroupEncoding};
use std::array::TryFromSliceError;
use std::convert::TryInto;
use subtle::{ConstantTimeEq, Choice};
use subtle::{Choice, ConstantTimeEq};
use crate::constants;
@ -218,7 +218,6 @@ impl ConstantTimeEq for Nullifier {
}
}
#[derive(Clone, Debug)]
pub struct Note {
/// The value of the note
@ -294,7 +293,8 @@ impl Note {
.update(&rho.to_bytes())
.finalize()
.as_bytes(),
).unwrap()
)
.unwrap()
}
/// Computes the note commitment