fix(rust): SaplingFrontier marshalling
This commit is contained in:
parent
96cfe3a52a
commit
5a9ed11c25
1 changed files with 14 additions and 32 deletions
|
@ -1403,39 +1403,21 @@ pub extern "C" fn rust_wrapper_read_sapling_commitment_tree(
|
||||||
out: *mut u8,
|
out: *mut u8,
|
||||||
out_len: &mut usize
|
out_len: &mut usize
|
||||||
){
|
){
|
||||||
let tree_in: Vec<u8> = marshall_from_haskell_var(tree, tree_len, RW);
|
let tree_in: Hfrontier = marshall_from_haskell_var(tree, tree_len, RW);
|
||||||
let tree_reader = Cursor::new(tree_in);
|
let leaf = Node::from_bytes(to_array(tree_in.leaf.bytes)).unwrap();
|
||||||
let mut ct = read_commitment_tree::<Node, Cursor<Vec<u8>>, SAPLING_DEPTH>(tree_reader);
|
let mut comm_tree = NonEmptyFrontier::from_parts(Position::from(tree_in.position), leaf, tree_in.ommers.iter().map(|x| Node::from_bytes(to_array(x.clone())).unwrap() ).collect()).unwrap();
|
||||||
match ct {
|
let node_in: Vec<u8> = marshall_from_haskell_var(node, node_len, RW);
|
||||||
Ok(mut comm_tree) => {
|
let sap_note_comm = SaplingNoteCommitment::from_bytes(&to_array(node_in));
|
||||||
let node_in: Vec<u8> = marshall_from_haskell_var(node, node_len, RW);
|
if sap_note_comm.is_some().into() {
|
||||||
let sap_note_comm = SaplingNoteCommitment::from_bytes(&to_array(node_in));
|
let n = Node::from_cmu(&sap_note_comm.unwrap());
|
||||||
if sap_note_comm.is_some().into() {
|
comm_tree.append(n);
|
||||||
let n = Node::from_cmu(&sap_note_comm.unwrap());
|
let (pos, leaf, omm) = comm_tree.into_parts();
|
||||||
comm_tree.append(n);
|
let f = Hfrontier { position: <u64>::from(pos), leaf: Hhex { bytes: leaf.to_bytes().to_vec()}, ommers: omm.iter().map(|&x| x.to_bytes().to_vec()).collect()};
|
||||||
let mut out_bytes: Vec<u8> = Vec::new();
|
marshall_to_haskell_var(&f, out, out_len, RW);
|
||||||
let result = write_commitment_tree(&comm_tree, &mut out_bytes );
|
} else {
|
||||||
match result {
|
let f0 = Hfrontier { position: 0, leaf: Hhex { bytes: vec![0]}, ommers: vec![vec![0]]};
|
||||||
Ok(()) => {
|
marshall_to_haskell_var(&f0, out, out_len, RW);
|
||||||
let h = Hhex { bytes: out_bytes};
|
|
||||||
marshall_to_haskell_var(&h, out, out_len, RW);
|
|
||||||
},
|
|
||||||
Err(_e) => {
|
|
||||||
let h0 = Hhex { bytes: vec![0]};
|
|
||||||
marshall_to_haskell_var(&h0, 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]
|
||||||
|
|
Loading…
Reference in a new issue