Skip to content

Commit

Permalink
refactor: make field names consistent with evm
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonehab committed Mar 19, 2024
1 parent 4072ee0 commit 5dc880c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 38 deletions.
8 changes: 4 additions & 4 deletions sys-utils/ioctl-echo-loop/ioctl-echo-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ static int handle_advance_state_request(cmt_rollup_t *me, struct parsed_args *ar
int rc = cmt_rollup_read_advance_state(me, &advance);
if (rc) return rc;

if (write_vouchers(me, args->voucher_count, advance.sender, advance.length, advance.data) != 0) {
if (write_vouchers(me, args->voucher_count, advance.msg_sender, advance.payload_length, advance.payload) != 0) {
return -1;
}
if (write_notices(me, args->notice_count, advance.length, advance.data) != 0) {
if (write_notices(me, args->notice_count, advance.payload_length, advance.payload) != 0) {
return -1;
}
if (write_reports(me, args->report_count, advance.length, advance.data) != 0) {
if (write_reports(me, args->report_count, advance.payload_length, advance.payload) != 0) {
return -1;
}
return 0;
Expand All @@ -139,7 +139,7 @@ static int handle_inspect_state_request(cmt_rollup_t *me, struct parsed_args *ar
int rc = cmt_rollup_read_inspect_state(me, &inspect);
if (rc) return rc;

if (write_reports(me, args->report_count, inspect.length, inspect.data) != 0) {
if (write_reports(me, args->report_count, inspect.payload_length, inspect.payload) != 0) {
return -1;
}
return 0;
Expand Down
20 changes: 10 additions & 10 deletions sys-utils/libcmt/include/libcmt/rollup.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ typedef struct cmt_rollup {

/** Public struct with the advance state contents */
typedef struct cmt_rollup_advance {
uint64_t chain_id; /**< network */
uint8_t app[CMT_ADDRESS_LENGTH]; /**< application contract address */
uint8_t sender[CMT_ADDRESS_LENGTH]; /**< input sender */
uint64_t block_number; /**< block number of this input */
uint64_t block_timestamp; /**< block timestamp of this input UNIX epoch format) */
uint64_t index; /**< input index (in relation to all inputs ever sent to the DApp) */
uint32_t length; /**< length in bytes of the data field */
void *data; /**< advance contents */
uint64_t chain_id; /**< network */
uint8_t app_contract[CMT_ADDRESS_LENGTH]; /**< application contract address */
uint8_t msg_sender[CMT_ADDRESS_LENGTH]; /**< input sender address */
uint64_t block_number; /**< block number of this input */
uint64_t block_timestamp; /**< block timestamp of this input UNIX epoch format) */
uint64_t index; /**< input index (in relation to all inputs ever sent to the DApp) */
uint32_t payload_length; /**< length in bytes of the payload field */
void *payload; /**< payload for this input */
} cmt_rollup_advance_t;

/** Public struct with the inspect state contents */
typedef struct cmt_rollup_inspect {
uint32_t length; /**< length in bytes of the data field */
void *data; /**< inspect contents */
uint32_t payload_length; /**< length in bytes of the payload field */
void *payload; /**< payload for this query */
} cmt_rollup_inspect_t;

/** Public struct with the finish state contents */
Expand Down
14 changes: 7 additions & 7 deletions sys-utils/libcmt/src/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,18 @@ int cmt_rollup_read_advance_state(cmt_rollup_t *me, cmt_rollup_advance_t *advanc
cmt_buf_t st[1] = {{rd->begin + 4, rd->end}}; // EVM offsets are from after funsel
cmt_buf_t of[1];

size_t length = 0;
size_t payload_length = 0;
if (DBG(cmt_abi_check_funsel(rd, EVM_ADVANCE)) ||
DBG(cmt_abi_get_uint(rd, sizeof(advance->chain_id), &advance->chain_id)) ||
DBG(cmt_abi_get_address(rd, advance->app)) ||
DBG(cmt_abi_get_address(rd, advance->sender)) ||
DBG(cmt_abi_get_address(rd, advance->app_contract)) ||
DBG(cmt_abi_get_address(rd, advance->msg_sender)) ||
DBG(cmt_abi_get_uint(rd, sizeof(advance->block_number), &advance->block_number)) ||
DBG(cmt_abi_get_uint(rd, sizeof(advance->block_timestamp), &advance->block_timestamp)) ||
DBG(cmt_abi_get_uint(rd, sizeof(advance->index), &advance->index)) ||
DBG(cmt_abi_get_bytes_s(rd, of)) ||
DBG(cmt_abi_get_bytes_d(st, of, &length, &advance->data)))
DBG(cmt_abi_get_bytes_d(st, of, &payload_length, &advance->payload)))
return -ENOBUFS;
advance->length = length;
advance->payload_length = payload_length;
return 0;
}

Expand All @@ -206,8 +206,8 @@ int cmt_rollup_read_inspect_state(cmt_rollup_t *me, cmt_rollup_inspect_t *inspec
if (!inspect)
return -EINVAL;
cmt_buf_t rx[1] = {cmt_io_get_rx(me->io)};
inspect->length = cmt_buf_length(rx);
inspect->data = rx->begin;
inspect->payload_length = cmt_buf_length(rx);
inspect->payload = rx->begin;
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions sys-utils/libcmt/src/tests/rollup_echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ int main(void) {
break;
}

rc = cmt_rollup_emit_voucher(&rollup, sizeof advance.sender, advance.sender, sizeof small, small, advance.length, advance.data);
rc = cmt_rollup_emit_voucher(&rollup, sizeof advance.msg_sender, advance.msg_sender, sizeof small, small, advance.payload_length, advance.payload);
if (rc < 0) {
fprintf(stderr, "%s:%d Error on voucher %s (%d)\n", __FILE__, __LINE__, strerror(-rc), (-rc));
break;
}

rc = cmt_rollup_emit_notice(&rollup, advance.length, advance.data);
rc = cmt_rollup_emit_notice(&rollup, advance.payload_length, advance.payload);
if (rc < 0) {
fprintf(stderr, "%s:%d Error on notice %s (%d)\n", __FILE__, __LINE__, strerror(-rc), (-rc));
break;
}

rc = cmt_rollup_emit_report(&rollup, advance.length, advance.data);
rc = cmt_rollup_emit_report(&rollup, advance.payload_length, advance.payload);
if (rc < 0) {
fprintf(stderr, "%s:%d Error on notice %s (%d)\n", __FILE__, __LINE__, strerror(-rc), (-rc));
break;
Expand Down
26 changes: 12 additions & 14 deletions sys-utils/rollup/rollup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,14 @@ static void print_help(void) {
when field "request_type" contains "advance_state",
field "data" contains a JSON object in the format
{
"metadata": {
"chain_id": <number>,
"app": <address>,
"sender": <address>,
"epoch_index": <number>,
"input_index": <number>,
"block_number": <number>,
"timestamp": <number>
},
"payload": <string>
"chain_id": <number>,
"app_contract": <address>,
"msg_sender": <address>,
"epoch_index": <number>,
"input_index": <number>,
"block_number": <number>,
"timestamp": <number>
"payload": <string>
},
where field <address> contains a 20-byte EVM address in hex
Expand Down Expand Up @@ -262,9 +260,9 @@ static void write_advance_state(rollup &r, cmt_rollup_finish_t *f) {
{"request_type", "advance_state"},
{"data", {
{"chain_id", advance.chain_id},
{"payload", hex(reinterpret_cast<const uint8_t *>(advance.data), advance.length)},
{"app", hex(advance.app, sizeof(advance.app))},
{"sender", hex(advance.sender, sizeof(advance.sender))},
{"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},
{"index", advance.index},
Expand All @@ -283,7 +281,7 @@ static void write_inspect_state(rollup &r, cmt_rollup_finish_t *f) {
nlohmann::json j = {
{"request_type", "inspect_state"},
{"data", {
{"payload", hex(reinterpret_cast<const uint8_t *>(inspect.data), inspect.length)},
{"payload", hex(reinterpret_cast<const uint8_t *>(inspect.payload), inspect.payload_length)},
}}
};
std::cout << j.dump(2) << '\n';
Expand Down

0 comments on commit 5dc880c

Please sign in to comment.