zcash_primitives: Temporarily expose v5 Sapling bundle parsing

This is currently exposed via `Transaction` for usage in `zcashd`, but
may be removed in future (if `zcashd` moves transaction parsing entirely
into Rust), or renamed and stabilised.
This commit is contained in:
Jack Grigg 2023-04-26 14:06:52 +00:00
parent 62bc15ccf0
commit 26d95b4a0e
2 changed files with 29 additions and 2 deletions

View File

@ -6,6 +6,11 @@ and this library adheres to Rust's notion of
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- `zcash_primitives::transaction`:
- `Transaction::temporary_zcashd_read_v5_sapling`
- `Transaction::temporary_zcashd_write_v5_sapling`
### Changed
- Bumped dependencies to `secp256k1 0.26`, `hdwallet 0.4`.
- `zcash_primitives::transactions::component::amount::DEFAULT_FEE` increased zip317

View File

@ -730,6 +730,13 @@ impl Transaction {
Ok((consensus_branch_id, lock_time, expiry_height))
}
#[cfg(feature = "temporary-zcashd")]
pub fn temporary_zcashd_read_v5_sapling<R: Read>(
reader: R,
) -> io::Result<Option<sapling::Bundle<sapling::Authorized>>> {
Self::read_v5_sapling(reader)
}
#[allow(clippy::redundant_closure)]
fn read_v5_sapling<R: Read>(
mut reader: R,
@ -917,8 +924,23 @@ impl Transaction {
Ok(())
}
pub fn write_v5_sapling<W: Write>(&self, mut writer: W) -> io::Result<()> {
if let Some(bundle) = &self.sapling_bundle {
#[cfg(feature = "temporary-zcashd")]
pub fn temporary_zcashd_write_v5_sapling<W: Write>(
sapling_bundle: Option<&sapling::Bundle<sapling::Authorized>>,
writer: W,
) -> io::Result<()> {
Self::write_v5_sapling_inner(sapling_bundle, writer)
}
pub fn write_v5_sapling<W: Write>(&self, writer: W) -> io::Result<()> {
Self::write_v5_sapling_inner(self.sapling_bundle.as_ref(), writer)
}
fn write_v5_sapling_inner<W: Write>(
sapling_bundle: Option<&sapling::Bundle<sapling::Authorized>>,
mut writer: W,
) -> io::Result<()> {
if let Some(bundle) = sapling_bundle {
Vector::write(&mut writer, bundle.shielded_spends(), |w, e| {
e.write_v5_without_witness_data(w)
})?;