use crate::sapling::{Bundle, Output, Spend};
impl super::Redactor {
pub fn redact_sapling_with<F>(mut self, f: F) -> Self
where
F: FnOnce(SaplingRedactor<'_>),
{
f(SaplingRedactor(&mut self.pczt.sapling));
self
}
}
pub struct SaplingRedactor<'a>(&'a mut Bundle);
impl SaplingRedactor<'_> {
pub fn redact_spends<F>(&mut self, f: F)
where
F: FnOnce(SpendRedactor<'_>),
{
f(SpendRedactor(Spends::All(&mut self.0.spends)));
}
pub fn redact_spend<F>(&mut self, index: usize, f: F)
where
F: FnOnce(SpendRedactor<'_>),
{
if let Some(spend) = self.0.spends.get_mut(index) {
f(SpendRedactor(Spends::One(spend)));
}
}
pub fn redact_outputs<F>(&mut self, f: F)
where
F: FnOnce(OutputRedactor<'_>),
{
f(OutputRedactor(Outputs::All(&mut self.0.outputs)));
}
pub fn redact_output<F>(&mut self, index: usize, f: F)
where
F: FnOnce(OutputRedactor<'_>),
{
if let Some(output) = self.0.outputs.get_mut(index) {
f(OutputRedactor(Outputs::One(output)));
}
}
pub fn clear_bsk(&mut self) {
self.0.bsk = None;
}
}
pub struct SpendRedactor<'a>(Spends<'a>);
enum Spends<'a> {
All(&'a mut [Spend]),
One(&'a mut Spend),
}
impl SpendRedactor<'_> {
fn redact<F>(&mut self, f: F)
where
F: Fn(&mut Spend),
{
match &mut self.0 {
Spends::All(spends) => {
for spend in spends.iter_mut() {
f(spend);
}
}
Spends::One(spend) => {
f(spend);
}
}
}
pub fn clear_zkproof(&mut self) {
self.redact(|spend| {
spend.zkproof = None;
});
}
pub fn clear_spend_auth_sig(&mut self) {
self.redact(|spend| {
spend.spend_auth_sig = None;
});
}
pub fn clear_recipient(&mut self) {
self.redact(|spend| {
spend.recipient = None;
});
}
pub fn clear_value(&mut self) {
self.redact(|spend| {
spend.value = None;
});
}
pub fn clear_rcm(&mut self) {
self.redact(|spend| {
spend.rcm = None;
});
}
pub fn clear_rseed(&mut self) {
self.redact(|spend| {
spend.rseed = None;
});
}
pub fn clear_rcv(&mut self) {
self.redact(|spend| {
spend.rcv = None;
});
}
pub fn clear_proof_generation_key(&mut self) {
self.redact(|spend| {
spend.proof_generation_key = None;
});
}
pub fn clear_witness(&mut self) {
self.redact(|spend| {
spend.witness = None;
});
}
pub fn clear_alpha(&mut self) {
self.redact(|spend| {
spend.alpha = None;
});
}
pub fn clear_zip32_derivation(&mut self) {
self.redact(|spend| {
spend.zip32_derivation = None;
});
}
pub fn clear_dummy_ask(&mut self) {
self.redact(|spend| {
spend.dummy_ask = None;
});
}
pub fn redact_proprietary(&mut self, key: &str) {
self.redact(|spend| {
spend.proprietary.remove(key);
});
}
pub fn clear_proprietary(&mut self) {
self.redact(|spend| {
spend.proprietary.clear();
});
}
}
pub struct OutputRedactor<'a>(Outputs<'a>);
enum Outputs<'a> {
All(&'a mut [Output]),
One(&'a mut Output),
}
impl OutputRedactor<'_> {
fn redact<F>(&mut self, f: F)
where
F: Fn(&mut Output),
{
match &mut self.0 {
Outputs::All(outputs) => {
for output in outputs.iter_mut() {
f(output);
}
}
Outputs::One(output) => {
f(output);
}
}
}
pub fn clear_zkproof(&mut self) {
self.redact(|output| {
output.zkproof = None;
});
}
pub fn clear_recipient(&mut self) {
self.redact(|output| {
output.recipient = None;
});
}
pub fn clear_value(&mut self) {
self.redact(|output| {
output.value = None;
});
}
pub fn clear_rseed(&mut self) {
self.redact(|output| {
output.rseed = None;
});
}
pub fn clear_rcv(&mut self) {
self.redact(|output| {
output.rcv = None;
});
}
pub fn clear_ock(&mut self) {
self.redact(|output| {
output.ock = None;
});
}
pub fn clear_zip32_derivation(&mut self) {
self.redact(|output| {
output.zip32_derivation = None;
});
}
pub fn clear_user_address(&mut self) {
self.redact(|output| {
output.user_address = None;
});
}
pub fn redact_proprietary(&mut self, key: &str) {
self.redact(|output| {
output.proprietary.remove(key);
});
}
pub fn clear_proprietary(&mut self) {
self.redact(|output| {
output.proprietary.clear();
});
}
}