@@ -119,9 +119,16 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
119119
120120 /// Iterate over all scripts in merkle tree. If there is no script path, the iterator
121121 /// 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 > {
123130 match self . tree {
124- Some ( ref t) => t. iter ( ) ,
131+ Some ( ref t) => t. leaves ( ) ,
125132 None => TapTreeIter :: empty ( ) ,
126133 }
127134 }
@@ -151,7 +158,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
151158 TaprootSpendInfo :: new_key_spend ( & secp, self . internal_key . to_x_only_pubkey ( ) , None )
152159 } else {
153160 let mut builder = TaprootBuilder :: new ( ) ;
154- for leaf in self . iter_scripts ( ) {
161+ for leaf in self . leaves ( ) {
155162 let script = leaf. miniscript ( ) . encode ( ) ;
156163 builder = builder
157164 . add_leaf ( leaf. depth ( ) , script)
@@ -170,7 +177,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
170177
171178 /// Checks whether the descriptor is safe.
172179 pub fn sanity_check ( & self ) -> Result < ( ) , Error > {
173- for leaf in self . iter_scripts ( ) {
180+ for leaf in self . leaves ( ) {
174181 leaf. miniscript ( ) . sanity_check ( ) ?;
175182 }
176183 Ok ( ( ) )
@@ -200,7 +207,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
200207 } ;
201208
202209 let wu = tree
203- . iter ( )
210+ . leaves ( )
204211 . filter_map ( |leaf| {
205212 let script_size = leaf. miniscript ( ) . script_size ( ) ;
206213 let max_sat_elems = leaf. miniscript ( ) . max_satisfaction_witness_elements ( ) . ok ( ) ?;
@@ -250,7 +257,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
250257 Some ( tree) => tree,
251258 } ;
252259
253- tree. iter ( )
260+ tree. leaves ( )
254261 . filter_map ( |leaf| {
255262 let script_size = leaf. miniscript ( ) . script_size ( ) ;
256263 let max_sat_elems = leaf. miniscript ( ) . max_satisfaction_witness_elements ( ) . ok ( ) ?;
@@ -495,7 +502,7 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Tr<Pk> {
495502impl < Pk : MiniscriptKey > ForEachKey < Pk > for Tr < Pk > {
496503 fn for_each_key < ' a , F : FnMut ( & ' a Pk ) -> bool > ( & ' a self , mut pred : F ) -> bool {
497504 let script_keys_res = self
498- . iter_scripts ( )
505+ . leaves ( )
499506 . all ( |leaf| leaf. miniscript ( ) . for_each_key ( & mut pred) ) ;
500507 script_keys_res && pred ( & self . internal_key )
501508 }
@@ -540,7 +547,7 @@ where
540547 absolute_timelock : None ,
541548 } ;
542549 let mut min_wit_len = None ;
543- for leaf in desc. iter_scripts ( ) {
550+ for leaf in desc. leaves ( ) {
544551 let mut satisfaction = if allow_mall {
545552 match leaf. miniscript ( ) . build_template ( provider) {
546553 s @ Satisfaction { stack : Witness :: Stack ( _) , .. } => s,
0 commit comments