cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
Loading...
Searching...
No Matches
assets.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
32
33#ifndef ASSETS_H
34#define ASSETS_H
35
36#include <stdbool.h>
37#include <stddef.h>
38
39#include "settings.h" /* pos_chain_t and the family predicates */
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
57
64
66typedef struct {
68 const char *ticker;
69 const char *standard;
77 const char *caption;
79 bool native;
80 unsigned decimals;
83
92typedef struct {
93 const char *name;
94 const char *long_test;
95 const char *long_main;
96 const char *sub_test;
97 const char *sub_main;
99
100/* Grouped by network, native coin first within each. The picker walks this in
101 * order and filters on `net`, so the order here IS the order on screen. */
102static const pos_asset_t POS_ASSETS[] = {
103 { POS_CHAIN_ETH_NATIVE, "ETH", "Native coin", "Asset",
104 POS_NET_ETH, true, 18U, POS_COIN_NET },
105 { POS_CHAIN_ETH_USDC, "USDC", "ERC-20", "USDC contract",
106 POS_NET_ETH, false, 6U, POS_COIN_USDC },
107 { POS_CHAIN_ETH_USDT, "USDT", "ERC-20", "USDT contract",
108 POS_NET_ETH, false, 6U, POS_COIN_USDT },
109
110 { POS_CHAIN_POLY_NATIVE, "POL", "Native coin", "Asset",
111 POS_NET_POLY, true, 18U, POS_COIN_NET },
112 { POS_CHAIN_POLY_USDC, "USDC", "ERC-20", "USDC contract",
113 POS_NET_POLY, false, 6U, POS_COIN_USDC },
114 { POS_CHAIN_POLY_USDT, "USDT", "ERC-20", "USDT contract",
115 POS_NET_POLY, false, 6U, POS_COIN_USDT },
116
117 { POS_CHAIN_TRON_TRX, "TRX", "Native coin", "Asset",
118 POS_NET_TRON, true, 6U, POS_COIN_NET },
119 { POS_CHAIN_TRON_USDT, "USDT", "TRC-20", "Token contract",
120 POS_NET_TRON, false, 6U, POS_COIN_USDT },
121 /* Testnet only: Circle stopped minting USDC on Tron in Feb 2024, so mainnet
122 * leaves its contract unset and the asset is refused. */
123 { POS_CHAIN_TRON_USDC, "USDC", "TRC-20", "Token contract",
124 POS_NET_TRON, false, 6U, POS_COIN_USDC },
125};
126
127#define POS_ASSET_COUNT (sizeof(POS_ASSETS) / sizeof(POS_ASSETS[0]))
128
130 { "Ethereum", "Ethereum Sepolia", "Ethereum", "Sepolia testnet", "Mainnet" },
131 { "Polygon", "Polygon Amoy", "Polygon", "Amoy testnet", "Mainnet" },
132 { "Tron", "Tron Nile", "Tron", "Nile testnet", "Mainnet" },
133};
134
145static inline const pos_asset_t *pos_asset_of(pos_chain_t chain)
146{
147 for (size_t i = 0U; i < POS_ASSET_COUNT; i++) {
148 if (POS_ASSETS[i].chain == chain) { return &POS_ASSETS[i]; }
149 }
150 return &POS_ASSETS[0];
151}
152
154static inline pos_net_t pos_net_of(pos_chain_t chain)
155{
156 return pos_asset_of(chain)->net;
157}
158
165static inline bool pos_chain_is_tron(pos_chain_t c)
166{
167 return pos_net_of(c) == POS_NET_TRON;
168}
169
175{
176 return pos_net_of(c) == POS_NET_POLY;
177}
178
184{
185 const pos_asset_t *a = pos_asset_of(c);
186 return a->native && (a->net != POS_NET_TRON);
187}
188
190static inline const pos_net_info_t *pos_net_info(pos_net_t net)
191{
192 return ((int)net >= 0 && net < POS_NET__COUNT) ? &POS_NETS[net]
194}
195
196#ifdef __cplusplus
197}
198#endif
199
200#endif /* ASSETS_H */
static pos_net_t pos_net_of(pos_chain_t chain)
Which network chain is on.
Definition assets.h:154
static const pos_asset_t * pos_asset_of(pos_chain_t chain)
The row describing chain.
Definition assets.h:145
pos_net_t
A network, as the picker's first step offers it.
Definition assets.h:51
@ POS_NET_TRON
Definition assets.h:54
@ POS_NET_ETH
Definition assets.h:52
@ POS_NET_POLY
Definition assets.h:53
@ POS_NET__COUNT
Definition assets.h:55
static bool pos_chain_is_native_evm(pos_chain_t c)
true for ETH and POL: no contract, the amount goes in value, 21000 gas, 18 decimals....
Definition assets.h:183
static bool pos_chain_is_tron(pos_chain_t c)
true for the Tron selections; every other one is EVM.
Definition assets.h:165
static const pos_net_info_t POS_NETS[POS_NET__COUNT]
Definition assets.h:129
static bool pos_chain_is_polygon(pos_chain_t c)
true for the Polygon selections. EVM like Ethereum, but its own endpoint, chain id and contracts.
Definition assets.h:174
static const pos_asset_t POS_ASSETS[]
Definition assets.h:102
#define POS_ASSET_COUNT
Definition assets.h:127
pos_coin_t
Which mark an asset wears. A native coin wears its network's.
Definition assets.h:59
@ POS_COIN_NET
Definition assets.h:60
@ POS_COIN_USDC
Definition assets.h:61
@ POS_COIN_USDT
Definition assets.h:62
static const pos_net_info_t * pos_net_info(pos_net_t net)
Names for net, or Ethereum's for a value out of range.
Definition assets.h:190
Persistent device settings stored in NVS (backlight, Wi-Fi creds).
pos_chain_t
Which chain (and therefore which asset) the terminal charges in.
Definition settings.h:33
@ POS_CHAIN_POLY_USDT
Definition settings.h:39
@ POS_CHAIN_POLY_USDC
Definition settings.h:38
@ POS_CHAIN_ETH_USDC
Definition settings.h:34
@ POS_CHAIN_TRON_USDT
Definition settings.h:36
@ POS_CHAIN_TRON_TRX
Definition settings.h:35
@ POS_CHAIN_POLY_NATIVE
Definition settings.h:42
@ POS_CHAIN_TRON_USDC
Definition settings.h:40
@ POS_CHAIN_ETH_NATIVE
Definition settings.h:41
@ POS_CHAIN_ETH_USDT
Definition settings.h:37
One selectable asset.
Definition assets.h:66
pos_net_t net
Definition assets.h:78
const char * standard
Definition assets.h:69
bool native
Definition assets.h:79
pos_chain_t chain
Definition assets.h:67
const char * ticker
Definition assets.h:68
const char * caption
Definition assets.h:77
pos_coin_t coin
Definition assets.h:81
unsigned decimals
Definition assets.h:80
Names for one network, in both deployments.
Definition assets.h:92
const char * name
Definition assets.h:93
const char * long_main
Definition assets.h:95
const char * long_test
Definition assets.h:94
const char * sub_main
Definition assets.h:97
const char * sub_test
Definition assets.h:96