feat(traverse): expose tx update field (#313)

This commit is contained in:
Harper 2023-10-24 10:59:36 +01:00 committed by GitHub
parent 794e725984
commit e7bee68d3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 1 deletions

View file

@ -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<Cow<'b, alonzo::Update>>),
Babbage(Box<Cow<'b, babbage::Update>>),
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum MultiEraSigners<'b> {

View file

@ -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<MultiEraUpdate> {
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<MultiEraPolicyAssets> {
match self {
MultiEraTx::AlonzoCompatible(x, _) => x

View file

@ -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,
}
}
}