pczt: Add the Spend Finalizer role
This commit is contained in:
parent
318254cc5c
commit
60961433ce
|
@ -56,4 +56,5 @@ zcp-builder = ["dep:zcash_primitives", "dep:zcash_protocol"]
|
|||
io-finalizer = ["orchard", "sapling"]
|
||||
prover = ["dep:rand_core", "sapling?/temporary-zcashd"]
|
||||
signer = ["dep:blake2b_simd", "dep:rand_core", "orchard", "sapling", "transparent"]
|
||||
spend-finalizer = ["transparent"]
|
||||
tx-extractor = ["dep:rand_core", "orchard", "sapling", "transparent"]
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
//! - A source of randomness.
|
||||
//! - Combiner (anyone can execute)
|
||||
//! - Combines several PCZTs that represent the same transaction into a single PCZT.
|
||||
//! - Spend Finalizer (anyone can execute)
|
||||
//! - Combines partial transparent signatures into `script_sig`s.
|
||||
//! - Transaction Extractor (anyone can execute)
|
||||
//! - Creates bindingSig and extracts the final transaction.
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@ pub mod signer;
|
|||
|
||||
pub mod combiner;
|
||||
|
||||
#[cfg(feature = "spend-finalizer")]
|
||||
pub mod spend_finalizer;
|
||||
|
||||
#[cfg(feature = "tx-extractor")]
|
||||
pub mod tx_extractor;
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
use zcash_primitives::transaction::components::transparent;
|
||||
|
||||
use crate::Pczt;
|
||||
|
||||
pub struct SpendFinalizer {
|
||||
pczt: Pczt,
|
||||
}
|
||||
|
||||
impl SpendFinalizer {
|
||||
/// Instantiates the Spend Finalizer role with the given PCZT.
|
||||
pub fn new(pczt: Pczt) -> Self {
|
||||
Self { pczt }
|
||||
}
|
||||
|
||||
/// Finalizes the spends of the PCZT.
|
||||
pub fn finalize_spends(self) -> Result<Pczt, Error> {
|
||||
let Pczt {
|
||||
global,
|
||||
transparent,
|
||||
sapling,
|
||||
orchard,
|
||||
} = self.pczt;
|
||||
|
||||
let mut transparent = transparent.into_parsed().map_err(Error::TransparentParse)?;
|
||||
|
||||
transparent
|
||||
.finalize_spends()
|
||||
.map_err(Error::TransparentFinalize)?;
|
||||
|
||||
Ok(Pczt {
|
||||
global,
|
||||
transparent: crate::transparent::Bundle::serialize_from(transparent),
|
||||
sapling,
|
||||
orchard,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Errors that can occur while finalizing the spends of a PCZT.
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
TransparentFinalize(transparent::pczt::SpendFinalizerError),
|
||||
TransparentParse(transparent::pczt::ParseError),
|
||||
}
|
Loading…
Reference in New Issue