Parser reference
This page lists every parser function with its exact signature per language. The enums, structs and error codes they use are defined in Types and selectors.
Decode advance
Decodes an advance input into a typed result. Pass the deposit type when the sender is a portal, or the automatic type to detect withdrawals and transfers from the payload.
Signature
- Python
- Rust
- C++
# One function per deposit type. Each takes the dict returned by
# read_advance_state() and returns a dict of decoded fields.
decode_ether_deposit(input: dict) -> dict
decode_erc20_deposit(input: dict) -> dict
decode_erc721_deposit(input: dict) -> dict
decode_erc1155_single_deposit(input: dict) -> dict
decode_erc1155_batch_deposit(input: dict) -> dict
# Automatic detection for withdrawals and transfers.
# Returns a dict with a "type" key naming the operation.
decode_advance(input: dict) -> dict
pub fn cma_decode_advance(
req_type: CmaParserInputType,
input: JsonValue,
) -> Result<CmaParserInput, CmaParserError>
int cma_parser_decode_advance(
cma_parser_input_type_t type,
const cmt_rollup_advance_t *input,
cma_parser_input_t *parser_input);
Parameters
- type / req_type: the input type to decode. Use a specific deposit type when you matched the sender to a portal. Use the automatic type (
CMA_PARSER_INPUT_TYPE_AUTOin C and C++,CmaParserInputTypeAutoin Rust) for everything else. The Python deposit functions carry the type in their name, anddecode_advancealways runs in automatic mode. - input: the advance request.
- Python: the dictionary returned by
read_advance_state(), containingmsg_senderandpayload. - Rust: a JSON object. The parser reads the payload from
data.payloadas a hex string and, in automatic mode, the sender fromdata.metadata.msg_sender. - C and C++: the
cmt_rollup_advance_tstruct filled bycmt_rollup_read_advance_state.
- Python: the dictionary returned by
- parser_input (C and C++ only): output struct the parser fills.
Returns
- Python: a dictionary of decoded fields.
decode_advanceadds atypekey, for exampleERC20_WITHDRAWAL. - Rust: a
CmaParserInputwithreq_type(the detected type) andinput(aCmaParserInputDatavariant holding the fields). - C and C++:
0on success, a negative error code on failure. The decoded data lands inparser_input, withparser_input.typenaming the variant.
Errors
Fails when the payload is shorter than the expected layout, the hex is invalid, or the input matches no supported operation. See error codes.
Decode inspect
Decodes a balance or total supply query from an inspect request. The payload is a JSON document with method and params fields, described in Parsing inputs.
Signature
- Python
- Rust
- C++
decode_inspect(input: dict) -> dict
pub fn cma_decode_inspect(
input: JsonValue,
) -> Result<CmaParserInput, CmaParserError>
int cma_parser_decode_inspect(
cma_parser_input_type_t type,
const cmt_rollup_inspect_t *input,
cma_parser_input_t *parser_input);
Parameters
- input: the inspect request. Python takes the dict from
read_inspect_state(). Rust takes a JSON object and reads the hex payload fromdata.payload. C and C++ take thecmt_rollup_inspect_tstruct. - type (C and C++ only): pass
CMA_PARSER_INPUT_TYPE_AUTOto accept both query methods, or a specific balance or supply type to accept only one.
Returns
- Python: a dict with
typeset toBALANCEorSUPPLY, plusaccount,tokenandtoken_idfields. Fields not present in the query areNone. - Rust: a
CmaParserInputwhosereq_typeis the balance or supply type and whose data variant holds the query fields. - C and C++:
0on success with the result inparser_input, or a negative error code.
Errors
Fails when the payload is not valid JSON, the method key is missing or unknown, or a parameter has the wrong format.
Encode voucher
Builds the destination and payload of a voucher that returns an asset to the base layer.
Signature
- Python
- Rust
- C++
# Methods of RollupCma. Each encodes the voucher and emits it
# to the machine in one step.
emit_ether_voucher(receiver: str, amount: int)
emit_erc20_voucher(token: str, receiver: str, amount: int)
emit_erc721_voucher(token: str, receiver: str, token_id: int)
emit_erc1155_single_voucher(token: str, receiver: str, token_id: int, amount: int)
emit_erc1155_batch_voucher(token: str, receiver: str, token_ids: list, amounts: list)
pub fn cma_encode_voucher(
req_type: CmaParserVoucherType,
app_address: Option<Address>,
voucher_request: CmaVoucherFieldType,
) -> Result<CmaVoucher, CmaParserError>
int cma_parser_encode_voucher(
cma_parser_voucher_type_t type,
const cma_abi_address_t *app_address,
const cma_parser_voucher_data_t *voucher_request,
cma_voucher_t *voucher);
Parameters
- type / req_type: the voucher type, one entry per asset standard. See voucher types.
- voucher_request: the fields for that voucher type, such as token address, receiver and amount.
- app_address: your application's address on the base layer, available in the advance request metadata. In C, C++ and Rust you pass it to the encode call, in Rust as
Some(address). The Python binding captures it for you fromread_advance_state(). ERC721 vouchers also keep the application address inside their fields struct, because the token contract moves the token out of the application's custody.
Returns
- Python: the emit methods send the voucher directly and return the emit result.
- Rust: a
CmaVoucherwithdestinationandpayloadstrings, ready to emit through your rollup I/O layer. - C and C++:
0on success with the result invoucher, holding the destination address and the call data.
Errors
Fails when the request fields do not match the voucher type.