mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-30 02:18:16 +00:00
feat(legacy): move Ethereum networks functions into *.c file
This commit is contained in:
parent
19e196701b
commit
7c4a3e826e
2
legacy/firmware/.gitignore
vendored
2
legacy/firmware/.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
coin_info.[ch]
|
||||
nem_mosaics.[ch]
|
||||
ethereum_networks.h
|
||||
ethereum_networks.c
|
||||
ethereum_tokens.[ch]
|
||||
u2f_knownapps.h
|
||||
|
||||
|
@ -60,6 +60,7 @@ OBJS += crypto.o
|
||||
ifneq ($(BITCOIN_ONLY),1)
|
||||
OBJS += u2f.o
|
||||
OBJS += ethereum.o
|
||||
OBJS += ethereum_networks.o
|
||||
OBJS += ethereum_tokens.o
|
||||
OBJS += nem2.o
|
||||
OBJS += nem_mosaics.o
|
||||
|
@ -329,7 +329,7 @@ static void ethereumFormatAmount(const bignum256 *amnt, const TokenType *token,
|
||||
suffix = " Wei";
|
||||
decimals = 0;
|
||||
} else {
|
||||
ASSIGN_ETHEREUM_SUFFIX(suffix, chain_id);
|
||||
suffix = get_ethereum_suffix(chain_id);
|
||||
}
|
||||
bn_format(amnt, NULL, suffix, decimals, 0, false, ',', buf, buflen);
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
<%
|
||||
BKSL = "\\"
|
||||
|
||||
networks = list(supported_on("trezor1", eth))
|
||||
max_chain_id_length = 0
|
||||
max_slip44_length = 0
|
||||
@ -22,23 +20,21 @@ def align_suffix(n):
|
||||
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
|
||||
|
||||
#ifndef __ETHEREUM_NETWORKS_H__
|
||||
#define __ETHEREUM_NETWORKS_H__
|
||||
#include "ethereum_networks.h"
|
||||
|
||||
#define SLIP44_UNKNOWN UINT32_MAX
|
||||
|
||||
#define ASSIGN_ETHEREUM_SUFFIX(suffix, chain_id) ${BKSL}
|
||||
switch (chain_id) { ${BKSL}
|
||||
const char *get_ethereum_suffix(uint64_t chain_id) {
|
||||
switch (chain_id) {
|
||||
% 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
|
||||
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) {
|
||||
% for slip44 in sorted(set(n.slip44 for n in networks)):
|
||||
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) {
|
||||
% for n in networks:
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
33
legacy/firmware/ethereum_networks.h
Normal file
33
legacy/firmware/ethereum_networks.h
Normal 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
|
Loading…
Reference in New Issue
Block a user