Compare commits

..

No commits in common. "33085a46bff80d63a2fb81a0fa2db705765c9ee0" and "b3ec3aecbd0d5555538ed8e431b430df40bb4855" have entirely different histories.

3 changed files with 44 additions and 98 deletions

View file

@ -15,7 +15,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Modified frontiers to use `HexString` for ommers - Modified frontiers to use `HexString` for ommers
- Optimized `createTransaction`
## [0.7.2.0] ## [0.7.2.0]

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, from_haskell::{marshall_from_haskell_var, marshall_from_haskell_fixed},
to_haskell::marshall_to_haskell_var, to_haskell::{marshall_to_haskell_var, marshall_to_haskell_fixed},
FromHaskell, ToHaskell FromHaskell, HaskellSize, ToHaskell
}; };
use secp256k1::SecretKey; use secp256k1::SecretKey;
@ -42,7 +42,8 @@ use incrementalmerkletree::{
}; };
use zip32::{ use zip32::{
Scope as SaplingScope Scope as SaplingScope,
ChildIndex
}; };
@ -727,6 +728,7 @@ 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);
} }
@ -1841,7 +1843,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()) {
@ -1864,7 +1866,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) => {
@ -1916,7 +1918,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();
@ -1952,49 +1954,21 @@ 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 => {
@ -2002,26 +1976,12 @@ 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);
match tb { println!("add sap: {:?}", 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 => {
@ -2033,26 +1993,12 @@ 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);
}
}
} }
}, },
_ => { _ => {
@ -2061,12 +2007,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);
@ -2093,7 +2039,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,21 +135,22 @@ 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 <-
withBorshBufferOfInitSize 51200 $ do print "calling FFI"
rustWrapperCreateTx withBorshBufferOfInitSize 51200 $
(case sapAnchor of rustWrapperCreateTx
Nothing -> "0" (case sapAnchor of
Just sA -> toBytes $ sapTree sA) Nothing -> "0"
(case orchAnchor of Just sA -> toBytes $ sapTree sA)
Nothing -> "0" (case orchAnchor of
Just oA -> toBytes $ orchTree oA) Nothing -> "0"
tSpend Just oA -> toBytes $ orchTree oA)
sSpend tSpend
oSpend sSpend
outgoing oSpend
(znet == MainNet) outgoing
(fromIntegral bh) (znet == MainNet)
build (fromIntegral bh)
build
if BS.length (hexBytes txResult) > 1 if BS.length (hexBytes txResult) > 1
then pure $ Right txResult then pure $ Right txResult
else case head (BS.unpack $ hexBytes txResult) of else case head (BS.unpack $ hexBytes txResult) of