cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
Loading...
Searching...
No Matches
assets.h File Reference

What each selectable asset IS — one row per pos_chain_t. More...

#include <stdbool.h>
#include <stddef.h>
#include "settings.h"
Include dependency graph for assets.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pos_asset_t
 One selectable asset. More...
struct  pos_net_info_t
 Names for one network, in both deployments. More...

Macros

#define POS_ASSET_COUNT   (sizeof(POS_ASSETS) / sizeof(POS_ASSETS[0]))

Enumerations

enum  pos_net_t { POS_NET_ETH = 0 , POS_NET_POLY , POS_NET_TRON , POS_NET__COUNT }
 A network, as the picker's first step offers it. More...
enum  pos_coin_t { POS_COIN_NET = 0 , POS_COIN_USDC , POS_COIN_USDT }
 Which mark an asset wears. A native coin wears its network's. More...

Functions

static const pos_asset_t * pos_asset_of (pos_chain_t chain)
 The row describing chain.
static pos_net_t pos_net_of (pos_chain_t chain)
 Which network chain is on.
static bool pos_chain_is_tron (pos_chain_t c)
 true for the Tron selections; every other one is EVM.
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.
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. Native TRX is not one — Tron signs on its own path.
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.

Variables

static const pos_asset_t POS_ASSETS []
static const pos_net_info_t POS_NETS [POS_NET__COUNT]

Detailed Description

What each selectable asset IS — one row per pos_chain_t.

The nine selections used to be described by four parallel switches in ui.cpp (ticker, network name, address-row caption, icon pair) plus three hand-written picker tables, so adding one asset meant ten coordinated edits and a missed one shipped a row that rendered wrong or named the wrong contract. The facts are data, so they live in a table and the switches became lookups.

The family predicates (pos_chain_is_tron and friends) are derived from it, so which network an asset is on is said once. Deliberately NOT here:

  • the images. Those are lv_img_dsc_t, and this header is kept free of LVGL and of ESP-IDF so a host test can reach it (tests/units/test_assets.cpp). The row says which mark (pos_coin_t); ui.cpp maps it to an image.
  • the contracts. Those are config.h macros, which a host test cannot see; main.cpp keeps them in TOKEN_CFG, next to the one store per row.

The table is indexed by nothing: it is ordered for the picker — grouped by network, native coin first, exactly as the three tables it replaced were — and looked up by pos_asset_of. test_assets.cpp proves every enumerator appears exactly once, which is the check that makes a table trustworthy in place of ten remembered edit sites.

Definition in file assets.h.

Macro Definition Documentation

◆ POS_ASSET_COUNT

#define POS_ASSET_COUNT   (sizeof(POS_ASSETS) / sizeof(POS_ASSETS[0]))

Definition at line 127 of file assets.h.

Referenced by open_coin_picker(), and pos_asset_of().

Enumeration Type Documentation

◆ pos_coin_t

enum pos_coin_t

Which mark an asset wears. A native coin wears its network's.

Enumerator
POS_COIN_NET 
POS_COIN_USDC 
POS_COIN_USDT 

Definition at line 59 of file assets.h.

◆ pos_net_t

enum pos_net_t

A network, as the picker's first step offers it.

Not pos_chain_t: several chains share one network (USDC and USDT are both Ethereum), and step 1 of the picker asks for the network alone.

Enumerator
POS_NET_ETH 
POS_NET_POLY 
POS_NET_TRON 
POS_NET__COUNT 

Definition at line 51 of file assets.h.

Function Documentation

◆ pos_asset_of()

const pos_asset_t * pos_asset_of ( pos_chain_t chain)
inlinestatic

The row describing chain.

Never NULL for a value that came out of settings_get_chain(), which already rejects anything past POS_CHAIN__COUNT — but the fallback is the default asset rather than a NULL a caller has to remember to test, for the same reason settings_get_chain() falls back rather than failing: a terminal that renders the wrong ticker is recoverable, one that dereferences NULL on the amount screen is not.

Definition at line 145 of file assets.h.

References POS_ASSET_COUNT, and POS_ASSETS.

Referenced by active_token(), asset(), evm_balance_ok(), make_asset_badge(), pos_chain_is_native_evm(), pos_net_of(), token_load(), and tron_balance_ok().

◆ pos_chain_is_native_evm()

bool pos_chain_is_native_evm ( pos_chain_t c)
inlinestatic

