diff --git a/src/ethUtils.c b/src/ethUtils.c index 0eb8ca3..38d21c9 100644 --- a/src/ethUtils.c +++ b/src/ethUtils.c @@ -348,32 +348,3 @@ bool adjustDecimals(const char *src, } return true; } - -// Returns the chain ID. Defaults to 0 if txType was not found (For TX). -uint64_t get_tx_chain_id(void) { - uint64_t chain_id = 0; - - switch (txContext.txType) { - case LEGACY: - chain_id = u64_from_BE(txContext.content->v, txContext.content->vLength); - break; - case EIP2930: - case EIP1559: - chain_id = u64_from_BE(tmpContent.txContent.chainID.value, - tmpContent.txContent.chainID.length); - break; - default: - PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType); - break; - } - return chain_id; -} - -const char *get_displayable_ticker(const uint64_t *chain_id) { - const char *ticker = get_network_ticker_from_chain_id(chain_id); - - if (ticker == NULL) { - ticker = chainConfig->coinName; - } - return ticker; -} diff --git a/src/ethUtils.h b/src/ethUtils.h index 2942243..89a3c63 100644 --- a/src/ethUtils.h +++ b/src/ethUtils.h @@ -84,10 +84,6 @@ static __attribute__((no_instrument_function)) inline int ismaxint(uint8_t *buf, return 1; } -uint64_t get_tx_chain_id(void); - -const char *get_displayable_ticker(const uint64_t *chain_id); - static const char HEXDIGITS[] = "0123456789abcdef"; #endif // _ETHUTILS_H_ diff --git a/src/network.c b/src/network.c index ce6dc67..5430b85 100644 --- a/src/network.c +++ b/src/network.c @@ -2,6 +2,8 @@ #include "os_utils.h" #include "os_pic.h" #include "network.h" +#include "shared_context.h" +#include "utils.h" typedef struct network_info_s { const char *name; @@ -113,3 +115,32 @@ const char *get_network_ticker_from_chain_id(const uint64_t *chain_id) { bool chain_is_ethereum_compatible(const uint64_t *chain_id) { return get_network_from_chain_id(chain_id) != NULL; } + +// Returns the chain ID. Defaults to 0 if txType was not found (For TX). +uint64_t get_tx_chain_id(void) { + uint64_t chain_id = 0; + + switch (txContext.txType) { + case LEGACY: + chain_id = u64_from_BE(txContext.content->v, txContext.content->vLength); + break; + case EIP2930: + case EIP1559: + chain_id = u64_from_BE(tmpContent.txContent.chainID.value, + tmpContent.txContent.chainID.length); + break; + default: + PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType); + break; + } + return chain_id; +} + +const char *get_displayable_ticker(const uint64_t *chain_id) { + const char *ticker = get_network_ticker_from_chain_id(chain_id); + + if (ticker == NULL) { + ticker = chainConfig->coinName; + } + return ticker; +} diff --git a/src/network.h b/src/network.h index 8361bcb..c6640d5 100644 --- a/src/network.h +++ b/src/network.h @@ -1,5 +1,4 @@ -#ifndef _NETWORK_H_ -#define _NETWORK_H_ +#pragma once #include #include @@ -9,4 +8,6 @@ const char *get_network_ticker_from_chain_id(const uint64_t *chain_id); bool chain_is_ethereum_compatible(const uint64_t *chain_id); -#endif // _NETWORK_H_ +uint64_t get_tx_chain_id(void); + +const char *get_displayable_ticker(const uint64_t *chain_id); diff --git a/src_features/provideNFTInformation/cmd_provideNFTInfo.c b/src_features/provideNFTInformation/cmd_provideNFTInfo.c index 9068b1e..1c329b2 100644 --- a/src_features/provideNFTInformation/cmd_provideNFTInfo.c +++ b/src_features/provideNFTInformation/cmd_provideNFTInfo.c @@ -6,6 +6,7 @@ #include "utils.h" #include "common_ui.h" #include "os_io_seproxyhal.h" +#include "network.h" #define TYPE_SIZE 1 #define VERSION_SIZE 1 diff --git a/src_features/setPlugin/cmd_setPlugin.c b/src_features/setPlugin/cmd_setPlugin.c index 6d3757a..1da01a1 100644 --- a/src_features/setPlugin/cmd_setPlugin.c +++ b/src_features/setPlugin/cmd_setPlugin.c @@ -6,6 +6,7 @@ #include "utils.h" #include "common_ui.h" #include "os_io_seproxyhal.h" +#include "network.h" // Supported internal plugins #define ERC721_STR "ERC721" diff --git a/src_nbgl/ui_approve_tx.c b/src_nbgl/ui_approve_tx.c index b3ddffb..ed5e0ae 100644 --- a/src_nbgl/ui_approve_tx.c +++ b/src_nbgl/ui_approve_tx.c @@ -8,6 +8,7 @@ #include "plugins.h" #include "domain_name.h" #include "network_icons.h" +#include "network.h" #define TEXT_TX "transaction" // 1 more than actually displayed on screen, because of calculations in StaticReview diff --git a/tools/gen_networks.py b/tools/gen_networks.py index 99b378d..7b7f9ab 100755 --- a/tools/gen_networks.py +++ b/tools/gen_networks.py @@ -90,7 +90,7 @@ def main(output_dir: str) -> bool: # get chain IDs and network names expr = r"{\.chain_id = ([0-9]*), \.name = \"(.*)\", \.ticker = \"(.*)\"}," - with open("src_common/network.c") as f: + with open("src/network.c") as f: for line in f.readlines(): line = line.strip() if line.startswith("{") and line.endswith("},"):