Functions to handle commitment tree nodes for Sapling and Orchard #100

Merged
pitmutt merged 50 commits from rav001 into milestone2 2024-11-15 18:48:36 +00:00
Showing only changes of commit c205bc6cf5 - Show all commits

View file

@ -1873,7 +1873,13 @@ pub extern "C" fn rust_wrapper_read_orchard_path_anchor(
){ ){
let path_in: Hpath = marshall_from_haskell_var(path, path_len, RW); 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 cmx_in: Vec<u8> = marshall_from_haskell_var(cmx, cmx_len, RW);
let mk_path = orchard::tree::MerklePath::from_parts(path_in.position, to_array(path_in.path.iter().map(|x| MerkleHashOrchard::from_bytes(&to_array(x.bytes.clone())).unwrap()).collect())); let mk_path = orchard::tree::MerklePath::from_parts(path_in.position, to_array(path_in.path.iter().map(|x|
if x.bytes.len() > 1 {
MerkleHashOrchard::from_bytes(&to_array(x.bytes.clone())).unwrap()
} else {
MerkleHashOrchard::empty_leaf()
}
).collect()));
let nc = ExtractedNoteCommitment::from_bytes(&to_array(cmx_in)); let nc = ExtractedNoteCommitment::from_bytes(&to_array(cmx_in));
if nc.is_some().into() { if nc.is_some().into() {
let anchor = mk_path.root(nc.unwrap()); let anchor = mk_path.root(nc.unwrap());
@ -2152,7 +2158,7 @@ pub extern "C" fn rust_wrapper_create_transaction(
} else { } else {
None None
}; };
println!("{:?}", sapling_anchor); //println!("{:?}", sapling_anchor);
let orch_input: Vec<HorchardInput> = marshall_from_haskell_var(o_input, o_input_len, RW); let orch_input: Vec<HorchardInput> = marshall_from_haskell_var(o_input, o_input_len, RW);
let orch_anchor_in : Vec<u8> = marshall_from_haskell_var(orch_wit, orch_wit_len, RW); let orch_anchor_in : Vec<u8> = marshall_from_haskell_var(orch_wit, orch_wit_len, RW);
let orch_anchor = MerkleHashOrchard::from_bytes(&to_array(orch_anchor_in)); let orch_anchor = MerkleHashOrchard::from_bytes(&to_array(orch_anchor_in));
@ -2162,7 +2168,7 @@ pub extern "C" fn rust_wrapper_create_transaction(
} else { } else {
None None
}; };
println!("{:?}", orchard_anchor); //println!("{:?}", orchard_anchor);
let build_config = BuildConfig::Standard {sapling_anchor, orchard_anchor}; let build_config = BuildConfig::Standard {sapling_anchor, orchard_anchor};
let mut main_builder = Builder::new(MainNetwork, BlockHeight::from(bl_height), build_config); let mut main_builder = Builder::new(MainNetwork, BlockHeight::from(bl_height), build_config);
let mut test_builder = Builder::new(TestNetwork, BlockHeight::from(bl_height), build_config); let mut test_builder = Builder::new(TestNetwork, BlockHeight::from(bl_height), build_config);
@ -2248,18 +2254,24 @@ pub extern "C" fn rust_wrapper_create_transaction(
let rho = Rho::from_bytes(&to_array(o_in.note.rho)).unwrap(); let rho = Rho::from_bytes(&to_array(o_in.note.rho)).unwrap();
let rseed = RandomSeed::from_bytes(to_array(o_in.note.rseed.bytes), &rho).unwrap(); let rseed = RandomSeed::from_bytes(to_array(o_in.note.rseed.bytes), &rho).unwrap();
let val = NoteValue::from_raw(o_in.note.note); let val = NoteValue::from_raw(o_in.note.note);
println!("o inp: {:?}", val); //println!("o inp: {:?}", val);
let note = Note::from_parts(pay_addr, val, rho, rseed).unwrap(); let note = Note::from_parts(pay_addr, val, rho, rseed).unwrap();
let merkle_path = orchard::tree::MerklePath::from_parts(o_in.iw.position, to_array(o_in.iw.path.iter().map(|x| MerkleHashOrchard::from_bytes(&to_array(x.bytes.clone())).unwrap()).collect())); let merkle_path = orchard::tree::MerklePath::from_parts(o_in.iw.position, to_array(o_in.iw.path.iter().map(|x|
if x.bytes.len() > 1 {
MerkleHashOrchard::from_bytes(&to_array(x.bytes.clone())).unwrap()
} else {
MerkleHashOrchard::empty_leaf()
}
).collect()));
if net { if net {
let mb = main_builder.add_orchard_spend::<String>(&sp_key, note, merkle_path); let mb = main_builder.add_orchard_spend::<String>(&sp_key, note, merkle_path);
match mb { match mb {
Ok(()) => { Ok(()) => {
println!("added orchard inp: {:?}", val); //println!("added orchard inp: {:?}", val);
continue; continue;
}, },
Err(e) => { Err(e) => {
println!("failed orchard inp: {:?}", e); //println!("failed orchard inp: {:?}", e);
let x = Hhex {bytes: vec![7]}; let x = Hhex {bytes: vec![7]};
marshall_to_haskell_var(&x, out, out_len, RW); marshall_to_haskell_var(&x, out, out_len, RW);
} }
@ -2268,11 +2280,11 @@ pub extern "C" fn rust_wrapper_create_transaction(
let tb = test_builder.add_orchard_spend::<String>(&sp_key, note, merkle_path); let tb = test_builder.add_orchard_spend::<String>(&sp_key, note, merkle_path);
match tb { match tb {
Ok(()) => { Ok(()) => {
println!("added orchard inp: {:?}", val); //println!("added orchard inp: {:?}", val);
continue; continue;
}, },
Err(e) => { Err(e) => {
println!("failed orchard inp: {:?}", e); //println!("failed orchard inp: {:?}", e);
let x = Hhex {bytes: vec![7]}; let x = Hhex {bytes: vec![7]};
marshall_to_haskell_var(&x, out, out_len, RW); marshall_to_haskell_var(&x, out, out_len, RW);
} }
@ -2367,7 +2379,7 @@ pub extern "C" fn rust_wrapper_create_transaction(
}; };
let recipient = OrchardAddress::from_raw_address_bytes(&to_array(output.to)).unwrap(); let recipient = OrchardAddress::from_raw_address_bytes(&to_array(output.to)).unwrap();
let val = output.amt; let val = output.amt;
println!("o out: {:?} {:?}", val, output.chg); //println!("o out: {:?} {:?}", val, output.chg);
let memo = MemoBytes::from_bytes(&output.memo).unwrap(); let memo = MemoBytes::from_bytes(&output.memo).unwrap();
if net { if net {
let mb = main_builder.add_orchard_output::<String>(ovk, recipient, val, memo); let mb = main_builder.add_orchard_output::<String>(ovk, recipient, val, memo);
@ -2423,7 +2435,7 @@ pub extern "C" fn rust_wrapper_create_transaction(
Err(e) => { Err(e) => {
match e { match e {
Error::InsufficientFunds(y) => { Error::InsufficientFunds(y) => {
println!("ins funds: {:?}", y); //println!("ins funds: {:?}", y);
let x = Hhex {bytes: vec![0]}; let x = Hhex {bytes: vec![0]};
marshall_to_haskell_var(&x, out, out_len, RW); marshall_to_haskell_var(&x, out, out_len, RW);
}, },