From 835df97c13423e8995a4101c6a683138ffe81d9a Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Sun, 11 Sep 2022 13:28:10 -0300 Subject: [PATCH] feat(traverse): Introduce new MultiEraTx helpers (#184) --- pallas-traverse/src/tx.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pallas-traverse/src/tx.rs b/pallas-traverse/src/tx.rs index 241630ad..d1433cfe 100644 --- a/pallas-traverse/src/tx.rs +++ b/pallas-traverse/src/tx.rs @@ -221,6 +221,41 @@ impl<'b> MultiEraTx<'b> { } } + /// Returns the list of inputs consumed by the Tx + /// + /// Helper method to abstract the logic of which inputs are consumed + /// depending on the validity of the Tx. If the Tx is valid, this method + /// will return the list of inputs. If the tx is invalid, it will return the + /// collateral. + pub fn consumes(&self) -> Vec { + match self.is_valid() { + true => self.inputs(), + false => self.collateral(), + } + } + + /// Returns the list of outputs produced by the Tx + /// + /// Helper method to abstract the logic of which outputs are produced + /// depending on the validity of the Tx. If the Tx is valid, this method + /// will return the list of inputs. If the tx is invalid, it will return the + /// collateral. + pub fn produces(&self) -> Vec { + match self.is_valid() { + true => self.outputs(), + false => self.collateral_return().into_iter().collect(), + } + } + + /// Returns the list of UTxO required by the Tx + /// + /// Helper method to yield all of the UTxO that the Tx requires in order to + /// be fulfilled. This includes normal inputs, reference inputs and + /// collateral. + pub fn requires(&self) -> Vec { + [self.inputs(), self.reference_inputs(), self.collateral()].concat() + } + pub fn withdrawals(&self) -> MultiEraWithdrawals { match self { MultiEraTx::AlonzoCompatible(x, _) => match &x.transaction_body.withdrawals {