feat(traverse): Add output-at helper method (#124)

This commit is contained in:
Santiago Carmuega 2022-06-17 08:31:26 -03:00 committed by GitHub
parent f708c9c687
commit 0ada7cb4c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -52,7 +52,7 @@ pub enum MultiEraBlock<'b> {
Byron(Box<Cow<'b, byron::MintedBlock<'b>>>),
}
#[derive(Debug)]
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum MultiEraTx<'b> {
AlonzoCompatible(Box<Cow<'b, alonzo::MintedTx<'b>>>, Era),

View file

@ -67,6 +67,21 @@ impl<'b> MultiEraTx<'b> {
}
}
pub fn output_at(&self, index: usize) -> Option<MultiEraOutput> {
match self {
MultiEraTx::AlonzoCompatible(x, _) => x
.transaction_body
.outputs
.get(index)
.map(MultiEraOutput::from_alonzo_compatible),
MultiEraTx::Byron(x) => x
.transaction
.outputs
.get(index)
.map(MultiEraOutput::from_byron),
}
}
pub fn inputs(&self) -> Vec<MultiEraInput> {
match self {
MultiEraTx::AlonzoCompatible(x, _) => x