Skip to content

Commit

Permalink
feat: add delegate call voucher to rollup tool
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Jan 8, 2025
1 parent d2d8e38 commit e1ab682
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions sys-utils/rollup/rollup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ static void print_help(void) {
{"index": <number> }
where field "index" is the index allocated for the voucher
delegate-call-voucher
emit a delegate call voucher read from stdin as a JSON object in the format
{"destination": <address>, "payload": <hex-data>}
where
<address> contains a 20-byte EVM address in hex,
<hex-data> contains arbitrary data in hex
if successful, prints to stdout a JSON object in the format
{"index": <number> }
where field "index" is the index allocated for the voucher
notice
emit a notice read from stdin as a JSON object in the format
{"payload": <hex-data> }
Expand Down Expand Up @@ -244,6 +254,34 @@ static int write_voucher(void) try {
return 1;
}

// Read input for delegate call voucher data, issue voucher, write result to output
static int write_delegate_call_voucher(void) try {
rollup r;
auto ji = nlohmann::json::parse(read_input());
auto payload_bytes = unhex(ji["payload"].get<std::string>());
auto destination_bytes = unhex20(ji["destination"].get<std::string>());
uint64_t index = 0;
cmt_abi_address_t destination;
cmt_abi_u256_t value;
cmt_abi_bytes_t payload;
payload.data = reinterpret_cast<unsigned char *>(payload_bytes.data());
payload.length = payload_bytes.size();

memcpy(destination.data, reinterpret_cast<unsigned char *>(destination_bytes.data()), destination_bytes.size());

int ret = cmt_rollup_emit_delegate_call_voucher(r, &destination, &payload, &index);
if (ret)
return ret;

nlohmann::json j = {{"index", index}};
std::cout << j.dump(2) << '\n';

return 0;
} catch (std::exception &x) {
std::cerr << x.what() << '\n';
return 1;
}

// Read input for notice data, issue notice, write result to output
static int write_notice(void) try {
rollup r;
Expand Down Expand Up @@ -426,6 +464,8 @@ int main(int argc, char *argv[]) {
const char *command = argv[1];
if (strcmp(command, "voucher") == 0) {
return write_voucher();
} else if (strcmp(command, "delegate-call-voucher") == 0) {
return write_delegate_call_voucher();
} else if (strcmp(command, "notice") == 0) {
return write_notice();
} else if (strcmp(command, "report") == 0) {
Expand Down

0 comments on commit e1ab682

Please sign in to comment.