Skip to content

Commit ba32fba

Browse files
nuttycomstr4d
andcommitted
Apply suggestions from code review
Co-authored-by: Jack Grigg <[email protected]>
1 parent dbb5eeb commit ba32fba

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

zcash_client_backend/src/data_api.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -931,14 +931,15 @@ pub trait WalletRead {
931931
///
932932
/// This is equivalent to (but may be implemented more efficiently than):
933933
/// ```compile_fail
934-
/// if let Some(result) = self.get_transparent_receivers(account)?.get(address) {
935-
/// return Ok(result.clone());
936-
/// }
937-
/// Ok(self
934+
/// Ok(if let Some(result) = self.get_transparent_receivers(account)?.get(address) {
935+
/// Ok(result.clone())
936+
/// } else {
937+
/// self
938938
/// .get_known_ephemeral_addresses(account, None)?
939939
/// .into_iter()
940940
/// .find(|(known_addr, _)| known_addr == address)
941-
/// .map(|(_, metadata)| metadata))
941+
/// .map(|(_, metadata)| metadata)
942+
/// })
942943
/// ```
943944
///
944945
/// Returns `Ok(None)` if the address is not recognized, or we do not have metadata for it.
@@ -950,14 +951,16 @@ pub trait WalletRead {
950951
address: &TransparentAddress,
951952
) -> Result<Option<TransparentAddressMetadata>, Self::Error> {
952953
// This should be overridden.
953-
if let Some(result) = self.get_transparent_receivers(account)?.get(address) {
954-
return Ok(result.clone());
955-
}
956-
Ok(self
957-
.get_known_ephemeral_addresses(account, None)?
958-
.into_iter()
959-
.find(|(known_addr, _)| known_addr == address)
960-
.map(|(_, metadata)| metadata))
954+
Ok(
955+
if let Some(result) = self.get_transparent_receivers(account)?.get(address) {
956+
result.clone()
957+
} else {
958+
self.get_known_ephemeral_addresses(account, None)?
959+
.into_iter()
960+
.find(|(known_addr, _)| known_addr == address)
961+
.map(|(_, metadata)| metadata)
962+
},
963+
)
961964
}
962965

963966
/// Returns a vector of ephemeral transparent addresses associated with the given
@@ -1001,7 +1004,7 @@ pub trait WalletRead {
10011004
Ok(vec![])
10021005
}
10031006

1004-
/// If a given transparent address has been reserved, i.e. would be included in
1007+
/// If a given ephemeral address might have been reserved, i.e. would be included in
10051008
/// the map returned by `get_known_ephemeral_addresses(account_id, false)` for any
10061009
/// of the wallet's accounts, then return `Ok(Some(account_id))`. Otherwise return
10071010
/// `Ok(None)`.

zcash_client_backend/src/data_api/wallet/input_selection.rs

+3
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ where
384384
let mut tr1_payments = vec![];
385385
#[cfg(feature = "transparent-inputs")]
386386
let mut tr1_payment_pools = BTreeMap::new();
387+
// this balance value is just used for overflow checking; the actual value of ephemeral
388+
// outputs will be computed from the constructed `tr1_transparent_outputs` value
389+
// constructed below.
387390
#[cfg(feature = "transparent-inputs")]
388391
let mut total_ephemeral = NonNegativeAmount::ZERO;
389392

zcash_client_sqlite/src/wallet/transparent/ephemeral.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub(crate) fn find_index_for_ephemeral_address_str(
187187
Ok(conn
188188
.query_row(
189189
"SELECT address_index FROM ephemeral_addresses
190-
WHERE account_id = :account_id AND address = :address",
190+
WHERE account_id = :account_id AND address = :address",
191191
named_params![":account_id": account_id.0, ":address": &address_str],
192192
|row| row.get::<_, u32>(0),
193193
)

zcash_primitives/src/legacy/keys.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ use super::TransparentAddress;
2121
pub struct TransparentKeyScope(u32);
2222

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

0 commit comments

Comments
 (0)