@@ -8,6 +8,7 @@ use actix_web::{
88 web:: { self , Data } ,
99 App , HttpRequest , HttpResponse , HttpServer , Responder ,
1010} ;
11+ use agg_mode_sdk:: types:: Network ;
1112use aligned_sdk:: aggregation_layer:: AggregationModeProvingSystem ;
1213use alloy:: signers:: Signature ;
1314use sp1_sdk:: { SP1ProofWithPublicValues , SP1VerifyingKey } ;
@@ -29,11 +30,17 @@ use crate::{
2930pub struct BatcherServer {
3031 db : Db ,
3132 config : Config ,
33+ network : Network ,
3234}
3335
3436impl BatcherServer {
3537 pub fn new ( db : Db , config : Config ) -> Self {
36- Self { db, config }
38+ let network = Network :: from_str ( & config. network ) . expect ( "A valid network in config file" ) ;
39+ Self {
40+ db,
41+ config,
42+ network,
43+ }
3744 }
3845
3946 pub async fn start ( & self ) {
@@ -96,6 +103,12 @@ impl BatcherServer {
96103 req : HttpRequest ,
97104 MultipartForm ( data) : MultipartForm < SubmitProofRequestSP1 > ,
98105 ) -> impl Responder {
106+ let Some ( state) = req. app_data :: < Data < BatcherServer > > ( ) else {
107+ return HttpResponse :: InternalServerError ( )
108+ . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
109+ } ;
110+
111+ let state = state. get_ref ( ) ;
99112 let Ok ( signature) = Signature :: from_str ( & data. signature_hex . 0 ) else {
100113 return HttpResponse :: InternalServerError ( )
101114 . json ( AppResponse :: new_unsucessfull ( "Invalid signature" , 500 ) ) ;
@@ -117,21 +130,14 @@ impl BatcherServer {
117130 proof_content. clone ( ) ,
118131 vk_content. clone ( ) ,
119132 ) ;
120- let Ok ( recovered_address) = signature. recover_address_from_prehash (
121- & msg. eip712_hash ( & agg_mode_sdk:: types:: Network :: Devnet )
122- . into ( ) ,
123- ) else {
133+ let Ok ( recovered_address) =
134+ signature. recover_address_from_prehash ( & msg. eip712_hash ( & state. network ) . into ( ) )
135+ else {
124136 return HttpResponse :: InternalServerError ( )
125137 . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
126138 } ;
127139 let recovered_address = recovered_address. to_string ( ) . to_lowercase ( ) ;
128140
129- let Some ( state) = req. app_data :: < Data < BatcherServer > > ( ) else {
130- return HttpResponse :: InternalServerError ( )
131- . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
132- } ;
133- let state = state. get_ref ( ) ;
134-
135141 let Ok ( count) = state. db . count_tasks_by_address ( & recovered_address) . await else {
136142 return HttpResponse :: InternalServerError ( )
137143 . json ( AppResponse :: new_unsucessfull ( "Internal server error" , 500 ) ) ;
0 commit comments