diff --git a/pallas-traverse/src/lib.rs b/pallas-traverse/src/lib.rs index 692f847..dc77935 100644 --- a/pallas-traverse/src/lib.rs +++ b/pallas-traverse/src/lib.rs @@ -26,6 +26,7 @@ pub mod signers; pub mod size; pub mod time; pub mod tx; +pub mod update; pub mod withdrawals; pub mod witnesses; @@ -139,6 +140,14 @@ pub enum MultiEraWithdrawals<'b> { AlonzoCompatible(&'b alonzo::Withdrawals), } +#[derive(Debug, Clone)] +#[non_exhaustive] +pub enum MultiEraUpdate<'b> { + NotApplicable, + AlonzoCompatible(Box>), + Babbage(Box>), +} + #[derive(Debug, Clone)] #[non_exhaustive] pub enum MultiEraSigners<'b> { diff --git a/pallas-traverse/src/tx.rs b/pallas-traverse/src/tx.rs index 356b0df..978209d 100644 --- a/pallas-traverse/src/tx.rs +++ b/pallas-traverse/src/tx.rs @@ -10,7 +10,7 @@ use pallas_primitives::{ use crate::{ Era, MultiEraCert, MultiEraInput, MultiEraMeta, MultiEraOutput, MultiEraPolicyAssets, - MultiEraSigners, MultiEraTx, MultiEraWithdrawals, OriginalHash, + MultiEraSigners, MultiEraTx, MultiEraUpdate, MultiEraWithdrawals, OriginalHash, }; impl<'b> MultiEraTx<'b> { @@ -182,6 +182,22 @@ impl<'b> MultiEraTx<'b> { } } + pub fn update(&self) -> Option { + match self { + MultiEraTx::AlonzoCompatible(x, _) => x + .transaction_body + .update + .as_ref() + .map(MultiEraUpdate::from_alonzo_compatible), + MultiEraTx::Babbage(x) => x + .transaction_body + .update + .as_ref() + .map(MultiEraUpdate::from_babbage), + MultiEraTx::Byron(_) => None, + } + } + pub fn mints(&self) -> Vec { match self { MultiEraTx::AlonzoCompatible(x, _) => x diff --git a/pallas-traverse/src/update.rs b/pallas-traverse/src/update.rs new file mode 100644 index 0000000..fe5730e --- /dev/null +++ b/pallas-traverse/src/update.rs @@ -0,0 +1,29 @@ +use std::borrow::Cow; + +use pallas_primitives::{alonzo, babbage}; + +use crate::MultiEraUpdate; + +impl<'b> MultiEraUpdate<'b> { + pub fn from_alonzo_compatible(update: &'b alonzo::Update) -> Self { + Self::AlonzoCompatible(Box::new(Cow::Borrowed(update))) + } + + pub fn from_babbage(update: &'b babbage::Update) -> Self { + Self::Babbage(Box::new(Cow::Borrowed(update))) + } + + pub fn as_alonzo(&self) -> Option<&alonzo::Update> { + match self { + Self::AlonzoCompatible(x) => Some(x), + _ => None, + } + } + + pub fn as_babbage(&self) -> Option<&babbage::Update> { + match self { + Self::Babbage(x) => Some(x), + _ => None, + } + } +}