Rename TapTree::from_builder

This commit is contained in:
Dr Maxim Orlovsky 2022-04-01 19:46:06 +02:00
parent 219273788c
commit 410412ff01
No known key found for this signature in database
GPG Key ID: FFC0250947E5C6F7
2 changed files with 11 additions and 11 deletions

View File

@ -135,18 +135,18 @@ impl TapTree {
self.0.branch()[0].as_ref().expect("from_inner only parses is_complete builders") self.0.branch()[0].as_ref().expect("from_inner only parses is_complete builders")
} }
/// Converts a [`TaprootBuilder`] into a tree if it is complete binary tree. /// Constructs [`TapTree`] from a [`TaprootBuilder`] if it is complete binary tree.
/// ///
/// # Returns /// # Returns
/// A [`TapTree`] iff the `inner` builder is complete, otherwise return [`IncompleteTapTree`] /// A [`TapTree`] iff the `builder` is complete, otherwise return [`IncompleteTapTree`]
/// error with the content of incomplete builder `inner` instance. /// error with the content of incomplete `builder` instance.
pub fn from_inner(inner: TaprootBuilder) -> Result<Self, IncompleteTapTree> { pub fn from_builder(builder: TaprootBuilder) -> Result<Self, IncompleteTapTree> {
if !inner.is_finalized() { if !builder.is_finalized() {
Err(IncompleteTapTree::NotFinalized(inner)) Err(IncompleteTapTree::NotFinalized(builder))
} else if inner.has_hidden_nodes() { } else if builder.has_hidden_nodes() {
Err(IncompleteTapTree::HiddenParts(inner)) Err(IncompleteTapTree::HiddenParts(builder))
} else { } else {
Ok(TapTree(inner)) Ok(TapTree(builder))
} }
} }

View File

@ -393,14 +393,14 @@ mod tests {
let mut builder = compose_taproot_builder(0x51, &[2, 2, 2]); let mut builder = compose_taproot_builder(0x51, &[2, 2, 2]);
builder = builder.add_leaf_with_ver(3, Script::from_hex("b9").unwrap(), LeafVersion::from_consensus(0xC2).unwrap()).unwrap(); builder = builder.add_leaf_with_ver(3, Script::from_hex("b9").unwrap(), LeafVersion::from_consensus(0xC2).unwrap()).unwrap();
builder = builder.add_hidden_node(3, sha256::Hash::default()).unwrap(); builder = builder.add_hidden_node(3, sha256::Hash::default()).unwrap();
assert!(TapTree::from_inner(builder.clone()).is_err()); assert!(TapTree::from_builder(builder.clone()).is_err());
} }
#[test] #[test]
fn taptree_roundtrip() { fn taptree_roundtrip() {
let mut builder = compose_taproot_builder(0x51, &[2, 2, 2, 3]); let mut builder = compose_taproot_builder(0x51, &[2, 2, 2, 3]);
builder = builder.add_leaf_with_ver(3, Script::from_hex("b9").unwrap(), LeafVersion::from_consensus(0xC2).unwrap()).unwrap(); builder = builder.add_leaf_with_ver(3, Script::from_hex("b9").unwrap(), LeafVersion::from_consensus(0xC2).unwrap()).unwrap();
let tree = TapTree::from_inner(builder).unwrap(); let tree = TapTree::from_builder(builder).unwrap();
let tree_prime = TapTree::deserialize(&tree.serialize()).unwrap(); let tree_prime = TapTree::deserialize(&tree.serialize()).unwrap();
assert_eq!(tree, tree_prime); assert_eq!(tree, tree_prime);
} }