Rename TapTree::from_builder
This commit is contained in:
parent
219273788c
commit
410412ff01
|
@ -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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue