Skip to content

Commit a2138aa

Browse files
author
ChallengeDev210
committed
Merge rust-bitcoin/rust-bitcoin#936: Make TaprooBuilder::finalize able to return keyspend only
7969b7a Make TaprooBuilder::finalize able to return keyspend only (Jeremy Rubin) Pull request description: ACKs for top commit: JeremyRubin: > ACK 7969b7a sanket1729: ACK 7969b7a apoelstra: ACK 7969b7a Tree-SHA512: 26d0b730590f610a858061394faafaa74b13dd353f34ccf1c6166d0cbb62937010eed5661a887f7bea4f983ac9eab8cdca10a5fe7bd74f2dd5701a7782cbac64
2 parents a314848 + 4f7388b commit a2138aa

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/util/taproot.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,20 +479,21 @@ impl TaprootBuilder {
479479
}
480480

481481
/// Creates a [`TaprootSpendInfo`] with the given internal key.
482+
///
483+
// TODO: in a future breaking API change, this no longer needs to return result
482484
pub fn finalize<C: secp256k1::Verification>(
483485
mut self,
484486
secp: &Secp256k1<C>,
485487
internal_key: UntweakedPublicKey,
486488
) -> Result<TaprootSpendInfo, TaprootBuilderError> {
487-
if self.branch.len() > 1 {
488-
return Err(TaprootBuilderError::IncompleteTree);
489+
match self.branch.pop() {
490+
None => Ok(TaprootSpendInfo::new_key_spend(secp, internal_key, None)),
491+
Some(Some(node)) => {
492+
Ok(TaprootSpendInfo::from_node_info(secp, internal_key, node))
493+
}
494+
_ => Err(TaprootBuilderError::IncompleteTree),
495+
489496
}
490-
let node = self
491-
.branch
492-
.pop()
493-
.ok_or(TaprootBuilderError::EmptyTree)?
494-
.expect("Builder invariant: last element of the branch must be some");
495-
Ok(TaprootSpendInfo::from_node_info(secp, internal_key, node))
496497
}
497498

498499
pub(crate) fn branch(&self) -> &[Option<NodeInfo>] {

0 commit comments

Comments
 (0)