You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Represents the node information in taproot tree. In contrast to TapTree, this is allowed to have hidden leaves as children.
894
+
///
895
+
/// Helper type used in merkle tree construction allowing one to build sparse merkle trees. The node represents part of the tree that has information about all of its descendants. See how TaprootBuilder works for more details.
896
+
/// You can use TaprootSpendInfo::from_node_info to a get a TaprootSpendInfo from the merkle root NodeInfo.
897
+
#[derive(Debug, uniffi::Object)]
898
+
#[uniffi::export(Display)]
899
+
pubstructNodeInfo(BdkNodeInfo);
900
+
901
+
#[uniffi::export]
902
+
implNodeInfo{
903
+
/// Creates an iterator over all leaves (including hidden leaves) in the tree.
904
+
pubfnleaf_nodes(&self) -> Vec<Arc<LeafNode>>{
905
+
self.0
906
+
.leaf_nodes()
907
+
.map(|ln| Arc::new(LeafNode(ln.clone())))
908
+
.collect()
909
+
}
910
+
911
+
/// Returns the root TapNodeHash of this node info.
assert!(!psbt_outputs.is_empty(),"Output should not be empty");
542
+
println!("Psbt Output: {:?}", psbt_outputs);
543
+
let output = &psbt_outputs[0];
544
+
let witness_script = output
545
+
.witness_script
546
+
.as_ref()
547
+
.expect("Witness script should be present");
548
+
let byte_witness = witness_script.to_bytes();
549
+
let witness_hex = DisplayHex::to_lower_hex_string(&byte_witness);
550
+
let expected_witness_hex = "522103b72bf1f4c738fb44fadd3333789626fa5f3efb0d695c90d126abea721ef6d417210326ee4ece63eabe2ec81eddb5400ae49af6bd7d26cfa536e4ed1217a15a4a5ed621027a51e6ce68730ec4130e702921c9d6473de8151ebc517d5a83c8df93f48aba8a53ae";
551
+
assert_eq!(
552
+
witness_hex, expected_witness_hex,
553
+
"Witness script hex does not match the expected value"
554
+
);
555
+
}
556
+
557
+
#[test]
558
+
fntest_psbt_output_tap_tree(){
559
+
let psbt = sample_psbt_taproot();
560
+
println!("Psbt: {:?}", psbt.json_serialize());
561
+
let psbt_outputs = psbt.output();
562
+
assert!(!psbt_outputs.is_empty(),"Output should not be empty");
"Tap tree root hash does not match the expected value"
576
+
);
577
+
578
+
//Check script and version
579
+
let expected_script_hex = "200f7e1b4af070857b37c203c8759915b7cb97ef99f7d3d9c51eb516791cdb7145ac20a2574e343ae4bcee78c2b061e508e5e817bfa7d8ac5a07f20ac9b39e9933df20ba20400d4657d75ff6b396b59c496f61e25d4d2fe489c792a777682f32655387cbcaba529c";
580
+
let expected_leaf_version = Some(192u8);// 0xc0 which is default for Taproot scripts. 192 in decimal
581
+
582
+
// Get script and version from the first leaf node
583
+
let node_info = tap_tree.node_info();
584
+
println!("Tap tree node infos: {:?}", node_info);
585
+
586
+
let leaf_nodes = node_info.leaf_nodes();
587
+
let leaf_node = &leaf_nodes[0];
588
+
let script = leaf_node.script();
589
+
590
+
let script_byte = script.unwrap().to_bytes();
591
+
let script_hex = DisplayHex::to_lower_hex_string(&script_byte);
592
+
593
+
let leaf_version = leaf_node.leaf_version();
594
+
595
+
assert_eq!(
596
+
script_hex, expected_script_hex,
597
+
"Tap tree script hex does not match the expected value"
598
+
);
599
+
assert_eq!(
600
+
leaf_version, expected_leaf_version,
601
+
"Tap tree leaf version does not match the expected value"
0 commit comments