cryptnox-pos
1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
Toggle main menu visibility
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
42
extern
"C"
{
43
#endif
44
51
typedef
enum
{
52
POS_NET_ETH
= 0,
53
POS_NET_POLY
,
54
POS_NET_TRON
,
55
POS_NET__COUNT
56
}
pos_net_t
;
57
59
typedef
enum
{
60
POS_COIN_NET
= 0,
61
POS_COIN_USDC
,
62
POS_COIN_USDT
,
63
}
pos_coin_t
;
64
66
typedef
struct
{
67
pos_chain_t
chain
;
68
const
char
*
ticker
;
69
const
char
*
standard
;
77
const
char
*
caption
;
78
pos_net_t
net
;
79
bool
native
;
80
unsigned
decimals
;
81
pos_coin_t
coin
;
82
}
pos_asset_t
;
83
92
typedef
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
;
98
}
pos_net_info_t
;
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. */
102
static
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
129
static
const
pos_net_info_t
POS_NETS
[
POS_NET__COUNT
] = {
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
145
static
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
154
static
inline
pos_net_t
pos_net_of
(
pos_chain_t
chain)
155
{
156
return
pos_asset_of
(chain)->
net
;
157
}
158
165
static
inline
bool
pos_chain_is_tron
(
pos_chain_t
c)
166
{
167
return
pos_net_of
(c) ==
POS_NET_TRON
;
168
}
169
174
static
inline
bool
pos_chain_is_polygon
(
pos_chain_t
c)
175
{
176
return
pos_net_of
(c) ==
POS_NET_POLY
;
177
}
178
183
static
inline
bool
pos_chain_is_native_evm
(
pos_chain_t
c)
184
{
185
const
pos_asset_t
*a =
pos_asset_of
(c);
186
return
a->
native
&& (a->
net
!=
POS_NET_TRON
);
187
}
188
190
static
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]
193
: &
POS_NETS
[
POS_NET_ETH
];
194
}
195
196
#ifdef __cplusplus
197
}
198
#endif
199
200
#endif
/* ASSETS_H */
pos_net_of
static pos_net_t pos_net_of(pos_chain_t chain)
Which network chain is on.
Definition
assets.h:154
pos_asset_of
static const pos_asset_t * pos_asset_of(pos_chain_t chain)
The row describing chain.
Definition
assets.h:145
pos_net_t
pos_net_t
A network, as the picker's first step offers it.
Definition
assets.h:51
POS_NET_TRON
@ POS_NET_TRON
Definition
assets.h:54
POS_NET_ETH
@ POS_NET_ETH
Definition
assets.h:52
POS_NET_POLY
@ POS_NET_POLY
Definition
assets.h:53
POS_NET__COUNT
@ POS_NET__COUNT
Definition
assets.h:55
pos_chain_is_native_evm
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
pos_chain_is_tron
static bool pos_chain_is_tron(pos_chain_t c)
true for the Tron selections; every other one is EVM.
Definition
assets.h:165
POS_NETS
static const pos_net_info_t POS_NETS[POS_NET__COUNT]
Definition
assets.h:129
pos_chain_is_polygon
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
POS_ASSETS
static const pos_asset_t POS_ASSETS[]
Definition
assets.h:102
POS_ASSET_COUNT
#define POS_ASSET_COUNT
Definition
assets.h:127
pos_coin_t
pos_coin_t
Which mark an asset wears. A native coin wears its network's.
Definition
assets.h:59
POS_COIN_NET
@ POS_COIN_NET
Definition
assets.h:60
POS_COIN_USDC
@ POS_COIN_USDC
Definition
assets.h:61
POS_COIN_USDT
@ POS_COIN_USDT
Definition
assets.h:62
pos_net_info
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
settings.h
Persistent device settings stored in NVS (backlight, Wi-Fi creds).
pos_chain_t
pos_chain_t
Which chain (and therefore which asset) the terminal charges in.
Definition
settings.h:33
POS_CHAIN_POLY_USDT
@ POS_CHAIN_POLY_USDT
Definition
settings.h:39
POS_CHAIN_POLY_USDC
@ POS_CHAIN_POLY_USDC
Definition
settings.h:38
POS_CHAIN_ETH_USDC
@ POS_CHAIN_ETH_USDC
Definition
settings.h:34
POS_CHAIN_TRON_USDT
@ POS_CHAIN_TRON_USDT
Definition
settings.h:36
POS_CHAIN_TRON_TRX
@ POS_CHAIN_TRON_TRX
Definition
settings.h:35
POS_CHAIN_POLY_NATIVE
@ POS_CHAIN_POLY_NATIVE
Definition
settings.h:42
POS_CHAIN_TRON_USDC
@ POS_CHAIN_TRON_USDC
Definition
settings.h:40
POS_CHAIN_ETH_NATIVE
@ POS_CHAIN_ETH_NATIVE
Definition
settings.h:41
POS_CHAIN_ETH_USDT
@ POS_CHAIN_ETH_USDT
Definition
settings.h:37
pos_asset_t
One selectable asset.
Definition
assets.h:66
pos_asset_t::net
pos_net_t net
Definition
assets.h:78
pos_asset_t::standard
const char * standard
Definition
assets.h:69
pos_asset_t::native
bool native
Definition
assets.h:79
pos_asset_t::chain
pos_chain_t chain
Definition
assets.h:67
pos_asset_t::ticker
const char * ticker
Definition
assets.h:68
pos_asset_t::caption
const char * caption
Definition
assets.h:77
pos_asset_t::coin
pos_coin_t coin
Definition
assets.h:81
pos_asset_t::decimals
unsigned decimals
Definition
assets.h:80
pos_net_info_t
Names for one network, in both deployments.
Definition
assets.h:92
pos_net_info_t::name
const char * name
Definition
assets.h:93
pos_net_info_t::long_main
const char * long_main
Definition
assets.h:95
pos_net_info_t::long_test
const char * long_test
Definition
assets.h:94
pos_net_info_t::sub_main
const char * sub_main
Definition
assets.h:97
pos_net_info_t::sub_test
const char * sub_test
Definition
assets.h:96
main
assets.h
Generated by
1.17.0