Merge branch 'master' into support_eip1559
This commit is contained in:
@@ -486,7 +486,6 @@ static parserStatus_e parseRLP(txContext_t *context) {
|
||||
}
|
||||
// Ready to process this field
|
||||
if (!rlpDecodeLength(context->rlpBuffer,
|
||||
context->rlpBufferPos,
|
||||
&context->currentFieldLength,
|
||||
&offset,
|
||||
&context->currentFieldIsList)) {
|
||||
|
||||
@@ -58,11 +58,7 @@ bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rlpDecodeLength(uint8_t *buffer,
|
||||
uint32_t bufferLength,
|
||||
uint32_t *fieldLength,
|
||||
uint32_t *offset,
|
||||
bool *list) {
|
||||
bool rlpDecodeLength(uint8_t *buffer, uint32_t *fieldLength, uint32_t *offset, bool *list) {
|
||||
if (*buffer <= 0x7f) {
|
||||
*offset = 0;
|
||||
*fieldLength = 1;
|
||||
@@ -128,7 +124,7 @@ void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out, cx_sha3
|
||||
}
|
||||
|
||||
void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey,
|
||||
uint8_t *out,
|
||||
char *out,
|
||||
cx_sha3_t *sha3Context,
|
||||
chain_config_t *chain_config) {
|
||||
uint8_t hashAddress[INT256_LENGTH];
|
||||
@@ -138,7 +134,7 @@ void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey,
|
||||
}
|
||||
|
||||
void getEthAddressStringFromBinary(uint8_t *address,
|
||||
uint8_t *out,
|
||||
char *out,
|
||||
cx_sha3_t *sha3Context,
|
||||
chain_config_t *chain_config) {
|
||||
// save some precious stack space
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
* @brief Decode an RLP encoded field - see
|
||||
* https://github.com/ethereum/wiki/wiki/RLP
|
||||
* @param [in] buffer buffer containing the RLP encoded field to decode
|
||||
* @param [in] bufferLength size of the buffer
|
||||
* @param [out] fieldLength length of the RLP encoded field
|
||||
* @param [out] offset offset to the beginning of the RLP encoded field from the
|
||||
* buffer
|
||||
@@ -34,23 +33,19 @@
|
||||
* string
|
||||
* @return true if the RLP header is consistent
|
||||
*/
|
||||
bool rlpDecodeLength(uint8_t *buffer,
|
||||
uint32_t bufferLength,
|
||||
uint32_t *fieldLength,
|
||||
uint32_t *offset,
|
||||
bool *list);
|
||||
bool rlpDecodeLength(uint8_t *buffer, uint32_t *fieldLength, uint32_t *offset, bool *list);
|
||||
|
||||
bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid);
|
||||
|
||||
void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out, cx_sha3_t *sha3Context);
|
||||
|
||||
void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey,
|
||||
uint8_t *out,
|
||||
char *out,
|
||||
cx_sha3_t *sha3Context,
|
||||
chain_config_t *chain_config);
|
||||
|
||||
void getEthAddressStringFromBinary(uint8_t *address,
|
||||
uint8_t *out,
|
||||
char *out,
|
||||
cx_sha3_t *sha3Context,
|
||||
chain_config_t *chain_config);
|
||||
|
||||
|
||||
71
src_common/network.c
Normal file
71
src_common/network.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "network.h"
|
||||
#include "os.h"
|
||||
#include "shared_context.h"
|
||||
#include "utils.h"
|
||||
|
||||
// Mappping of chain ids to networks.
|
||||
const network_info_t NETWORK_MAPPING[] = {
|
||||
{.chain_id = 1, .name = "Ethereum", .ticker = "ETH "},
|
||||
{.chain_id = 3, .name = "Ropsten", .ticker = "ETH "},
|
||||
{.chain_id = 4, .name = "Rinkeby", .ticker = "ETH "},
|
||||
{.chain_id = 5, .name = "Goerli", .ticker = "ETH "},
|
||||
{.chain_id = 10, .name = "Optimism", .ticker = "ETH "},
|
||||
{.chain_id = 42, .name = "Kovan", .ticker = "ETH "},
|
||||
{.chain_id = 56, .name = "BSC", .ticker = "BNB "},
|
||||
{.chain_id = 100, .name = "xDai", .ticker = "xDAI "},
|
||||
{.chain_id = 137, .name = "Polygon", .ticker = "MATIC "},
|
||||
{.chain_id = 250, .name = "Fantom", .ticker = "FTM "},
|
||||
{.chain_id = 43114, .name = "Avalanche", .ticker = "AVAX "}};
|
||||
|
||||
uint32_t get_chain_id(void) {
|
||||
uint32_t chain_id = 0;
|
||||
|
||||
switch (txContext.txType) {
|
||||
case LEGACY:
|
||||
chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength, true);
|
||||
break;
|
||||
case EIP2930:
|
||||
case EIP1559:
|
||||
chain_id = u32_from_BE(tmpContent.txContent.chainID.value,
|
||||
tmpContent.txContent.chainID.length,
|
||||
true);
|
||||
break;
|
||||
default:
|
||||
PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType);
|
||||
break;
|
||||
}
|
||||
PRINTF("ChainID: %d\n", chain_id);
|
||||
return chain_id;
|
||||
}
|
||||
|
||||
network_info_t *get_network(void) {
|
||||
uint32_t chain_id = get_chain_id();
|
||||
for (uint8_t i = 0; i < sizeof(NETWORK_MAPPING) / sizeof(*NETWORK_MAPPING); i++) {
|
||||
if (NETWORK_MAPPING[i].chain_id == chain_id) {
|
||||
return (network_info_t *) PIC(&NETWORK_MAPPING[i]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *get_network_name(void) {
|
||||
network_info_t *network = get_network();
|
||||
if (network == NULL) {
|
||||
return NULL;
|
||||
} else {
|
||||
return (char *) PIC(network->name);
|
||||
}
|
||||
}
|
||||
|
||||
char *get_network_ticker(void) {
|
||||
network_info_t *network = get_network();
|
||||
if (network == NULL) {
|
||||
return chainConfig->coinName;
|
||||
} else {
|
||||
return (char *) PIC(network->ticker);
|
||||
}
|
||||
}
|
||||
19
src_common/network.h
Normal file
19
src_common/network.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stdint.h>
|
||||
#include "tokens.h"
|
||||
|
||||
#define NETWORK_STRING_MAX_SIZE 12
|
||||
|
||||
typedef struct network_info_s {
|
||||
const char name[NETWORK_STRING_MAX_SIZE];
|
||||
const char ticker[MAX_TICKER_LEN];
|
||||
uint32_t chain_id;
|
||||
} network_info_t;
|
||||
|
||||
// Returns the current chain id. Defaults to 0 if txType was not found.
|
||||
uint32_t get_chain_id(void);
|
||||
// Returns a pointer to the network struct, or NULL if there is none.
|
||||
network_info_t *get_network(void);
|
||||
// Returns a pointer to the network name, or NULL if there is none.
|
||||
char *get_network_name(void);
|
||||
// Returns a pointer to the network ticker, or chainConfig->coinName if there is none.
|
||||
char *get_network_ticker(void);
|
||||
Reference in New Issue
Block a user