Skip to content

Commit 5bfd5e6

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

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
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_backend/src/fees.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,11 @@ impl Default for DustOutputPolicy {
330330
}
331331
}
332332

333-
/// `EphemeralBalance` describes the ephemeral input or output value for
334-
/// a transaction. It is use in the computation of fees are relevant to transactions using
335-
/// ephemeral transparent outputs.
333+
/// `EphemeralBalance` describes the ephemeral input or output value for a transaction. It is used
334+
/// in fee computation for series of transactions that use an ephemeral transparent output in an
335+
/// intermediate step, such as when sending from a shielded pool to a [ZIP 320] "TEX" address.
336+
///
337+
/// [ZIP 320]: https://zips.z.cash/zip-0320
336338
#[derive(Clone, Debug, PartialEq, Eq)]
337339
pub enum EphemeralBalance {
338340
Input(NonNegativeAmount),
@@ -388,16 +390,12 @@ pub trait ChangeStrategy {
388390
/// inputs from most to least preferred to spend within each pool, so that the most
389391
/// preferred ones are less likely to be indicated to remove.
390392
///
391-
#[cfg_attr(
392-
feature = "transparent-inputs",
393-
doc = "`ephemeral_parameters` can be used to specify variations on how balance
394-
and fees are computed that are relevant to transactions using ephemeral
395-
transparent outputs; see [`EphemeralParameters::new`]."
396-
)]
397-
#[cfg_attr(
398-
not(feature = "transparent-inputs"),
399-
doc = "`ephemeral_parameters` should be set to `&EphemeralParameters::NONE`."
400-
)]
393+
/// - `ephemeral_balance`: if the transaction is to be constructed with either an
394+
/// ephemeral transparent input or an ephemeral transparent output this argument
395+
/// may be used to provide the value of that input or output. The value of this
396+
/// output should be `None` in the case that there are no such items.
397+
///
398+
/// [ZIP 320]: https://zips.z.cash/zip-0320
401399
#[allow(clippy::too_many_arguments)]
402400
fn compute_balance<P: consensus::Parameters, NoteRefT: Clone>(
403401
&self,

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)