|
cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
|
Implementation of the JSON-RPC response parsing helpers. More...
Go to the source code of this file.
Functions | |
| bool | eth_json_result_string (const char *resp, char *out, size_t out_size) |
Extract the top-level "result" string from a JSON-RPC response. | |
| bool | eth_json_error_message (const char *resp, char *out, size_t out_size) |
Extract the JSON-RPC error.message from a response body. | |
| eth_json_receipt_t | eth_json_receipt_status (const char *resp) |
Classify an eth_getTransactionReceipt response body. | |
| static char | lc (char c) |
| static bool | str_is (const cJSON *j, const char *want) |
true if a JSON string equals want, ignoring hex case. | |
| static void | addr_hex (const uint8_t a[20], bool word, char *out) |
| "0x" + the 20 bytes as hex, or left-padded to a 32-byte word. | |
| static void | word_hex (uint64_t v, char *out) |
"0x" + v as a 32-byte big-endian word. | |
| static bool | has_transfer (const cJSON *logs, const char *token, const char *payee_word, const char *amount_word) |
true if logs holds a Transfer(*, payee, amount) from token. | |
| eth_json_receipt_t | eth_json_receipt_check (const char *resp, const eth_receipt_expect_t *want) |
| Classify a receipt AND check it is the payment that was asked for. | |
Variables | |
| static const char | TRANSFER_TOPIC [] |
Implementation of the JSON-RPC response parsing helpers.
Definition in file eth_json.cpp.
|
static |
"0x" + the 20 bytes as hex, or left-padded to a 32-byte word.
Definition at line 114 of file eth_json.cpp.
Referenced by eth_json_receipt_check().
| bool eth_json_error_message | ( | const char * | resp, |
| char * | out, | ||
| size_t | out_size ) |
Extract the JSON-RPC error.message from a response body.
The counterpart to eth_json_result_string, and the only place a node ever says why it refused a transaction: "insufficient funds for gas * price + value", "nonce too low", "transaction underpriced". Dropping it on the floor is what turns every one of those into an identical "Broadcast failed" on the panel, which tells an operator nothing they can act on.
A message longer than out_size is truncated rather than rejected — half a reason beats none, and the caller's buffer is a panel line, not a log.
| [in] | resp | NUL-terminated response body. |
| [out] | out | NUL-terminated message on success; untouched otherwise. |
| [in] | out_size | Capacity of out. |
Definition at line 39 of file eth_json.cpp.
References ok().
Referenced by eth_rpc_send_raw_tx().
| eth_json_receipt_t eth_json_receipt_check | ( | const char * | resp, |
| const eth_receipt_expect_t * | want ) |
Classify a receipt AND check it is the payment that was asked for.
A status of 0x1 alone proves nothing: a node that never broadcast our transaction can answer with the receipt of any other successful one. So on top of eth_json_receipt_status this requires transactionHash to be the hash computed on the device, to to be the expected contract (or payee), and — for a token — a Transfer log from that contract to payee for exactly amount. A mined receipt failing any of those is ETH_JSON_RECEIPT_MISMATCH, never SUCCESS or REVERTED.
| [in] | resp | NUL-terminated response body. |
| [in] | want | What the receipt must show; NULL yields ERROR. |
Definition at line 162 of file eth_json.cpp.
References addr_hex(), eth_receipt_expect_t::amount, ETH_JSON_RECEIPT_ERROR, ETH_JSON_RECEIPT_MISMATCH, ETH_JSON_RECEIPT_REVERTED, eth_json_receipt_status(), ETH_JSON_RECEIPT_SUCCESS, has_transfer(), eth_receipt_expect_t::payee, str_is(), eth_receipt_expect_t::to, eth_receipt_expect_t::tx_hash, and word_hex().
Referenced by eth_rpc_get_tx_receipt().
| eth_json_receipt_t eth_json_receipt_status | ( | const char * | resp | ) |
Classify an eth_getTransactionReceipt response body.
Parses the JSON and inspects the top-level result: null means the tx is still pending; an object's status field ("0x1" = success, anything else = reverted) gives the final verdict. Any other shape (invalid JSON, result neither null nor object, missing/non-string status) yields ETH_JSON_RECEIPT_ERROR.
| [in] | resp | NUL-terminated response body. |
Definition at line 69 of file eth_json.cpp.
References ETH_JSON_RECEIPT_ERROR, ETH_JSON_RECEIPT_PENDING, ETH_JSON_RECEIPT_REVERTED, and ETH_JSON_RECEIPT_SUCCESS.
Referenced by eth_json_receipt_check().
| bool eth_json_result_string | ( | const char * | resp, |
| char * | out, | ||
| size_t | out_size ) |
Extract the top-level "result" string from a JSON-RPC response.
Uses a real JSON parser (cJSON) instead of strstr so that JSON-RPC error objects, HTTP error bodies, or look-alike substrings are rejected.
| [in] | resp | NUL-terminated response body. |
| [out] | out | NUL-terminated "result" value on success; untouched on failure. |
| [in] | out_size | Capacity of out. |
out. Definition at line 18 of file eth_json.cpp.
References ok().
Referenced by eth_rpc_get_balance(), eth_rpc_get_nonce(), eth_rpc_get_token_balance(), eth_rpc_get_token_decimals(), and eth_rpc_send_raw_tx().
|
static |
true if logs holds a Transfer(*, payee, amount) from token.
Definition at line 143 of file eth_json.cpp.
References str_is(), and TRANSFER_TOPIC.
Referenced by eth_json_receipt_check().
|
static |
Definition at line 96 of file eth_json.cpp.
Referenced by str_is().
|
static |
true if a JSON string equals want, ignoring hex case.
Definition at line 102 of file eth_json.cpp.
References lc().
Referenced by eth_json_receipt_check(), and has_transfer().
|
static |
"0x" + v as a 32-byte big-endian word.
Definition at line 129 of file eth_json.cpp.
Referenced by eth_json_receipt_check().
|
static |
Definition at line 93 of file eth_json.cpp.
Referenced by has_transfer().