Skip to content

Commit 24b6d50

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

File tree

6 files changed

+43
-37
lines changed

6 files changed

+43
-37
lines changed

zcash_client_backend/src/data_api.rs

+21-17
Original file line numberDiff line numberDiff line change
@@ -931,14 +931,16 @@ 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
938-
/// .get_known_ephemeral_addresses(account, None)?
939-
/// .into_iter()
940-
/// .find(|(known_addr, _)| known_addr == address)
941-
/// .map(|(_, metadata)| metadata))
934+
/// Ok(
935+
/// if let Some(result) = self.get_transparent_receivers(account)?.get(address) {
936+
/// result.clone()
937+
/// } else {
938+
/// self.get_known_ephemeral_addresses(account, None)?
939+
/// .into_iter()
940+
/// .find(|(known_addr, _)| known_addr == address)
941+
/// .map(|(_, metadata)| metadata)
942+
/// },
943+
/// )
942944
/// ```
943945
///
944946
/// Returns `Ok(None)` if the address is not recognized, or we do not have metadata for it.
@@ -950,14 +952,16 @@ pub trait WalletRead {
950952
address: &TransparentAddress,
951953
) -> Result<Option<TransparentAddressMetadata>, Self::Error> {
952954
// 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))
955+
Ok(
956+
if let Some(result) = self.get_transparent_receivers(account)?.get(address) {
957+
result.clone()
958+
} else {
959+
self.get_known_ephemeral_addresses(account, None)?
960+
.into_iter()
961+
.find(|(known_addr, _)| known_addr == address)
962+
.map(|(_, metadata)| metadata)
963+
},
964+
)
961965
}
962966

963967
/// Returns a vector of ephemeral transparent addresses associated with the given
@@ -1001,7 +1005,7 @@ pub trait WalletRead {
10011005
Ok(vec![])
10021006
}
10031007

1004-
/// If a given transparent address has been reserved, i.e. would be included in
1008+
/// If a given ephemeral address might have been reserved, i.e. would be included in
10051009
/// the map returned by `get_known_ephemeral_addresses(account_id, false)` for any
10061010
/// of the wallet's accounts, then return `Ok(Some(account_id))`. Otherwise return
10071011
/// `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_backend/src/fees/zip317.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl ChangeStrategy for SingleOutputChangeStrategy {
6767
sapling: &impl sapling_fees::BundleView<NoteRefT>,
6868
#[cfg(feature = "orchard")] orchard: &impl orchard_fees::BundleView<NoteRefT>,
6969
dust_output_policy: &DustOutputPolicy,
70-
ephemeral_parameters: Option<&EphemeralBalance>,
70+
ephemeral_balance: Option<&EphemeralBalance>,
7171
) -> Result<TransactionBalance, ChangeError<Self::Error, NoteRefT>> {
7272
single_change_output_balance(
7373
params,
@@ -84,7 +84,7 @@ impl ChangeStrategy for SingleOutputChangeStrategy {
8484
self.fallback_change_pool,
8585
self.fee_rule.marginal_fee(),
8686
self.fee_rule.grace_actions(),
87-
ephemeral_parameters,
87+
ephemeral_balance,
8888
)
8989
}
9090
}

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)