true for ETH and POL: no contract, the amount goes in value, 21000 gas, 18 decimals. Native TRX is not one — Tron signs on its own path.

Definition at line 183 of file assets.h.

References pos_asset_t::native, pos_asset_t::net, pos_asset_of(), and POS_NET_TRON.

Referenced by amount_cents_max(), and chain_is_native_evm().

◆ pos_chain_is_polygon()

bool pos_chain_is_polygon ( pos_chain_t c)
inlinestatic

true for the Polygon selections. EVM like Ethereum, but its own endpoint, chain id and contracts.

Definition at line 174 of file assets.h.

References pos_net_of(), and POS_NET_POLY.

Referenced by chain_is_polygon(), token_decimals_ok(), and ui_refresh_addresses_for().

◆ pos_chain_is_tron()

bool pos_chain_is_tron ( pos_chain_t c)
inlinestatic

true for the Tron selections; every other one is EVM.

This decides which signing path runs, which payout is spent and which endpoint is called — pinned per enumerator in tests/units/test_chain.cpp.

Definition at line 165 of file assets.h.

References pos_net_of(), and POS_NET_TRON.

Referenced by build_settings(), chain_is_tron(), token_decimals_ok(), token_load(), and ui_refresh_addresses_for().

◆ pos_net_info()

const pos_net_info_t * pos_net_info ( pos_net_t net)
inlinestatic

Names for net, or Ethereum's for a value out of range.

Definition at line 190 of file assets.h.

References POS_NET__COUNT, POS_NET_ETH, and POS_NETS.

Referenced by asset_network(), open_coin_picker(), open_network_picker(), and token_load().

◆ pos_net_of()

pos_net_t pos_net_of ( pos_chain_t chain)
inlinestatic

Which network chain is on.

Definition at line 154 of file assets.h.

References pos_asset_t::net, and pos_asset_of().

Referenced by pos_chain_is_polygon(), and pos_chain_is_tron().

Variable Documentation

◆ POS_ASSETS

const pos_asset_t POS_ASSETS[]
static
Initial value:
= {
{ POS_CHAIN_ETH_NATIVE, "ETH", "Native coin", "Asset",
POS_NET_ETH, true, 18U, POS_COIN_NET },
{ POS_CHAIN_ETH_USDC, "USDC", "ERC-20", "USDC contract",
POS_NET_ETH, false, 6U, POS_COIN_USDC },
{ POS_CHAIN_ETH_USDT, "USDT", "ERC-20", "USDT contract",
POS_NET_ETH, false, 6U, POS_COIN_USDT },
{ POS_CHAIN_POLY_NATIVE, "POL", "Native coin", "Asset",
POS_NET_POLY, true, 18U, POS_COIN_NET },
{ POS_CHAIN_POLY_USDC, "USDC", "ERC-20", "USDC contract",
POS_NET_POLY, false, 6U, POS_COIN_USDC },
{ POS_CHAIN_POLY_USDT, "USDT", "ERC-20", "USDT contract",
POS_NET_POLY, false, 6U, POS_COIN_USDT },
{ POS_CHAIN_TRON_TRX, "TRX", "Native coin", "Asset",
POS_NET_TRON, true, 6U, POS_COIN_NET },
{ POS_CHAIN_TRON_USDT, "USDT", "TRC-20", "Token contract",
POS_NET_TRON, false, 6U, POS_COIN_USDT },
{ POS_CHAIN_TRON_USDC, "USDC", "TRC-20", "Token contract",
POS_NET_TRON, false, 6U, POS_COIN_USDC },
}
@ POS_NET_TRON
Definition assets.h:54
@ POS_NET_ETH
Definition assets.h:52
@ POS_NET_POLY
Definition assets.h:53
@ POS_COIN_NET
Definition assets.h:60
@ POS_COIN_USDC
Definition assets.h:61
@ POS_COIN_USDT
Definition assets.h:62
@ 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

Definition at line 102 of file assets.h.

Referenced by open_coin_picker(), and pos_asset_of().

◆ POS_NETS

const pos_net_info_t POS_NETS[POS_NET__COUNT]
static
Initial value:
= {
{ "Ethereum", "Ethereum Sepolia", "Ethereum", "Sepolia testnet", "Mainnet" },
{ "Polygon", "Polygon Amoy", "Polygon", "Amoy testnet", "Mainnet" },
{ "Tron", "Tron Nile", "Tron", "Nile testnet", "Mainnet" },
}

Definition at line 129 of file assets.h.

Referenced by pos_net_info().