Move network features out of ethUtils
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _NETWORK_H_
|
||||
#define _NETWORK_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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("},"):
|
||||
|
||||
Reference in New Issue
Block a user