diff --git a/src/util/taproot.rs b/src/util/taproot.rs index b7880402f2..e7112fc88d 100644 --- a/src/util/taproot.rs +++ b/src/util/taproot.rs @@ -467,20 +467,20 @@ impl TaprootBuilder { } /// Creates a [`TaprootSpendInfo`] with the given internal key. + /// + // TODO: in a future breaking API change, this no longer needs to return result pub fn finalize( mut self, secp: &Secp256k1, internal_key: UntweakedPublicKey, ) -> Result { - if self.branch.len() > 1 { - return Err(TaprootBuilderError::IncompleteTree); - } - let node = self + if let Some(node) = self .branch - .pop() - .ok_or(TaprootBuilderError::EmptyTree)? - .expect("Builder invariant: last element of the branch must be some"); - Ok(TaprootSpendInfo::from_node_info(secp, internal_key, node)) + .pop() { + Ok(TaprootSpendInfo::from_node_info(secp, internal_key, node)) + } else { + Ok(TaprootSpendInfo::new_key_spend(secp, internal_key, None)) + } } pub(crate) fn branch(&self) -> &[Option] {