zcash_client_backend: Improve type safety of `get_known_ephemeral_addresses`

This commit is contained in:
Kris Nuttycombe 2024-12-23 17:52:43 -07:00
parent 5290d13942
commit 29d8f10cdc
7 changed files with 43 additions and 37 deletions

View File

@ -166,6 +166,7 @@ lightwalletd-tonic-transport = ["lightwalletd-tonic", "tonic?/transport"]
## Enables receiving transparent funds and shielding them. ## Enables receiving transparent funds and shielding them.
transparent-inputs = [ transparent-inputs = [
"dep:bip32", "dep:bip32",
"transparent/transparent-inputs",
"zcash_keys/transparent-inputs", "zcash_keys/transparent-inputs",
"zcash_primitives/transparent-inputs", "zcash_primitives/transparent-inputs",
] ]

View File

@ -74,15 +74,12 @@ use zcash_keys::{
UnifiedAddressRequest, UnifiedFullViewingKey, UnifiedIncomingViewingKey, UnifiedSpendingKey, UnifiedAddressRequest, UnifiedFullViewingKey, UnifiedIncomingViewingKey, UnifiedSpendingKey,
}, },
}; };
use zcash_primitives::{ use zcash_primitives::{block::BlockHash, transaction::Transaction};
block::BlockHash,
transaction::{Transaction, TxId},
};
use zcash_protocol::{ use zcash_protocol::{
consensus::BlockHeight, consensus::BlockHeight,
memo::{Memo, MemoBytes}, memo::{Memo, MemoBytes},
value::{BalanceError, Zatoshis}, value::{BalanceError, Zatoshis},
ShieldedProtocol, ShieldedProtocol, TxId,
}; };
use zip32::fingerprint::SeedFingerprint; use zip32::fingerprint::SeedFingerprint;
@ -99,8 +96,8 @@ use crate::{
#[cfg(feature = "transparent-inputs")] #[cfg(feature = "transparent-inputs")]
use { use {
crate::wallet::TransparentAddressMetadata, crate::wallet::TransparentAddressMetadata,
::transparent::{address::TransparentAddress, bundle::OutPoint},
std::ops::Range, std::ops::Range,
transparent::{address::TransparentAddress, bundle::OutPoint, keys::NonHardenedChildIndex},
}; };
#[cfg(feature = "test-dependencies")] #[cfg(feature = "test-dependencies")]
@ -1465,7 +1462,7 @@ pub trait WalletRead {
fn get_known_ephemeral_addresses( fn get_known_ephemeral_addresses(
&self, &self,
_account: Self::AccountId, _account: Self::AccountId,
_index_range: Option<Range<u32>>, _index_range: Option<Range<NonHardenedChildIndex>>,
) -> Result<Vec<(TransparentAddress, TransparentAddressMetadata)>, Self::Error> { ) -> Result<Vec<(TransparentAddress, TransparentAddressMetadata)>, Self::Error> {
Ok(vec![]) Ok(vec![])
} }

View File

@ -8,11 +8,6 @@ use std::{
num::NonZeroU32, num::NonZeroU32,
}; };
use ::sapling::{
note_encryption::{sapling_note_encryption, SaplingDomain},
util::generate_random_rseed,
zip32::DiversifiableFullViewingKey,
};
use assert_matches::assert_matches; use assert_matches::assert_matches;
use group::ff::Field; use group::ff::Field;
use incrementalmerkletree::{Marking, Retention}; use incrementalmerkletree::{Marking, Retention};
@ -23,6 +18,11 @@ use secrecy::{ExposeSecret, Secret, SecretVec};
use shardtree::{error::ShardTreeError, store::memory::MemoryShardStore, ShardTree}; use shardtree::{error::ShardTreeError, store::memory::MemoryShardStore, ShardTree};
use subtle::ConditionallySelectable; use subtle::ConditionallySelectable;
use ::sapling::{
note_encryption::{sapling_note_encryption, SaplingDomain},
util::generate_random_rseed,
zip32::DiversifiableFullViewingKey,
};
use zcash_address::ZcashAddress; use zcash_address::ZcashAddress;
use zcash_keys::{ use zcash_keys::{
address::{Address, UnifiedAddress}, address::{Address, UnifiedAddress},
@ -44,6 +44,21 @@ use zcash_protocol::{
use zip32::{fingerprint::SeedFingerprint, DiversifierIndex}; use zip32::{fingerprint::SeedFingerprint, DiversifierIndex};
use zip321::Payment; use zip321::Payment;
use super::{
chain::{scan_cached_blocks, BlockSource, ChainState, CommitmentTreeRoot, ScanSummary},
error::Error,
scanning::ScanRange,
wallet::{
create_proposed_transactions,
input_selection::{GreedyInputSelector, InputSelector},
propose_standard_transfer_to_address, propose_transfer,
},
Account, AccountBalance, AccountBirthday, AccountMeta, AccountPurpose, AccountSource,
BlockMetadata, DecryptedTransaction, InputSource, NoteFilter, NullifierQuery, ScannedBlock,
SeedRelevance, SentTransaction, SpendableNotes, TransactionDataRequest, TransactionStatus,
WalletCommitmentTrees, WalletRead, WalletSummary, WalletTest, WalletWrite,
SAPLING_SHARD_HEIGHT,
};
use crate::{ use crate::{
fees::{ fees::{
standard::{self, SingleOutputChangeStrategy}, standard::{self, SingleOutputChangeStrategy},
@ -56,26 +71,12 @@ use crate::{
wallet::{Note, NoteId, OvkPolicy, ReceivedNote, WalletTransparentOutput}, wallet::{Note, NoteId, OvkPolicy, ReceivedNote, WalletTransparentOutput},
}; };
use super::{
chain::{scan_cached_blocks, BlockSource, ChainState, CommitmentTreeRoot, ScanSummary},
scanning::ScanRange,
wallet::{
create_proposed_transactions,
input_selection::{GreedyInputSelector, InputSelector},
propose_standard_transfer_to_address, propose_transfer,
},
Account, AccountBalance, AccountBirthday, AccountMeta, AccountPurpose, AccountSource,
BlockMetadata, DecryptedTransaction, InputSource, NullifierQuery, ScannedBlock, SeedRelevance,
SentTransaction, SpendableNotes, TransactionDataRequest, TransactionStatus,
WalletCommitmentTrees, WalletRead, WalletSummary, WalletTest, WalletWrite,
SAPLING_SHARD_HEIGHT,
};
use super::{error::Error, NoteFilter};
#[cfg(feature = "transparent-inputs")] #[cfg(feature = "transparent-inputs")]
use { use {
super::wallet::input_selection::ShieldingSelector, crate::wallet::TransparentAddressMetadata, super::wallet::input_selection::ShieldingSelector,
::transparent::address::TransparentAddress, std::ops::Range, crate::wallet::TransparentAddressMetadata,
::transparent::{address::TransparentAddress, keys::NonHardenedChildIndex},
std::ops::Range,
}; };
#[cfg(feature = "orchard")] #[cfg(feature = "orchard")]
@ -2624,7 +2625,7 @@ impl WalletRead for MockWalletDb {
fn get_known_ephemeral_addresses( fn get_known_ephemeral_addresses(
&self, &self,
_account: Self::AccountId, _account: Self::AccountId,
_index_range: Option<Range<u32>>, _index_range: Option<Range<NonHardenedChildIndex>>,
) -> Result<Vec<(TransparentAddress, TransparentAddressMetadata)>, Self::Error> { ) -> Result<Vec<(TransparentAddress, TransparentAddressMetadata)>, Self::Error> {
Ok(vec![]) Ok(vec![])
} }

View File

@ -827,7 +827,13 @@ pub fn send_multi_step_proposed_transfer<T: ShieldedPoolTester, DSF>(
// the start of the gap to index 12. This also tests the `index_range` parameter. // the start of the gap to index 12. This also tests the `index_range` parameter.
let newer_known_addrs = st let newer_known_addrs = st
.wallet() .wallet()
.get_known_ephemeral_addresses(account_id, Some(5..100)) .get_known_ephemeral_addresses(
account_id,
Some(
NonHardenedChildIndex::from_index(5).unwrap()
..NonHardenedChildIndex::from_index(100).unwrap(),
),
)
.unwrap(); .unwrap();
assert_eq!(newer_known_addrs.len(), (GAP_LIMIT as usize) + 12 - 5); assert_eq!(newer_known_addrs.len(), (GAP_LIMIT as usize) + 12 - 5);
assert!(newer_known_addrs.starts_with(&new_known_addrs[5..])); assert!(newer_known_addrs.starts_with(&new_known_addrs[5..]));

View File

@ -123,6 +123,7 @@ test-dependencies = [
## Enables receiving transparent funds and sending to transparent recipients ## Enables receiving transparent funds and sending to transparent recipients
transparent-inputs = [ transparent-inputs = [
"dep:bip32", "dep:bip32",
"transparent/transparent-inputs",
"zcash_keys/transparent-inputs", "zcash_keys/transparent-inputs",
"zcash_client_backend/transparent-inputs" "zcash_client_backend/transparent-inputs"
] ]

View File

@ -92,9 +92,9 @@ use {
#[cfg(feature = "transparent-inputs")] #[cfg(feature = "transparent-inputs")]
use { use {
::transparent::{address::TransparentAddress, bundle::OutPoint}, ::transparent::{address::TransparentAddress, bundle::OutPoint, keys::NonHardenedChildIndex},
zcash_client_backend::wallet::TransparentAddressMetadata, zcash_client_backend::wallet::TransparentAddressMetadata,
zcash_keys::encoding::AddressCodec as _, zcash_keys::encoding::AddressCodec,
}; };
#[cfg(feature = "multicore")] #[cfg(feature = "multicore")]
@ -659,14 +659,14 @@ impl<C: Borrow<rusqlite::Connection>, P: consensus::Parameters> WalletRead for W
fn get_known_ephemeral_addresses( fn get_known_ephemeral_addresses(
&self, &self,
account: Self::AccountId, account: Self::AccountId,
index_range: Option<Range<u32>>, index_range: Option<Range<NonHardenedChildIndex>>,
) -> Result<Vec<(TransparentAddress, TransparentAddressMetadata)>, Self::Error> { ) -> Result<Vec<(TransparentAddress, TransparentAddressMetadata)>, Self::Error> {
let account_id = wallet::get_account_ref(self.conn.borrow(), account)?; let account_id = wallet::get_account_ref(self.conn.borrow(), account)?;
wallet::transparent::ephemeral::get_known_ephemeral_addresses( wallet::transparent::ephemeral::get_known_ephemeral_addresses(
self.conn.borrow(), self.conn.borrow(),
&self.params, &self.params,
account_id, account_id,
index_range, index_range.map(|i| i.start.index()..i.end.index()),
) )
} }

View File

@ -42,7 +42,7 @@ use crate::{
#[cfg(feature = "transparent-inputs")] #[cfg(feature = "transparent-inputs")]
use { use {
crate::TransparentAddressMetadata, crate::TransparentAddressMetadata,
::transparent::{address::TransparentAddress, bundle::OutPoint}, ::transparent::{address::TransparentAddress, bundle::OutPoint, keys::NonHardenedChildIndex},
core::ops::Range, core::ops::Range,
}; };