Skip to content

Commit a65eabe

Browse files
committed
feat: Add TxBuilder::exclude_unbroadcasted
If the caller wishes to avoid spending unbroadcasted UTXOs without double-spending any of the unbroadcasted transactions.
1 parent 75bc892 commit a65eabe

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

wallet/src/wallet/tx_builder.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,20 @@ impl<'a, Cs> TxBuilder<'a, Cs> {
459459
self
460460
}
461461

462+
/// Add unbroadcasted transactions to the unspendable list.
463+
pub fn exclude_unbroadcasted(&mut self) -> &mut Self {
464+
let unbroadcasted_ops = self.wallet.broadcast_queue().flat_map(|tx| {
465+
let txid = tx.compute_txid();
466+
(0_u32..)
467+
.take(tx.output.len())
468+
.map(move |vout| OutPoint::new(txid, vout))
469+
});
470+
for op in unbroadcasted_ops {
471+
self.params.unspendable.insert(op);
472+
}
473+
self
474+
}
475+
462476
/// Sign with a specific sig hash
463477
///
464478
/// **Use this option very carefully**

0 commit comments

Comments
 (0)