Move spends_per_anchor to TransferData

And update its docs for ZIP-244
This commit is contained in:
teor 2021-04-21 09:55:21 +10:00 committed by Deirdre Connolly
parent 9e45e6bb23
commit d3836e6fd8
1 changed files with 29 additions and 11 deletions

View File

@ -165,22 +165,14 @@ where
AnchorV: AnchorVariant + Clone,
Spend<PerSpendAnchor>: From<(Spend<AnchorV>, AnchorV::Shared)>,
{
/// Iterate over the [`Spend`]s for this transaction.
///
/// Returns `Spend<PerSpendAnchor>` regardless of the underlying transaction
/// version, to allow generic verification over V4 and V5 transactions.
/// Iterate over the [`Spend`]s for this transaction, returning
/// `Spend<PerSpendAnchor>` regardless of the underlying transaction version.
///
/// # Correctness
///
/// Do not use this function for serialization.
pub fn spends_per_anchor(&self) -> impl Iterator<Item = Spend<PerSpendAnchor>> + '_ {
self.spends().cloned().map(move |spend| {
Spend::<PerSpendAnchor>::from((
spend,
self.shared_anchor()
.expect("shared anchor must be Some if there are any spends"),
))
})
self.transfers.spends_per_anchor()
}
}
@ -257,6 +249,32 @@ where
}
}
impl<AnchorV> TransferData<AnchorV>
where
AnchorV: AnchorVariant + Clone,
Spend<PerSpendAnchor>: From<(Spend<AnchorV>, AnchorV::Shared)>,
{
/// Iterate over the [`Spend`]s for this transaction, returning
/// `Spend<PerSpendAnchor>` regardless of the underlying transaction version.
///
/// Allows generic operations over V4 and V5 transactions, including:
/// * spend verification, and
/// * non-malleable transaction ID generation.
///
/// # Correctness
///
/// Do not use this function for serialization.
pub fn spends_per_anchor(&self) -> impl Iterator<Item = Spend<PerSpendAnchor>> + '_ {
self.spends().cloned().map(move |spend| {
Spend::<PerSpendAnchor>::from((
spend,
self.shared_anchor()
.expect("shared anchor must be Some if there are any spends"),
))
})
}
}
impl<AnchorV> TransferData<AnchorV>
where
AnchorV: AnchorVariant + Clone,