Functions to create and manage Orchard commitment trees #99
3 changed files with 18 additions and 9 deletions
|
@ -1563,12 +1563,20 @@ pub extern "C" fn rust_wrapper_read_orchard_tree_anchor(
|
||||||
out: *mut u8,
|
out: *mut u8,
|
||||||
out_len: &mut usize
|
out_len: &mut usize
|
||||||
){
|
){
|
||||||
let tree_in: Hfrontier = marshall_from_haskell_var(tree, tree_len, RW);
|
let tree_in: Vec<u8> = marshall_from_haskell_var(tree, tree_len, RW);
|
||||||
let leaf = MerkleHashOrchard::from_bytes(&to_array(tree_in.leaf.bytes)).unwrap();
|
let tree_reader = Cursor::new(tree_in);
|
||||||
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 comm_tree = read_commitment_tree(tree_reader);
|
||||||
let root = comm_tree.root();
|
match comm_tree {
|
||||||
let h = Hhex { bytes: root.to_bytes().to_vec() };
|
Ok::<CommitmentTree<MerkleHashOrchard, 32>, _>(c1) => {
|
||||||
marshall_to_haskell_var(&h, out, out_len, RW);
|
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]
|
#[no_mangle]
|
||||||
|
|
|
@ -263,7 +263,7 @@ import ZcashHaskell.Types
|
||||||
#}
|
#}
|
||||||
|
|
||||||
{# fun unsafe rust_wrapper_read_orchard_tree_anchor as rustWrapperReadOrchardTreeAnchor
|
{# fun unsafe rust_wrapper_read_orchard_tree_anchor as rustWrapperReadOrchardTreeAnchor
|
||||||
{ toBorshVar* `OrchardFrontier'&
|
{ toBorshVar* `BS.ByteString'&
|
||||||
, getVarBuffer `Buffer HexString'&
|
, getVarBuffer `Buffer HexString'&
|
||||||
}
|
}
|
||||||
-> `()'
|
-> `()'
|
||||||
|
|
|
@ -212,9 +212,10 @@ getOrchardFrontier tree =
|
||||||
withPureBorshVarBuffer $
|
withPureBorshVarBuffer $
|
||||||
rustWrapperReadOrchardFrontier $ toBytes $ orchTree tree
|
rustWrapperReadOrchardFrontier $ toBytes $ orchTree tree
|
||||||
|
|
||||||
getOrchardTreeAnchor :: OrchardFrontier -> HexString
|
getOrchardTreeAnchor :: OrchardCommitmentTree -> HexString
|
||||||
getOrchardTreeAnchor tree =
|
getOrchardTreeAnchor tree =
|
||||||
withPureBorshVarBuffer $ rustWrapperReadOrchardTreeAnchor tree
|
withPureBorshVarBuffer $
|
||||||
|
rustWrapperReadOrchardTreeAnchor $ toBytes $ orchTree tree
|
||||||
|
|
||||||
getOrchardWitnessAnchor :: OrchardWitness -> HexString
|
getOrchardWitnessAnchor :: OrchardWitness -> HexString
|
||||||
getOrchardWitnessAnchor wit =
|
getOrchardWitnessAnchor wit =
|
||||||
|
|
Loading…
Reference in a new issue