@@ -248,34 +248,37 @@ impl BatcherServer {
248248 ) ) ;
249249 } ;
250250
251- let mut responses: Vec < GetReceiptsResponse > = Vec :: new ( ) ;
252- for receipt in receipts {
253- let Some ( merkle_path) = receipt. merkle_path else {
254- responses. push ( GetReceiptsResponse {
251+ let responses: Result < Vec < GetReceiptsResponse > , String > = receipts
252+ . into_iter ( )
253+ . map ( |receipt| {
254+ let Some ( merkle_path) = receipt. merkle_path else {
255+ return Ok ( GetReceiptsResponse {
256+ status : receipt. status ,
257+ merkle_path : Vec :: new ( ) ,
258+ nonce : receipt. nonce ,
259+ address : receipt. address ,
260+ } ) ;
261+ } ;
262+
263+ let Ok ( formatted) = format_merkle_path ( & merkle_path) else {
264+ return Err ( "Error formatting merkle path" . into ( ) ) ;
265+ } ;
266+
267+ Ok ( GetReceiptsResponse {
255268 status : receipt. status ,
256- merkle_path : Vec :: new ( ) ,
269+ merkle_path : formatted ,
257270 nonce : receipt. nonce ,
258271 address : receipt. address ,
259- } ) ;
260-
261- continue ;
262- } ;
263-
264- let Ok ( formatted_merkle_path) = format_merkle_path ( & merkle_path) else {
265- return HttpResponse :: InternalServerError ( )
266- . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
267- } ;
268-
269- responses. push ( GetReceiptsResponse {
270- status : receipt. status ,
271- merkle_path : formatted_merkle_path,
272- nonce : receipt. nonce ,
273- address : receipt. address ,
274- } ) ;
272+ } )
273+ } )
274+ . collect ( ) ;
275+
276+ match responses {
277+ Ok ( resp) => HttpResponse :: Ok ( ) . json ( AppResponse :: new_sucessfull ( serde_json:: json!( {
278+ "receipts" : resp
279+ } ) ) ) ,
280+ Err ( _) => HttpResponse :: InternalServerError ( )
281+ . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ,
275282 }
276-
277- HttpResponse :: Ok ( ) . json ( AppResponse :: new_sucessfull ( serde_json:: json!( {
278- "receipts" : responses
279- } ) ) )
280283 }
281284}
0 commit comments