Merge pull request #844 from zcash/temporary-zcashd-parse-sapling

zcash_primitives: Changes needed for `zcashd` Sapling oxidation
This commit is contained in:
Kris Nuttycombe 2023-05-30 17:30:47 -06:00 committed by GitHub
commit 36d7222685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 2 deletions

View File

@ -6,6 +6,15 @@ 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`
- Implementations of `memuse::DynamicUsage` for the following types:
- `zcash_primitives::transaction::components::sapling`:
- `Bundle<Authorized>`
- `SpendDescription<Authorized>`
### Changed
- MSRV is now 1.65.0.
- Bumped dependencies to `secp256k1 0.26`, `hdwallet 0.4`.

View File

@ -192,6 +192,24 @@ impl<A: Authorization> Bundle<A> {
}
}
impl DynamicUsage for Bundle<Authorized> {
fn dynamic_usage(&self) -> usize {
self.shielded_spends.dynamic_usage() + self.shielded_outputs.dynamic_usage()
}
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
let bounds = (
self.shielded_spends.dynamic_usage_bounds(),
self.shielded_outputs.dynamic_usage_bounds(),
);
(
bounds.0 .0 + bounds.1 .0,
bounds.0 .1.zip(bounds.1 .1).map(|(a, b)| a + b),
)
}
}
#[derive(Clone)]
pub struct SpendDescription<A: Authorization> {
cv: ValueCommitment,
@ -263,6 +281,16 @@ impl<A: Authorization> SpendDescription<A> {
}
}
impl DynamicUsage for SpendDescription<Authorized> {
fn dynamic_usage(&self) -> usize {
self.zkproof.dynamic_usage()
}
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
self.zkproof.dynamic_usage_bounds()
}
}
/// Consensus rules (§4.4) & (§4.5):
/// - Canonical encoding is enforced here.
/// - "Not small order" is enforced here.

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)
})?;