Merge rust-bitcoin/rust-bitcoin#936: Make TaprooBuilder::finalize able to return keyspend only

7969b7a43e Make TaprooBuilder::finalize able to return keyspend only (Jeremy Rubin)

Pull request description:

ACKs for top commit:
  JeremyRubin:
    > ACK 7969b7a
  sanket1729:
    ACK 7969b7a43e
  apoelstra:
    ACK 7969b7a43e

Tree-SHA512: 26d0b730590f610a858061394faafaa74b13dd353f34ccf1c6166d0cbb62937010eed5661a887f7bea4f983ac9eab8cdca10a5fe7bd74f2dd5701a7782cbac64
This commit is contained in:
sanket1729 2022-04-20 09:38:44 -07:00
commit 9f79f8d1ce
No known key found for this signature in database
GPG Key ID: 648FFB183E0870A2
1 changed files with 9 additions and 8 deletions

View File

@ -479,20 +479,21 @@ impl TaprootBuilder {
} }
/// Creates a [`TaprootSpendInfo`] with the given internal key. /// 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<C: secp256k1::Verification>( pub fn finalize<C: secp256k1::Verification>(
mut self, mut self,
secp: &Secp256k1<C>, secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey, internal_key: UntweakedPublicKey,
) -> Result<TaprootSpendInfo, TaprootBuilderError> { ) -> Result<TaprootSpendInfo, TaprootBuilderError> {
if self.branch.len() > 1 { match self.branch.pop() {
return Err(TaprootBuilderError::IncompleteTree); None => Ok(TaprootSpendInfo::new_key_spend(secp, internal_key, None)),
Some(Some(node)) => {
Ok(TaprootSpendInfo::from_node_info(secp, internal_key, node))
}
_ => Err(TaprootBuilderError::IncompleteTree),
} }
let 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))
} }
pub(crate) fn branch(&self) -> &[Option<NodeInfo>] { pub(crate) fn branch(&self) -> &[Option<NodeInfo>] {