diff --git a/librustzcash-wrapper/src/lib.rs b/librustzcash-wrapper/src/lib.rs index a0e98b6..3209737 100644 --- a/librustzcash-wrapper/src/lib.rs +++ b/librustzcash-wrapper/src/lib.rs @@ -1445,9 +1445,10 @@ pub extern "C" fn rust_wrapper_read_sapling_witness( out: *mut u8, out_len: &mut usize ){ - let tree_in: Vec = marshall_from_haskell_var(tree, tree_len, RW); - let tree_reader = Cursor::new(tree_in); - let ct: CommitmentTree = read_commitment_tree(tree_reader).unwrap(); + let tree_in: Hfrontier = marshall_from_haskell_var(tree, tree_len, RW); + let leaf = Node::from_bytes(to_array(tree_in.leaf.bytes)).unwrap(); + let frontier: Frontier = Frontier::from_parts(Position::from(tree_in.position), leaf, tree_in.ommers.iter().map(|x| Node::from_bytes(to_array(x.clone())).unwrap() ).collect()).unwrap(); + let ct: CommitmentTree = CommitmentTree::from_frontier(&frontier); let inc_wit = IncrementalWitness::from_tree(ct); let mut out_bytes: Vec = Vec::new(); let result = write_incremental_witness(&inc_wit, &mut out_bytes); diff --git a/src/C/Zcash.chs b/src/C/Zcash.chs index ab4bd54..71c73e5 100644 --- a/src/C/Zcash.chs +++ b/src/C/Zcash.chs @@ -212,7 +212,7 @@ import ZcashHaskell.Types #} {# fun unsafe rust_wrapper_read_sapling_witness as rustWrapperReadSaplingWitness - { toBorshVar* `BS.ByteString'& + { toBorshVar* `SaplingFrontier'& , getVarBuffer `Buffer HexString'& } -> `()' diff --git a/src/ZcashHaskell/Sapling.hs b/src/ZcashHaskell/Sapling.hs index 4b7c286..e15bf4f 100644 --- a/src/ZcashHaskell/Sapling.hs +++ b/src/ZcashHaskell/Sapling.hs @@ -210,15 +210,13 @@ updateSaplingCommitmentTree tree cmu = rustWrapperReadSaplingCommitmentTree tree (hexBytes cmu) -- | Get the Sapling incremental witness from a commitment tree -getSaplingWitness :: SaplingCommitmentTree -> Maybe SaplingWitness +getSaplingWitness :: SaplingFrontier -> Maybe SaplingWitness getSaplingWitness tree = if BS.length (hexBytes wit) > 1 then Just $ SaplingWitness wit else Nothing where - wit = - withPureBorshVarBuffer $ - rustWrapperReadSaplingWitness (hexBytes $ sapTree tree) + wit = withPureBorshVarBuffer $ rustWrapperReadSaplingWitness tree -- | Get the Sapling note position from a witness getSaplingNotePosition :: SaplingWitness -> Integer