zcash_client_backend: Return UFVKs from `WalletRead` instead of ExtFVKs

This commit is contained in:
Jack Grigg 2022-06-14 00:57:20 +00:00
parent 0d0527dbf3
commit c0e8ee0fa0
6 changed files with 61 additions and 25 deletions

View File

@ -27,6 +27,8 @@ and this library adheres to Rust's notion of
provides substantially greater flexibility in transaction creation.
- `zcash_client_backend::address`:
- `RecipientAddress::Unified`
- `zcash_client_backend::data_api`:
`WalletRead::get_unified_full_viewing_keys`
- `zcash_client_backend::proto`:
- `actions` field on `compact_formats::CompactTx`
- `compact_formats::CompactOrchardAction`
@ -103,6 +105,9 @@ and this library adheres to Rust's notion of
- `Zip321Error::ParseError(String)`
### Removed
- `zcash_client_backend::data_api`:
- `WalletRead::get_extended_full_viewing_keys` (use
`WalletRead::get_unified_full_viewing_keys` instead).
- The hardcoded `data_api::wallet::ANCHOR_OFFSET` constant.
- `zcash_client_backend::wallet::AccountId` (moved to `zcash_primitives::zip32::AccountId`).

View File

@ -17,6 +17,7 @@ use zcash_primitives::{
use crate::{
address::RecipientAddress,
decrypt::DecryptedOutput,
keys::UnifiedFullViewingKey,
proto::compact_formats::CompactBlock,
wallet::{SpendableNote, WalletTx},
};
@ -118,10 +119,10 @@ pub trait WalletRead {
// TODO: This does not appear to be the case.
fn get_address(&self, account: AccountId) -> Result<Option<PaymentAddress>, Self::Error>;
/// Returns all extended full viewing keys known about by this wallet.
fn get_extended_full_viewing_keys(
/// Returns all unified full viewing keys known to this wallet.
fn get_unified_full_viewing_keys(
&self,
) -> Result<HashMap<AccountId, ExtendedFullViewingKey>, Self::Error>;
) -> Result<HashMap<AccountId, UnifiedFullViewingKey>, Self::Error>;
/// Checks whether the specified extended full viewing key is
/// associated with the account.
@ -330,6 +331,7 @@ pub mod testing {
};
use crate::{
keys::UnifiedFullViewingKey,
proto::compact_formats::CompactBlock,
wallet::{SpendableNote, WalletTransparentOutput},
};
@ -386,9 +388,9 @@ pub mod testing {
Ok(None)
}
fn get_extended_full_viewing_keys(
fn get_unified_full_viewing_keys(
&self,
) -> Result<HashMap<AccountId, ExtendedFullViewingKey>, Self::Error> {
) -> Result<HashMap<AccountId, UnifiedFullViewingKey>, Self::Error> {
Ok(HashMap::new())
}

View File

@ -210,9 +210,14 @@ where
.unwrap_or(sapling_activation_height - 1)
})?;
// Fetch the ExtendedFullViewingKeys we are tracking
let extfvks = data.get_extended_full_viewing_keys()?;
let extfvks: Vec<(&AccountId, &ExtendedFullViewingKey)> = extfvks.iter().collect();
// Fetch the UnifiedFullViewingKeys we are tracking
let ufvks = data.get_unified_full_viewing_keys()?;
// TODO: Change `scan_block` to also scan Orchard.
// https://github.com/zcash/librustzcash/issues/403
let extfvks: Vec<(&AccountId, &ExtendedFullViewingKey)> = ufvks
.iter()
.map(|(account, ufvk)| (account, ufvk.sapling().expect("TODO Add Orchard support")))
.collect();
// Get the most recent CommitmentTree
let mut tree = data

View File

@ -41,8 +41,17 @@ where
P: consensus::Parameters,
D: WalletWrite<Error = E>,
{
// Fetch the ExtendedFullViewingKeys we are tracking
let extfvks = data.get_extended_full_viewing_keys()?;
// Fetch the UnifiedFullViewingKeys we are tracking
let ufvks = data.get_unified_full_viewing_keys()?;
let extfvks = ufvks
.into_iter()
.map(|(account, ufvk)| {
(
account,
ufvk.sapling().cloned().expect("TODO Add Orchard support"),
)
})
.collect();
// Height is block height for mined transactions, and the "mempool height" (chain height + 1)
// for mempool transactions.

View File

@ -53,6 +53,7 @@ use zcash_client_backend::{
data_api::{
BlockSource, DecryptedTransaction, PrunedBlock, SentTransaction, WalletRead, WalletWrite,
},
keys::UnifiedFullViewingKey,
proto::compact_formats::CompactBlock,
wallet::SpendableNote,
};
@ -224,11 +225,11 @@ impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
wallet::get_tx_height(self, txid).map_err(SqliteClientError::from)
}
fn get_extended_full_viewing_keys(
fn get_unified_full_viewing_keys(
&self,
) -> Result<HashMap<AccountId, ExtendedFullViewingKey>, Self::Error> {
) -> Result<HashMap<AccountId, UnifiedFullViewingKey>, Self::Error> {
#[allow(deprecated)]
wallet::get_extended_full_viewing_keys(self)
wallet::get_unified_full_viewing_keys(self)
}
fn get_address(&self, account: AccountId) -> Result<Option<PaymentAddress>, Self::Error> {
@ -380,10 +381,10 @@ impl<'a, P: consensus::Parameters> WalletRead for DataConnStmtCache<'a, P> {
self.wallet_db.get_tx_height(txid)
}
fn get_extended_full_viewing_keys(
fn get_unified_full_viewing_keys(
&self,
) -> Result<HashMap<AccountId, ExtendedFullViewingKey>, Self::Error> {
self.wallet_db.get_extended_full_viewing_keys()
) -> Result<HashMap<AccountId, UnifiedFullViewingKey>, Self::Error> {
self.wallet_db.get_unified_full_viewing_keys()
}
fn get_address(&self, account: AccountId) -> Result<Option<PaymentAddress>, Self::Error> {

View File

@ -176,12 +176,29 @@ pub fn get_address<P: consensus::Parameters>(
///
/// [`ExtendedFullViewingKey`]: zcash_primitives::zip32::ExtendedFullViewingKey
#[deprecated(
note = "This function will be removed in a future release. Use zcash_client_backend::data_api::WalletRead::get_extended_full_viewing_keys instead."
note = "This function will be removed in a future release. Use zcash_client_backend::data_api::WalletRead::get_unified_full_viewing_keys instead."
)]
pub fn get_extended_full_viewing_keys<P: consensus::Parameters>(
wdb: &WalletDb<P>,
) -> Result<HashMap<AccountId, ExtendedFullViewingKey>, SqliteClientError> {
// Fetch the ExtendedFullViewingKeys we are tracking
get_unified_full_viewing_keys(wdb).map(|ufvks| {
ufvks
.into_iter()
.map(|(account, ufvk)| {
(
account,
ufvk.sapling().cloned().expect("TODO: Add Orchard support"),
)
})
.collect()
})
}
/// Returns the [`UnifiedFullViewingKey`]s for the wallet.
pub(crate) fn get_unified_full_viewing_keys<P: consensus::Parameters>(
wdb: &WalletDb<P>,
) -> Result<HashMap<AccountId, UnifiedFullViewingKey>, SqliteClientError> {
// Fetch the UnifiedFullViewingKeys we are tracking
let mut stmt_fetch_accounts = wdb
.conn
.prepare("SELECT account, ufvk FROM accounts ORDER BY account ASC")?;
@ -193,18 +210,15 @@ pub fn get_extended_full_viewing_keys<P: consensus::Parameters>(
let ufvk_str: String = row.get(1)?;
let ufvk = UnifiedFullViewingKey::decode(&wdb.params, &ufvk_str, account)
.map_err(SqliteClientError::CorruptedData);
// TODO: Return the UFVK, not its Sapling component.
let extfvk =
ufvk.map(|ufvk| ufvk.sapling().cloned().expect("TODO: Add Orchard support"));
Ok((account, extfvk))
Ok((account, ufvk))
})
.map_err(SqliteClientError::from)?;
let mut res: HashMap<AccountId, ExtendedFullViewingKey> = HashMap::new();
let mut res: HashMap<AccountId, UnifiedFullViewingKey> = HashMap::new();
for row in rows {
let (account_id, efvkr) = row?;
res.insert(account_id, efvkr?);
let (account_id, ufvkr) = row?;
res.insert(account_id, ufvkr?);
}
Ok(res)