Skip to content

Commit 7d2faa4

Browse files
committed
feat(core): add TxUpdate::map_anchors
1 parent 56970a9 commit 7d2faa4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/core/src/tx_update.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ impl<A> Default for TxUpdate<A> {
3333
}
3434

3535
impl<A: Ord> TxUpdate<A> {
36+
/// Transforms the [`TxUpdate`] to have `anchors` (`A`) of another type (`A2`).
37+
///
38+
/// This takes in a closure with signature `FnMut(A) -> A2` which is called for each anchor to
39+
/// transform it.
40+
pub fn map_anchors<A2: Ord, F: FnMut(A) -> A2>(self, mut map: F) -> TxUpdate<A2> {
41+
TxUpdate {
42+
txs: self.txs,
43+
txouts: self.txouts,
44+
anchors: self
45+
.anchors
46+
.into_iter()
47+
.map(|(a, txid)| (map(a), txid))
48+
.collect(),
49+
seen_ats: self.seen_ats,
50+
}
51+
}
52+
3653
/// Extend this update with `other`.
3754
pub fn extend(&mut self, other: TxUpdate<A>) {
3855
self.txs.extend(other.txs);

0 commit comments

Comments
 (0)