@@ -67,21 +67,25 @@ pub mod add_request_fees {
6767 let total_payments = _count_total_payments ( & outputs_json) ;
6868
6969 let err = if total_amount >= total_payments + fee {
70+ match parse_req_id_from_request ( & req_json) {
71+ Err ( ec) => return ec,
72+ _ => ( )
73+ } ;
7074 //we have enough money for this txn, give it back
7175 let seq_no = payment_ledger:: add_txn ( inputs_json. clone ( ) , outputs_json. clone ( ) ) ;
7276
73- _process_inputs ( inputs_json) ;
74- let infos: Vec < UTXOInfo > = _process_outputs ( outputs_json, seq_no) ;
77+ _process_inputs ( & inputs_json) ;
78+ let infos: Vec < UTXOInfo > = _process_outputs ( & outputs_json, seq_no) ;
7579
76- _save_response ( infos, req_json. clone ( ) )
80+ _save_response ( & infos, & req_json)
7781 } else {
7882 //we don't have enough money, send GET_TXN transaction to callback and in response PaymentsInsufficientFundsError will be returned
7983 ledger:: build_get_txn_request (
8084 submitter_did. as_str ( ) ,
8185 1 ,
8286 Box :: new ( move |ec, res| {
8387 let ec = if ec == ErrorCode :: Success {
84- _add_response ( res. clone ( ) , "INSUFFICIENT_FUNDS" . to_string ( ) )
88+ _add_response ( & res, "INSUFFICIENT_FUNDS" )
8589 } else { ec } ;
8690 trace ! ( "libnullpay::add_request_fees::handle >>" ) ;
8791 _process_callback ( cmd_handle, ec, res, cb) ;
@@ -117,9 +121,9 @@ pub mod build_get_utxo_request {
117121 1 ,
118122 Box :: new ( move |ec, res| {
119123 let ec = if ec == ErrorCode :: Success {
120- let utxos = utxo_cache:: get_utxos_by_payment_address ( payment_address. clone ( ) ) ;
121- let infos: Vec < UTXOInfo > = utxos. into_iter ( ) . filter_map ( |utxo| payment_ledger:: get_utxo_info ( utxo ) ) . collect ( ) ;
122- _save_response ( infos, res. clone ( ) )
124+ let utxos = utxo_cache:: get_utxos_by_payment_address ( & payment_address) ;
125+ let infos: Vec < UTXOInfo > = utxos. into_iter ( ) . filter_map ( payment_ledger:: get_utxo_info) . collect ( ) ;
126+ _save_response ( & infos, & res)
123127 } else { ec } ;
124128
125129 trace ! ( "libnullpay::build_get_utxo_request::handle >>" ) ;
@@ -161,12 +165,12 @@ pub mod build_payment_req {
161165 if total_balance >= total_payments {
162166 let seq_no = payment_ledger:: add_txn ( inputs_json. clone ( ) , outputs_json. clone ( ) ) ;
163167
164- _process_inputs ( inputs_json. clone ( ) ) ;
165- let infos = _process_outputs ( outputs_json. clone ( ) , seq_no) ;
168+ _process_inputs ( & inputs_json) ;
169+ let infos = _process_outputs ( & outputs_json, seq_no) ;
166170
167- _save_response ( infos, res. clone ( ) )
171+ _save_response ( & infos, & res)
168172 } else {
169- _add_response ( res. clone ( ) , "INSUFFICIENT_FUNDS" . to_string ( ) ) ;
173+ _add_response ( & res, "INSUFFICIENT_FUNDS" ) ;
170174 ErrorCode :: Success
171175 }
172176 } else {
@@ -206,7 +210,7 @@ pub mod build_mint_req {
206210 let seq_no = payment_ledger:: add_txn ( vec ! [ ] , outputs_json. clone ( ) ) ;
207211
208212 outputs_json. clone ( ) . into_iter ( ) . for_each ( |output| {
209- utxo_cache:: add_utxo ( output. payment_address , seq_no, output. amount ) ;
213+ utxo_cache:: add_utxo ( & output. payment_address , seq_no, output. amount ) ;
210214 } ) ;
211215 }
212216
@@ -255,7 +259,7 @@ pub mod build_get_txn_fees_req {
255259 let info = config_ledger:: get_all_fees ( ) ;
256260
257261 match to_string ( & info) . map_err ( |_| ErrorCode :: CommonInvalidState ) {
258- Ok ( str) => _add_response ( res. clone ( ) , str) ,
262+ Ok ( str) => _add_response ( & res, & str) ,
259263 Err ( ec) => ec
260264 }
261265 } else { ec } ;
@@ -295,40 +299,40 @@ fn _process_callback(cmd_handle: i32, err: ErrorCode, response: String, cb: Opti
295299 }
296300}
297301
298- fn _process_outputs ( outputs : Vec < UTXOOutput > , seq_no : i32 ) -> Vec < UTXOInfo > {
302+ fn _process_outputs ( outputs : & Vec < UTXOOutput > , seq_no : i32 ) -> Vec < UTXOInfo > {
299303 outputs. into_iter ( ) . map ( |out| {
300- match utxo_cache:: add_utxo ( out. payment_address , seq_no, out. amount )
304+ match utxo_cache:: add_utxo ( & out. payment_address , seq_no, out. amount )
301305 . map ( |utxo| payment_ledger:: get_utxo_info ( utxo) ) {
302306 Some ( Some ( utxo_info) ) => utxo_info,
303307 _ => panic ! ( "Some UTXO was not processed!" )
304308 }
305309 } ) . collect ( )
306310}
307311
308- fn _process_inputs ( inputs : Vec < String > ) {
312+ fn _process_inputs ( inputs : & Vec < String > ) {
309313 inputs. into_iter ( ) . for_each ( |s| {
310314 utxo_cache:: remove_utxo ( s) ;
311315 } ) ;
312316}
313317
314- fn _save_response ( infos : Vec < UTXOInfo > , request : String ) -> ErrorCode {
315- match serialize_infos ( infos) {
316- Ok ( str) => _add_response ( request, str) ,
318+ fn _save_response ( infos : & Vec < UTXOInfo > , request : & str ) -> ErrorCode {
319+ match serialize_infos ( & infos) {
320+ Ok ( str) => _add_response ( request, & str) ,
317321 Err ( ec) => ec
318322 }
319323}
320324
321- fn _add_response ( request : String , response : String ) -> ErrorCode {
325+ fn _add_response ( request : & str , response : & str ) -> ErrorCode {
322326 match add_response ( request, response) {
323327 Err ( ec) => ec,
324328 _ => ErrorCode :: Success
325329 }
326330}
327331
328332fn _count_total_inputs ( inputs : & Vec < String > ) -> i32 {
329- inputs. clone ( ) . into_iter ( ) . filter_map ( utxo_cache:: get_balanse_of_utxo) . fold ( 0 , |acc, next| acc + next)
333+ inputs. into_iter ( ) . filter_map ( utxo_cache:: get_balanse_of_utxo) . fold ( 0 , |acc, next| acc + next)
330334}
331335
332336fn _count_total_payments ( outputs : & Vec < UTXOOutput > ) -> i32 {
333- outputs. clone ( ) . into_iter ( ) . fold ( 0 , |acc, next| acc + next. amount )
337+ outputs. into_iter ( ) . fold ( 0 , |acc, next| acc + next. amount )
334338}
0 commit comments