Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TaprooBuilder::finalize able to return keyspend only #936

Merged
merged 1 commit into from Apr 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/util/taproot.rs
Expand Up @@ -467,20 +467,21 @@ 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);
match self.branch.pop() {
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),
JeremyRubin marked this conversation as resolved.
Show resolved Hide resolved

}
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>] {
Expand Down