feat(traverse): Add tx input traversing (#121)
Co-authored-by: Mateusz Czeladka <mateusz.szczap[at]gmail.com>
This commit is contained in:
parent
0150cbab49
commit
9f5ab4f6ec
3 changed files with 56 additions and 1 deletions
29
pallas-traverse/src/input.rs
Normal file
29
pallas-traverse/src/input.rs
Normal file
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Cow<'b, alonzo::TransactionOutput>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub enum MultiEraInput<'b> {
|
||||
Byron(Box<Cow<'b, byron::TxIn>>),
|
||||
AlonzoCompatible(Box<Cow<'b, alonzo::TransactionInput>>),
|
||||
}
|
||||
|
||||
pub enum MultiEraCert<'b> {
|
||||
NotApplicable,
|
||||
AlonzoCompatible(Box<Cow<'b, alonzo::Certificate>>),
|
||||
|
|
|
|||
|
|
@ -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<MultiEraInput> {
|
||||
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<MultiEraCert> {
|
||||
match self {
|
||||
MultiEraTx::AlonzoCompatible(x) => x
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue