@@ -494,67 +494,66 @@ where
494
494
amount : String ,
495
495
tx_hash : H256 ,
496
496
) -> impl Future < Item = ( ) , Error = ( ) > {
497
- let mut url = self . connector_url . clone ( ) ;
498
- let account_id_clone = account_id. clone ( ) ;
499
497
let engine_scale = self . asset_scale ;
498
+ let mut url = self . connector_url . clone ( ) ;
500
499
url. path_segments_mut ( )
501
500
. expect ( "Invalid connector URL" )
502
501
. push ( "accounts" )
503
502
. push ( & account_id. clone ( ) )
504
503
. push ( "settlements" ) ;
505
504
debug ! ( "Making POST to {:?} {:?} about {:?}" , url, amount, tx_hash) ;
506
- let self_clone = self . clone ( ) ;
507
- let store = self . store . clone ( ) ;
508
- let amount_clone = amount. clone ( ) ;
509
- let action = move || {
510
- // need to make 2 clones, one to own the variables in the function
511
- // and one for the retry closure..
512
- let self_clone = self_clone. clone ( ) ;
513
- let store = store. clone ( ) ;
514
- let account_id = account_id. clone ( ) ;
515
- let account_id_clone2 = account_id. clone ( ) ;
516
- let amount = amount. clone ( ) ;
517
- let url = url. clone ( ) ;
518
-
519
- // settle for amount + leftovers
520
- store. pop_leftovers ( account_id. clone ( ) )
505
+
506
+ // settle for amount + leftovers
507
+ self . store
508
+ . pop_leftovers ( account_id. clone ( ) )
521
509
. and_then ( move |leftovers| {
522
- result ( BigUint :: from_str ( & amount. clone ( ) ) . map_err ( move |err| {
510
+ debug ! ( "POPPED LEFTOVERS {:?}" , leftovers) ;
511
+ result ( BigUint :: from_str ( & amount) . map_err ( move |err| {
523
512
let error_msg = format ! ( "Error converting to BigUint {:?}" , err) ;
524
513
error ! ( "{:?}" , error_msg) ;
525
514
} ) )
526
515
. and_then ( move |amount| {
527
- Ok ( amount + leftovers)
528
- } )
529
- } )
530
- . and_then ( move |full_amount| {
531
- let client = Client :: new ( ) ;
532
- let full_amount_clone = full_amount. clone ( ) ;
533
- client
534
- . post ( url. clone ( ) )
535
- . header ( "Idempotency-Key" , tx_hash. to_string ( ) )
536
- . json ( & json ! ( { "amount" : full_amount. clone( ) . to_string( ) , "scale" : engine_scale } ) )
537
- . send ( )
538
- . map_err ( move |err| {
539
- error ! (
540
- "Error notifying Accounting System's account: {:?}, amount: {:?}: {:?}" ,
541
- account_id, full_amount_clone, err
542
- )
516
+ debug ! ( "Got uncredited amount {}" , amount) ;
517
+ let full_amount = amount + leftovers;
518
+ let client = Client :: new ( ) ;
519
+ debug ! (
520
+ "Notifying accounting system about full amount: {}" ,
521
+ full_amount
522
+ ) ;
523
+ let url = url. clone ( ) ;
524
+ let account_id_clone = account_id. clone ( ) ;
525
+ let full_amount_clone = full_amount. clone ( ) ;
526
+
527
+ let action = move || {
528
+ let account_id = account_id. clone ( ) ;
529
+ let full_amount = full_amount. clone ( ) ;
530
+ client
531
+ . post ( url. clone ( ) )
532
+ . header ( "Idempotency-Key" , tx_hash. to_string ( ) )
533
+ . json ( & json ! ( Quantity :: new( full_amount. clone( ) , engine_scale) ) )
534
+ . send ( )
535
+ . map_err ( move |err| {
536
+ error ! (
537
+ "Error notifying Accounting System's account: {:?}, amount: {:?}: {:?}" ,
538
+ account_id. clone( ) , full_amount. clone( ) , err
539
+ ) ;
540
+ } )
541
+ } ;
542
+
543
+ Retry :: spawn (
544
+ ExponentialBackoff :: from_millis ( 10 ) . take ( MAX_RETRIES ) ,
545
+ action,
546
+ )
547
+ . map_err ( move |_| {
548
+ error ! ( "Exceeded max retries when notifying connector about account {:?} for amount {:?} and transaction hash {:?}. Please check your API." , account_id_clone, full_amount_clone, tx_hash)
543
549
} )
544
550
. and_then ( move |response| {
545
551
trace ! ( "Accounting system responded with {:?}" , response) ;
546
552
Ok ( ( ) ) // This call causes the type_length_error
547
553
// self_clone.process_connector_response(account_id_clone2, response, full_amount.clone())
548
554
} )
555
+ } )
549
556
} )
550
- } ;
551
- Retry :: spawn (
552
- ExponentialBackoff :: from_millis ( 10 ) . take ( MAX_RETRIES ) ,
553
- action,
554
- )
555
- . map_err ( move |_| {
556
- error ! ( "Exceeded max retries when notifying connector about account {:?} for amount {:?} and transaction hash {:?}. Please check your API." , account_id_clone, amount_clone, tx_hash)
557
- } )
558
557
}
559
558
560
559
fn process_connector_response (
0 commit comments