From c3820b44eb82a80b006e5b19ff9552bd0b3cbf66 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 25 May 2021 23:02:42 -0300 Subject: [PATCH] Add action methods (#2199) * add action methods Co-authored-by: teor Co-authored-by: Janito Vaqueiro Ferreira Filho --- zebra-chain/src/orchard/shielded_data.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/zebra-chain/src/orchard/shielded_data.rs b/zebra-chain/src/orchard/shielded_data.rs index 3adb25f51..6dcd083f3 100644 --- a/zebra-chain/src/orchard/shielded_data.rs +++ b/zebra-chain/src/orchard/shielded_data.rs @@ -3,7 +3,7 @@ use crate::{ amount::Amount, block::MAX_BLOCK_BYTES, - orchard::{tree, Action}, + orchard::{tree, Action, Nullifier}, primitives::{ redpallas::{Binding, Signature, SpendAuth}, Halo2Proof, @@ -38,6 +38,27 @@ pub struct ShieldedData { pub binding_sig: Signature, } +impl ShieldedData { + /// Iterate over the [`Action`]s for the [`AuthorizedAction`]s in this transaction. + pub fn actions(&self) -> impl Iterator { + self.actions.actions() + } + + /// Collect the [`Nullifier`]s for this transaction, if it contains + /// [`Action`]s. + pub fn nullifiers(&self) -> impl Iterator { + self.actions().map(|action| &action.nullifier) + } +} + +impl AtLeastOne { + /// Iterate over the [`Action`]s of each [`AuthorizedAction`]. + pub fn actions(&self) -> impl Iterator { + self.iter() + .map(|authorized_action| &authorized_action.action) + } +} + /// An authorized action description. /// /// Every authorized Orchard `Action` must have a corresponding `SpendAuth` signature.