11use std:: time:: { SystemTime , UNIX_EPOCH } ;
22
33use actix_web:: {
4- http:: StatusCode ,
54 web:: { self , Data } ,
65 App , HttpRequest , HttpResponse , HttpServer , Responder ,
76} ;
@@ -31,11 +30,12 @@ impl BatcherServer {
3130 Self { db, config }
3231 }
3332
34- pub async fn start ( & self ) -> Result < ( ) , std :: io :: Error > {
33+ pub async fn start ( & self ) {
3534 // Note: BatcherServer is thread safe so we can just clone it (no need to add mutexes)
3635 let port = self . config . port ;
3736 let state = self . clone ( ) ;
3837
38+ tracing:: info!( "Starting server at port {}" , self . config. port) ;
3939 HttpServer :: new ( move || {
4040 App :: new ( )
4141 . app_data ( Data :: new ( state. clone ( ) ) )
@@ -44,9 +44,11 @@ impl BatcherServer {
4444 . route ( "/proof/sp1" , web:: post ( ) . to ( Self :: post_proof_sp1) )
4545 . route ( "/proof/risc0" , web:: post ( ) . to ( Self :: post_proof_risc0) )
4646 } )
47- . bind ( ( "127.0.0.1" , port) ) ?
47+ . bind ( ( "127.0.0.1" , port) )
48+ . expect ( "To bind socket correctly" )
4849 . run ( )
4950 . await
51+ . expect ( "Server to never end" ) ;
5052 }
5153
5254 async fn get_nonce ( req : HttpRequest ) -> impl Responder {
@@ -74,15 +76,14 @@ impl BatcherServer {
7476 }
7577 }
7678
77- // TODO: receive the proof and 1. decode it, 2. verify it, 3. add to the db
7879 async fn post_proof_sp1 (
7980 req : HttpRequest ,
8081 body : web:: Json < SubmitProofRequest < SubmitProofRequestMessageSP1 > > ,
8182 ) -> impl Responder {
8283 let data = body. into_inner ( ) ;
8384
8485 // TODO: validate signature
85- let recovered_address = "0x0000000000000000000000000000000000000000 " ;
86+ let recovered_address = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8 " ;
8687
8788 let Some ( state) = req. app_data :: < Data < BatcherServer > > ( ) else {
8889 return HttpResponse :: InternalServerError ( )
@@ -102,7 +103,7 @@ impl BatcherServer {
102103 ) ) ;
103104 }
104105
105- let now_ts = match SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) {
106+ let now_epoch = match SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) {
106107 Ok ( duration) => duration. as_secs ( ) as i64 ,
107108 Err ( _) => {
108109 return HttpResponse :: InternalServerError ( )
@@ -112,7 +113,7 @@ impl BatcherServer {
112113
113114 let has_payment = match state
114115 . db
115- . has_active_payment_event ( recovered_address, now_ts )
116+ . has_active_payment_event ( recovered_address, now_epoch )
116117 . await
117118 {
118119 Ok ( result) => result,
@@ -129,6 +130,8 @@ impl BatcherServer {
129130 ) ) ;
130131 }
131132
133+ // TODO: decode proof and validate it
134+
132135 match state
133136 . db
134137 . insert_proof (
0 commit comments