feat(traverse): Expose aux data scripts (#232)

This commit is contained in:
Santiago Carmuega 2023-03-11 22:07:09 +01:00 committed by GitHub
parent 9740dc0560
commit 4133268e99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 2 deletions

View file

@ -0,0 +1,42 @@
use std::ops::Deref;
use pallas_primitives::alonzo;
use crate::MultiEraTx;
impl<'b> MultiEraTx<'b> {
pub fn aux_plutus_v1_scripts(&self) -> &[alonzo::PlutusScript] {
if let Some(aux_data) = self.aux_data() {
match aux_data.deref() {
alonzo::AuxiliaryData::PostAlonzo(x) => {
if let Some(plutus) = &x.plutus_scripts {
return plutus.as_ref();
}
}
_ => (),
}
}
&[]
}
pub fn aux_native_scripts(&self) -> &[alonzo::NativeScript] {
if let Some(aux_data) = self.aux_data() {
match aux_data.deref() {
alonzo::AuxiliaryData::PostAlonzo(x) => {
if let Some(scripts) = &x.native_scripts {
return scripts.as_ref();
}
}
alonzo::AuxiliaryData::ShelleyMa(x) => {
if let Some(scripts) = &x.auxiliary_scripts {
return scripts.as_ref();
}
}
_ => (),
}
}
&[]
}
}

View file

@ -9,7 +9,10 @@ use pallas_codec::utils::KeepRaw;
use pallas_crypto::hash::Hash;
use pallas_primitives::{alonzo, babbage, byron};
mod support;
pub mod assets;
pub mod aux;
pub mod block;
pub mod cert;
pub mod era;
@ -21,7 +24,6 @@ pub mod meta;
pub mod output;
pub mod probe;
pub mod signers;
mod support;
pub mod time;
pub mod tx;
pub mod withdrawals;

View file

@ -319,7 +319,7 @@ impl<'b> MultiEraTx<'b> {
}
}
fn aux_data(&self) -> Option<&KeepRaw<'_, alonzo::AuxiliaryData>> {
pub(crate) fn aux_data(&self) -> Option<&KeepRaw<'_, alonzo::AuxiliaryData>> {
match self {
MultiEraTx::AlonzoCompatible(x, _) => match &x.auxiliary_data {
pallas_codec::utils::Nullable::Some(x) => Some(x),