Add identity `MapAuth` implementations

This commit is contained in:
Jack Grigg 2022-11-09 04:50:04 +00:00
parent d65a3fe84f
commit 69665b9284
3 changed files with 52 additions and 2 deletions

View File

@ -31,8 +31,13 @@ and this library adheres to Rust's notion of
fee rule.
- `zip317`, a new module containing an implementation of the ZIP 317 fee
rules.
- Added to `zcash_primitives::transaction::components::sapling::builder`
- `SaplingBuilder::{inputs, outputs}`: accessors for Sapling builder state.
- Added to `zcash_primitives::transaction::components::orchard`:
- `impl MapAuth<orchard::bundle::Authorized, orchard::bundle::Authorized> for ()`
(the identity map).
- Added to `zcash_primitives::transaction::components::sapling`:
- `impl MapAuth<Authorized, Authorized> for ()` (the identity map).
- `builder::SaplingBuilder::{inputs, outputs}`: accessors for Sapling builder
state.
- `zcash_primitives::transaction::components::sapling::fees`
- Added to `zcash_primitives::transaction::components::transparent::builder`
- `TransparentBuilder::{inputs, outputs}`: accessors for transparent builder state.

View File

@ -33,6 +33,25 @@ pub trait MapAuth<A: Authorization, B: Authorization> {
fn map_authorization(&self, a: A) -> B;
}
/// The identity map.
///
/// This can be used with [`TransactionData::map_authorization`] when you want to map the
/// authorization of a subset of the transaction's bundles.
///
/// [`TransactionData::map_authorization`]: crate::transaction::TransactionData::map_authorization
impl MapAuth<Authorized, Authorized> for () {
fn map_spend_auth(
&self,
s: <Authorized as Authorization>::SpendAuth,
) -> <Authorized as Authorization>::SpendAuth {
s
}
fn map_authorization(&self, a: Authorized) -> Authorized {
a
}
}
/// Reads an [`orchard::Bundle`] from a v5 transaction format.
pub fn read_v5_bundle<R: Read>(
mut reader: R,

View File

@ -55,6 +55,32 @@ pub trait MapAuth<A: Authorization, B: Authorization> {
fn map_authorization(&self, a: A) -> B;
}
/// The identity map.
///
/// This can be used with [`TransactionData::map_authorization`] when you want to map the
/// authorization of a subset of the transaction's bundles.
///
/// [`TransactionData::map_authorization`]: crate::transaction::TransactionData::map_authorization
impl MapAuth<Authorized, Authorized> for () {
fn map_proof(
&self,
p: <Authorized as Authorization>::Proof,
) -> <Authorized as Authorization>::Proof {
p
}
fn map_auth_sig(
&self,
s: <Authorized as Authorization>::AuthSig,
) -> <Authorized as Authorization>::AuthSig {
s
}
fn map_authorization(&self, a: Authorized) -> Authorized {
a
}
}
#[derive(Debug, Clone)]
pub struct Bundle<A: Authorization> {
pub shielded_spends: Vec<SpendDescription<A>>,