From 17f629b514e8ed5b6de946e074c97952c6e717e2 Mon Sep 17 00:00:00 2001 From: Jeremy Rubin Date: Sun, 3 Apr 2022 12:19:55 -0400 Subject: [PATCH] Make TaprooBuilder::finalize able to return keyspend only --- src/util/taproot.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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] {