Expose less information about Sapling outputs to change calculation.
This commit is contained in:
parent
1be97e9cef
commit
37e78e1fe3
|
@ -82,7 +82,7 @@ pub trait ChangeStrategy {
|
||||||
transparent_inputs: &[impl TransparentInput],
|
transparent_inputs: &[impl TransparentInput],
|
||||||
transparent_outputs: &[TxOut],
|
transparent_outputs: &[TxOut],
|
||||||
sapling_inputs: &[impl SaplingInput],
|
sapling_inputs: &[impl SaplingInput],
|
||||||
sapling_outputs: &[SaplingOutput],
|
sapling_outputs: &[impl SaplingOutput],
|
||||||
) -> Result<TransactionBalance, ChangeError<Self::Error>>;
|
) -> Result<TransactionBalance, ChangeError<Self::Error>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ impl ChangeStrategy for BasicFixedFeeChangeStrategy {
|
||||||
transparent_inputs: &[impl TransparentInput],
|
transparent_inputs: &[impl TransparentInput],
|
||||||
transparent_outputs: &[TxOut],
|
transparent_outputs: &[TxOut],
|
||||||
sapling_inputs: &[impl SaplingInput],
|
sapling_inputs: &[impl SaplingInput],
|
||||||
sapling_outputs: &[SaplingOutput],
|
sapling_outputs: &[impl SaplingOutput],
|
||||||
) -> Result<TransactionBalance, ChangeError<Self::Error>> {
|
) -> Result<TransactionBalance, ChangeError<Self::Error>> {
|
||||||
let overflow = || ChangeError::StrategyError(BalanceError::Overflow);
|
let overflow = || ChangeError::StrategyError(BalanceError::Overflow);
|
||||||
let underflow = || ChangeError::StrategyError(BalanceError::Underflow);
|
let underflow = || ChangeError::StrategyError(BalanceError::Underflow);
|
||||||
|
|
|
@ -21,15 +21,15 @@ and this library adheres to Rust's notion of
|
||||||
- `Builder::sapling_inputs()`
|
- `Builder::sapling_inputs()`
|
||||||
- `Builder::sapling_outputs()`
|
- `Builder::sapling_outputs()`
|
||||||
- `zcash_primitives::transaction::fees` a new module containing abstractions
|
- `zcash_primitives::transaction::fees` a new module containing abstractions
|
||||||
and types related to fee calculations.
|
and types related to fee calculations.
|
||||||
- `FeeRule` a trait that describes how to compute the fee required for a
|
- `FeeRule` a trait that describes how to compute the fee required for a
|
||||||
transaction given inputs and outputs to the transaction.
|
transaction given inputs and outputs to the transaction.
|
||||||
- Added to `zcash_primitives::transaction::components::sapling::builder`
|
- Added to `zcash_primitives::transaction::components::sapling::builder`
|
||||||
- `SaplingInput` a trait that provides a minimized view of a Sapling input suitable
|
- `SaplingInput` a trait that provides a minimized view of a Sapling input suitable
|
||||||
for use in fee computation.
|
for use in change and fee computation.
|
||||||
- The `SaplingOutput` type has been made public, so that it can now be used in fee
|
- `SaplingOutput` a trait that provides a minimized view of a Sapling output suitable
|
||||||
computation.
|
for use in change and fee computation.
|
||||||
- `SaplingBuilder::inputs` and `SaplingBuilder::outputs`: accessors for Sapling
|
- `SaplingBuilder::inputs` and `SaplingBuilder::outputs`: accessors for Sapling
|
||||||
builder state.
|
builder state.
|
||||||
- Added to `zcash_primitives::transaction::components::transparent::builder`
|
- Added to `zcash_primitives::transaction::components::transparent::builder`
|
||||||
- `TransparentInput` a trait that provides a minimized view of a transparent input suitable
|
- `TransparentInput` a trait that provides a minimized view of a transparent input suitable
|
||||||
|
@ -74,9 +74,9 @@ and this library adheres to Rust's notion of
|
||||||
- `ChainCode::as_bytes`
|
- `ChainCode::as_bytes`
|
||||||
- `DiversifierIndex::{as_bytes}`
|
- `DiversifierIndex::{as_bytes}`
|
||||||
- Implementations of `From<u32>` and `From<u64>` for `DiversifierIndex`
|
- Implementations of `From<u32>` and `From<u64>` for `DiversifierIndex`
|
||||||
- `zcash_primitives::zip32::sapling` has been added and now contains
|
- `zcash_primitives::zip32::sapling` has been added and now contains
|
||||||
all of the Sapling zip32 key types that were previously located in
|
all of the Sapling zip32 key types that were previously located in
|
||||||
`zcash_primitives::zip32` directly. The base `zip32` module reexports
|
`zcash_primitives::zip32` directly. The base `zip32` module reexports
|
||||||
the moved types for backwards compatibility.
|
the moved types for backwards compatibility.
|
||||||
- `DiversifierKey::{from_bytes, as_bytes}`
|
- `DiversifierKey::{from_bytes, as_bytes}`
|
||||||
- `ExtendedSpendingKey::{from_bytes, to_bytes}`
|
- `ExtendedSpendingKey::{from_bytes, to_bytes}`
|
||||||
|
|
|
@ -177,7 +177,7 @@ impl<'a, P, R> Builder<'a, P, R> {
|
||||||
|
|
||||||
/// Returns the set of Sapling outputs currently set to be produced by
|
/// Returns the set of Sapling outputs currently set to be produced by
|
||||||
/// the transaction.
|
/// the transaction.
|
||||||
pub fn sapling_outputs(&self) -> &[SaplingOutput] {
|
pub fn sapling_outputs(&self) -> &[impl SaplingOutput] {
|
||||||
self.sapling_builder.outputs()
|
self.sapling_builder.outputs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,13 @@ pub trait SaplingInput {
|
||||||
fn value(&self) -> Amount;
|
fn value(&self) -> Amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A trait that provides a minimized view of a Sapling output suitable for use in
|
||||||
|
/// fee and change calculation.
|
||||||
|
pub trait SaplingOutput {
|
||||||
|
/// The value of the output being produced.
|
||||||
|
fn value(&self) -> Amount;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SpendDescriptionInfo {
|
pub struct SpendDescriptionInfo {
|
||||||
extsk: ExtendedSpendingKey,
|
extsk: ExtendedSpendingKey,
|
||||||
|
@ -87,7 +94,7 @@ impl SaplingInput for SpendDescriptionInfo {
|
||||||
/// A struct containing the information required in order to construct a
|
/// A struct containing the information required in order to construct a
|
||||||
/// Sapling output to a transaction.
|
/// Sapling output to a transaction.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SaplingOutput {
|
struct SaplingOutputInfo {
|
||||||
/// `None` represents the `ovk = ⊥` case.
|
/// `None` represents the `ovk = ⊥` case.
|
||||||
ovk: Option<OutgoingViewingKey>,
|
ovk: Option<OutgoingViewingKey>,
|
||||||
to: PaymentAddress,
|
to: PaymentAddress,
|
||||||
|
@ -95,7 +102,7 @@ pub struct SaplingOutput {
|
||||||
memo: MemoBytes,
|
memo: MemoBytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SaplingOutput {
|
impl SaplingOutputInfo {
|
||||||
fn new_internal<P: consensus::Parameters, R: RngCore>(
|
fn new_internal<P: consensus::Parameters, R: RngCore>(
|
||||||
params: &P,
|
params: &P,
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
|
@ -119,7 +126,7 @@ impl SaplingOutput {
|
||||||
rseed,
|
rseed,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(SaplingOutput {
|
Ok(SaplingOutputInfo {
|
||||||
ovk,
|
ovk,
|
||||||
to,
|
to,
|
||||||
note,
|
note,
|
||||||
|
@ -127,12 +134,6 @@ impl SaplingOutput {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value(&self) -> Amount {
|
|
||||||
// this unwrap is safe because the note's value was initially
|
|
||||||
// constructed from an `Amount`.
|
|
||||||
Amount::from_u64(self.note.value).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build<P: consensus::Parameters, Pr: TxProver, R: RngCore>(
|
fn build<P: consensus::Parameters, Pr: TxProver, R: RngCore>(
|
||||||
self,
|
self,
|
||||||
prover: &Pr,
|
prover: &Pr,
|
||||||
|
@ -173,6 +174,12 @@ impl SaplingOutput {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SaplingOutput for SaplingOutputInfo {
|
||||||
|
fn value(&self) -> Amount {
|
||||||
|
Amount::from_u64(self.note.value).expect("Note values should be checked at construction.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Metadata about a transaction created by a [`SaplingBuilder`].
|
/// Metadata about a transaction created by a [`SaplingBuilder`].
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct SaplingMetadata {
|
pub struct SaplingMetadata {
|
||||||
|
@ -217,7 +224,7 @@ pub struct SaplingBuilder<P> {
|
||||||
target_height: BlockHeight,
|
target_height: BlockHeight,
|
||||||
value_balance: Amount,
|
value_balance: Amount,
|
||||||
spends: Vec<SpendDescriptionInfo>,
|
spends: Vec<SpendDescriptionInfo>,
|
||||||
outputs: Vec<SaplingOutput>,
|
outputs: Vec<SaplingOutputInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -255,7 +262,7 @@ impl<P> SaplingBuilder<P> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the Sapling outputs that will be produced by the transaction being constructed
|
/// Returns the Sapling outputs that will be produced by the transaction being constructed
|
||||||
pub fn outputs(&self) -> &[SaplingOutput] {
|
pub fn outputs(&self) -> &[impl SaplingOutput] {
|
||||||
&self.outputs
|
&self.outputs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +321,7 @@ impl<P: consensus::Parameters> SaplingBuilder<P> {
|
||||||
value: Amount,
|
value: Amount,
|
||||||
memo: MemoBytes,
|
memo: MemoBytes,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let output = SaplingOutput::new_internal(
|
let output = SaplingOutputInfo::new_internal(
|
||||||
&self.params,
|
&self.params,
|
||||||
&mut rng,
|
&mut rng,
|
||||||
self.target_height,
|
self.target_height,
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub trait FeeRule {
|
||||||
transparent_inputs: &[impl TransparentInput],
|
transparent_inputs: &[impl TransparentInput],
|
||||||
transparent_outputs: &[TxOut],
|
transparent_outputs: &[TxOut],
|
||||||
sapling_inputs: &[impl SaplingInput],
|
sapling_inputs: &[impl SaplingInput],
|
||||||
sapling_outputs: &[SaplingOutput],
|
sapling_outputs: &[impl SaplingOutput],
|
||||||
) -> Result<Amount, Self::Error>;
|
) -> Result<Amount, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ pub trait FutureFeeRule: FeeRule {
|
||||||
transparent_inputs: &[impl TransparentInput],
|
transparent_inputs: &[impl TransparentInput],
|
||||||
transparent_outputs: &[TxOut],
|
transparent_outputs: &[TxOut],
|
||||||
sapling_inputs: &[impl SaplingInput],
|
sapling_inputs: &[impl SaplingInput],
|
||||||
sapling_outputs: &[SaplingOutput],
|
sapling_outputs: &[impl SaplingOutput],
|
||||||
tze_inputs: &[impl TzeInput],
|
tze_inputs: &[impl TzeInput],
|
||||||
tze_outputs: &[TzeOut],
|
tze_outputs: &[TzeOut],
|
||||||
) -> Result<Amount, Self::Error>;
|
) -> Result<Amount, Self::Error>;
|
||||||
|
@ -79,7 +79,7 @@ impl FeeRule for FixedFeeRule {
|
||||||
_transparent_inputs: &[impl TransparentInput],
|
_transparent_inputs: &[impl TransparentInput],
|
||||||
_transparent_outputs: &[TxOut],
|
_transparent_outputs: &[TxOut],
|
||||||
_sapling_inputs: &[impl SaplingInput],
|
_sapling_inputs: &[impl SaplingInput],
|
||||||
_sapling_outputs: &[SaplingOutput],
|
_sapling_outputs: &[impl SaplingOutput],
|
||||||
) -> Result<Amount, Self::Error> {
|
) -> Result<Amount, Self::Error> {
|
||||||
Ok(self.fixed_fee)
|
Ok(self.fixed_fee)
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ impl FutureFeeRule for FixedFeeRule {
|
||||||
_transparent_inputs: &[impl TransparentInput],
|
_transparent_inputs: &[impl TransparentInput],
|
||||||
_transparent_outputs: &[TxOut],
|
_transparent_outputs: &[TxOut],
|
||||||
_sapling_inputs: &[impl SaplingInput],
|
_sapling_inputs: &[impl SaplingInput],
|
||||||
_sapling_outputs: &[SaplingOutput],
|
_sapling_outputs: &[impl SaplingOutput],
|
||||||
_tze_inputs: &[impl TzeInput],
|
_tze_inputs: &[impl TzeInput],
|
||||||
_tze_outputs: &[TzeOut],
|
_tze_outputs: &[TzeOut],
|
||||||
) -> Result<Amount, Self::Error> {
|
) -> Result<Amount, Self::Error> {
|
||||||
|
|
Loading…
Reference in New Issue