@@ -12,7 +12,7 @@ use sqlx::types::BigDecimal;
1212
1313use super :: {
1414 helpers:: format_merkle_path,
15- types:: { AppResponse , GetProofMerklePathQueryParams } ,
15+ types:: { AppResponse , GetReceiptsParams } ,
1616} ;
1717
1818use crate :: {
@@ -44,7 +44,7 @@ impl BatcherServer {
4444 App :: new ( )
4545 . app_data ( Data :: new ( state. clone ( ) ) )
4646 . route ( "/nonce/{address}" , web:: get ( ) . to ( Self :: get_nonce) )
47- . route ( "/proof/merkle " , web:: get ( ) . to ( Self :: get_proof_merkle_path ) )
47+ . route ( "/receipts " , web:: get ( ) . to ( Self :: get_receipts ) )
4848 . route ( "/proof/sp1" , web:: post ( ) . to ( Self :: post_proof_sp1) )
4949 . route ( "/proof/risc0" , web:: post ( ) . to ( Self :: post_proof_risc0) )
5050 } )
@@ -55,6 +55,7 @@ impl BatcherServer {
5555 . expect ( "Server to never end" ) ;
5656 }
5757
58+ // Returns the nonce (number of submitted tasks) for a given address
5859 async fn get_nonce ( req : HttpRequest ) -> impl Responder {
5960 let Some ( address) = req. match_info ( ) . get ( "address" ) else {
6061 return HttpResponse :: BadRequest ( )
@@ -80,6 +81,7 @@ impl BatcherServer {
8081 }
8182 }
8283
84+ // Posts an SP1 proof to the batcher, recovering the address from the signature
8385 async fn post_proof_sp1 (
8486 req : HttpRequest ,
8587 body : web:: Json < SubmitProofRequest < SubmitProofRequestMessageSP1 > > ,
@@ -160,16 +162,19 @@ impl BatcherServer {
160162 }
161163
162164 /// TODO: complete for risc0 (see `post_proof_sp1`)
165+ // Posts a Risc0 proof to the batcher, recovering the address from the signature
163166 async fn post_proof_risc0 (
164167 _req : HttpRequest ,
165168 _body : web:: Json < SubmitProofRequest < SubmitProofRequestMessageRisc0 > > ,
166169 ) -> impl Responder {
167170 HttpResponse :: Ok ( ) . json ( AppResponse :: new_sucessfull ( serde_json:: json!( { } ) ) )
168171 }
169172
170- async fn get_proof_merkle_path (
173+ // Returns the last 100 receipt merkle proofs for the address received in the URL.
174+ // In case of also receiving a nonce on the query param, it returns only the merkle proof for that nonce.
175+ async fn get_receipts (
171176 req : HttpRequest ,
172- params : web:: Query < GetProofMerklePathQueryParams > ,
177+ params : web:: Query < GetReceiptsParams > ,
173178 ) -> impl Responder {
174179 let Some ( state) = req. app_data :: < Data < BatcherServer > > ( ) else {
175180 return HttpResponse :: InternalServerError ( )
@@ -179,34 +184,23 @@ impl BatcherServer {
179184 let state = state. get_ref ( ) ;
180185
181186 // TODO: maybe also accept proof commitment in query param
182- let Some ( id ) = params. id . clone ( ) else {
187+ let Some ( address ) = params. address . clone ( ) else {
183188 return HttpResponse :: BadRequest ( ) . json ( AppResponse :: new_unsucessfull (
184- "Provide task `id ` query param" ,
189+ "Provide task `address ` query param" ,
185190 400 ,
186191 ) ) ;
187192 } ;
188193
189- if id . is_empty ( ) {
194+ if address . is_empty ( ) {
190195 return HttpResponse :: BadRequest ( ) . json ( AppResponse :: new_unsucessfull (
191- "Proof id cannot be empty" ,
196+ "Address cannot be empty" ,
192197 400 ,
193198 ) ) ;
194199 }
195200
196- let Ok ( proof_id) = sqlx:: types:: Uuid :: parse_str ( & id) else {
197- return HttpResponse :: BadRequest ( )
198- . json ( AppResponse :: new_unsucessfull ( "Proof id invalid uuid" , 400 ) ) ;
199- } ;
200-
201- let db_result = state. db . get_merkle_path_by_task_id ( proof_id) . await ;
202- let merkle_path = match db_result {
203- Ok ( Some ( merkle_path) ) => merkle_path,
204- Ok ( None ) => {
205- return HttpResponse :: NotFound ( ) . json ( AppResponse :: new_unsucessfull (
206- "Proof merkle path not found" ,
207- 404 ,
208- ) )
209- }
201+ let db_result = state. db . get_tasks_by_address ( & address, 100 ) . await ;
202+ let merkle_paths = match db_result {
203+ Ok ( merkle_paths) => merkle_paths,
210204 Err ( _) => {
211205 return HttpResponse :: InternalServerError ( )
212206 . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
0 commit comments