feat(traverse): Add missing getters for witness fields (#160)

This commit is contained in:
Sebastien Guillemot 2022-08-07 03:46:33 +09:00 committed by GitHub
parent a4873c404e
commit 74d5731118
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(),