cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
Loading...
Searching...
No Matches
eth_rpc.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: LGPL-3.0-or-later
3 * Copyright (c) 2026 Cryptnox SA
4 */
5
13
14#ifndef ETH_RPC_H
15#define ETH_RPC_H
16
17/******************************************************************
18 * 1. Included files
19 ******************************************************************/
20
21#include <stdint.h>
22#include <stddef.h>
23#include <stdbool.h>
24
25#include "eth_json.h" /* eth_receipt_expect_t */
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/******************************************************************
32 * 2. Types
33 ******************************************************************/
34
43
44/******************************************************************
45 * 3. Public API
46 ******************************************************************/
47
61void eth_rpc_init(const char *rpc_url, const char *from_addr);
62
80bool eth_rpc_set_from(const char *addr);
81
90void eth_rpc_set_auth(const char *project_id, const char *api_secret);
91
102void eth_rpc_set_ca_cert(const char *ca_pem);
103
117bool eth_rpc_get_nonce(uint64_t *nonce_out);
118
133bool eth_rpc_get_balance(uint64_t *wei_out);
134
152bool eth_rpc_get_token_balance(const char *token_addr, uint64_t *units_out);
153
165bool eth_rpc_get_token_decimals(const char *token_addr, uint64_t *dec_out);
166
184bool eth_rpc_send_raw_tx(const uint8_t *tx, size_t tx_len,
185 char *tx_hash_out, size_t tx_hash_max,
186 char *err_out, size_t err_max);
187
206
212bool eth_rpc_err_already_known(const char *node_err);
213
214#ifdef __cplusplus
215}
216#endif
217
218#endif // ETH_RPC_H
JSON-RPC response parsing helpers — kept in their own unit (cJSON + CW_Utils only,...
eth_rpc_receipt_result_t eth_rpc_get_tx_receipt(const eth_receipt_expect_t *want)
Poll the receipt of a broadcast transaction (one shot).
Definition eth_rpc.cpp:385
bool eth_rpc_get_nonce(uint64_t *nonce_out)
Fetch the confirmed transaction count (nonce) for from_addr.
Definition eth_rpc.cpp:157
void eth_rpc_init(const char *rpc_url, const char *from_addr)
Set the RPC URL and the from-address used for nonce queries and ecrecover comparison.
Definition eth_rpc.cpp:122
void eth_rpc_set_auth(const char *project_id, const char *api_secret)
Optional: set Infura-style HTTP Basic Auth credentials.
Definition eth_rpc.cpp:146
bool eth_rpc_get_token_decimals(const char *token_addr, uint64_t *dec_out)
Read an ERC-20 contract's decimals().
Definition eth_rpc.cpp:354
bool eth_rpc_get_balance(uint64_t *wei_out)
Fetch the native balance of from_addr, in wei.
Definition eth_rpc.cpp:212
bool eth_rpc_get_token_balance(const char *token_addr, uint64_t *units_out)
Fetch from_addr's balance of an ERC-20, via balanceOf over eth_call.
Definition eth_rpc.cpp:239
eth_rpc_receipt_result_t
Outcome of one eth_getTransactionReceipt poll.
Definition eth_rpc.h:36
@ ETH_RPC_RECEIPT_RPC_ERROR
Definition eth_rpc.h:40
@ ETH_RPC_RECEIPT_MISMATCH
Definition eth_rpc.h:41
@ ETH_RPC_RECEIPT_REVERTED
Definition eth_rpc.h:39
@ ETH_RPC_RECEIPT_PENDING
Definition eth_rpc.h:37
@ ETH_RPC_RECEIPT_SUCCESS
Definition eth_rpc.h:38
bool eth_rpc_send_raw_tx(const uint8_t *tx, size_t tx_len, char *tx_hash_out, size_t tx_hash_max, char *err_out, size_t err_max)
Broadcast a raw signed transaction (type-prefixed RLP bytes).
Definition eth_rpc.cpp:286
bool eth_rpc_err_already_known(const char *node_err)
true if a broadcast error message means the node already HAS this transaction ("already known",...
Definition eth_rpc.cpp:377
void eth_rpc_set_ca_cert(const char *ca_pem)
Optional: pin the RPC endpoint's TLS certificate.
Definition eth_rpc.cpp:152
bool eth_rpc_set_from(const char *addr)
Replace the from-address — the account a sale spends from.
Definition eth_rpc.cpp:133
What a receipt must show for the payment to count — see eth_json_receipt_check.
Definition eth_json.h:40