feat: return indexes along with outputs returned by produces() (#193)

This commit is contained in:
Harper 2022-09-20 23:39:44 +01:00 committed by GitHub
parent bfc5a0a312
commit dc41f7b212
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -232,16 +232,32 @@ impl<'b> MultiEraTx<'b> {
}
}
/// Returns the list of outputs produced by the Tx
/// Returns a list of tuples of the outputs produced by the Tx with their indexes
///
/// 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<MultiEraOutput> {
/// will return the list of outputs. If the Tx is invalid it will return the
/// collateral return if one is present or an empty list if not. Note that the
/// collateral return output index is defined as the next available index after
/// the txouts (Babbage spec, ch 4).
pub fn produces(&self) -> Vec<(usize, MultiEraOutput)> {
match self.is_valid() {
true => self.outputs(),
false => self.collateral_return().into_iter().collect(),
true => {
self
.outputs()
.into_iter()
.enumerate()
.collect()
}
false => {
self
.collateral_return()
.into_iter()
.map(|txo| {
(self.outputs().len(), txo)
})
.collect()
}
}
}