From: 志宇 Date: Tue, 3 Sep 2024 07:28:27 +0000 (+0800) Subject: feat(core): add `TxUpdate::map_anchors` X-Git-Tag: v1.0.0-beta.3~13^2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/enum.EncodeError.html?a=commitdiff_plain;h=7d2faa4a5b09a1ec3f4e87552dacb8716ac235bb;p=bdk feat(core): add `TxUpdate::map_anchors` --- diff --git a/crates/core/src/tx_update.rs b/crates/core/src/tx_update.rs index a1ff75de..29d6c253 100644 --- a/crates/core/src/tx_update.rs +++ b/crates/core/src/tx_update.rs @@ -33,6 +33,23 @@ impl Default for TxUpdate { } impl TxUpdate { + /// Transforms the [`TxUpdate`] to have `anchors` (`A`) of another type (`A2`). + /// + /// This takes in a closure with signature `FnMut(A) -> A2` which is called for each anchor to + /// transform it. + pub fn map_anchors A2>(self, mut map: F) -> TxUpdate { + TxUpdate { + txs: self.txs, + txouts: self.txouts, + anchors: self + .anchors + .into_iter() + .map(|(a, txid)| (map(a), txid)) + .collect(), + seen_ats: self.seen_ats, + } + } + /// Extend this update with `other`. pub fn extend(&mut self, other: TxUpdate) { self.txs.extend(other.txs);