From 3969490283420af0bb193590a1e5d4b6828cc2f9 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 30 Sep 2024 14:50:54 -0500 Subject: [PATCH] feat: Use the notes to determine anchors --- librustzcash-wrapper/src/lib.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/librustzcash-wrapper/src/lib.rs b/librustzcash-wrapper/src/lib.rs index 6034424..10e8df0 100644 --- a/librustzcash-wrapper/src/lib.rs +++ b/librustzcash-wrapper/src/lib.rs @@ -1702,14 +1702,24 @@ pub extern "C" fn rust_wrapper_create_transaction( let orch_wit_in: Vec = marshall_from_haskell_var(orch_wit, orch_wit_len, RW); let orch_wit_reader = Cursor::new(orch_wit_in); let orch_iw = read_commitment_tree::>, 32>(orch_wit_reader); - let orch_anchor = match orch_iw { - Ok(o_iw) => { - Some(OrchardAnchor::from(o_iw.root())) - }, - Err(_e) => { + let orch_input: Vec = marshall_from_haskell_var(o_input, o_input_len, RW); + //let orch_anchor = match orch_iw { + //Ok(o_iw) => { + //Some(OrchardAnchor::from(o_iw.root())) + //}, + //Err(_e) => { + //None + //} + //}; + let orch_anchor = + if orch_input.is_empty() { None - } - }; + } else { + let oi = &orch_input[0]; + let wit_reader = Cursor::new(&oi.iw); + let iw: IncrementalWitness = read_incremental_witness(wit_reader).unwrap(); + Some(OrchardAnchor::from(iw.root())) + }; let build_config = BuildConfig::Standard {sapling_anchor: sap_anchor, orchard_anchor: orch_anchor}; 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); @@ -1764,7 +1774,6 @@ pub extern "C" fn rust_wrapper_create_transaction( } } } - let orch_input: Vec = marshall_from_haskell_var(o_input, o_input_len, RW); for o_in in orch_input { if o_in.sk.len() > 1 { let sp_key = SpendingKey::from_bytes(o_in.sk[0..32].try_into().unwrap()).unwrap();