Skip to content

Commit 58bae98

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 7e0280e commit 58bae98

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
@@ -518,6 +518,20 @@ impl<'a, Cs> TxBuilder<'a, Cs> {
518518
self.exclude_below_confirmations(1)
519519
}
520520

521+
/// Add unbroadcasted transactions to the unspendable list.
522+
pub fn exclude_unbroadcasted(&mut self) -> &mut Self {
523+
let unbroadcasted_ops = self.wallet.broadcast_queue().flat_map(|tx| {
524+
let txid = tx.compute_txid();
525+
(0_u32..)
526+
.take(tx.output.len())
527+
.map(move |vout| OutPoint::new(txid, vout))
528+
});
529+
for op in unbroadcasted_ops {
530+
self.params.unspendable.insert(op);
531+
}
532+
self
533+
}
534+
521535
/// Sign with a specific sig hash
522536
///
523537
/// **Use this option very carefully**

0 commit comments

Comments
 (0)