diff --git a/librustzcash-wrapper/src/lib.rs b/librustzcash-wrapper/src/lib.rs index 926aa42..a234c82 100644 --- a/librustzcash-wrapper/src/lib.rs +++ b/librustzcash-wrapper/src/lib.rs @@ -1563,12 +1563,20 @@ pub extern "C" fn rust_wrapper_read_orchard_tree_anchor( out: *mut u8, out_len: &mut usize ){ - let tree_in: Hfrontier = marshall_from_haskell_var(tree, tree_len, RW); - let leaf = MerkleHashOrchard::from_bytes(&to_array(tree_in.leaf.bytes)).unwrap(); - let comm_tree: Frontier = Frontier::from_parts(Position::from(tree_in.position), leaf, tree_in.ommers.iter().map(|x| MerkleHashOrchard::from_bytes(&to_array(x.bytes.clone())).unwrap() ).collect()).unwrap(); - let root = comm_tree.root(); - let h = Hhex { bytes: root.to_bytes().to_vec() }; - marshall_to_haskell_var(&h, out, out_len, RW); + let tree_in: Vec = marshall_from_haskell_var(tree, tree_len, RW); + let tree_reader = Cursor::new(tree_in); + let comm_tree = read_commitment_tree(tree_reader); + match comm_tree { + Ok::, _>(c1) => { + let root = c1.root(); + 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); + } + } } #[no_mangle] diff --git a/src/C/Zcash.chs b/src/C/Zcash.chs index 6e721de..9c485d2 100644 --- a/src/C/Zcash.chs +++ b/src/C/Zcash.chs @@ -263,7 +263,7 @@ import ZcashHaskell.Types #} {# fun unsafe rust_wrapper_read_orchard_tree_anchor as rustWrapperReadOrchardTreeAnchor - { toBorshVar* `OrchardFrontier'& + { toBorshVar* `BS.ByteString'& , getVarBuffer `Buffer HexString'& } -> `()' diff --git a/src/ZcashHaskell/Orchard.hs b/src/ZcashHaskell/Orchard.hs index 6a21eb8..e99e9e3 100644 --- a/src/ZcashHaskell/Orchard.hs +++ b/src/ZcashHaskell/Orchard.hs @@ -212,9 +212,10 @@ getOrchardFrontier tree = withPureBorshVarBuffer $ rustWrapperReadOrchardFrontier $ toBytes $ orchTree tree -getOrchardTreeAnchor :: OrchardFrontier -> HexString +getOrchardTreeAnchor :: OrchardCommitmentTree -> HexString getOrchardTreeAnchor tree = - withPureBorshVarBuffer $ rustWrapperReadOrchardTreeAnchor tree + withPureBorshVarBuffer $ + rustWrapperReadOrchardTreeAnchor $ toBytes $ orchTree tree getOrchardWitnessAnchor :: OrchardWitness -> HexString getOrchardWitnessAnchor wit =