Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pczt/tests/end_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn transparent_to_orchard() {
},
);
builder
.add_transparent_input(transparent_pubkey, utxo, coin.clone())
.add_transparent_p2pkh_input(transparent_pubkey, utxo, coin.clone())
.unwrap();
builder
.add_orchard_output::<zip317::FeeRule>(
Expand Down
4 changes: 4 additions & 0 deletions zcash_client_backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ workspace.
- `LightdInfo` has added fields `upgrade_name`, `upgrade_height`, and `lighwallet_protocol_version`
- `GetMempoolTxRequest` (previously named `Exclude`) has added field `pool_types`
- `impl From<zcash_client_backend::proposal::ProposalError> for zcash_client_backend::data_api::wallet::input_selection::InputSelectorError<...>`
- `zcash_client_backend::fees::MetaSource`

### Changed
- Migrated to `orchard 0.12`, `sapling-crypto 0.6`, `zip321 0.7`
Expand Down Expand Up @@ -51,6 +52,9 @@ workspace.
IVK.
- `zcash_client_backend::data_api::WalletRead` has added method `get_received_outputs`.
- `zcash_client_backend::proposal::ProposalError` has added variant `PaymentAmountMissing`
- The associated type `zcash_client_backend::fees::ChangeStrategy::MetaSource` is now
bounded on the newly added `MetaSource` type instead of
`zcash_client_backend::data_api::InputSource`.

## [0.21.0] - 2025-11-05

Expand Down
8 changes: 4 additions & 4 deletions zcash_client_backend/src/data_api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ where
#[cfg(feature = "transparent-inputs")]
let utxos_spent = {
let mut utxos_spent: Vec<OutPoint> = vec![];
let mut add_transparent_input =
let mut add_transparent_p2pkh_input =
|builder: &mut Builder<_, _>,
utxos_spent: &mut Vec<_>,
recipient_address: &TransparentAddress,
Expand All @@ -1320,13 +1320,13 @@ where
};

utxos_spent.push(outpoint.clone());
builder.add_transparent_input(pubkey, outpoint, txout)?;
builder.add_transparent_p2pkh_input(pubkey, outpoint, txout)?;

Ok(())
};

