diff --git a/legacy/firmware/.gitignore b/legacy/firmware/.gitignore index 543117bf31..fce40a938d 100644 --- a/legacy/firmware/.gitignore +++ b/legacy/firmware/.gitignore @@ -1,6 +1,6 @@ coin_info.[ch] nem_mosaics.[ch] -ethereum_networks.h +ethereum_networks.c ethereum_tokens.[ch] u2f_knownapps.h diff --git a/legacy/firmware/Makefile b/legacy/firmware/Makefile index 75a46b6ece..37264a4ac1 100644 --- a/legacy/firmware/Makefile +++ b/legacy/firmware/Makefile @@ -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 diff --git a/legacy/firmware/ethereum.c b/legacy/firmware/ethereum.c index a6a01ccf14..5394603425 100644 --- a/legacy/firmware/ethereum.c +++ b/legacy/firmware/ethereum.c @@ -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); } diff --git a/legacy/firmware/ethereum_networks.h.mako b/legacy/firmware/ethereum_networks.c.mako similarity index 66% rename from legacy/firmware/ethereum_networks.h.mako rename to legacy/firmware/ethereum_networks.c.mako index 5049f883c6..c8f02b86e1 100644 --- a/legacy/firmware/ethereum_networks.h.mako +++ b/legacy/firmware/ethereum_networks.c.mako @@ -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 diff --git a/legacy/firmware/ethereum_networks.h b/legacy/firmware/ethereum_networks.h new file mode 100644 index 0000000000..00490f907b --- /dev/null +++ b/legacy/firmware/ethereum_networks.h @@ -0,0 +1,33 @@ +/* + * This file is part of the Trezor project, https://trezor.io/ + * + * Copyright (C) 2018 Pavol Rusnak + * + * 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 . + */ + +#ifndef __ETHEREUM_NETWORKS_H__ +#define __ETHEREUM_NETWORKS_H__ + +#include +#include + +#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