Skip to content

Commit

Permalink
fix: rollup-http-server and rollup util
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonehab committed May 20, 2024
1 parent 99b9e8a commit 6942b71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
26 changes: 20 additions & 6 deletions rollup-http/rollup-http-server/src/rollup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,36 @@ pub struct GIOResponse {
pub response: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
pub struct AdvanceMetadata {
pub chain_id: u64,
#[validate(regex = "ETH_ADDR_REGEXP")]
pub app_contract: String,
#[validate(regex = "ETH_ADDR_REGEXP")]
pub msg_sender: String,
pub input_index: u64,
pub block_number: u64,
pub block_timestamp: u64,
#[validate(regex = "ETH_U256_REGEXP")]
pub prev_randao: String,
pub input_index: u64,
}

impl From<cmt_rollup_advance_t> for AdvanceMetadata {
fn from(other: cmt_rollup_advance_t) -> Self {
let mut address = "0x".to_string();
address.push_str(&hex::encode(&other.msg_sender));
let mut msg_sender = "0x".to_string();
msg_sender.push_str(&hex::encode(&other.msg_sender));
let mut app_contract = "0x".to_string();
app_contract.push_str(&hex::encode(&other.app_contract));
let mut prev_randao = "0x".to_string();
prev_randao.push_str(&hex::encode(&other.prev_randao));
AdvanceMetadata {
input_index: other.index,
chain_id: other.chain_id,
app_contract: app_contract,
msg_sender: msg_sender,
block_timestamp: other.block_timestamp,
block_number: other.block_number,
msg_sender: address,
input_index: other.index,
prev_randao: prev_randao,
}
}
}
Expand Down Expand Up @@ -245,6 +258,7 @@ pub fn rollup_read_advance_state_request(
app_contract: Default::default(),
block_number: 0,
block_timestamp: 0,
prev_randao: Default::default(),
index: 0,
payload_length: 0,
payload: std::ptr::null::<::std::os::raw::c_uchar>() as *mut c_void,
Expand Down
10 changes: 6 additions & 4 deletions sys-utils/rollup/rollup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ static void print_help(void) {
"chain_id": <number>,
"app_contract": <address>,
"msg_sender": <address>,
"epoch_index": <number>,
"input_index": <number>,
"block_number": <number>,
"block_timestamp": <number>
"prev_randao": <hex-uint256>,
"index": <number>,
"payload": <hex-data>
},
where
<address> contains a 20-byte EVM address in hex, and
<address> contains a 20-byte EVM address in hex,
<hex-uint256> contains a big-endian 32-byte unsigned integer in hex, and
<hex-data> contains arbitrary data in hex
when field "request_type" contains "inspect_state",
Expand Down Expand Up @@ -292,12 +293,13 @@ static int write_advance_state(rollup &r, const cmt_rollup_finish_t *f) {
{"data",
{
{"chain_id", advance.chain_id},
{"payload", hex(reinterpret_cast<const uint8_t *>(advance.payload), advance.payload_length)},
{"app_contract", hex(advance.app_contract, sizeof(advance.app_contract))},
{"msg_sender", hex(advance.msg_sender, sizeof(advance.msg_sender))},
{"block_number", advance.block_number},
{"block_timestamp", advance.block_timestamp},
{"prev_randao", hex(advance.prev_randao, sizeof(advance.prev_randao))},
{"index", advance.index},
{"payload", hex(reinterpret_cast<const uint8_t *>(advance.payload), advance.payload_length)},
}}};
std::cout << j.dump(2) << '\n';
return 0;
Expand Down

0 comments on commit 6942b71

Please sign in to comment.