Skip to content

Commit

Permalink
Make TaprooBuilder::finalize able to return keyspend only
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRubin committed Apr 3, 2022
1 parent 06b697c commit b4158a9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/util/taproot.rs
Expand Up @@ -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<C: secp256k1::Verification>(
mut self,
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
) -> Result<TaprootSpendInfo, TaprootBuilderError> {
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<NodeInfo>] {
Expand Down

0 comments on commit b4158a9

Please sign in to comment.