Skip to content

Commit e68cbb5

Browse files
committed
fix: epoch in payment as BigDecimal
1 parent 8a76723 commit e68cbb5

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

aggregation_mode/batcher/src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ impl Db {
104104
pub async fn has_active_payment_event(
105105
&self,
106106
address: &str,
107-
epoch: i64,
107+
epoch: BigDecimal,
108108
) -> Result<bool, sqlx::Error> {
109109
sqlx::query_scalar::<_, bool>(
110-
"SELECT EXISTS(
110+
"SELECT EXISTS (
111111
SELECT 1 FROM payment_events
112112
WHERE address = $1 AND started_at < $2 AND $2 < valid_until
113113
)",

aggregation_mode/batcher/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ async fn main() {
3939
let http_server_handle = tokio::spawn(async move { http_server.start().await });
4040

4141
// TODO: abort the process if one stops instead of waiting for them both
42+
// TODO: ctrl + c handler for aborting the process should work
4243
let _ = tokio::join!(payment_poller_handle, http_server_handle);
4344
}

aggregation_mode/batcher/src/server/http.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
use std::time::{SystemTime, UNIX_EPOCH};
1+
use std::{
2+
str::FromStr,
3+
time::{SystemTime, UNIX_EPOCH},
4+
};
25

36
use actix_web::{
47
web::{self, Data},
58
App, HttpRequest, HttpResponse, HttpServer, Responder,
69
};
710
use aligned_sdk::aggregation_layer::AggregationModeProvingSystem;
11+
use sqlx::types::BigDecimal;
812

913
use super::{
1014
helpers::format_merkle_path,
@@ -83,15 +87,15 @@ impl BatcherServer {
8387
let data = body.into_inner();
8488

8589
// TODO: validate signature
86-
let recovered_address = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";
90+
let recovered_address = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8".to_lowercase();
8791

8892
let Some(state) = req.app_data::<Data<BatcherServer>>() else {
8993
return HttpResponse::InternalServerError()
9094
.json(AppResponse::new_unsucessfull("Internal server error", 500));
9195
};
9296
let state = state.get_ref();
9397

94-
let Ok(count) = state.db.count_proofs_by_address(recovered_address).await else {
98+
let Ok(count) = state.db.count_proofs_by_address(&recovered_address).await else {
9599
return HttpResponse::InternalServerError()
96100
.json(AppResponse::new_unsucessfull("Internal server error", 500));
97101
};
@@ -104,7 +108,7 @@ impl BatcherServer {
104108
}
105109

106110
let now_epoch = match SystemTime::now().duration_since(UNIX_EPOCH) {
107-
Ok(duration) => duration.as_secs() as i64,
111+
Ok(duration) => duration.as_secs(),
108112
Err(_) => {
109113
return HttpResponse::InternalServerError()
110114
.json(AppResponse::new_unsucessfull("Internal server error", 500));
@@ -113,7 +117,11 @@ impl BatcherServer {
113117

114118
let has_payment = match state
115119
.db
116-
.has_active_payment_event(recovered_address, now_epoch)
120+
.has_active_payment_event(
121+
&recovered_address,
122+
// safe unwrap the number comes from a valid u64 primitive
123+
BigDecimal::from_str(&now_epoch.to_string()).unwrap(),
124+
)
117125
.await
118126
{
119127
Ok(result) => result,
@@ -135,7 +143,7 @@ impl BatcherServer {
135143
match state
136144
.db
137145
.insert_proof(
138-
recovered_address,
146+
&recovered_address,
139147
AggregationModeProvingSystem::SP1.as_u16() as i32,
140148
&data.message.proof,
141149
&data.message.program_vk_commitment,

0 commit comments

Comments
 (0)