pczt/roles/verifier/
orchard.rs1use crate::{Pczt, common::AnchorRequirement};
2
3impl super::Verifier {
4 pub fn with_orchard<E, F>(self, f: F) -> Result<Self, OrchardError<E>>
6 where
7 F: FnOnce(&orchard::pczt::Bundle) -> Result<(), OrchardError<E>>,
8 {
9 let Pczt {
10 global,
11 transparent,
12 sapling,
13 orchard,
14 ironwood,
15 } = self.pczt;
16 let anchor_requirement = AnchorRequirement::for_pre_authorization(global.tx_version);
17
18 let parsed = orchard
19 .into_parsed_with_version(
20 crate::orchard::orchard_bundle_version(&global)
21 .ok_or(OrchardError::UnsupportedConsensusBranchId)?,
22 anchor_requirement,
23 )
24 .map_err(OrchardError::Parse)?;
25
26 f(&parsed.bundle)?;
27
28 Ok(Self {
29 pczt: Pczt {
30 global,
31 transparent,
32 sapling,
33 orchard: parsed.reserialize(),
34 ironwood,
35 },
36 })
37 }
38
39 pub fn with_ironwood<E, F>(self, f: F) -> Result<Self, OrchardError<E>>
41 where
42 F: FnOnce(&orchard::pczt::Bundle) -> Result<(), OrchardError<E>>,
43 {
44 let Pczt {
45 global,
46 transparent,
47 sapling,
48 orchard,
49 ironwood,
50 } = self.pczt;
51 let anchor_requirement = AnchorRequirement::for_pre_authorization(global.tx_version);
52
53 let parsed = ironwood
54 .into_ironwood_parsed(anchor_requirement)
55 .map_err(OrchardError::Parse)?;
56
57 f(&parsed.bundle)?;
58
59 Ok(Self {
60 pczt: Pczt {
61 global,
62 transparent,
63 sapling,
64 orchard,
65 ironwood: parsed.reserialize(),
66 },
67 })
68 }
69}
70
71#[derive(Debug)]
73pub enum OrchardError<E> {
74 Parse(crate::orchard::ParseError),
75 UnsupportedConsensusBranchId,
78 Verify(orchard::pczt::VerifyError),
79 Custom(E),
80}
81
82impl<E> From<orchard::pczt::VerifyError> for OrchardError<E> {
83 fn from(e: orchard::pczt::VerifyError) -> Self {
84 OrchardError::Verify(e)
85 }
86}