feat: add sapling tree anchor function
This commit is contained in:
parent
4c3a188c32
commit
1dcc549bd5
3 changed files with 36 additions and 0 deletions
|
@ -1660,6 +1660,29 @@ pub extern "C" fn rust_wrapper_read_sapling_commitment_tree_parts(
|
|||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_wrapper_read_sapling_tree_anchor(
|
||||
tree: *const u8,
|
||||
tree_len: usize,
|
||||
out: *mut u8,
|
||||
out_len: &mut usize
|
||||
){
|
||||
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<Node, 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]
|
||||
pub extern "C" fn rust_wrapper_read_orchard_frontier(
|
||||
tree: *const u8,
|
||||
|
|
|
@ -276,6 +276,13 @@ import ZcashHaskell.Types
|
|||
-> `()'
|
||||
#}
|
||||
|
||||
{# fun unsafe rust_wrapper_read_sapling_tree_anchor as rustWrapperReadSaplingTreeAnchor
|
||||
{ toBorshVar* `BS.ByteString'&
|
||||
, getVarBuffer `Buffer HexString'&
|
||||
}
|
||||
-> `()'
|
||||
#}
|
||||
|
||||
{# fun unsafe rust_wrapper_read_orchard_node as rustWrapperReadOrchardNode
|
||||
{ toBorshVar* `BS.ByteString'&
|
||||
, getVarBuffer `Buffer HexString'&
|
||||
|
|
|
@ -26,6 +26,7 @@ import C.Zcash
|
|||
, rustWrapperReadSaplingFrontier
|
||||
, rustWrapperReadSaplingNode
|
||||
, rustWrapperReadSaplingPosition
|
||||
, rustWrapperReadSaplingTreeAnchor
|
||||
, rustWrapperReadSaplingTreeParts
|
||||
, rustWrapperReadSaplingWitness
|
||||
, rustWrapperSaplingCheck
|
||||
|
@ -231,6 +232,11 @@ getSaplingTreeParts h =
|
|||
withPureBorshVarBuffer $
|
||||
rustWrapperReadSaplingTreeParts $ toBytes $ sapTree h
|
||||
|
||||
getSaplingTreeAnchor :: SaplingCommitmentTree -> HexString
|
||||
getSaplingTreeAnchor tree =
|
||||
withPureBorshVarBuffer $
|
||||
rustWrapperReadSaplingTreeAnchor $ toBytes $ sapTree tree
|
||||
|
||||
getSaplingFrontier :: SaplingCommitmentTree -> Maybe SaplingFrontier
|
||||
getSaplingFrontier tree =
|
||||
if sf_pos updatedTree > 1
|
||||
|
|
Loading…
Reference in a new issue