pczt/roles/redactor/
orchard.rs1use crate::orchard::{Action, Bundle, EncCiphertext, MEMO_SIZE, MemoPlaintext};
2
3impl super::Redactor {
4 pub fn redact_orchard_with<F>(mut self, f: F) -> Self
6 where
7 F: FnOnce(OrchardRedactor<'_>),
8 {
9 f(OrchardRedactor(&mut self.pczt.orchard));
10 self
11 }
12
13 pub fn redact_ironwood_with<F>(mut self, f: F) -> Self
14 where
15 F: FnOnce(OrchardRedactor<'_>),
16 {
17 f(OrchardRedactor(&mut self.pczt.ironwood));
18 self
19 }
20}
21
22pub struct OrchardRedactor<'a>(&'a mut Bundle);
24
25impl OrchardRedactor<'_> {
26 #[cfg(feature = "orchard")]
39 pub fn compact_resolvable_fields(&mut self) {
40 let note_version = self.0.note_version;
41 self.redact_actions(|mut action| {
42 action.redact(|action| action.compact_resolvable_fields(note_version));
43 });
44 }
45
46 pub fn redact_actions<F>(&mut self, f: F)
48 where
49 F: FnOnce(ActionRedactor<'_>),
50 {
51 f(ActionRedactor(Actions::All(&mut self.0.actions)));
52 }
53
54 pub fn redact_action<F>(&mut self, index: usize, f: F)
58 where
59 F: FnOnce(ActionRedactor<'_>),
60 {
61 if let Some(action) = self.0.actions.get_mut(index) {
62 f(ActionRedactor(Actions::One(action)));
63 }
64 }
65
66 pub fn clear_zkproof(&mut self) {
68 self.0.zkproof = None;
69 }
70
71 pub fn clear_bsk(&mut self) {
73 self.0.bsk = None;
74 }
75
76 pub fn clear_anchor(&mut self) {
81 self.0.anchor = None;
82 }
83}
84
85pub struct ActionRedactor<'a>(Actions<'a>);
87
88enum Actions<'a> {
89 All(&'a mut [Action]),
90 One(&'a mut Action),
91}
92
93impl ActionRedactor<'_> {
94 fn redact<F>(&mut self, f: F)
95 where
96 F: Fn(&mut Action),
97 {
98 match &mut self.0 {
99 Actions::All(actions) => {
100 for action in actions.iter_mut() {
101 f(action);
102 }
103 }
104 Actions::One(action) => {
105 f(action);
106 }
107 }
108 }
109
110 pub fn clear_cv_net(&mut self) {
114 self.redact(|action| {
115 action.cv_net = None;
116 });
117 }
118
119 pub fn clear_cmx(&mut self) {
124 self.redact(|action| {
125 action.output.cmx = None;
126 });
127 }
128
129 pub fn clear_spend_auth_sig(&mut self) {
131 self.redact(|action| {
132 action.spend.spend_auth_sig = None;
133 });
134 }
135
136 pub fn clear_spend_recipient(&mut self) {
138 self.redact(|action| {
139 action.spend.recipient = None;
140 });
141 }
142
143 pub fn clear_spend_value(&mut self) {
145 self.redact(|action| {
146 action.spend.value = None;
147 });
148 }
149
150 pub fn clear_spend_rho(&mut self) {
152 self.redact(|action| {
153 action.spend.rho = None;
154 });
155 }
156
157 pub fn clear_spend_rseed(&mut self) {
159 self.redact(|action| {
160 action.spend.rseed = None;
161 });
162 }
163
164 pub fn clear_spend_fvk(&mut self) {
166 self.redact(|action| {
167 action.spend.fvk = None;
168 });
169 }
170
171 pub fn clear_spend_witness(&mut self) {
173 self.redact(|action| {
174 action.spend.witness = None;
175 });
176 }
177
178 pub fn clear_spend_alpha(&mut self) {
180 self.redact(|action| {
181 action.spend.alpha = None;
182 });
183 }
184
185 pub fn clear_spend_zip32_derivation(&mut self) {
188 self.redact(|action| {
189 action.spend.zip32_derivation = None;
190 });
191 }
192
193 pub fn clear_spend_dummy_sk(&mut self) {
195 self.redact(|action| {
196 action.spend.dummy_sk = None;
197 });
198 }
199
200 pub fn redact_spend_proprietary(&mut self, key: &str) {
202 self.redact(|action| {
203 action.spend.proprietary.remove(key);
204 });
205 }
206
207 pub fn clear_spend_proprietary(&mut self) {
209 self.redact(|action| {
210 action.spend.proprietary.clear();
211 });
212 }
213
214 pub fn replace_enc_ciphertext_with_memo_plaintext(&mut self, memo: [u8; MEMO_SIZE]) {
221 self.redact(|action| {
222 action.output.enc_ciphertext =
223 EncCiphertext::MemoPlaintext(MemoPlaintext::from_memo(memo));
224 });
225 }
226
227 #[cfg(feature = "orchard")]
233 pub fn replace_enc_ciphertext_with_decrypted_memo_plaintext(
234 &mut self,
235 note_version: ::orchard::note::NoteVersion,
236 ) {
237 self.redact(|action| {
238 action.replace_enc_ciphertext_with_decrypted_memo_plaintext(note_version);
239 });
240 }
241
242 pub fn clear_output_recipient(&mut self) {
244 self.redact(|action| {
245 action.output.recipient = None;
246 });
247 }
248
249 pub fn clear_output_value(&mut self) {
251 self.redact(|action| {
252 action.output.value = None;
253 });
254 }
255
256 pub fn clear_output_rseed(&mut self) {
258 self.redact(|action| {
259 action.output.rseed = None;
260 });
261 }
262
263 pub fn clear_output_ock(&mut self) {
265 self.redact(|action| {
266 action.output.ock = None;
267 });
268 }
269
270 pub fn clear_output_zip32_derivation(&mut self) {
273 self.redact(|action| {
274 action.output.zip32_derivation = None;
275 });
276 }
277
278 pub fn clear_output_user_address(&mut self) {
280 self.redact(|spend| {
281 spend.output.user_address = None;
282 });
283 }
284
285 pub fn redact_output_proprietary(&mut self, key: &str) {
287 self.redact(|action| {
288 action.output.proprietary.remove(key);
289 });
290 }
291
292 pub fn clear_output_proprietary(&mut self) {
294 self.redact(|action| {
295 action.output.proprietary.clear();
296 });
297 }
298
299 pub fn clear_rcv(&mut self) {
301 self.redact(|action| {
302 action.rcv = None;
303 });
304 }
305}