@@ -40,6 +40,8 @@ pub struct TxBuilder {
40
40
locktime : Option < LockTime > ,
41
41
allow_dust : bool ,
42
42
version : Option < i32 > ,
43
+ exclude_unconfirmed : bool ,
44
+ exclude_below_confirmations : Option < u32 > ,
43
45
}
44
46
45
47
#[ allow( clippy:: new_without_default) ]
@@ -66,6 +68,8 @@ impl TxBuilder {
66
68
locktime : None ,
67
69
allow_dust : false ,
68
70
version : None ,
71
+ exclude_unconfirmed : false ,
72
+ exclude_below_confirmations : None ,
69
73
}
70
74
}
71
75
@@ -81,6 +85,34 @@ impl TxBuilder {
81
85
} )
82
86
}
83
87
88
+ /// Exclude outpoints whose enclosing transaction is unconfirmed.
89
+ /// This is a shorthand for exclude_below_confirmations(1).
90
+ pub fn exclude_unconfirmed ( & self ) -> Arc < Self > {
91
+ Arc :: new ( TxBuilder {
92
+ exclude_unconfirmed : true ,
93
+ ..self . clone ( )
94
+ } )
95
+ }
96
+
97
+ /// Excludes any outpoints whose enclosing transaction has fewer than `min_confirms`
98
+ /// confirmations.
99
+ ///
100
+ /// `min_confirms` is the minimum number of confirmations a transaction must have in order for
101
+ /// its outpoints to remain spendable.
102
+ /// - Passing `0` will include all transactions (no filtering).
103
+ /// - Passing `1` will exclude all unconfirmed transactions (equivalent to
104
+ /// `exclude_unconfirmed`).
105
+ /// - Passing `6` will only allow outpoints from transactions with at least 6 confirmations.
106
+ ///
107
+ /// If you chain this with other filtering methods, the final set of unspendable outpoints will
108
+ /// be the union of all filters.
109
+ pub fn exclude_below_confirmations ( & self , min_confirms : u32 ) -> Arc < Self > {
110
+ Arc :: new ( TxBuilder {
111
+ exclude_below_confirmations : Some ( min_confirms) ,
112
+ ..self . clone ( )
113
+ } )
114
+ }
115
+
84
116
/// Add a recipient to the internal list of recipients.
85
117
pub fn add_recipient ( & self , script : & Script , amount : Arc < Amount > ) -> Arc < Self > {
86
118
let mut recipients: Vec < ( BdkScriptBuf , BdkAmount ) > = self . recipients . clone ( ) ;
@@ -402,7 +434,12 @@ impl TxBuilder {
402
434
if let Some ( version) = self . version {
403
435
tx_builder. version ( version) ;
404
436
}
405
-
437
+ if self . exclude_unconfirmed {
438
+ tx_builder. exclude_unconfirmed ( ) ;
439
+ }
440
+ if let Some ( min_confirms) = self . exclude_below_confirmations {
441
+ tx_builder. exclude_below_confirmations ( min_confirms) ;
442
+ }
406
443
let psbt = tx_builder. finish ( ) . map_err ( CreateTxError :: from) ?;
407
444
408
445
Ok ( Arc :: new ( psbt. into ( ) ) )
0 commit comments