Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Grigg <[email protected]>
  • Loading branch information
nuttycom and str4d committed Jul 16, 2024
1 parent dbb5eeb commit ba32fba
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
31 changes: 17 additions & 14 deletions zcash_client_backend/src/data_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,15 @@ pub trait WalletRead {
///
/// This is equivalent to (but may be implemented more efficiently than):
/// ```compile_fail
/// if let Some(result) = self.get_transparent_receivers(account)?.get(address) {
/// return Ok(result.clone());
/// }
/// Ok(self
/// Ok(if let Some(result) = self.get_transparent_receivers(account)?.get(address) {
/// Ok(result.clone())
/// } else {
/// self
/// .get_known_ephemeral_addresses(account, None)?
/// .into_iter()
/// .find(|(known_addr, _)| known_addr == address)
/// .map(|(_, metadata)| metadata))
/// .map(|(_, metadata)| metadata)
/// })
/// ```
///
/// Returns `Ok(None)` if the address is not recognized, or we do not have metadata for it.
Expand All @@ -950,14 +951,16 @@ pub trait WalletRead {
address: &TransparentAddress,
) -> Result<Option<TransparentAddressMetadata>, Self::Error> {
// This should be overridden.
if let Some(result) = self.get_transparent_receivers(account)?.get(address) {
return Ok(result.clone());
}
Ok(self
.get_known_ephemeral_addresses(account, None)?
.into_iter()
.find(|(known_addr, _)| known_addr == address)
.map(|(_, metadata)| metadata))
Ok(
if let Some(result) = self.get_transparent_receivers(account)?.get(address) {
result.clone()

Check warning on line 956 in zcash_client_backend/src/data_api.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api.rs#L955-L956

Added lines #L955 - L956 were not covered by tests
} else {
self.get_known_ephemeral_addresses(account, None)?
.into_iter()
.find(|(known_addr, _)| known_addr == address)
.map(|(_, metadata)| metadata)

Check warning on line 961 in zcash_client_backend/src/data_api.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api.rs#L958-L961

Added lines #L958 - L961 were not covered by tests
},
)
}

/// Returns a vector of ephemeral transparent addresses associated with the given
Expand Down Expand Up @@ -1001,7 +1004,7 @@ pub trait WalletRead {
Ok(vec![])

Check warning on line 1004 in zcash_client_backend/src/data_api.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api.rs#L1004

Added line #L1004 was not covered by tests
}

/// If a given transparent address has been reserved, i.e. would be included in
/// If a given ephemeral address might have been reserved, i.e. would be included in
/// the map returned by `get_known_ephemeral_addresses(account_id, false)` for any
/// of the wallet's accounts, then return `Ok(Some(account_id))`. Otherwise return
/// `Ok(None)`.
Expand Down
3 changes: 3 additions & 0 deletions zcash_client_backend/src/data_api/wallet/input_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ where
let mut tr1_payments = vec![];
#[cfg(feature = "transparent-inputs")]
let mut tr1_payment_pools = BTreeMap::new();
// this balance value is just used for overflow checking; the actual value of ephemeral
// outputs will be computed from the constructed `tr1_transparent_outputs` value
// constructed below.
#[cfg(feature = "transparent-inputs")]
let mut total_ephemeral = NonNegativeAmount::ZERO;

Expand Down
2 changes: 1 addition & 1 deletion zcash_client_sqlite/src/wallet/transparent/ephemeral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub(crate) fn find_index_for_ephemeral_address_str(
Ok(conn
.query_row(
"SELECT address_index FROM ephemeral_addresses
WHERE account_id = :account_id AND address = :address",
WHERE account_id = :account_id AND address = :address",
named_params![":account_id": account_id.0, ":address": &address_str],
|row| row.get::<_, u32>(0),
)
Expand Down
9 changes: 5 additions & 4 deletions zcash_primitives/src/legacy/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ use super::TransparentAddress;
pub struct TransparentKeyScope(u32);

impl TransparentKeyScope {
/// Returns an arbitrary custom `TransparentKeyScope`. This should be used
/// with care: funds associated with keys derived under a custom scope may
/// not be recoverable if the wallet seed is restored in another wallet.
/// It is usually preferable to use standardized key scopes.
/// Returns an arbitrary custom `TransparentKeyScope`.
///
/// This should be used with care: funds associated with keys derived under a custom
/// scope may not be recoverable if the wallet seed is restored in another wallet. It
/// is usually preferable to use standardized key scopes.
pub const fn custom(i: u32) -> Option<Self> {

Check warning on line 29 in zcash_primitives/src/legacy/keys.rs

View check run for this annotation

Codecov / codecov/patch

zcash_primitives/src/legacy/keys.rs#L29

Added line #L29 was not covered by tests
if i < (1 << 31) {
Some(TransparentKeyScope(i))
Expand Down

0 comments on commit ba32fba

Please sign in to comment.