diff --git a/librustzcash-wrapper/src/lib.rs b/librustzcash-wrapper/src/lib.rs index c4f3316..a027dc5 100644 --- a/librustzcash-wrapper/src/lib.rs +++ b/librustzcash-wrapper/src/lib.rs @@ -170,7 +170,7 @@ use bech32::{ pub enum RW {} pub const RW: PhantomData = PhantomData; -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct RawData { hrp: Vec, bytes: Vec @@ -190,7 +190,7 @@ impl ToHaskell for RawData { //} //} -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct HrawTx { bytes: Vec, s: bool, @@ -204,7 +204,7 @@ impl ToHaskell for HrawTx { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct HshieldedOutput { pub cv: Hhex, cmu: Hhex, @@ -248,7 +248,7 @@ impl HshieldedOutput { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Hhex { bytes: Vec } @@ -261,7 +261,7 @@ impl ToHaskell for Hhex { } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Haction { nf: Hhex, rk: Hhex, @@ -290,7 +290,7 @@ impl Haction { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Hnote { note: u64, recipient: Vec, @@ -307,7 +307,7 @@ impl ToHaskell for Hnote { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Hrseed { kind: u8, bytes: Vec @@ -328,7 +328,7 @@ impl ToHaskell for Hrseed { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Hua { net: u8, o_rec: Vec, @@ -361,7 +361,7 @@ impl Hua { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Htx { txid: Vec, locktime: u32, @@ -379,7 +379,7 @@ impl ToHaskell for Htx { } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct HTBundle { empty: bool, vin: Vec, @@ -400,7 +400,7 @@ impl HTBundle { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct HTxIn { outpoint: Houtpoint, script: Vec, @@ -420,7 +420,7 @@ impl HTxIn { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct HTxOut { amt: i64, script: Vec @@ -449,7 +449,7 @@ impl HTxOut { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Houtpoint { hash: Vec, index: u32 @@ -479,7 +479,7 @@ impl Houtpoint { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct HtransparentInput { sk: Vec, utxo: Houtpoint, @@ -500,7 +500,7 @@ impl ToHaskell for HtransparentInput { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct HSBundle { empty: bool, spends: Vec, @@ -523,7 +523,7 @@ impl HSBundle { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Hspend { cv: Hhex, anchor: Hhex, @@ -552,7 +552,7 @@ impl Hspend { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct HsaplingInput { sk: Vec, note: Hnote, @@ -567,7 +567,7 @@ impl FromHaskell for HsaplingInput { } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct HorchardInput { sk: Vec, note: Hnote, @@ -581,7 +581,7 @@ impl FromHaskell for HorchardInput { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Houtput { kind: u8, ovk: Vec, @@ -598,7 +598,7 @@ impl FromHaskell for Houtput { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct HOBundle { empty: bool, actions: Vec, @@ -623,7 +623,7 @@ impl HOBundle { } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Hflags { spends: bool, outputs: bool @@ -642,7 +642,7 @@ impl Hflags { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Hufvk { net: u8, orchard: Vec, @@ -671,7 +671,7 @@ impl Hufvk { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct Hsvk { vk: Vec, ovk: Vec @@ -795,7 +795,7 @@ pub extern "C" fn rust_wrapper_svk_decode( true } Err(e) => { - print!("{}", e); + print!("{:?}", e); false } } @@ -1647,23 +1647,24 @@ pub extern "C" fn rust_wrapper_create_transaction( out_len: &mut usize){ let sap_wit_in: Vec = marshall_from_haskell_var(sap_wit, sap_wit_len, RW); let sap_wit_reader = Cursor::new(sap_wit_in); - let sap_iw: Option> = read_incremental_witness(sap_wit_reader).ok(); + let sap_iw = read_commitment_tree::>, SAPLING_DEPTH>(sap_wit_reader); let sap_anchor = match sap_iw { - Some(s_iw) => { + Ok(s_iw) => { Some(SaplingAnchor::from(s_iw.root())) }, - None => { + Err(_e) => { None } }; + println!("{:?}", sap_anchor); 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: Option> = read_incremental_witness(orch_wit_reader).ok(); + let orch_iw = read_commitment_tree::>, 32>(orch_wit_reader); let orch_anchor = match orch_iw { - Some(o_iw) => { + Ok(o_iw) => { Some(OrchardAnchor::from(o_iw.root())) }, - None => { + Err(_e) => { None } }; @@ -1677,6 +1678,7 @@ pub extern "C" fn rust_wrapper_create_transaction( if net { match main_builder.add_transparent_input(k, t_in.utxo.unpack(), t_in.coin.unpack()) { Ok(()) => { + println!("added t-input in main"); continue; }, Err(_e) => { println!("Error reading transparent input"); } @@ -1684,6 +1686,7 @@ pub extern "C" fn rust_wrapper_create_transaction( } else { match test_builder.add_transparent_input(k, t_in.utxo.unpack(), t_in.coin.unpack()) { Ok(()) => { + println!("added t-input in test"); continue; }, Err(_e) => { println!("Error reading transparent input"); } @@ -1771,12 +1774,13 @@ pub extern "C" fn rust_wrapper_create_transaction( } }, 4 => { - let sk = SpendingKey::from_bytes(output.ovk[0..32].try_into().unwrap()).unwrap(); - let ovk = if output.chg { - Some(FullViewingKey::from(&sk).to_ovk(Scope::Internal)) - }else { - Some(FullViewingKey::from(&sk).to_ovk(Scope::External)) - }; + //let sk = SpendingKey::from_bytes(output.ovk[0..32].try_into().unwrap()).unwrap(); + //let ovk = if output.chg { + //Some(FullViewingKey::from(&sk).to_ovk(Scope::Internal)) + //} else { + //Some(FullViewingKey::from(&sk).to_ovk(Scope::External)) + //}; + let ovk = None; let recipient = OrchardAddress::from_raw_address_bytes(&to_array(output.to)).unwrap(); let val = output.amt; let memo = MemoBytes::from_bytes(&output.memo).unwrap(); @@ -1793,10 +1797,10 @@ pub extern "C" fn rust_wrapper_create_transaction( } let spend_params_in: Vec = marshall_from_haskell_var(sapspend, sapspend_len, RW); let spend_params_reader = Cursor::new(spend_params_in); - let spend_prover = SpendParameters::read(spend_params_reader, true).unwrap(); + let spend_prover = SpendParameters::read(spend_params_reader, false).unwrap(); let output_params_in: Vec = marshall_from_haskell_var(sapoutput, sapoutput_len, RW); let output_params_reader = Cursor::new(output_params_in); - let output_prover = OutputParameters::read(output_params_reader, true).unwrap(); + let output_prover = OutputParameters::read(output_params_reader, false).unwrap(); let result = if net { main_builder.build(OsRng, &spend_prover, &output_prover, &FeeRule::standard()) } else { @@ -1811,11 +1815,11 @@ pub extern "C" fn rust_wrapper_create_transaction( }, Err(e) => { match e { - Error::InsufficientFunds(_y) => { + Error::InsufficientFunds(y) => { let x = Hhex {bytes: vec![0]}; marshall_to_haskell_var(&x, out, out_len, RW); }, - Error::ChangeRequired(_y1) => { + Error::ChangeRequired(y1) => { let x = Hhex {bytes: vec![1]}; marshall_to_haskell_var(&x, out, out_len, RW); }, @@ -1823,27 +1827,27 @@ pub extern "C" fn rust_wrapper_create_transaction( let x = Hhex {bytes: vec![2]}; marshall_to_haskell_var(&x, out, out_len, RW); }, - Error::Balance(x) => { + Error::Balance(y3) => { let x = Hhex {bytes: vec![3]}; marshall_to_haskell_var(&x, out, out_len, RW); }, - Error::TransparentBuild(x) => { + Error::TransparentBuild(y4) => { let x = Hhex {bytes: vec![4]}; marshall_to_haskell_var(&x, out, out_len, RW); }, - Error::SaplingBuild(x) => { + Error::SaplingBuild(y5) => { let x = Hhex {bytes: vec![5]}; marshall_to_haskell_var(&x, out, out_len, RW); }, - Error::OrchardBuild(x) => { + Error::OrchardBuild(y7) => { let x = Hhex {bytes: vec![6]}; marshall_to_haskell_var(&x, out, out_len, RW); }, - Error::OrchardSpend(x) => { + Error::OrchardSpend(y8) => { let x = Hhex {bytes: vec![7]}; marshall_to_haskell_var(&x, out, out_len, RW); }, - Error::OrchardRecipient(x) => { + Error::OrchardRecipient(y9) => { let x = Hhex {bytes: vec![8]}; marshall_to_haskell_var(&x, out, out_len, RW); }, diff --git a/src/ZcashHaskell/Utils.hs b/src/ZcashHaskell/Utils.hs index 9c87f39..db001c8 100644 --- a/src/ZcashHaskell/Utils.hs +++ b/src/ZcashHaskell/Utils.hs @@ -123,8 +123,8 @@ readZebraTransaction hex = rawTx = (withPureBorshVarBuffer . rustWrapperTxRead) $ hexBytes hex createTransaction :: - Maybe SaplingWitness -- ^ to obtain the Sapling anchor - -> Maybe OrchardWitness -- ^ to obtain the Orchard anchor + Maybe SaplingCommitmentTree -- ^ to obtain the Sapling anchor + -> Maybe OrchardCommitmentTree -- ^ to obtain the Orchard anchor -> [TransparentTxSpend] -- ^ the list of transparent notes to spend -> [SaplingTxSpend] -- ^ the list of Sapling notes to spend -> [OrchardTxSpend] -- ^ the list of Orchard notes to spend @@ -156,10 +156,10 @@ createTransaction sapAnchor orchAnchor tSpend sSpend oSpend outgoing sParams oPa rustWrapperCreateTx (case sapAnchor of Nothing -> "0" - Just sA -> toBytes $ sapWit sA) + Just sA -> toBytes $ sapTree sA) (case orchAnchor of Nothing -> "0" - Just oA -> toBytes $ orchWit oA) + Just oA -> toBytes $ orchTree oA) tSpend sSpend oSpend