feat: add sapling merkle path test
This commit is contained in:
parent
1dcc549bd5
commit
8244ffa1ce
4 changed files with 45 additions and 0 deletions
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Sapling commitment node functions
|
- Sapling commitment node functions
|
||||||
|
- Sapling Merkle path test
|
||||||
|
|
||||||
## [0.7.4.0]
|
## [0.7.4.0]
|
||||||
|
|
||||||
|
|
|
@ -1683,6 +1683,37 @@ pub extern "C" fn rust_wrapper_read_sapling_tree_anchor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn rust_wrapper_read_sapling_path_anchor(
|
||||||
|
path: *const u8,
|
||||||
|
path_len: usize,
|
||||||
|
cmx: *const u8,
|
||||||
|
cmx_len: usize,
|
||||||
|
out: *mut u8,
|
||||||
|
out_len: &mut usize
|
||||||
|
){
|
||||||
|
let path_in: Hpath = marshall_from_haskell_var(path, path_len, RW);
|
||||||
|
let cmx_in: Vec<u8> = marshall_from_haskell_var(cmx, cmx_len, RW);
|
||||||
|
let mk_path = sapling_crypto::MerklePath::from_parts(path_in.path.iter().map(|x| Node::from_bytes(to_array(x.bytes.clone())).unwrap()).collect(), Position::from(u64::from(path_in.position)));
|
||||||
|
match mk_path {
|
||||||
|
Ok(mp1) => {
|
||||||
|
let nc = SaplingNoteCommitment::from_bytes(&to_array(cmx_in));
|
||||||
|
if nc.is_some().into() {
|
||||||
|
let anchor = mp1.root(Node::from_cmu(&nc.unwrap()));
|
||||||
|
let h = Hhex { bytes: anchor.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);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(_e) =>{
|
||||||
|
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_frontier(
|
pub extern "C" fn rust_wrapper_read_orchard_frontier(
|
||||||
tree: *const u8,
|
tree: *const u8,
|
||||||
|
|
|
@ -283,6 +283,14 @@ import ZcashHaskell.Types
|
||||||
-> `()'
|
-> `()'
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
{# fun unsafe rust_wrapper_read_sapling_path_anchor as rustWrapperReadSaplingPathAnchor
|
||||||
|
{ toBorshVar* `MerklePath'&
|
||||||
|
, toBorshVar* `BS.ByteString'&
|
||||||
|
, getVarBuffer `Buffer HexString'&
|
||||||
|
}
|
||||||
|
-> `()'
|
||||||
|
#}
|
||||||
|
|
||||||
{# fun unsafe rust_wrapper_read_orchard_node as rustWrapperReadOrchardNode
|
{# fun unsafe rust_wrapper_read_orchard_node as rustWrapperReadOrchardNode
|
||||||
{ toBorshVar* `BS.ByteString'&
|
{ toBorshVar* `BS.ByteString'&
|
||||||
, getVarBuffer `Buffer HexString'&
|
, getVarBuffer `Buffer HexString'&
|
||||||
|
|
|
@ -25,6 +25,7 @@ import C.Zcash
|
||||||
, rustWrapperReadSaplingCommitmentTree
|
, rustWrapperReadSaplingCommitmentTree
|
||||||
, rustWrapperReadSaplingFrontier
|
, rustWrapperReadSaplingFrontier
|
||||||
, rustWrapperReadSaplingNode
|
, rustWrapperReadSaplingNode
|
||||||
|
, rustWrapperReadSaplingPathAnchor
|
||||||
, rustWrapperReadSaplingPosition
|
, rustWrapperReadSaplingPosition
|
||||||
, rustWrapperReadSaplingTreeAnchor
|
, rustWrapperReadSaplingTreeAnchor
|
||||||
, rustWrapperReadSaplingTreeParts
|
, rustWrapperReadSaplingTreeParts
|
||||||
|
@ -237,6 +238,10 @@ getSaplingTreeAnchor tree =
|
||||||
withPureBorshVarBuffer $
|
withPureBorshVarBuffer $
|
||||||
rustWrapperReadSaplingTreeAnchor $ toBytes $ sapTree tree
|
rustWrapperReadSaplingTreeAnchor $ toBytes $ sapTree tree
|
||||||
|
|
||||||
|
getSaplingPathAnchor :: HexString -> MerklePath -> HexString
|
||||||
|
getSaplingPathAnchor hex p =
|
||||||
|
withPureBorshVarBuffer $ rustWrapperReadSaplingPathAnchor p (hexBytes hex)
|
||||||
|
|
||||||
getSaplingFrontier :: SaplingCommitmentTree -> Maybe SaplingFrontier
|
getSaplingFrontier :: SaplingCommitmentTree -> Maybe SaplingFrontier
|
||||||
getSaplingFrontier tree =
|
getSaplingFrontier tree =
|
||||||
if sf_pos updatedTree > 1
|
if sf_pos updatedTree > 1
|
||||||
|
|
Loading…
Reference in a new issue