@@ -266,6 +266,13 @@ pub struct ZcoinTxDetails {
266
266
internal_id : i64 ,
267
267
}
268
268
269
+ struct GenTxData < ' a > {
270
+ tx : ZTransaction ,
271
+ data : AdditionalTxData ,
272
+ sync_guard : SaplingSyncGuard < ' a > ,
273
+ rseeds : Vec < String > ,
274
+ }
275
+
269
276
impl ZCoin {
270
277
#[ inline]
271
278
pub fn utxo_rpc_client ( & self ) -> & UtxoRpcClientEnum { & self . utxo_arc . rpc_client }
@@ -375,11 +382,7 @@ impl ZCoin {
375
382
}
376
383
}
377
384
378
- async fn gen_tx (
379
- & self ,
380
- t_outputs : Vec < TxOut > ,
381
- z_outputs : Vec < ZOutput > ,
382
- ) -> Result < ( ZTransaction , AdditionalTxData , SaplingSyncGuard < ' _ > ) , MmError < GenTxError > > {
385
+ async fn gen_tx ( & self , t_outputs : Vec < TxOut > , z_outputs : Vec < ZOutput > ) -> Result < GenTxData , MmError < GenTxError > > {
383
386
const MAX_RETRIES : usize = 40 ;
384
387
const RETRY_DELAY : f64 = 15.0 ;
385
388
let mut retries = 0 ;
@@ -439,7 +442,7 @@ impl ZCoin {
439
442
& self ,
440
443
t_outputs : Vec < TxOut > ,
441
444
z_outputs : Vec < ZOutput > ,
442
- ) -> Result < ( ZTransaction , AdditionalTxData , SaplingSyncGuard < ' _ > ) , MmError < GenTxError > > {
445
+ ) -> Result < GenTxData , MmError < GenTxError > > {
443
446
let sync_guard = self . wait_for_gen_tx_blockchain_sync ( ) . await ?;
444
447
445
448
let tx_fee = self . get_one_kbyte_tx_fee ( ) . await ?;
@@ -462,15 +465,15 @@ impl ZCoin {
462
465
463
466
let mut tx_builder = ZTxBuilder :: new ( self . consensus_params ( ) , sync_guard. respawn_guard . current_block ( ) ) ;
464
467
465
- let mut selected_notes_rseed : Vec < String > = vec ! [ ] ;
468
+ let mut rseeds : Vec < String > = vec ! [ ] ;
466
469
for spendable_note in spendable_notes {
467
470
let rseed = match & spendable_note. rseed {
468
471
Rseed :: BeforeZip212 ( rcm) => rcm. to_string ( ) ,
469
472
Rseed :: AfterZip212 ( rseed) => {
470
473
jubjub:: Fr :: from_bytes_wide ( prf_expand ( rseed, & [ 0x04 ] ) . as_array ( ) ) . to_string ( )
471
474
} ,
472
475
} ;
473
- selected_notes_rseed . push ( rseed) ;
476
+ rseeds . push ( rseed) ;
474
477
475
478
total_input_amount += big_decimal_from_sat_unsigned ( spendable_note. note_value . into ( ) , self . decimals ( ) ) ;
476
479
@@ -547,31 +550,33 @@ impl ZCoin {
547
550
. await ?
548
551
. tx_result ?;
549
552
550
- info ! ( "rseeds :{:?}" , selected_notes_rseed) ;
551
- for rseed in selected_notes_rseed {
552
- info ! ( "saving tx notes rseed!" ) ;
553
- self . z_fields
554
- . locked_notes_db
555
- . insert_note ( tx. txid ( ) . to_string ( ) , rseed)
556
- . await ?;
557
- }
558
-
559
- let additional_data = AdditionalTxData {
553
+ let data = AdditionalTxData {
560
554
received_by_me,
561
555
spent_by_me : sat_from_big_decimal ( & total_input_amount, self . decimals ( ) ) ?,
562
556
fee_amount : sat_from_big_decimal ( & tx_fee, self . decimals ( ) ) ?,
563
557
unused_change : 0 ,
564
558
kmd_rewards : None ,
565
559
} ;
566
- Ok ( ( tx, additional_data, sync_guard) )
560
+
561
+ Ok ( GenTxData {
562
+ tx,
563
+ data,
564
+ sync_guard,
565
+ rseeds,
566
+ } )
567
567
}
568
568
569
569
pub async fn send_outputs (
570
570
& self ,
571
571
t_outputs : Vec < TxOut > ,
572
572
z_outputs : Vec < ZOutput > ,
573
573
) -> Result < ZTransaction , MmError < SendOutputsErr > > {
574
- let ( tx, _, mut sync_guard) = self . gen_tx ( t_outputs, z_outputs) . await ?;
574
+ let GenTxData {
575
+ tx,
576
+ rseeds,
577
+ mut sync_guard,
578
+ ..
579
+ } = self . gen_tx ( t_outputs, z_outputs) . await ?;
575
580
let mut tx_bytes = Vec :: with_capacity ( 1024 ) ;
576
581
tx. write ( & mut tx_bytes) . expect ( "Write should not fail" ) ;
577
582
@@ -580,6 +585,15 @@ impl ZCoin {
580
585
. compat ( )
581
586
. await ?;
582
587
588
+ for rseed in rseeds {
589
+ info ! ( "saving tx notes rseed for {}!" , tx. txid( ) . to_string( ) ) ;
590
+ self . z_fields
591
+ . locked_notes_db
592
+ . insert_note ( tx. txid ( ) . to_string ( ) , rseed)
593
+ . await
594
+ . mm_err ( |err| SendOutputsErr :: InternalError ( err. to_string ( ) ) ) ?;
595
+ }
596
+
583
597
sync_guard. respawn_guard . watch_for_tx ( tx. txid ( ) ) ;
584
598
Ok ( tx)
585
599
}
@@ -1987,7 +2001,7 @@ impl InitWithdrawCoin for ZCoin {
1987
2001
memo,
1988
2002
} ;
1989
2003
1990
- let ( tx, data, _sync_guard ) = self . gen_tx ( vec ! [ ] , vec ! [ z_output] ) . await ?;
2004
+ let GenTxData { tx, data, rseeds , .. } = self . gen_tx ( vec ! [ ] , vec ! [ z_output] ) . await ?;
1991
2005
let mut tx_bytes = Vec :: with_capacity ( 1024 ) ;
1992
2006
tx. write ( & mut tx_bytes)
1993
2007
. map_to_mm ( |e| WithdrawError :: InternalError ( e. to_string ( ) ) ) ?;
@@ -1997,8 +2011,18 @@ impl InitWithdrawCoin for ZCoin {
1997
2011
let received_by_me = big_decimal_from_sat_unsigned ( data. received_by_me , self . decimals ( ) ) ;
1998
2012
let spent_by_me = big_decimal_from_sat_unsigned ( data. spent_by_me , self . decimals ( ) ) ;
1999
2013
2014
+ let tx_hash_hex = hex:: encode ( & tx_hash) ;
2015
+ for rseed in rseeds {
2016
+ info ! ( "saving tx notes rseed for {}!" , tx_hash_hex) ;
2017
+ self . z_fields
2018
+ . locked_notes_db
2019
+ . insert_note ( tx. txid ( ) . to_string ( ) , rseed)
2020
+ . await
2021
+ . mm_err ( |err| WithdrawError :: InternalError ( err. to_string ( ) ) ) ?;
2022
+ }
2023
+
2000
2024
Ok ( TransactionDetails {
2001
- tx : TransactionData :: new_signed ( tx_bytes. into ( ) , hex :: encode ( & tx_hash ) ) ,
2025
+ tx : TransactionData :: new_signed ( tx_bytes. into ( ) , tx_hash_hex ) ,
2002
2026
from : vec ! [ self . z_fields. my_z_addr_encoded. clone( ) ] ,
2003
2027
to : vec ! [ req. to] ,
2004
2028
my_balance_change : & received_by_me - & spent_by_me,
0 commit comments