Merge pull request #844 from zcash/temporary-zcashd-parse-sapling
zcash_primitives: Changes needed for `zcashd` Sapling oxidation
This commit is contained in:
commit
36d7222685
|
@ -6,6 +6,15 @@ and this library adheres to Rust's notion of
|
||||||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [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
|
### Changed
|
||||||
- MSRV is now 1.65.0.
|
- MSRV is now 1.65.0.
|
||||||
- Bumped dependencies to `secp256k1 0.26`, `hdwallet 0.4`.
|
- Bumped dependencies to `secp256k1 0.26`, `hdwallet 0.4`.
|
||||||
|
|
|
@ -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)]
|
#[derive(Clone)]
|
||||||
pub struct SpendDescription<A: Authorization> {
|
pub struct SpendDescription<A: Authorization> {
|
||||||
cv: ValueCommitment,
|
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):
|
/// Consensus rules (§4.4) & (§4.5):
|
||||||
/// - Canonical encoding is enforced here.
|
/// - Canonical encoding is enforced here.
|
||||||
/// - "Not small order" is enforced here.
|
/// - "Not small order" is enforced here.
|
||||||
|
|
|
@ -730,6 +730,13 @@ impl Transaction {
|
||||||
Ok((consensus_branch_id, lock_time, expiry_height))
|
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)]
|
#[allow(clippy::redundant_closure)]
|
||||||
fn read_v5_sapling<R: Read>(
|
fn read_v5_sapling<R: Read>(
|
||||||
mut reader: R,
|
mut reader: R,
|
||||||
|
@ -917,8 +924,23 @@ impl Transaction {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_v5_sapling<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
#[cfg(feature = "temporary-zcashd")]
|
||||||
if let Some(bundle) = &self.sapling_bundle {
|
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| {
|
Vector::write(&mut writer, bundle.shielded_spends(), |w, e| {
|
||||||
e.write_v5_without_witness_data(w)
|
e.write_v5_without_witness_data(w)
|
||||||
})?;
|
})?;
|
||||||
|
|
Loading…
Reference in New Issue