fix(rust): remove debug messages

This commit is contained in:
Rene Vergara 2024-10-30 11:42:36 -05:00
parent b3ec3aecbd
commit c793e0c4ff
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
2 changed files with 97 additions and 44 deletions

View file

@ -20,9 +20,9 @@ use borsh::{BorshDeserialize, BorshSerialize};
use haskell_ffi::{ use haskell_ffi::{
error::Result, error::Result,
from_haskell::{marshall_from_haskell_var, marshall_from_haskell_fixed}, from_haskell::marshall_from_haskell_var,
to_haskell::{marshall_to_haskell_var, marshall_to_haskell_fixed}, to_haskell::marshall_to_haskell_var,
FromHaskell, HaskellSize, ToHaskell FromHaskell, ToHaskell
}; };
use secp256k1::SecretKey; use secp256k1::SecretKey;
@ -42,8 +42,7 @@ use incrementalmerkletree::{
}; };
use zip32::{ use zip32::{
Scope as SaplingScope, Scope as SaplingScope
ChildIndex
}; };
@ -728,7 +727,6 @@ pub extern "C" fn rust_wrapper_f4jumble(
out: *mut u8, out: *mut u8,
out_len: &mut usize) { out_len: &mut usize) {
let input: Vec<u8> = marshall_from_haskell_var(input, input_len, RW); let input: Vec<u8> = marshall_from_haskell_var(input, input_len, RW);
println!("testy mc testface");
let result = f4jumble::f4jumble(&input).unwrap(); let result = f4jumble::f4jumble(&input).unwrap();
marshall_to_haskell_var(&result, out, out_len, RW); marshall_to_haskell_var(&result, out, out_len, RW);
} }
@ -1843,7 +1841,7 @@ pub extern "C" fn rust_wrapper_create_transaction(
let trans_input: Vec<HtransparentInput> = marshall_from_haskell_var(t_input, t_input_len, RW); let trans_input: Vec<HtransparentInput> = marshall_from_haskell_var(t_input, t_input_len, RW);
for t_in in trans_input { for t_in in trans_input {
if t_in.sk.len() > 1 { if t_in.sk.len() > 1 {
println!("t inp: {:?}", t_in); //println!("t inp: {:?}", t_in);
let k = SecretKey::from_slice(&t_in.sk).unwrap(); let k = SecretKey::from_slice(&t_in.sk).unwrap();
if net { if net {
match main_builder.add_transparent_input(k, t_in.utxo.unpack(), t_in.coin.unpack()) { match main_builder.add_transparent_input(k, t_in.utxo.unpack(), t_in.coin.unpack()) {
@ -1866,7 +1864,7 @@ pub extern "C" fn rust_wrapper_create_transaction(
} }
for s_in in sap_input { for s_in in sap_input {
if s_in.sk.len() > 1 { if s_in.sk.len() > 1 {
println!("s inp: {:?}", s_in); //println!("s inp: {:?}", s_in);
let sp_key = ExtendedSpendingKey::from_bytes(&s_in.sk); let sp_key = ExtendedSpendingKey::from_bytes(&s_in.sk);
match sp_key { match sp_key {
Ok(sk) => { Ok(sk) => {
@ -1918,7 +1916,7 @@ 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 wit_reader = Cursor::new(o_in.iw); let wit_reader = Cursor::new(o_in.iw);
let iw: IncrementalWitness<MerkleHashOrchard, 32> = read_incremental_witness(wit_reader).unwrap(); let iw: IncrementalWitness<MerkleHashOrchard, 32> = read_incremental_witness(wit_reader).unwrap();
@ -1954,21 +1952,49 @@ pub extern "C" fn rust_wrapper_create_transaction(
1 => { 1 => {
let recipient = TransparentAddress::PublicKeyHash(to_array(output.to)); let recipient = TransparentAddress::PublicKeyHash(to_array(output.to));
let val = NonNegativeAmount::from_u64(output.amt).unwrap(); let val = NonNegativeAmount::from_u64(output.amt).unwrap();
println!("t out: {:?} {:?}", val, output.chg); //println!("t out: {:?} {:?}", val, output.chg);
if net { if net {
let _mb = main_builder.add_transparent_output(&recipient, val); let mb = main_builder.add_transparent_output(&recipient, val);
match mb {
Ok(()) => { continue; },
Err(_e) => {
let x = Hhex {bytes: vec![4]};
marshall_to_haskell_var(&x, out, out_len, RW);
}
}
} else { } else {
let _tb = test_builder.add_transparent_output(&recipient, val); let tb = test_builder.add_transparent_output(&recipient, val);
match tb {
Ok(()) => { continue; },
Err(_e) => {
let x = Hhex {bytes: vec![4]};
marshall_to_haskell_var(&x, out, out_len, RW);
}
}
} }
}, },
2 => { 2 => {
let recipient = TransparentAddress::ScriptHash(to_array(output.to)); let recipient = TransparentAddress::ScriptHash(to_array(output.to));
let val = NonNegativeAmount::from_u64(output.amt).unwrap(); let val = NonNegativeAmount::from_u64(output.amt).unwrap();
println!("t out: {:?} {:?}", val, output.chg); //println!("t out: {:?} {:?}", val, output.chg);
if net { if net {
let _mb = main_builder.add_transparent_output(&recipient, val); let mb = main_builder.add_transparent_output(&recipient, val);
match mb {
Ok(()) => { continue; },
Err(_e) => {
let x = Hhex {bytes: vec![4]};
marshall_to_haskell_var(&x, out, out_len, RW);
}
}
} else { } else {
let _tb = test_builder.add_transparent_output(&recipient, val); let tb = test_builder.add_transparent_output(&recipient, val);
match tb {
Ok(()) => { continue; },
Err(_e) => {
let x = Hhex {bytes: vec![4]};
marshall_to_haskell_var(&x, out, out_len, RW);
}
}
} }
}, },
3 => { 3 => {
@ -1976,12 +2002,26 @@ pub extern "C" fn rust_wrapper_create_transaction(
let recipient = PaymentAddress::from_bytes(&to_array(output.to)).unwrap(); let recipient = PaymentAddress::from_bytes(&to_array(output.to)).unwrap();
let val = NonNegativeAmount::from_u64(output.amt).unwrap(); let val = NonNegativeAmount::from_u64(output.amt).unwrap();
let memo = MemoBytes::from_bytes(&output.memo).unwrap(); let memo = MemoBytes::from_bytes(&output.memo).unwrap();
println!("s out: {:?} {:?}", val, output.chg); //println!("s out: {:?} {:?}", val, output.chg);
if net { if net {
let _mb = main_builder.add_sapling_output::<String>(ovk, recipient, val, memo); let mb = main_builder.add_sapling_output::<String>(ovk, recipient, val, memo);
match mb {
Ok(()) => { continue; },
Err(_e) => {
let x = Hhex {bytes: vec![5]};
marshall_to_haskell_var(&x, out, out_len, RW);
}
}
} else { } else {
let tb = test_builder.add_sapling_output::<String>(ovk, recipient, val, memo); let tb = test_builder.add_sapling_output::<String>(ovk, recipient, val, memo);
println!("add sap: {:?}", tb); match tb {
Ok(()) => { continue; },
Err(_e) => {
let x = Hhex {bytes: vec![5]};
marshall_to_haskell_var(&x, out, out_len, RW);
}
}
//println!("add sap: {:?}", tb);
} }
}, },
4 => { 4 => {
@ -1993,12 +2033,26 @@ 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);
match mb {
Ok(()) => { continue; },
Err(_e) => {
let x = Hhex {bytes: vec![6]};
marshall_to_haskell_var(&x, out, out_len, RW);
}
}
} else { } else {
let _tb = test_builder.add_orchard_output::<String>(ovk, recipient, val, memo); let tb = test_builder.add_orchard_output::<String>(ovk, recipient, val, memo);
match tb {
Ok(()) => { continue; },
Err(_e) => {
let x = Hhex {bytes: vec![6]};
marshall_to_haskell_var(&x, out, out_len, RW);
}
}
} }
}, },
_ => { _ => {
@ -2007,12 +2061,12 @@ pub extern "C" fn rust_wrapper_create_transaction(
} }
} }
if build { if build {
let fee_result = if net { //let fee_result = if net {
main_builder.get_fee(&FeeRule::standard()) //main_builder.get_fee(&FeeRule::standard())
} else { //} else {
test_builder.get_fee(&FeeRule::standard()) //test_builder.get_fee(&FeeRule::standard())
}; //};
println!("fee: {:?}", fee_result); //println!("fee: {:?}", fee_result);
let (spend_params_in, output_params_in) = load_sapling_parameters(); let (spend_params_in, output_params_in) = load_sapling_parameters();
//let spend_params_in: Vec<u8> = marshall_from_haskell_var(sapspend, sapspend_len, RW); //let spend_params_in: Vec<u8> = marshall_from_haskell_var(sapspend, sapspend_len, RW);
let spend_params_reader = Cursor::new(spend_params_in); let spend_params_reader = Cursor::new(spend_params_in);
@ -2039,7 +2093,7 @@ pub extern "C" fn rust_wrapper_create_transaction(
marshall_to_haskell_var(&x, out, out_len, RW); marshall_to_haskell_var(&x, out, out_len, RW);
}, },
Error::ChangeRequired(y1) => { Error::ChangeRequired(y1) => {
println!("change req: {:?}", y1); //println!("change req: {:?}", y1);
let x = Hhex {bytes: vec![1]}; let x = Hhex {bytes: vec![1]};
marshall_to_haskell_var(&x, out, out_len, RW); marshall_to_haskell_var(&x, out, out_len, RW);
}, },

View file

@ -135,7 +135,6 @@ createTransaction ::
-> IO (Either TxError HexString) -> IO (Either TxError HexString)
createTransaction sapAnchor orchAnchor tSpend sSpend oSpend outgoing znet bh build = do createTransaction sapAnchor orchAnchor tSpend sSpend oSpend outgoing znet bh build = do
txResult <- txResult <-
do print "calling FFI"
withBorshBufferOfInitSize 51200 $ withBorshBufferOfInitSize 51200 $
rustWrapperCreateTx rustWrapperCreateTx
(case sapAnchor of (case sapAnchor of