feat: update root testing functions

This commit is contained in:
Rene Vergara 2024-10-30 16:24:02 -05:00
parent 96ee5f4179
commit 1938e162f4
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
3 changed files with 18 additions and 9 deletions

View file

@ -1626,13 +1626,14 @@ pub extern "C" fn rust_wrapper_get_orchard_root(
out_len: &mut usize
){
let tree: CommitmentTree<MerkleHashOrchard, 32> = CommitmentTree::empty();
let root = tree.root_at_depth(level, PathFiller::empty());
let root = tree.root();
let h = Hhex { bytes: root.to_bytes().to_vec() };
marshall_to_haskell_var(&h, out, out_len, RW);
}
#[no_mangle]
pub extern "C" fn rust_wrapper_orchard_add_node(
level: u8,
node: *const u8,
node_len: usize,
out: *mut u8,
@ -1643,10 +1644,17 @@ pub extern "C" fn rust_wrapper_orchard_add_node(
let orchard_note_comm = ExtractedNoteCommitment::from_bytes(&to_array(node_in));
if orchard_note_comm.is_some().into() {
let n = MerkleHashOrchard::from_cmx(&orchard_note_comm.unwrap());
tree.append(n);
let root = tree.root();
let h = Hhex { bytes: root.to_bytes().to_vec() };
marshall_to_haskell_var(&h, out, out_len, RW);
match tree.append(n) {
Ok(()) => {
let root = tree.root_at_depth(level, PathFiller::empty());
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);
}
}
} else {
let h0 = Hhex { bytes: vec![0] };
marshall_to_haskell_var(&h0, out, out_len, RW);

View file

@ -312,7 +312,8 @@ import ZcashHaskell.Types
#}
{# fun unsafe rust_wrapper_orchard_add_node as rustWrapperOrchardAddNodeTest
{ toBorshVar* `BS.ByteString'&
{ `Int8'
, toBorshVar* `BS.ByteString'&
, getVarBuffer `Buffer HexString'&
}
-> `()'

View file

@ -224,9 +224,9 @@ getOrchardRootTest :: Int -> HexString
getOrchardRootTest level =
withPureBorshVarBuffer $ rustWrapperGetOrchardRootTest $ fromIntegral level
addOrchardNodeGetRoot :: BS.ByteString -> HexString
addOrchardNodeGetRoot n =
withPureBorshVarBuffer $ rustWrapperOrchardAddNodeTest n
addOrchardNodeGetRoot :: Int -> BS.ByteString -> HexString
addOrchardNodeGetRoot l n =
withPureBorshVarBuffer $ rustWrapperOrchardAddNodeTest (fromIntegral l) n
-- | Update a Orchard commitment tree
updateOrchardCommitmentTree ::