Functions to create and manage Orchard commitment trees #99

Merged
pitmutt merged 30 commits from rav001 into milestone2 2024-11-05 18:28:46 +00:00
3 changed files with 18 additions and 9 deletions
Showing only changes of commit 1cdd1d75fa - Show all commits

View file

@ -1563,12 +1563,20 @@ pub extern "C" fn rust_wrapper_read_orchard_tree_anchor(
out: *mut u8,
out_len: &mut usize
){
let tree_in: Hfrontier = marshall_from_haskell_var(tree, tree_len, RW);
let leaf = MerkleHashOrchard::from_bytes(&to_array(tree_in.leaf.bytes)).unwrap();
let comm_tree: Frontier<MerkleHashOrchard,32> = Frontier::from_parts(Position::from(tree_in.position), leaf, tree_in.ommers.iter().map(|x| MerkleHashOrchard::from_bytes(&to_array(x.bytes.clone())).unwrap() ).collect()).unwrap();
let root = comm_tree.root();
let h = Hhex { bytes: root.to_bytes().to_vec() };
marshall_to_haskell_var(&h, out, out_len, RW);
let tree_in: Vec<u8> = marshall_from_haskell_var(tree, tree_len, RW);
let tree_reader = Cursor::new(tree_in);
let comm_tree = read_commitment_tree(tree_reader);
match comm_tree {
Ok::<CommitmentTree<MerkleHashOrchard, 32>, _>(c1) => {
let root = c1.root();
let h = Hhex { bytes: root.to_bytes().to_vec() };
marshall_to_haskell_var(&h, out, out_len, RW);
},
Err(_) => {
let h0 = Hhex { bytes: vec![0] };
marshall_to_haskell_var(&h0, out, out_len, RW);
}
}
}
#[no_mangle]

View file

@ -263,7 +263,7 @@ import ZcashHaskell.Types
#}
{# fun unsafe rust_wrapper_read_orchard_tree_anchor as rustWrapperReadOrchardTreeAnchor
{ toBorshVar* `OrchardFrontier'&
{ toBorshVar* `BS.ByteString'&
, getVarBuffer `Buffer HexString'&
}
-> `()'

View file

@ -212,9 +212,10 @@ getOrchardFrontier tree =
withPureBorshVarBuffer $
rustWrapperReadOrchardFrontier $ toBytes $ orchTree tree
getOrchardTreeAnchor :: OrchardFrontier -> HexString
getOrchardTreeAnchor :: OrchardCommitmentTree -> HexString
getOrchardTreeAnchor tree =
withPureBorshVarBuffer $ rustWrapperReadOrchardTreeAnchor tree
withPureBorshVarBuffer $
rustWrapperReadOrchardTreeAnchor $ toBytes $ orchTree tree
getOrchardWitnessAnchor :: OrchardWitness -> HexString
getOrchardWitnessAnchor wit =