@@ -119,9 +119,16 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
119
119
120
120
/// Iterate over all scripts in merkle tree. If there is no script path, the iterator
121
121
/// yields [`None`]
122
- pub fn iter_scripts ( & self ) -> TapTreeIter < Pk > {
122
+ #[ deprecated( since = "TBD" , note = "use `leaves` instead" ) ]
123
+ pub fn iter_scripts ( & self ) -> TapTreeIter < Pk > { self . leaves ( ) }
124
+
125
+ /// Iterates over all the leaves of the tree in depth-first preorder.
126
+ ///
127
+ /// The yielded elements include the Miniscript for each leave as well as its depth
128
+ /// in the tree, which is the data required by PSBT (BIP 371).
129
+ pub fn leaves ( & self ) -> TapTreeIter < Pk > {
123
130
match self . tree {
124
- Some ( ref t) => t. iter ( ) ,
131
+ Some ( ref t) => t. leaves ( ) ,
125
132
None => TapTreeIter :: empty ( ) ,
126
133
}
127
134
}
@@ -151,7 +158,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
151
158
TaprootSpendInfo :: new_key_spend ( & secp, self . internal_key . to_x_only_pubkey ( ) , None )
152
159
} else {
153
160
let mut builder = TaprootBuilder :: new ( ) ;
154
- for leaf in self . iter_scripts ( ) {
161
+ for leaf in self . leaves ( ) {
155
162
let script = leaf. miniscript ( ) . encode ( ) ;
156
163
builder = builder
157
164
. add_leaf ( leaf. depth ( ) , script)
@@ -170,7 +177,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
170
177
171
178
/// Checks whether the descriptor is safe.
172
179
pub fn sanity_check ( & self ) -> Result < ( ) , Error > {
173
- for leaf in self . iter_scripts ( ) {
180
+ for leaf in self . leaves ( ) {
174
181
leaf. miniscript ( ) . sanity_check ( ) ?;
175
182
}
176
183
Ok ( ( ) )
@@ -200,7 +207,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
200
207
} ;
201
208
202
209
let wu = tree
203
- . iter ( )
210
+ . leaves ( )
204
211
. filter_map ( |leaf| {
205
212
let script_size = leaf. miniscript ( ) . script_size ( ) ;
206
213
let max_sat_elems = leaf. miniscript ( ) . max_satisfaction_witness_elements ( ) . ok ( ) ?;
@@ -250,7 +257,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
250
257
Some ( tree) => tree,
251
258
} ;
252
259
253
- tree. iter ( )
260
+ tree. leaves ( )
254
261
. filter_map ( |leaf| {
255
262
let script_size = leaf. miniscript ( ) . script_size ( ) ;
256
263
let max_sat_elems = leaf. miniscript ( ) . max_satisfaction_witness_elements ( ) . ok ( ) ?;
@@ -495,7 +502,7 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Tr<Pk> {
495
502
impl < Pk : MiniscriptKey > ForEachKey < Pk > for Tr < Pk > {
496
503
fn for_each_key < ' a , F : FnMut ( & ' a Pk ) -> bool > ( & ' a self , mut pred : F ) -> bool {
497
504
let script_keys_res = self
498
- . iter_scripts ( )
505
+ . leaves ( )
499
506
. all ( |leaf| leaf. miniscript ( ) . for_each_key ( & mut pred) ) ;
500
507
script_keys_res && pred ( & self . internal_key )
501
508
}
@@ -540,7 +547,7 @@ where
540
547
absolute_timelock : None ,
541
548
} ;
542
549
let mut min_wit_len = None ;
543
- for leaf in desc. iter_scripts ( ) {
550
+ for leaf in desc. leaves ( ) {
544
551
let mut satisfaction = if allow_mall {
545
552
match leaf. miniscript ( ) . build_template ( provider) {
546
553
s @ Satisfaction { stack : Witness :: Stack ( _) , .. } => s,
0 commit comments