From 4133268e99577e8ceddb11c58ad6f0c6d1eec436 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Sat, 11 Mar 2023 22:07:09 +0100 Subject: [PATCH] feat(traverse): Expose aux data scripts (#232) --- pallas-traverse/src/aux.rs | 42 ++++++++++++++++++++++++++++++++++++++ pallas-traverse/src/lib.rs | 4 +++- pallas-traverse/src/tx.rs | 2 +- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 pallas-traverse/src/aux.rs diff --git a/pallas-traverse/src/aux.rs b/pallas-traverse/src/aux.rs new file mode 100644 index 0000000..7d35e95 --- /dev/null +++ b/pallas-traverse/src/aux.rs @@ -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(); + } + } + _ => (), + } + } + + &[] + } +} diff --git a/pallas-traverse/src/lib.rs b/pallas-traverse/src/lib.rs index ce2f900..31d6594 100644 --- a/pallas-traverse/src/lib.rs +++ b/pallas-traverse/src/lib.rs @@ -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; diff --git a/pallas-traverse/src/tx.rs b/pallas-traverse/src/tx.rs index 8e6224f..f2915ca 100644 --- a/pallas-traverse/src/tx.rs +++ b/pallas-traverse/src/tx.rs @@ -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),