diff --git a/pallas-traverse/src/input.rs b/pallas-traverse/src/input.rs new file mode 100644 index 0000000..4804710 --- /dev/null +++ b/pallas-traverse/src/input.rs @@ -0,0 +1,29 @@ +use std::borrow::Cow; + +use pallas_primitives::{alonzo, byron}; + +use crate::MultiEraInput; + +impl<'b> MultiEraInput<'b> { + pub fn from_byron(input: &'b byron::TxIn) -> Self { + Self::Byron(Box::new(Cow::Borrowed(input))) + } + + pub fn from_alonzo_compatible(input: &'b alonzo::TransactionInput) -> Self { + Self::AlonzoCompatible(Box::new(Cow::Borrowed(input))) + } + + pub fn as_alonzo(&self) -> Option<&alonzo::TransactionInput> { + match self { + MultiEraInput::Byron(_) => None, + MultiEraInput::AlonzoCompatible(x) => Some(x), + } + } + + pub fn as_byron(&self) -> Option<&byron::TxIn> { + match self { + MultiEraInput::Byron(x) => Some(x), + MultiEraInput::AlonzoCompatible(_) => None, + } + } +} diff --git a/pallas-traverse/src/lib.rs b/pallas-traverse/src/lib.rs index 22e4466..02ec310 100644 --- a/pallas-traverse/src/lib.rs +++ b/pallas-traverse/src/lib.rs @@ -10,6 +10,7 @@ pub mod block; pub mod cert; pub mod era; pub mod output; +pub mod input; pub mod probe; mod support; pub mod tx; @@ -55,6 +56,13 @@ pub enum MultiEraOutput<'b> { AlonzoCompatible(Box>), } +#[derive(Debug)] +#[non_exhaustive] +pub enum MultiEraInput<'b> { + Byron(Box>), + AlonzoCompatible(Box>), +} + pub enum MultiEraCert<'b> { NotApplicable, AlonzoCompatible(Box>), diff --git a/pallas-traverse/src/tx.rs b/pallas-traverse/src/tx.rs index cd93763..f6707d1 100644 --- a/pallas-traverse/src/tx.rs +++ b/pallas-traverse/src/tx.rs @@ -3,7 +3,7 @@ use pallas_crypto::hash::Hash; use pallas_primitives::{alonzo, byron, ToHash}; use std::borrow::Cow; -use crate::{MultiEraCert, MultiEraOutput, MultiEraTx}; +use crate::{MultiEraCert, MultiEraOutput, MultiEraInput, MultiEraTx}; impl<'b> MultiEraTx<'b> { pub fn from_byron(tx: &'b byron::MintedTxPayload<'b>) -> Self { @@ -45,6 +45,24 @@ impl<'b> MultiEraTx<'b> { } } + pub fn inputs(&self) -> Vec { + match self { + MultiEraTx::AlonzoCompatible(x) => x + .transaction_body + .inputs + .iter() + .map(MultiEraInput::from_alonzo_compatible) + .collect(), + + MultiEraTx::Byron(x) => x + .transaction + .inputs + .iter() + .map(MultiEraInput::from_byron) + .collect(), + } + } + pub fn certs(&self) -> Vec { match self { MultiEraTx::AlonzoCompatible(x) => x