Functions to handle commitment tree nodes for Sapling and Orchard #100
3 changed files with 35 additions and 0 deletions
|
@ -1631,6 +1631,28 @@ pub extern "C" fn rust_wrapper_get_orchard_root(
|
||||||
marshall_to_haskell_var(&h, out, out_len, RW);
|
marshall_to_haskell_var(&h, out, out_len, RW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn rust_wrapper_orchard_add_node(
|
||||||
|
node: *const u8,
|
||||||
|
node_len: usize,
|
||||||
|
out: *mut u8,
|
||||||
|
out_len: &mut usize
|
||||||
|
){
|
||||||
|
let mut tree: CommitmentTree<MerkleHashOrchard, 32> = CommitmentTree::empty();
|
||||||
|
let node_in: Vec<u8> = marshall_from_haskell_var(node, node_len, RW);
|
||||||
|
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);
|
||||||
|
} else {
|
||||||
|
let h0 = Hhex { bytes: vec![0] };
|
||||||
|
marshall_to_haskell_var(&h0, out, out_len, RW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_wrapper_read_orchard_commitment_tree(
|
pub extern "C" fn rust_wrapper_read_orchard_commitment_tree(
|
||||||
tree: *const u8,
|
tree: *const u8,
|
||||||
|
|
|
@ -311,6 +311,14 @@ import ZcashHaskell.Types
|
||||||
-> `Word64'
|
-> `Word64'
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
{# fun unsafe rust_wrapper_orchard_add_node as rustWrapperOrchardAddNodeTest
|
||||||
|
{ toBorshVar* `BS.ByteString'&
|
||||||
|
, getVarBuffer `Buffer HexString'&
|
||||||
|
}
|
||||||
|
-> `()'
|
||||||
|
|
||||||
|
#}
|
||||||
|
|
||||||
{# fun unsafe rust_wrapper_update_sapling_witness as rustWrapperUpdateSaplingWitness
|
{# fun unsafe rust_wrapper_update_sapling_witness as rustWrapperUpdateSaplingWitness
|
||||||
{ toBorshVar* `BS.ByteString'&
|
{ toBorshVar* `BS.ByteString'&
|
||||||
, toBorshVar* `[BS.ByteString]'&
|
, toBorshVar* `[BS.ByteString]'&
|
||||||
|
|
|
@ -22,6 +22,7 @@ import C.Zcash
|
||||||
, rustWrapperGenOrchardReceiver
|
, rustWrapperGenOrchardReceiver
|
||||||
, rustWrapperGenOrchardSpendKey
|
, rustWrapperGenOrchardSpendKey
|
||||||
, rustWrapperGetOrchardRootTest
|
, rustWrapperGetOrchardRootTest
|
||||||
|
, rustWrapperOrchardAddNodeTest
|
||||||
, rustWrapperOrchardCheck
|
, rustWrapperOrchardCheck
|
||||||
, rustWrapperOrchardNoteDecode
|
, rustWrapperOrchardNoteDecode
|
||||||
, rustWrapperOrchardNoteDecodeSK
|
, rustWrapperOrchardNoteDecodeSK
|
||||||
|
@ -223,6 +224,10 @@ getOrchardRootTest :: Int -> HexString
|
||||||
getOrchardRootTest level =
|
getOrchardRootTest level =
|
||||||
withPureBorshVarBuffer $ rustWrapperGetOrchardRootTest $ fromIntegral level
|
withPureBorshVarBuffer $ rustWrapperGetOrchardRootTest $ fromIntegral level
|
||||||
|
|
||||||
|
addOrchardNodeGetRoot :: BS.ByteString -> HexString
|
||||||
|
addOrchardNodeGetRoot n =
|
||||||
|
withPureBorshVarBuffer $ rustWrapperOrchardAddNodeTest n
|
||||||
|
|
||||||
-- | Update a Orchard commitment tree
|
-- | Update a Orchard commitment tree
|
||||||
updateOrchardCommitmentTree ::
|
updateOrchardCommitmentTree ::
|
||||||
OrchardFrontier -- ^ the base tree
|
OrchardFrontier -- ^ the base tree
|
||||||
|
|
Loading…
Reference in a new issue