From 74d573111826bfa32aa1053dc88583fc04805403 Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Sun, 7 Aug 2022 03:46:33 +0900 Subject: [PATCH] feat(traverse): Add missing getters for witness fields (#160) --- pallas-traverse/src/witnesses.rs | 57 +++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/pallas-traverse/src/witnesses.rs b/pallas-traverse/src/witnesses.rs index dbc0da7..6c8e1ea 100644 --- a/pallas-traverse/src/witnesses.rs +++ b/pallas-traverse/src/witnesses.rs @@ -1,4 +1,4 @@ -use pallas_primitives::{alonzo, babbage}; +use pallas_primitives::{alonzo::{self, VKeyWitness, Redeemer, PlutusData, BootstrapWitness, NativeScript}, babbage::{self, PlutusV2Script}}; use crate::MultiEraWitnesses; @@ -17,6 +17,61 @@ impl<'b> MultiEraWitnesses<'b> { } } + pub fn vkeywitness(&self) -> Option<&[VKeyWitness]> { + match self { + Self::AlonzoCompatible(x) => x.vkeywitness.as_ref().map(|x| x.as_ref()), + Self::Babbage(x) => x.vkeywitness.as_ref().map(|x| x.as_ref()), + _ => None, + } + } + + pub fn native_script(&self) -> Option<&[NativeScript]> { + match self { + Self::AlonzoCompatible(x) => x.native_script.as_ref().map(|x| x.as_ref()), + Self::Babbage(x) => x.native_script.as_ref().map(|x| x.as_ref()), + _ => None, + } + } + + pub fn bootstrap_witness(&self) -> Option<&[BootstrapWitness]> { + match self { + Self::AlonzoCompatible(x) => x.bootstrap_witness.as_ref().map(|x| x.as_ref()), + Self::Babbage(x) => x.bootstrap_witness.as_ref().map(|x| x.as_ref()), + _ => None, + } + } + + pub fn plutus_v1_script(&self) -> Option<&[alonzo::PlutusScript]> { + match self { + Self::AlonzoCompatible(x) => x.plutus_script.as_ref().map(|x| x.as_ref()), + Self::Babbage(x) => x.plutus_v1_script.as_ref().map(|x| x.as_ref()), + _ => None, + } + } + + pub fn plutus_data(&self) -> Option<&[PlutusData]> { + match self { + Self::AlonzoCompatible(x) => x.plutus_data.as_ref().map(|x| x.as_ref()), + Self::Babbage(x) => x.plutus_data.as_ref().map(|x| x.as_ref()), + _ => None, + } + } + + pub fn redeemer(&self) -> Option<&[Redeemer]> { + match self { + Self::AlonzoCompatible(x) => x.redeemer.as_ref().map(|x| x.as_ref()), + Self::Babbage(x) => x.redeemer.as_ref().map(|x| x.as_ref()), + _ => None, + } + } + + pub fn plutus_v2_script(&self) -> Option<&[PlutusV2Script]> { + match self { + Self::Babbage(x) => x.plutus_v2_script.as_ref().map(|x| x.as_ref()), + _ => None, + } + } + pub fn cbor(&self) -> &[u8] { match self { MultiEraWitnesses::AlonzoCompatible(x) => x.raw_cbor(),