for utxo in proposal_step.transparent_inputs() {
add_transparent_input(
add_transparent_p2pkh_input(
&mut builder,
&mut utxos_spent,
utxo.recipient_address(),
Expand All @@ -1349,7 +1349,7 @@ where
.ok_or(ProposalError::ReferenceError(*input_ref))?
.vout[outpoint.n() as usize];

add_transparent_input(
add_transparent_p2pkh_input(
&mut builder,
&mut utxos_spent,
&address,
Expand Down
40 changes: 32 additions & 8 deletions zcash_client_backend/src/fees.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
convert::Infallible,
fmt::{self, Debug, Display},
num::{NonZeroU64, NonZeroUsize},
};
Expand Down Expand Up @@ -483,18 +484,41 @@ impl EphemeralBalance {
}
}

/// A trait that defines a set of types used in wallet metadata retrieval. Ordinarily, this will
/// correspond to a type that implements [`InputSource`], and a blanket implementation of this
/// trait is provided for all types that implement [`InputSource`].
///
/// If more capabilities are required of the backend than are exposed in the [`InputSource`] trait,
/// the implementer of this trait should define their own trait that descends from [`InputSource`]
/// and adds the required capabilities there, and then implement that trait for their desired
/// database backend.
pub trait MetaSource {
type Error;
type AccountId;
type NoteRef;
}

impl MetaSource for Infallible {
type Error = Infallible;
type AccountId = Infallible;
type NoteRef = Infallible;
}

impl<I: InputSource> MetaSource for I {
type Error = I::Error;
type AccountId = I::AccountId;
type NoteRef = I::NoteRef;
}

/// A trait that represents the ability to compute the suggested change and fees that must be paid
/// by a transaction having a specified set of inputs and outputs.
pub trait ChangeStrategy {
type FeeRule: FeeRule + Clone;
type Error: From<<Self::FeeRule as FeeRule>::Error>;

/// The type of metadata source that this change strategy requires in order to be able to
/// retrieve required wallet metadata. If more capabilities are required of the backend than
/// are exposed in the [`InputSource`] trait, the implementer of this trait should define their
/// own trait that descends from [`InputSource`] and adds the required capabilities there, and
/// then implement that trait for their desired database backend.
type MetaSource: InputSource;
/// retrieve required wallet metadata.
type MetaSource: MetaSource;

/// Tye type of wallet metadata that this change strategy relies upon in order to compute
/// change.
Expand All @@ -509,10 +533,10 @@ pub trait ChangeStrategy {
fn fetch_wallet_meta(
&self,
meta_source: &Self::MetaSource,
account: <Self::MetaSource as InputSource>::AccountId,
account: <Self::MetaSource as MetaSource>::AccountId,
target_height: TargetHeight,
exclude: &[<Self::MetaSource as InputSource>::NoteRef],
) -> Result<Self::AccountMetaT, <Self::MetaSource as InputSource>::Error>;
exclude: &[<Self::MetaSource as MetaSource>::NoteRef],
) -> Result<Self::AccountMetaT, <Self::MetaSource as MetaSource>::Error>;

/// Computes the totals of inputs, suggested change amounts, and fees given the
/// provided inputs and outputs being used to construct a transaction.
Expand Down
10 changes: 5 additions & 5 deletions zcash_client_backend/src/fees/zip317.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
};

use super::{
ChangeError, ChangeStrategy, DustOutputPolicy, EphemeralBalance, SplitPolicy,
ChangeError, ChangeStrategy, DustOutputPolicy, EphemeralBalance, MetaSource, SplitPolicy,
TransactionBalance,
common::{SinglePoolBalanceConfig, single_pool_output_balance},
sapling as sapling_fees,
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<R, I> SingleOutputChangeStrategy<R, I> {
impl<R, I> ChangeStrategy for SingleOutputChangeStrategy<R, I>
where
R: Zip317FeeRule + Clone,
I: InputSource,
I: MetaSource,
<R as FeeRule>::Error: From<BalanceError>,
{
type FeeRule = R;
Expand All @@ -110,10 +110,10 @@ where
fn fetch_wallet_meta(
&self,
_meta_source: &Self::MetaSource,
_account: <Self::MetaSource as InputSource>::AccountId,
_account: <Self::MetaSource as MetaSource>::AccountId,
_target_height: TargetHeight,
_exclude: &[<Self::MetaSource as InputSource>::NoteRef],
) -> Result<Self::AccountMetaT, <Self::MetaSource as InputSource>::Error> {
_exclude: &[<Self::MetaSource as MetaSource>::NoteRef],
) -> Result<Self::AccountMetaT, <Self::MetaSource as MetaSource>::Error> {
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ mod tests {
);
let mut transparent_signing_set = TransparentSigningSet::new();
builder
.add_transparent_input(
.add_transparent_p2pkh_input(
transparent_signing_set.add_key(
usk0.transparent()
.derive_external_secret_key(NonHardenedChildIndex::ZERO)
Expand Down
4 changes: 4 additions & 0 deletions zcash_primitives/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ workspace.
### Added
- `zcash_primitives::transaction::builder`:
- `impl<FE> From<coinbase::Error> for Error<FE>`
- `Builder::add_transparent_p2pkh_input`

### Changed
- MSRV is now 1.85.1.
Expand All @@ -21,6 +22,9 @@ workspace.
- `Error` has a new `Coinbase` variant.
- `Builder::add_orchard_output`'s `value` parameter now has type `Zatoshis`
instead of `u64`.
- `Builder::add_transparent_input` now takes a `zcash_transparent::builder::TransparentInputInfo`
instead of its constituent parts. Use `Builder::add_transparent_p2pkh_input` if you need the
previous API.
- `BuildConfig`:
- The `Coinbase` variant now includes an `Option<zcash_script::opcode::PushValue>` payload.
- No longer implements `Copy`.
Expand Down
12 changes: 9 additions & 3 deletions zcash_primitives/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,21 @@ impl<P: consensus::Parameters, U> Builder<'_, P, U> {
.map_err(Error::SaplingBuild)
}

/// Adds a transparent coin to be spent in this transaction.
#[cfg(feature = "transparent-inputs")]
pub fn add_transparent_input(&mut self, input: TransparentInputInfo) {
self.transparent_builder.add_input(input)
}

/// Adds a transparent P2PKH coin to be spent in this transaction.
#[cfg(feature = "transparent-inputs")]
pub fn add_transparent_input(
pub fn add_transparent_p2pkh_input(
&mut self,
pubkey: secp256k1::PublicKey,
utxo: transparent::bundle::OutPoint,
coin: TxOut,
) -> Result<(), transparent::builder::Error> {
self.transparent_builder.add_input(pubkey, utxo, coin)
self.transparent_builder.add_p2pkh_input(pubkey, utxo, coin)
}

/// Adds a transparent P2SH coin to be spent in this transaction.
Expand Down Expand Up @@ -1383,7 +1389,7 @@ mod tests {
.into(),
);
builder
.add_transparent_input(pubkey, OutPoint::fake(), prev_coin)
.add_transparent_p2pkh_input(pubkey, OutPoint::fake(), prev_coin)
.unwrap();

// Create a tx with only t output. No binding_sig should be present
Expand Down
6 changes: 6 additions & 0 deletions zcash_transparent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ workspace.
- `impl core::error::Error` for:
-` zcash_transparent::builder::Error`
- `zcash_transparent::coinbase::Error`
- `zcash_transparent::builder::SpendInfo`
- `zcash_transparent::builder::TransparentInputInfo::{from_parts, spend_info}`
- `zcash_transparent::builder::Builder::add_p2pkh_input`

### Changed
- MSRV is now 1.85.1.
Expand All @@ -25,6 +28,9 @@ workspace.
- `InvalidExternalSignature`
- `MissingPreimage`
- `UnsupportedPubkey`
- `zcash_transparent::builder::Builder::add_input` now takes a `TransparentInputInfo`
instead of its constituent parts. Use `Builder::add_p2pkh_input` if you need the
previous API.

## [0.6.3] - 2025-12-17

Expand Down
Loading
Loading