pczt/
roles.rs

1//! Implementations of the PCZT roles.
2//!
3//! The roles currently without an implementation are:
4//! - Constructor (anyone can contribute)
5//!   - Adds spends and outputs to the PCZT.
6//!   - Before any input or output may be added, the constructor must check the
7//!     `Global.tx_modifiable` field. Inputs may only be added if the Inputs Modifiable
8//!     flag is True. Outputs may only be added if the Outputs Modifiable flag is True.
9//!   - A single entity is likely to be both a Creator and Constructor.
10
11pub mod creator;
12
13#[cfg(feature = "io-finalizer")]
14pub mod io_finalizer;
15
16pub mod verifier;
17
18pub mod updater;
19
20pub mod redactor;
21
22#[cfg(feature = "prover")]
23pub mod prover;
24
25#[cfg(feature = "signer")]
26pub mod signer;
27
28pub mod low_level_signer;
29
30pub mod combiner;
31
32#[cfg(feature = "spend-finalizer")]
33pub mod spend_finalizer;
34
35#[cfg(feature = "tx-extractor")]
36pub mod tx_extractor;
37
38#[cfg(test)]
39mod tests {
40    #[cfg(feature = "tx-extractor")]
41    #[test]
42    fn extract_fails_on_empty() {
43        use zcash_protocol::consensus::BranchId;
44
45        use crate::roles::{
46            creator::Creator,
47            tx_extractor::{self, TransactionExtractor},
48        };
49
50        let pczt = Creator::new(BranchId::Nu6.into(), 10_000_000, 133, [0; 32], [0; 32]).build();
51
52        // Extraction fails because we haven't run the IO Finalizer.
53        // Extraction fails in Sapling because we happen to extract it before Orchard.
54        assert!(matches!(
55            TransactionExtractor::new(pczt).extract().unwrap_err(),
56            tx_extractor::Error::Sapling(tx_extractor::SaplingError::Extract(
57                sapling::pczt::TxExtractorError::MissingBindingSignatureSigningKey
58            )),
59        ));
60    }
61
62    #[cfg(feature = "io-finalizer")]
63    #[test]
64    fn io_finalizer_fails_on_empty() {
65        use zcash_protocol::consensus::BranchId;
66
67        use crate::roles::{
68            creator::Creator,
69            io_finalizer::{self, IoFinalizer},
70        };
71
72        let pczt = Creator::new(BranchId::Nu6.into(), 10_000_000, 133, [0; 32], [0; 32]).build();
73
74        // IO finalization fails on spends because we happen to check them first.
75        assert!(matches!(
76            IoFinalizer::new(pczt).finalize_io().unwrap_err(),
77            io_finalizer::Error::NoSpends,
78        ));
79    }
80}