File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -467,20 +467,21 @@ impl TaprootBuilder {
467
467
}
468
468
469
469
/// Creates a [`TaprootSpendInfo`] with the given internal key.
470
+ ///
471
+ // TODO: in a future breaking API change, this no longer needs to return result
470
472
pub fn finalize < C : secp256k1:: Verification > (
471
473
mut self ,
472
474
secp : & Secp256k1 < C > ,
473
475
internal_key : UntweakedPublicKey ,
474
476
) -> Result < TaprootSpendInfo , TaprootBuilderError > {
475
- if self . branch . len ( ) > 1 {
476
- return Err ( TaprootBuilderError :: IncompleteTree ) ;
477
+ match self . branch . pop ( ) {
478
+ None => Ok ( TaprootSpendInfo :: new_key_spend ( secp, internal_key, None ) ) ,
479
+ Some ( Some ( node) ) => {
480
+ Ok ( TaprootSpendInfo :: from_node_info ( secp, internal_key, node) )
481
+ }
482
+ _ => Err ( TaprootBuilderError :: IncompleteTree ) ,
483
+
477
484
}
478
- let node = self
479
- . branch
480
- . pop ( )
481
- . ok_or ( TaprootBuilderError :: EmptyTree ) ?
482
- . expect ( "Builder invariant: last element of the branch must be some" ) ;
483
- Ok ( TaprootSpendInfo :: from_node_info ( secp, internal_key, node) )
484
485
}
485
486
486
487
pub ( crate ) fn branch ( & self ) -> & [ Option < NodeInfo > ] {
You can’t perform that action at this time.
0 commit comments