pczt/roles/redactor/mod.rs
1//! The Redactor role (anyone can execute).
2//!
3//! - Removes information that is unnecessary for subsequent entities to proceed.
4//! - This can be useful e.g. when creating a transaction that has inputs from multiple
5//! independent Signers; each can receive a PCZT with just the information they need
6//! to sign, but (e.g.) not the `alpha` values for other Signers.
7
8use crate::{Pczt, common::Global};
9
10pub mod orchard;
11pub mod sapling;
12pub mod transparent;
13
14pub struct Redactor {
15 pczt: Pczt,
16}
17
18impl Redactor {
19 /// Instantiates the Redactor role with the given PCZT.
20 pub fn new(pczt: Pczt) -> Self {
21 Self { pczt }
22 }
23
24 /// Redacts the global transaction details with the given closure.
25 pub fn redact_global_with<F>(mut self, f: F) -> Self
26 where
27 F: FnOnce(GlobalRedactor<'_>),
28 {
29 f(GlobalRedactor(&mut self.pczt.global));
30 self
31 }
32
33 /// Finishes the Redactor role, returning the redacted PCZT.
34 pub fn finish(self) -> Pczt {
35 self.pczt
36 }
37}
38
39/// An Redactor for the global transaction details.
40pub struct GlobalRedactor<'a>(&'a mut Global);
41
42impl GlobalRedactor<'_> {
43 /// Redacts the proprietary value at the given key.
44 pub fn redact_proprietary(&mut self, key: &str) {
45 self.0.proprietary.remove(key);
46 }
47
48 /// Removes all proprietary values.
49 pub fn clear_proprietary(&mut self) {
50 self.0.proprietary.clear();
51 }
52}