@@ -67,25 +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. clone ( ) ) {
70+ match parse_req_id_from_request ( & req_json) {
7171 Err ( ec) => return ec,
7272 _ => ( )
7373 } ;
7474 //we have enough money for this txn, give it back
7575 let seq_no = payment_ledger:: add_txn ( inputs_json. clone ( ) , outputs_json. clone ( ) ) ;
7676
77- _process_inputs ( inputs_json) ;
78- 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) ;
7979
80- _save_response ( infos, req_json. clone ( ) )
80+ _save_response ( & infos, & req_json)
8181 } else {
8282 //we don't have enough money, send GET_TXN transaction to callback and in response PaymentsInsufficientFundsError will be returned
8383 ledger:: build_get_txn_request (
8484 submitter_did. as_str ( ) ,
8585 1 ,
8686 Box :: new ( move |ec, res| {
8787 let ec = if ec == ErrorCode :: Success {
88- _add_response ( res. clone ( ) , "INSUFFICIENT_FUNDS" . to_string ( ) )
88+ _add_response ( & res, "INSUFFICIENT_FUNDS" )
8989 } else { ec } ;
9090 trace ! ( "libnullpay::add_request_fees::handle >>" ) ;
9191 _process_callback ( cmd_handle, ec, res, cb) ;
@@ -121,9 +121,9 @@ pub mod build_get_utxo_request {
121121 1 ,
122122 Box :: new ( move |ec, res| {
123123 let ec = if ec == ErrorCode :: Success {
124- let utxos = utxo_cache:: get_utxos_by_payment_address ( payment_address. clone ( ) ) ;
125- let infos: Vec < UTXOInfo > = utxos. into_iter ( ) . filter_map ( |utxo| payment_ledger:: get_utxo_info ( utxo ) ) . collect ( ) ;
126- _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)
127127 } else { ec } ;
128128
129129 trace ! ( "libnullpay::build_get_utxo_request::handle >>" ) ;
@@ -165,12 +165,12 @@ pub mod build_payment_req {
165165 if total_balance >= total_payments {
166166 let seq_no = payment_ledger:: add_txn ( inputs_json. clone ( ) , outputs_json. clone ( ) ) ;
167167
168- _process_inputs ( inputs_json. clone ( ) ) ;
169- let infos = _process_outputs ( outputs_json. clone ( ) , seq_no) ;
168+ _process_inputs ( & inputs_json) ;
169+ let infos = _process_outputs ( & outputs_json, seq_no) ;
170170
171- _save_response ( infos, res. clone ( ) )
171+ _save_response ( & infos, & res)
172172 } else {
173- _add_response ( res. clone ( ) , "INSUFFICIENT_FUNDS" . to_string ( ) ) ;
173+ _add_response ( & res, "INSUFFICIENT_FUNDS" ) ;
174174 ErrorCode :: Success
175175 }
176176 } else {
@@ -210,7 +210,7 @@ pub mod build_mint_req {
210210 let seq_no = payment_ledger:: add_txn ( vec ! [ ] , outputs_json. clone ( ) ) ;
211211
212212 outputs_json. clone ( ) . into_iter ( ) . for_each ( |output| {
213- utxo_cache:: add_utxo ( output. payment_address , seq_no, output. amount ) ;
213+ utxo_cache:: add_utxo ( & output. payment_address , seq_no, output. amount ) ;
214214 } ) ;
215215 }
216216
@@ -259,7 +259,7 @@ pub mod build_get_txn_fees_req {
259259 let info = config_ledger:: get_all_fees ( ) ;
260260
261261 match to_string ( & info) . map_err ( |_| ErrorCode :: CommonInvalidState ) {
262- Ok ( str) => _add_response ( res. clone ( ) , str) ,
262+ Ok ( str) => _add_response ( & res, & str) ,
263263 Err ( ec) => ec
264264 }
265265 } else { ec } ;
@@ -299,40 +299,40 @@ fn _process_callback(cmd_handle: i32, err: ErrorCode, response: String, cb: Opti
299299 }
300300}
301301
302- fn _process_outputs ( outputs : Vec < UTXOOutput > , seq_no : i32 ) -> Vec < UTXOInfo > {
302+ fn _process_outputs ( outputs : & Vec < UTXOOutput > , seq_no : i32 ) -> Vec < UTXOInfo > {
303303 outputs. into_iter ( ) . map ( |out| {
304- 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 )
305305 . map ( |utxo| payment_ledger:: get_utxo_info ( utxo) ) {
306306 Some ( Some ( utxo_info) ) => utxo_info,
307307 _ => panic ! ( "Some UTXO was not processed!" )
308308 }
309309 } ) . collect ( )
310310}
311311
312- fn _process_inputs ( inputs : Vec < String > ) {
312+ fn _process_inputs ( inputs : & Vec < String > ) {
313313 inputs. into_iter ( ) . for_each ( |s| {
314314 utxo_cache:: remove_utxo ( s) ;
315315 } ) ;
316316}
317317
318- fn _save_response ( infos : Vec < UTXOInfo > , request : String ) -> ErrorCode {
319- match serialize_infos ( infos) {
320- 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) ,
321321 Err ( ec) => ec
322322 }
323323}
324324
325- fn _add_response ( request : String , response : String ) -> ErrorCode {
325+ fn _add_response ( request : & str , response : & str ) -> ErrorCode {
326326 match add_response ( request, response) {
327327 Err ( ec) => ec,
328328 _ => ErrorCode :: Success
329329 }
330330}
331331
332332fn _count_total_inputs ( inputs : & Vec < String > ) -> i32 {
333- 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)
334334}
335335
336336fn _count_total_payments ( outputs : & Vec < UTXOOutput > ) -> i32 {
337- outputs. clone ( ) . into_iter ( ) . fold ( 0 , |acc, next| acc + next. amount )
337+ outputs. into_iter ( ) . fold ( 0 , |acc, next| acc + next. amount )
338338}
0 commit comments