Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getters for witness fields #160

Merged
merged 2 commits into from
Aug 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion pallas-traverse/src/witnesses.rs
Original file line number Diff line number Diff line change
@@ -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;

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