1- use actix_web:: { web, App , HttpResponse , HttpServer } ;
1+ use actix_web:: {
2+ web:: { self , Data } ,
3+ App , HttpRequest , HttpResponse , HttpServer , Responder ,
4+ } ;
25
36use crate :: { config:: Config , db:: Db } ;
47
8+ /// Starts the http server to receive proofs
9+ ///
10+ /// It is also thread safe to share and it is used as the shared state between endpoints
11+ #[ derive( Clone , Debug ) ]
512pub struct BatcherServer {
613 db : Db ,
714 config : Config ,
@@ -20,14 +27,36 @@ impl BatcherServer {
2027 }
2128
2229 pub async fn start ( & self ) -> Result < ( ) , std:: io:: Error > {
23- HttpServer :: new ( || {
24- App :: new ( ) . route (
25- "/" ,
26- web:: get ( ) . to ( async || HttpResponse :: Ok ( ) . body ( "Hey there!" ) ) ,
30+ // Note: BatcherServer is thread safe so we can just clone it (no need to add mutexes)
31+ let port = self . config . port ;
32+ let state = self . clone ( ) ;
33+
34+ HttpServer :: new ( move || Self :: build_app ( state. clone ( ) ) )
35+ . bind ( ( "127.0.0.1" , port) ) ?
36+ . run ( )
37+ . await
38+ }
39+
40+ fn build_app ( state : BatcherServer ) -> App {
41+ App :: new ( )
42+ . app_data ( Data :: new ( state) )
43+ . route ( "/nonce/:address" , web:: get ( ) . to ( Self :: get_nonce) )
44+ . route (
45+ "/proof/merkle/:receipt" ,
46+ web:: get ( ) . to ( Self :: get_proof_merkle_path) ,
2747 )
28- } )
29- . bind ( ( "127.0.0.1" , self . config . port ) ) ?
30- . run ( )
31- . await
48+ . route ( "/proof" , web:: post ( ) . to ( Self :: post_proof) )
49+ }
50+
51+ async fn get_nonce ( req : HttpRequest ) -> impl Responder {
52+ HttpResponse :: Ok ( )
53+ }
54+
55+ async fn post_proof ( req : HttpRequest ) -> impl Responder {
56+ HttpResponse :: Ok ( )
57+ }
58+
59+ async fn get_proof_merkle_path ( req : HttpRequest ) -> impl Responder {
60+ HttpResponse :: Ok ( )
3261 }
3362}
0 commit comments