Support for Zebra 2.1.0 #102

Merged
pitmutt merged 97 commits from rav001 into master 2024-12-14 12:51:07 +00:00
4 changed files with 45 additions and 0 deletions
Showing only changes of commit 8244ffa1ce - Show all commits

View file

@ -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]

View file

@ -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,

View file

@ -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'&

View file

@ -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