1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-31 19:08:28 +00:00

feat(legacy): move Ethereum networks functions into *.c file

This commit is contained in:
Martin Novak 2022-09-27 12:53:21 +02:00
parent 19e196701b
commit 7c4a3e826e
5 changed files with 45 additions and 17 deletions

View File

@ -1,6 +1,6 @@
coin_info.[ch] coin_info.[ch]
nem_mosaics.[ch] nem_mosaics.[ch]
ethereum_networks.h ethereum_networks.c
ethereum_tokens.[ch] ethereum_tokens.[ch]
u2f_knownapps.h u2f_knownapps.h

View File

@ -60,6 +60,7 @@ OBJS += crypto.o
ifneq ($(BITCOIN_ONLY),1) ifneq ($(BITCOIN_ONLY),1)
OBJS += u2f.o OBJS += u2f.o
OBJS += ethereum.o OBJS += ethereum.o
OBJS += ethereum_networks.o
OBJS += ethereum_tokens.o OBJS += ethereum_tokens.o
OBJS += nem2.o OBJS += nem2.o
OBJS += nem_mosaics.o OBJS += nem_mosaics.o

View File

@ -329,7 +329,7 @@ static void ethereumFormatAmount(const bignum256 *amnt, const TokenType *token,
suffix = " Wei"; suffix = " Wei";
decimals = 0; decimals = 0;
} else { } else {
ASSIGN_ETHEREUM_SUFFIX(suffix, chain_id); suffix = get_ethereum_suffix(chain_id);
} }
bn_format(amnt, NULL, suffix, decimals, 0, false, ',', buf, buflen); bn_format(amnt, NULL, suffix, decimals, 0, false, ',', buf, buflen);
} }

View File

@ -1,6 +1,4 @@
<% <%
BKSL = "\\"
networks = list(supported_on("trezor1", eth)) networks = list(supported_on("trezor1", eth))
max_chain_id_length = 0 max_chain_id_length = 0
max_slip44_length = 0 max_slip44_length = 0
@ -22,23 +20,21 @@ def align_suffix(n):
return "{:<{w}}".format(cstr, w=max_suffix_length + 4) return "{:<{w}}".format(cstr, w=max_suffix_length + 4)
%>\ %>\
// This file is automatically generated from ethereum_networks.h.mako // This file is automatically generated from ethereum_networks.c.mako
// DO NOT EDIT // DO NOT EDIT
#ifndef __ETHEREUM_NETWORKS_H__ #include "ethereum_networks.h"
#define __ETHEREUM_NETWORKS_H__
#define SLIP44_UNKNOWN UINT32_MAX const char *get_ethereum_suffix(uint64_t chain_id) {
switch (chain_id) {
#define ASSIGN_ETHEREUM_SUFFIX(suffix, chain_id) ${BKSL}
switch (chain_id) { ${BKSL}
% for n in networks: % for n in networks:
case ${align_chain_id(n)}: suffix = ${align_suffix(n)} break; /* ${n.name} */ ${BKSL} case ${align_chain_id(n)}: return ${align_suffix(n)} /* ${n.name} */
% endfor % endfor
default: suffix = " UNKN"; break; /* unknown chain */ ${BKSL} default: return UNKNOWN_NETWORK_SHORTCUT; /* unknown chain */
} }
}
static bool is_ethereum_slip44(uint32_t slip44) { bool is_ethereum_slip44(uint32_t slip44) {
switch (slip44) { switch (slip44) {
% for slip44 in sorted(set(n.slip44 for n in networks)): % for slip44 in sorted(set(n.slip44 for n in networks)):
case ${slip44}: case ${slip44}:
@ -49,7 +45,7 @@ static bool is_ethereum_slip44(uint32_t slip44) {
} }
} }
static int32_t ethereum_slip44_by_chain_id(uint64_t chain_id) { int32_t ethereum_slip44_by_chain_id(uint64_t chain_id) {
switch (chain_id) { switch (chain_id) {
% for n in networks: % for n in networks:
case ${align_chain_id(n)}: return ${align_slip44(n)}; /* ${n.name} */ case ${align_chain_id(n)}: return ${align_slip44(n)}; /* ${n.name} */
@ -57,5 +53,3 @@ static int32_t ethereum_slip44_by_chain_id(uint64_t chain_id) {
default: return SLIP44_UNKNOWN; /* unknown chain */ default: return SLIP44_UNKNOWN; /* unknown chain */
} }
} }
#endif

View File

@ -0,0 +1,33 @@
/*
* This file is part of the Trezor project, https://trezor.io/
*
* Copyright (C) 2018 Pavol Rusnak <stick@satoshilabs.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ETHEREUM_NETWORKS_H__
#define __ETHEREUM_NETWORKS_H__
#include <stdbool.h>
#include <stdint.h>
#define SLIP44_UNKNOWN UINT32_MAX
#define UNKNOWN_NETWORK_SHORTCUT " UNKN"
const char *get_ethereum_suffix(uint64_t chain_id);
bool is_ethereum_slip44(uint32_t slip44);
int32_t ethereum_slip44_by_chain_id(uint64_t chain_id);
#endif