Compare commits
2 commits
b3ec3aecbd
...
33085a46bf
Author | SHA1 | Date | |
---|---|---|---|
33085a46bf | |||
c793e0c4ff |
3 changed files with 98 additions and 44 deletions
|
@ -15,6 +15,7 @@ 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]
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ use borsh::{BorshDeserialize, BorshSerialize};
|
|||
|
||||
use haskell_ffi::{
|
||||
error::Result,
|
||||
from_haskell::{marshall_from_haskell_var, marshall_from_haskell_fixed},
|
||||
to_haskell::{marshall_to_haskell_var, marshall_to_haskell_fixed},
|
||||
FromHaskell, HaskellSize, ToHaskell
|
||||
from_haskell::marshall_from_haskell_var,
|
||||
to_haskell::marshall_to_haskell_var,
|
||||
FromHaskell, ToHaskell
|
||||
};
|
||||
|
||||
use secp256k1::SecretKey;
|
||||
|
@ -42,8 +42,7 @@ use incrementalmerkletree::{
|
|||
};
|
||||
|
||||
use zip32::{
|
||||
Scope as SaplingScope,
|
||||
ChildIndex
|
||||
Scope as SaplingScope
|
||||
};
|
||||
|
||||
|
||||
|
@ -728,7 +727,6 @@ 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);
|
||||
}
|
||||
|
@ -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);
|
||||
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()) {
|
||||
|
@ -1866,7 +1864,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) => {
|
||||
|
@ -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 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();
|
||||
|
@ -1954,21 +1952,49 @@ 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);
|
||||
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 {
|
||||
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 => {
|
||||
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);
|
||||
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 {
|
||||
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 => {
|
||||
|
@ -1976,12 +2002,26 @@ 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);
|
||||
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 {
|
||||
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 => {
|
||||
|
@ -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 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);
|
||||
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 {
|
||||
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 {
|
||||
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);
|
||||
|
@ -2039,7 +2093,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);
|
||||
},
|
||||
|
|
|
@ -135,22 +135,21 @@ createTransaction ::
|
|||
-> IO (Either TxError HexString)
|
||||
createTransaction sapAnchor orchAnchor tSpend sSpend oSpend outgoing znet bh build = do
|
||||
txResult <-
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue