Implement Frontier for Sapling #97
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 {
|
|
||||||
Ok(mut comm_tree) => {
|
|
||||||
let node_in: Vec<u8> = marshall_from_haskell_var(node, node_len, RW);
|
let node_in: Vec<u8> = marshall_from_haskell_var(node, node_len, RW);
|
||||||
let sap_note_comm = SaplingNoteCommitment::from_bytes(&to_array(node_in));
|
let sap_note_comm = SaplingNoteCommitment::from_bytes(&to_array(node_in));
|
||||||
if sap_note_comm.is_some().into() {
|
if sap_note_comm.is_some().into() {
|
||||||
let n = Node::from_cmu(&sap_note_comm.unwrap());
|
let n = Node::from_cmu(&sap_note_comm.unwrap());
|
||||||
comm_tree.append(n);
|
comm_tree.append(n);
|
||||||
let mut out_bytes: Vec<u8> = Vec::new();
|
let (pos, leaf, omm) = comm_tree.into_parts();
|
||||||
let result = write_commitment_tree(&comm_tree, &mut out_bytes );
|
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()};
|
||||||
match result {
|
marshall_to_haskell_var(&f, out, out_len, RW);
|
||||||
Ok(()) => {
|
|
||||||
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 {
|
} else {
|
||||||
let h0 = Hhex { bytes: vec![0]};
|
let f0 = Hfrontier { position: 0, leaf: Hhex { bytes: vec![0]}, ommers: vec![vec![0]]};
|
||||||
marshall_to_haskell_var(&h0, out, out_len, RW);
|
marshall_to_haskell_var(&f0, 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