From 0a444d7368f7930cf3876bdcbaee30b2854e5aa6 Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Sun, 7 Aug 2022 00:24:46 +0900 Subject: [PATCH 1/2] Getters for witness fields --- pallas-traverse/src/witnesses.rs | 58 +++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/pallas-traverse/src/witnesses.rs b/pallas-traverse/src/witnesses.rs index dbc0da79..93535329 100644 --- a/pallas-traverse/src/witnesses.rs +++ b/pallas-traverse/src/witnesses.rs @@ -1,4 +1,5 @@ -use pallas_primitives::{alonzo, babbage}; +use pallas_codec::utils::MaybeIndefArray; +use pallas_primitives::{alonzo::{self, VKeyWitness, Redeemer, PlutusData, BootstrapWitness, NativeScript}, babbage::{self, PlutusV2Script}}; use crate::MultiEraWitnesses; @@ -17,6 +18,61 @@ impl<'b> MultiEraWitnesses<'b> { } } + pub fn vkeywitness(&self) -> Option<&MaybeIndefArray> { + match self { + Self::AlonzoCompatible(x) => x.vkeywitness.as_ref(), + Self::Babbage(x) => x.vkeywitness.as_ref(), + _ => None, + } + } + + pub fn native_script(&self) -> Option<&MaybeIndefArray> { + match self { + Self::AlonzoCompatible(x) => x.native_script.as_ref(), + Self::Babbage(x) => x.native_script.as_ref(), + _ => None, + } + } + + pub fn bootstrap_witness(&self) -> Option<&MaybeIndefArray> { + match self { + Self::AlonzoCompatible(x) => x.bootstrap_witness.as_ref(), + Self::Babbage(x) => x.bootstrap_witness.as_ref(), + _ => None, + } + } + + pub fn plutus_v1_script(&self) -> Option<&MaybeIndefArray> { + match self { + Self::AlonzoCompatible(x) => x.plutus_script.as_ref(), + Self::Babbage(x) => x.plutus_v1_script.as_ref(), + _ => None, + } + } + + pub fn plutus_data(&self) -> Option<&MaybeIndefArray> { + match self { + Self::AlonzoCompatible(x) => x.plutus_data.as_ref(), + Self::Babbage(x) => x.plutus_data.as_ref(), + _ => None, + } + } + + pub fn redeemer(&self) -> Option<&MaybeIndefArray> { + match self { + Self::AlonzoCompatible(x) => x.redeemer.as_ref(), + Self::Babbage(x) => x.redeemer.as_ref(), + _ => None, + } + } + + pub fn plutus_v2_script(&self) -> Option<&MaybeIndefArray> { + match self { + Self::Babbage(x) => x.plutus_v2_script.as_ref(), + _ => None, + } + } + pub fn cbor(&self) -> &[u8] { match self { MultiEraWitnesses::AlonzoCompatible(x) => x.raw_cbor(), From e9ea3fd47b0b4cd008d76831c905ab6b9eaf5f83 Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Sun, 7 Aug 2022 03:43:28 +0900 Subject: [PATCH 2/2] Abstract getters to slice --- pallas-traverse/src/witnesses.rs | 41 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/pallas-traverse/src/witnesses.rs b/pallas-traverse/src/witnesses.rs index 93535329..6c8e1ea1 100644 --- a/pallas-traverse/src/witnesses.rs +++ b/pallas-traverse/src/witnesses.rs @@ -1,4 +1,3 @@ -use pallas_codec::utils::MaybeIndefArray; use pallas_primitives::{alonzo::{self, VKeyWitness, Redeemer, PlutusData, BootstrapWitness, NativeScript}, babbage::{self, PlutusV2Script}}; use crate::MultiEraWitnesses; @@ -18,57 +17,57 @@ impl<'b> MultiEraWitnesses<'b> { } } - pub fn vkeywitness(&self) -> Option<&MaybeIndefArray> { + pub fn vkeywitness(&self) -> Option<&[VKeyWitness]> { match self { - Self::AlonzoCompatible(x) => x.vkeywitness.as_ref(), - Self::Babbage(x) => x.vkeywitness.as_ref(), + 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<&MaybeIndefArray> { + pub fn native_script(&self) -> Option<&[NativeScript]> { match self { - Self::AlonzoCompatible(x) => x.native_script.as_ref(), - Self::Babbage(x) => x.native_script.as_ref(), + 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<&MaybeIndefArray> { + pub fn bootstrap_witness(&self) -> Option<&[BootstrapWitness]> { match self { - Self::AlonzoCompatible(x) => x.bootstrap_witness.as_ref(), - Self::Babbage(x) => x.bootstrap_witness.as_ref(), + 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<&MaybeIndefArray> { + pub fn plutus_v1_script(&self) -> Option<&[alonzo::PlutusScript]> { match self { - Self::AlonzoCompatible(x) => x.plutus_script.as_ref(), - Self::Babbage(x) => x.plutus_v1_script.as_ref(), + 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<&MaybeIndefArray> { + pub fn plutus_data(&self) -> Option<&[PlutusData]> { match self { - Self::AlonzoCompatible(x) => x.plutus_data.as_ref(), - Self::Babbage(x) => x.plutus_data.as_ref(), + 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<&MaybeIndefArray> { + pub fn redeemer(&self) -> Option<&[Redeemer]> { match self { - Self::AlonzoCompatible(x) => x.redeemer.as_ref(), - Self::Babbage(x) => x.redeemer.as_ref(), + 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<&MaybeIndefArray> { + pub fn plutus_v2_script(&self) -> Option<&[PlutusV2Script]> { match self { - Self::Babbage(x) => x.plutus_v2_script.as_ref(), + Self::Babbage(x) => x.plutus_v2_script.as_ref().map(|x| x.as_ref()), _ => None, } }