Skip to content

Commit 04d0fde

Browse files
Move network features out of ethUtils
1 parent 82d776f commit 04d0fde

File tree

8 files changed

+39
-37
lines changed

8 files changed

+39
-37
lines changed

src/ethUtils.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -348,32 +348,3 @@ bool adjustDecimals(const char *src,
348348
}
349349
return true;
350350
}
351-
352-
// Returns the chain ID. Defaults to 0 if txType was not found (For TX).
353-
uint64_t get_tx_chain_id(void) {
354-
uint64_t chain_id = 0;
355-
356-
switch (txContext.txType) {
357-
case LEGACY:
358-
chain_id = u64_from_BE(txContext.content->v, txContext.content->vLength);
359-
break;
360-
case EIP2930:
361-
case EIP1559:
362-
chain_id = u64_from_BE(tmpContent.txContent.chainID.value,
363-
tmpContent.txContent.chainID.length);
364-
break;
365-
default:
366-
PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType);
367-
break;
368-
}
369-
return chain_id;
370-
}
371-
372-
const char *get_displayable_ticker(const uint64_t *chain_id) {
373-
const char *ticker = get_network_ticker_from_chain_id(chain_id);
374-
375-
if (ticker == NULL) {
376-
ticker = chainConfig->coinName;
377-
}
378-
return ticker;
379-
}

src/ethUtils.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ static __attribute__((no_instrument_function)) inline int ismaxint(uint8_t *buf,
8484
return 1;
8585
}
8686

87-
uint64_t get_tx_chain_id(void);
88-
89-
const char *get_displayable_ticker(const uint64_t *chain_id);
90-
9187
static const char HEXDIGITS[] = "0123456789abcdef";
9288

9389
#endif // _ETHUTILS_H_

src/network.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "os_utils.h"
33
#include "os_pic.h"
44
#include "network.h"
5+
#include "shared_context.h"
6+
#include "utils.h"
57

68
typedef struct network_info_s {
79
const char *name;
@@ -113,3 +115,32 @@ const char *get_network_ticker_from_chain_id(const uint64_t *chain_id) {
113115
bool chain_is_ethereum_compatible(const uint64_t *chain_id) {
114116
return get_network_from_chain_id(chain_id) != NULL;
115117
}
118+
119+
// Returns the chain ID. Defaults to 0 if txType was not found (For TX).
120+
uint64_t get_tx_chain_id(void) {
121+
uint64_t chain_id = 0;
122+
123+
switch (txContext.txType) {
124+
case LEGACY:
125+
chain_id = u64_from_BE(txContext.content->v, txContext.content->vLength);
126+
break;
127+
case EIP2930:
128+
case EIP1559:
129+
chain_id = u64_from_BE(tmpContent.txContent.chainID.value,
130+
tmpContent.txContent.chainID.length);
131+
break;
132+
default:
133+
PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType);
134+
break;
135+
}
136+
return chain_id;
137+
}
138+
139+
const char *get_displayable_ticker(const uint64_t *chain_id) {
140+
const char *ticker = get_network_ticker_from_chain_id(chain_id);
141+
142+
if (ticker == NULL) {
143+
ticker = chainConfig->coinName;
144+
}
145+
return ticker;
146+
}

src/network.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef _NETWORK_H_
2-
#define _NETWORK_H_
1+
#pragma once
32

43
#include <stdint.h>
54
#include <stdbool.h>
@@ -9,4 +8,6 @@ const char *get_network_ticker_from_chain_id(const uint64_t *chain_id);
98

109
bool chain_is_ethereum_compatible(const uint64_t *chain_id);
1110

12-
#endif // _NETWORK_H_
11+
uint64_t get_tx_chain_id(void);
12+
13+
const char *get_displayable_ticker(const uint64_t *chain_id);

src_features/provideNFTInformation/cmd_provideNFTInfo.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "utils.h"
77
#include "common_ui.h"
88
#include "os_io_seproxyhal.h"
9+
#include "network.h"
910

1011
#define TYPE_SIZE 1
1112
#define VERSION_SIZE 1

src_features/setPlugin/cmd_setPlugin.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "utils.h"
77
#include "common_ui.h"
88
#include "os_io_seproxyhal.h"
9+
#include "network.h"
910

1011
// Supported internal plugins
1112
#define ERC721_STR "ERC721"

src_nbgl/ui_approve_tx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "plugins.h"
99
#include "domain_name.h"
1010
#include "network_icons.h"
11+
#include "network.h"
1112

1213
#define TEXT_TX "transaction"
1314
// 1 more than actually displayed on screen, because of calculations in StaticReview

tools/gen_networks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def main(output_dir: str) -> bool:
9090

9191
# get chain IDs and network names
9292
expr = r"{\.chain_id = ([0-9]*), \.name = \"(.*)\", \.ticker = \"(.*)\"},"
93-
with open("src_common/network.c") as f:
93+
with open("src/network.c") as f:
9494
for line in f.readlines():
9595
line = line.strip()
9696
if line.startswith("{") and line.endswith("},"):

0 commit comments

Comments
 (0)