Skip to main content

pczt/roles/prover/
mod.rs

1//! The Prover role (capability holders can contribute).
2//!
3//! - Needs all private information for a single spend or output.
4//! - In practice, the Updater that adds a given spend or output will either act as
5//!   the Prover themselves, or add the necessary data, offload to the Prover, and
6//!   then receive back the PCZT with private data stripped and proof added.
7
8use crate::Pczt;
9
10#[cfg(feature = "orchard")]
11mod orchard;
12#[cfg(feature = "orchard")]
13pub use orchard::OrchardError;
14
15#[cfg(feature = "sapling")]
16mod sapling;
17#[cfg(feature = "sapling")]
18pub use sapling::SaplingError;
19
20pub struct Prover {
21    pczt: Pczt,
22}
23
24impl Prover {
25    /// Instantiates the Prover role with the given PCZT.
26    pub fn new(pczt: Pczt) -> Self {
27        Self { pczt }
28    }
29
30    /// Returns `true` if this PCZT contains Sapling Spends or Outputs that are missing
31    /// proofs.
32    pub fn requires_sapling_proofs(&self) -> bool {
33        let sapling_bundle = self.pczt.sapling();
34
35        sapling_bundle.spends().iter().any(|s| s.zkproof.is_none())
36            || sapling_bundle.outputs().iter().any(|o| o.zkproof.is_none())
37    }
38
39    /// Returns `true` if this PCZT contains Orchard Actions but no Orchard proof.
40    pub fn requires_orchard_proof(&self) -> bool {
41        !self.pczt.orchard().actions().is_empty() && self.pczt.orchard().zkproof.is_none()
42    }
43
44    /// Returns `true` if this PCZT contains Ironwood Actions but no Ironwood proof.
45    pub fn requires_ironwood_proof(&self) -> bool {
46        !self.pczt.ironwood().actions().is_empty() && self.pczt.ironwood().zkproof.is_none()
47    }
48
49    /// Finishes the Prover role, returning the updated PCZT.
50    pub fn finish(self) -> Pczt {
51        self.pczt
52    }
53}