feat(traverse): produces_at method for MultiEraTx (#200)
This commit is contained in:
parent
54008c934e
commit
1e18603ed2
1 changed files with 22 additions and 0 deletions
|
|
@ -251,6 +251,28 @@ impl<'b> MultiEraTx<'b> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the *produced* output at the given index if one exists
|
||||
///
|
||||
/// If the transaction is valid the outputs are produced, otherwise the
|
||||
/// collateral return output is produced at index |outputs.len()| if one is
|
||||
/// present. This function gets the *produced* output for an index if one
|
||||
/// exists. It behaves exactly as `outputs_at` for valid transactions, but
|
||||
/// for invalid transactions it returns None except for if the index points
|
||||
/// to the collateral-return output and one is present in the transaction,
|
||||
/// in which case it returns the collateral-return output.
|
||||
pub fn produces_at(&self, index: usize) -> Option<MultiEraOutput> {
|
||||
match self.is_valid() {
|
||||
true => self.output_at(index),
|
||||
false => {
|
||||
if index == self.outputs().len() {
|
||||
self.collateral_return()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the list of UTxO required by the Tx
|
||||
///
|
||||
/// Helper method to yield all of the UTxO that the Tx requires in order to
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue