feat(traverse): Add missing getters on output (#162)
This commit is contained in:
parent
74d5731118
commit
865b25b58b
2 changed files with 24 additions and 3 deletions
|
|
@ -93,7 +93,7 @@ pub use crate::alonzo::Coin;
|
|||
|
||||
pub use crate::alonzo::Value;
|
||||
|
||||
pub use crate::alonzo::TransactionOutput as LegacyTransacionOutput;
|
||||
pub use crate::alonzo::TransactionOutput as LegacyTransactionOutput;
|
||||
|
||||
pub use crate::alonzo::PoolKeyhash;
|
||||
|
||||
|
|
@ -285,7 +285,7 @@ pub struct TransactionBody {
|
|||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum TransactionOutput {
|
||||
Legacy(LegacyTransacionOutput),
|
||||
Legacy(LegacyTransactionOutput),
|
||||
PostAlonzo(PostAlonzoTransactionOutput),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::{borrow::Cow, ops::Deref};
|
|||
|
||||
use pallas_addresses::{Address, ByronAddress, Error as AddressError};
|
||||
use pallas_codec::minicbor;
|
||||
use pallas_primitives::{alonzo, babbage, byron};
|
||||
use pallas_primitives::{alonzo, babbage::{self, DatumOption, ScriptRef}, byron};
|
||||
|
||||
use crate::{Era, MultiEraOutput};
|
||||
|
||||
|
|
@ -19,6 +19,27 @@ impl<'b> MultiEraOutput<'b> {
|
|||
Self::Babbage(Box::new(Cow::Borrowed(output)))
|
||||
}
|
||||
|
||||
pub fn datum(&self) -> Option<DatumOption> {
|
||||
match self {
|
||||
MultiEraOutput::AlonzoCompatible(x) => x.datum_hash.map(DatumOption::Hash),
|
||||
MultiEraOutput::Babbage(x) => match x.deref().deref() {
|
||||
babbage::TransactionOutput::Legacy(x) => x.datum_hash.map(DatumOption::Hash),
|
||||
babbage::TransactionOutput::PostAlonzo(x) => x.datum_option.clone(),
|
||||
},
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn script_ref(&self) -> Option<&ScriptRef> {
|
||||
match &self {
|
||||
MultiEraOutput::Babbage(x) => match x.deref().deref() {
|
||||
babbage::TransactionOutput::Legacy(_) => None,
|
||||
babbage::TransactionOutput::PostAlonzo(x) => x.script_ref.as_ref(),
|
||||
},
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn address(&self) -> Result<Address, AddressError> {
|
||||
match self {
|
||||
MultiEraOutput::AlonzoCompatible(x) => Address::from_bytes(&x.address),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue