Functions to handle commitment tree nodes for Sapling and Orchard #100
3 changed files with 18 additions and 9 deletions
|
@ -1626,13 +1626,14 @@ pub extern "C" fn rust_wrapper_get_orchard_root(
|
||||||
out_len: &mut usize
|
out_len: &mut usize
|
||||||
){
|
){
|
||||||
let tree: CommitmentTree<MerkleHashOrchard, 32> = CommitmentTree::empty();
|
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() };
|
let h = Hhex { bytes: root.to_bytes().to_vec() };
|
||||||
marshall_to_haskell_var(&h, out, out_len, RW);
|
marshall_to_haskell_var(&h, out, out_len, RW);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_wrapper_orchard_add_node(
|
pub extern "C" fn rust_wrapper_orchard_add_node(
|
||||||
|
level: u8,
|
||||||
node: *const u8,
|
node: *const u8,
|
||||||
node_len: usize,
|
node_len: usize,
|
||||||
out: *mut u8,
|
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));
|
let orchard_note_comm = ExtractedNoteCommitment::from_bytes(&to_array(node_in));
|
||||||
if orchard_note_comm.is_some().into() {
|
if orchard_note_comm.is_some().into() {
|
||||||
let n = MerkleHashOrchard::from_cmx(&orchard_note_comm.unwrap());
|
let n = MerkleHashOrchard::from_cmx(&orchard_note_comm.unwrap());
|
||||||
tree.append(n);
|
match tree.append(n) {
|
||||||
let root = tree.root();
|
Ok(()) => {
|
||||||
|
let root = tree.root_at_depth(level, PathFiller::empty());
|
||||||
let h = Hhex { bytes: root.to_bytes().to_vec() };
|
let h = Hhex { bytes: root.to_bytes().to_vec() };
|
||||||
marshall_to_haskell_var(&h, out, out_len, RW);
|
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 {
|
} else {
|
||||||
let h0 = Hhex { bytes: vec![0] };
|
let h0 = Hhex { bytes: vec![0] };
|
||||||
marshall_to_haskell_var(&h0, out, out_len, RW);
|
marshall_to_haskell_var(&h0, out, out_len, RW);
|
||||||
|
|
|
@ -312,7 +312,8 @@ import ZcashHaskell.Types
|
||||||
#}
|
#}
|
||||||
|
|
||||||
{# fun unsafe rust_wrapper_orchard_add_node as rustWrapperOrchardAddNodeTest
|
{# fun unsafe rust_wrapper_orchard_add_node as rustWrapperOrchardAddNodeTest
|
||||||
{ toBorshVar* `BS.ByteString'&
|
{ `Int8'
|
||||||
|
, toBorshVar* `BS.ByteString'&
|
||||||
, getVarBuffer `Buffer HexString'&
|
, getVarBuffer `Buffer HexString'&
|
||||||
}
|
}
|
||||||
-> `()'
|
-> `()'
|
||||||
|
|
|
@ -224,9 +224,9 @@ getOrchardRootTest :: Int -> HexString
|
||||||
getOrchardRootTest level =
|
getOrchardRootTest level =
|
||||||
withPureBorshVarBuffer $ rustWrapperGetOrchardRootTest $ fromIntegral level
|
withPureBorshVarBuffer $ rustWrapperGetOrchardRootTest $ fromIntegral level
|
||||||
|
|
||||||
addOrchardNodeGetRoot :: BS.ByteString -> HexString
|
addOrchardNodeGetRoot :: Int -> BS.ByteString -> HexString
|
||||||
addOrchardNodeGetRoot n =
|
addOrchardNodeGetRoot l n =
|
||||||
withPureBorshVarBuffer $ rustWrapperOrchardAddNodeTest n
|
withPureBorshVarBuffer $ rustWrapperOrchardAddNodeTest (fromIntegral l) n
|
||||||
|
|
||||||
-- | Update a Orchard commitment tree
|
-- | Update a Orchard commitment tree
|
||||||
updateOrchardCommitmentTree ::
|
updateOrchardCommitmentTree ::
|
||||||
|
|
Loading…
Reference in a new issue