cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
eth_rpc.cpp File Reference
#include "eth_rpc.h"
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "esp_log.h"
#include "esp_http_client.h"
#include "esp_crt_bundle.h"
Include dependency graph for eth_rpc.cpp:

Go to the source code of this file.

Macros

#define WIFI_CONNECTED_BIT   BIT0
#define WIFI_FAIL_BIT   BIT1
#define WIFI_MAX_RETRY   5
#define WIFI_TIMEOUT_MS   30000
#define RESP_BUF_SIZE   1024U
#define HEX_PER_BYTE   2U

Functions

static void wifi_event_handler (void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
static bool do_post (const char *body, char *resp_buf, size_t resp_buf_size)
static char hex_nibble (uint8_t n)
static void bytes_to_hex (const uint8_t *data, size_t len, char *out)
void eth_rpc_init (const char *rpc_url, const char *from_addr)
void eth_rpc_set_auth (const char *project_id, const char *api_secret)
bool eth_rpc_wifi_connect (const char *ssid, const char *password)
bool eth_rpc_get_nonce (uint64_t *nonce_out)
uint8_t eth_rpc_ecrecover_parity (const uint8_t hash[32], const uint8_t r[32], const uint8_t s[32])
bool eth_rpc_send_raw_tx (const uint8_t *tx, size_t tx_len, char *tx_hash_out, size_t tx_hash_max)

Variables

static const char *const TAG = "eth_rpc"
static const char * s_rpc_url = NULL
static const char * s_from_addr = NULL
static const char * s_project_id = NULL
static const char * s_api_secret = NULL
static EventGroupHandle_t s_wifi_event_group
static int s_retry_num = 0

Macro Definition Documentation

◆ HEX_PER_BYTE

#define HEX_PER_BYTE   2U

Definition at line 34 of file eth_rpc.cpp.

Referenced by bytes_to_hex(), eth_rpc_ecrecover_parity(), and eth_rpc_send_raw_tx().

◆ RESP_BUF_SIZE

#define RESP_BUF_SIZE   1024U

Definition at line 31 of file eth_rpc.cpp.

Referenced by eth_rpc_ecrecover_parity(), eth_rpc_get_nonce(), and eth_rpc_send_raw_tx().

◆ WIFI_CONNECTED_BIT

#define WIFI_CONNECTED_BIT   BIT0

Definition at line 25 of file eth_rpc.cpp.

◆ WIFI_FAIL_BIT

#define WIFI_FAIL_BIT   BIT1

Definition at line 26 of file eth_rpc.cpp.

◆ WIFI_MAX_RETRY

#define WIFI_MAX_RETRY   5

◆ WIFI_TIMEOUT_MS

#define WIFI_TIMEOUT_MS   30000

Function Documentation

◆ bytes_to_hex()

void bytes_to_hex ( const uint8_t * data,
size_t len,
char * out )
static

Definition at line 156 of file eth_rpc.cpp.

References hex_nibble(), and HEX_PER_BYTE.

Referenced by eth_rpc_ecrecover_parity(), and eth_rpc_send_raw_tx().

◆ do_post()

bool do_post ( const char * body,
char * resp_buf,
size_t resp_buf_size )
static

Definition at line 85 of file eth_rpc.cpp.

References s_api_secret, s_project_id, s_rpc_url, and TAG.

Referenced by eth_rpc_ecrecover_parity(), eth_rpc_get_nonce(), and eth_rpc_send_raw_tx().

◆ eth_rpc_ecrecover_parity()

uint8_t eth_rpc_ecrecover_parity ( const uint8_t hash[32],
const uint8_t r[32],
const uint8_t s[32] )
Examples
UsdcSigning/main/main.cpp.

Definition at line 257 of file eth_rpc.cpp.

References bytes_to_hex(), do_post(), hex_nibble(), HEX_PER_BYTE, RESP_BUF_SIZE, s_from_addr, and TAG.

Referenced by signing_loop().

◆ eth_rpc_get_nonce()

bool eth_rpc_get_nonce ( uint64_t * nonce_out)
Examples
UsdcSigning/main/main.cpp.

Definition at line 231 of file eth_rpc.cpp.

References do_post(), RESP_BUF_SIZE, s_from_addr, and TAG.

Referenced by signing_loop().

◆ eth_rpc_init()

void eth_rpc_init ( const char * rpc_url,
const char * from_addr )
Examples
UsdcSigning/main/main.cpp.

Definition at line 169 of file eth_rpc.cpp.

References s_from_addr, and s_rpc_url.

Referenced by app_main().

◆ eth_rpc_send_raw_tx()

bool eth_rpc_send_raw_tx ( const uint8_t * tx,
size_t tx_len,
char * tx_hash_out,
size_t tx_hash_max )
Examples
UsdcSigning/main/main.cpp.

Definition at line 332 of file eth_rpc.cpp.

References bytes_to_hex(), do_post(), HEX_PER_BYTE, RESP_BUF_SIZE, and TAG.

Referenced by signing_loop().

◆ eth_rpc_set_auth()

void eth_rpc_set_auth ( const char * project_id,
const char * api_secret )
Examples
UsdcSigning/main/main.cpp.

Definition at line 175 of file eth_rpc.cpp.

References s_api_secret, and s_project_id.

Referenced by app_main().

◆ eth_rpc_wifi_connect()

bool eth_rpc_wifi_connect ( const char * ssid,
const char * password )

◆ hex_nibble()

char hex_nibble ( uint8_t n)
static

Definition at line 151 of file eth_rpc.cpp.

Referenced by bytes_to_hex(), and eth_rpc_ecrecover_parity().

◆ wifi_event_handler()

void wifi_event_handler ( void * arg,
esp_event_base_t event_base,
int32_t event_id,
void * event_data )
static

Variable Documentation

◆ s_api_secret

const char* s_api_secret = NULL
static

Definition at line 43 of file eth_rpc.cpp.

Referenced by do_post(), and eth_rpc_set_auth().

◆ s_from_addr

const char* s_from_addr = NULL
static

Definition at line 41 of file eth_rpc.cpp.

Referenced by eth_rpc_ecrecover_parity(), eth_rpc_get_nonce(), and eth_rpc_init().

◆ s_project_id

const char* s_project_id = NULL
static

Definition at line 42 of file eth_rpc.cpp.

Referenced by do_post(), and eth_rpc_set_auth().

◆ s_retry_num

int s_retry_num = 0
static

Definition at line 46 of file eth_rpc.cpp.

◆ s_rpc_url

const char* s_rpc_url = NULL
static

Definition at line 40 of file eth_rpc.cpp.

Referenced by do_post(), and eth_rpc_init().

◆ s_wifi_event_group

EventGroupHandle_t s_wifi_event_group
static

Definition at line 45 of file eth_rpc.cpp.

◆ TAG

const char* const TAG = "eth_rpc"
static

Definition at line 23 of file eth_rpc.cpp.