Define a constant `EphemeralParameters::NONE` instead of deriving `Default`.

Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira-Emma Hopwood 2024-06-29 01:33:50 +01:00
parent d32b7dbd8f
commit 286439aa96
5 changed files with 31 additions and 16 deletions

View File

@ -70,7 +70,8 @@ funds to those addresses. See [ZIP 320](https://zips.z.cash/zip-0320) for detail
`&EphemeralParameters` parameter when the "transparent-inputs" feature is
enabled. This can be used to specify whether the change memo should be
ignored, and the amounts of additional transparent P2PKH inputs and
outputs. Passing `&Default::default()` will retain the previous behaviour.
outputs. Passing `&EphemeralParameters::NONE` will retain the previous
behaviour.
- `zcash_client_backend::input_selection::GreedyInputSelectorError` has a
new variant `UnsupportedTexAddress`.
- `zcash_client_backend::proto::ProposalDecodingError` has a new variant

View File

@ -462,7 +462,7 @@ where
#[cfg(feature = "transparent-inputs")]
let (ephemeral_parameters, tr1_balance_opt) = {
if tr1_transparent_outputs.is_empty() {
(Default::default(), None)
(EphemeralParameters::NONE, None)
} else {
// The ephemeral input going into transaction 1 must be able to pay that
// transaction's fee, as well as the TEX address payments.
@ -772,7 +772,7 @@ where
&orchard_fees::EmptyBundleView,
&self.dust_output_policy,
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
let balance = match trial_balance {
@ -791,7 +791,7 @@ where
&orchard_fees::EmptyBundleView,
&self.dust_output_policy,
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
)?
}
Err(other) => {

View File

@ -334,7 +334,7 @@ impl Default for DustOutputPolicy {
/// and fees are computed that are relevant to transactions using ephemeral
/// transparent outputs.
#[cfg(feature = "transparent-inputs")]
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct EphemeralParameters {
ignore_change_memo: bool,
ephemeral_input_amount: Option<NonNegativeAmount>,
@ -343,6 +343,14 @@ pub struct EphemeralParameters {
#[cfg(feature = "transparent-inputs")]
impl EphemeralParameters {
/// An `EphemeralParameters` indicating no use of ephemeral inputs
/// or outputs. It has:
///
/// * `ignore_change_memo: false`,
/// * `ephemeral_input_amount: None`,
/// * `ephemeral_output_amount: None`.
pub const NONE: Self = Self::new(false, None, None);
/// Returns an `EphemeralParameters` with the following parameters:
///
/// * `ignore_change_memo`: `true` if the change memo should be
@ -352,7 +360,7 @@ impl EphemeralParameters {
/// additional P2PKH input of the given amount.
/// * `ephemeral_output_amount`: specifies that there will be an
/// additional P2PKH output of the given amount.
pub fn new(
pub const fn new(
ignore_change_memo: bool,
ephemeral_input_amount: Option<NonNegativeAmount>,
ephemeral_output_amount: Option<NonNegativeAmount>,

View File

@ -109,6 +109,9 @@ mod tests {
ShieldedProtocol,
};
#[cfg(feature = "transparent-inputs")]
use crate::fees::EphemeralParameters;
#[cfg(feature = "orchard")]
use crate::fees::orchard as orchard_fees;
@ -141,7 +144,7 @@ mod tests {
&orchard_fees::EmptyBundleView,
&DustOutputPolicy::default(),
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
assert_matches!(
@ -188,7 +191,7 @@ mod tests {
&orchard_fees::EmptyBundleView,
&DustOutputPolicy::default(),
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
assert_matches!(

View File

@ -116,6 +116,9 @@ mod tests {
ShieldedProtocol,
};
#[cfg(feature = "transparent-inputs")]
use crate::fees::EphemeralParameters;
#[cfg(feature = "orchard")]
use {
crate::data_api::wallet::input_selection::OrchardPayment,
@ -152,7 +155,7 @@ mod tests {
&orchard_fees::EmptyBundleView,
&DustOutputPolicy::default(),
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
assert_matches!(
@ -197,7 +200,7 @@ mod tests {
),
&DustOutputPolicy::default(),
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
assert_matches!(
@ -251,7 +254,7 @@ mod tests {
&orchard_fees::EmptyBundleView,
dust_output_policy,
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
assert_matches!(
@ -296,7 +299,7 @@ mod tests {
&orchard_fees::EmptyBundleView,
&DustOutputPolicy::default(),
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
assert_matches!(
@ -341,7 +344,7 @@ mod tests {
&orchard_fees::EmptyBundleView,
&DustOutputPolicy::default(),
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
assert_matches!(
@ -392,7 +395,7 @@ mod tests {
Some(NonNegativeAmount::const_from_u64(1000)),
),
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
assert_matches!(
@ -454,7 +457,7 @@ mod tests {
&orchard_fees::EmptyBundleView,
dust_output_policy,
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
assert_matches!(
@ -506,7 +509,7 @@ mod tests {
&orchard_fees::EmptyBundleView,
&DustOutputPolicy::default(),
#[cfg(feature = "transparent-inputs")]
&Default::default(),
&EphemeralParameters::NONE,
);
// We will get an error here, because the dust input isn't free to add