Move network features out of ethUtils

This commit is contained in:
Francois Beutin
2024-01-15 18:48:48 +01:00
parent 82d776f771
commit 04d0fde47a
8 changed files with 39 additions and 37 deletions

View File

@@ -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;
}

View File

@@ -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_

View File

@@ -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;
}

View File

@@ -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);