Skip to content

Commit fe53ac3

Browse files
committed
feat: build server app and define routes
1 parent bdea05c commit fe53ac3

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,11 @@ proof_aggregator_write_program_ids: ## Write proof aggregator zkvm programs ids
303303
@cd aggregation_mode/proof_aggregator && ./scripts/build_programs.sh
304304

305305
agg_mode_batcher_start_local:
306+
@cd aggregation_mode && docker-compose up -d
306307
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin agg_mode_batcher -- config-files/config-agg-mode-batcher.yaml
307308

308309
agg_mode_batcher_start_ethereum_package:
310+
@cd aggregation_mode && docker-compose up -d
309311
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin agg_mode_batcher -- config-files/config-agg-mode-batcher-ethereum-package.yaml
310312

311313
__AGGREGATOR__: ## ____

aggregation_mode/batcher/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{fs::File, io::Read};
22

33
use serde::{Deserialize, Serialize};
44

5-
#[derive(Debug, Deserialize, Serialize)]
5+
#[derive(Clone, Debug, Deserialize, Serialize)]
66
pub struct Config {
77
pub port: u16,
88
pub db_connection_url: String,

aggregation_mode/batcher/src/server.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
use actix_web::{web, App, HttpResponse, HttpServer};
1+
use actix_web::{
2+
web::{self, Data},
3+
App, HttpRequest, HttpResponse, HttpServer, Responder,
4+
};
25

36
use 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)]
512
pub 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

Comments
 (0)