Skip to content

Commit 1ccd9d2

Browse files
Fix the types handling on format_merkle_paths func
1 parent 7ae7cae commit 1ccd9d2

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

aggregation_mode/batcher/src/db.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ pub enum DbError {
1717
#[derive(Debug, Clone, sqlx::Type, serde::Serialize)]
1818
#[sqlx(type_name = "task_status")]
1919
#[sqlx(rename_all = "lowercase")]
20-
enum TaskStatus {
20+
pub enum TaskStatus {
2121
Pending,
2222
Processing,
2323
Verified,
2424
}
2525

2626
#[derive(Debug, Clone, sqlx::FromRow, sqlx::Type, serde::Serialize)]
2727
pub struct Receipt {
28-
status: TaskStatus,
28+
pub status: TaskStatus,
2929
pub merkle_path: Option<Vec<u8>>,
30-
nonce: i64,
31-
address: String,
30+
pub nonce: i64,
31+
pub address: String,
3232
}
3333

3434
impl Db {

aggregation_mode/batcher/src/server/helpers.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
use crate::db::Receipt;
1+
use crate::{db::Receipt, server::types::GetReceiptsResponse};
22

3-
pub(super) fn format_merkle_paths(
4-
paths: Vec<Receipt>,
5-
) -> Result<Vec<(Receipt, Vec<String>)>, String> {
3+
pub(super) fn format_merkle_paths(paths: Vec<Receipt>) -> Result<Vec<GetReceiptsResponse>, String> {
64
paths
75
.into_iter()
86
.map(|receipt| {
97
if let Some(merkle_path) = &receipt.merkle_path {
108
if merkle_path.is_empty() {
11-
return Ok((receipt, vec![]));
9+
return Ok(GetReceiptsResponse {
10+
status: receipt.status,
11+
merkle_path: Vec::new(),
12+
nonce: receipt.nonce,
13+
address: receipt.address,
14+
});
1215
}
1316
if merkle_path.len() % 32 != 0 {
1417
return Err("merkle path length is not a multiple of 32 bytes".into());
@@ -19,9 +22,19 @@ pub(super) fn format_merkle_paths(
1922
.map(|chunk| format!("0x{}", hex::encode(chunk)))
2023
.collect();
2124

22-
Ok((receipt, formatted_merkle_path))
25+
Ok(GetReceiptsResponse {
26+
status: receipt.status,
27+
merkle_path: formatted_merkle_path,
28+
nonce: receipt.nonce,
29+
address: receipt.address,
30+
})
2331
} else {
24-
Ok((receipt, vec![]))
32+
Ok(GetReceiptsResponse {
33+
status: receipt.status,
34+
merkle_path: Vec::new(),
35+
nonce: receipt.nonce,
36+
address: receipt.address,
37+
})
2538
}
2639
})
2740
.collect()

aggregation_mode/batcher/src/server/types.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use serde::{Deserialize, Serialize};
22
use serde_json::Value;
33

4+
use crate::db::TaskStatus;
5+
46
#[derive(Serialize, Deserialize)]
57
pub(super) struct AppResponse {
68
status: u16,
@@ -51,3 +53,11 @@ pub(super) struct SubmitProofRequestMessageRisc0 {
5153
pub program_image_id: Vec<u8>,
5254
pub public_inputs: Vec<u8>,
5355
}
56+
57+
#[derive(Debug, Clone, sqlx::FromRow, sqlx::Type, serde::Serialize)]
58+
pub struct GetReceiptsResponse {
59+
pub status: TaskStatus,
60+
pub merkle_path: Vec<String>,
61+
pub nonce: i64,
62+
pub address: String,
63+
}

0 commit comments

Comments
 (0)