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
- Modified frontiers to use `HexString` for ommers
- Optimized `createTransaction`
## [0.7.2.0]

View file

@ -20,9 +20,9 @@ use borsh::{BorshDeserialize, BorshSerialize};
use haskell_ffi::{
error::Result,
from_haskell::marshall_from_haskell_var,
to_haskell::marshall_to_haskell_var,
FromHaskell, ToHaskell
from_haskell::{marshall_from_haskell_var, marshall_from_haskell_fixed},
to_haskell::{marshall_to_haskell_var, marshall_to_haskell_fixed},
FromHaskell, HaskellSize, ToHaskell
};
use secp256k1::SecretKey;
@ -42,7 +42,8 @@ use incrementalmerkletree::{
};
use zip32::{
Scope as SaplingScope
Scope as SaplingScope,
ChildIndex
};
@ -727,6 +728,7 @@ pub extern "C" fn rust_wrapper_f4jumble(
out: *mut u8,
out_len: &mut usize) {
let input: Vec<u8> = marshall_from_haskell_var(input, input_len, RW);
println!("testy mc testface");
let result = f4jumble::f4jumble(&input).unwrap();
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);
for t_in in trans_input {
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();
if net {
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 {
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);
match sp_key {
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 rseed = RandomSeed::from_bytes(to_array(o_in.note.rseed.bytes), &rho).unwrap();
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 wit_reader = Cursor::new(o_in.iw);
let iw: IncrementalWitness<MerkleHashOrchard, 32> = read_incremental_witness(wit_reader).unwrap();
@ -1952,49 +1954,21 @@ pub extern "C" fn rust_wrapper_create_transaction(
1 => {
let recipient = TransparentAddress::PublicKeyHash(to_array(output.to));
let val = NonNegativeAmount::from_u64(output.amt).unwrap();
//println!("t out: {:?} {:?}", val, output.chg);
println!("t out: {:?} {:?}", val, output.chg);
if net {
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);
}
}
let _mb = main_builder.add_transparent_output(&recipient, val);
} else {
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);
}
}
let _tb = test_builder.add_transparent_output(&recipient, val);
}
},
2 => {
let recipient = TransparentAddress::ScriptHash(to_array(output.to));
let val = NonNegativeAmount::from_u64(output.amt).unwrap();
//println!("t out: {:?} {:?}", val, output.chg);
println!("t out: {:?} {:?}", val, output.chg);
if net {
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);
}
}
let _mb = main_builder.add_transparent_output(&recipient, val);
} else {
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);
}
}
let _tb = test_builder.add_transparent_output(&recipient, val);
}
},
3 => {
@ -2002,26 +1976,12 @@ pub extern "C" fn rust_wrapper_create_transaction(
let recipient = PaymentAddress::from_bytes(&to_array(output.to)).unwrap();
let val = NonNegativeAmount::from_u64(output.amt).unwrap();
let memo = MemoBytes::from_bytes(&output.memo).unwrap();
//println!("s out: {:?} {:?}", val, output.chg);
println!("s out: {:?} {:?}", val, output.chg);
if net {
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);
}
}
let _mb = main_builder.add_sapling_output::<String>(ovk, recipient, val, memo);
} else {
let tb = test_builder.add_sapling_output::<String>(ovk, recipient, val, memo);
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);
println!("add sap: {:?}", tb);
}
},
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 val = output.amt;
//println!("o out: {:?} {:?}", val, output.chg);
println!("o out: {:?} {:?}", val, output.chg);
let memo = MemoBytes::from_bytes(&output.memo).unwrap();
if net {
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);
}
}
let _mb = main_builder.add_orchard_output::<String>(ovk, recipient, val, memo);
} else {
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);
}
}
let _tb = test_builder.add_orchard_output::<String>(ovk, recipient, val, memo);
}
},
_ => {
@ -2061,12 +2007,12 @@ pub extern "C" fn rust_wrapper_create_transaction(
}
}
if build {
//let fee_result = if net {
//main_builder.get_fee(&FeeRule::standard())
//} else {
//test_builder.get_fee(&FeeRule::standard())
//};
//println!("fee: {:?}", fee_result);
let fee_result = if net {
main_builder.get_fee(&FeeRule::standard())
} else {
test_builder.get_fee(&FeeRule::standard())
};
println!("fee: {:?}", fee_result);
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_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);
},
Error::ChangeRequired(y1) => {
//println!("change req: {:?}", y1);
println!("change req: {:?}", y1);
let x = Hhex {bytes: vec![1]};
marshall_to_haskell_var(&x, out, out_len, RW);
},

View file

@ -135,21 +135,22 @@ createTransaction ::
-> IO (Either TxError HexString)
createTransaction sapAnchor orchAnchor tSpend sSpend oSpend outgoing znet bh build = do
txResult <-
withBorshBufferOfInitSize 51200 $
rustWrapperCreateTx
(case sapAnchor of
Nothing -> "0"
Just sA -> toBytes $ sapTree sA)
(case orchAnchor of
Nothing -> "0"
Just oA -> toBytes $ orchTree oA)
tSpend
sSpend
oSpend
outgoing
(znet == MainNet)
(fromIntegral bh)
build
do print "calling FFI"
withBorshBufferOfInitSize 51200 $
rustWrapperCreateTx
(case sapAnchor of
Nothing -> "0"
Just sA -> toBytes $ sapTree sA)
(case orchAnchor of
Nothing -> "0"
Just oA -> toBytes $ orchTree oA)
tSpend
sSpend
oSpend
outgoing
(znet == MainNet)
(fromIntegral bh)
build
if BS.length (hexBytes txResult) > 1
then pure $ Right txResult
else case head (BS.unpack $ hexBytes txResult) of