Merge pull request #131 from LedgerHQ/eip_2718

Support EIP2718 (transaction types) and EIP2930 (access list transactions) and display ChainID
This commit is contained in:
Jean P
2021-05-04 11:54:30 +02:00
committed by GitHub
13 changed files with 409 additions and 141 deletions

View File

@@ -61,4 +61,6 @@ typedef struct chain_config_s {
chain_kind_t kind;
} chain_config_t;
#define ETHEREUM_MAINNET_CHAINID 1
#endif /* _CHAIN_CONFIG_H_ */

View File

@@ -750,7 +750,11 @@ void coin_main(chain_config_t *coin_config) {
if (N_storage.initialized != 0x01) {
internalStorage_t storage;
#ifdef HAVE_ALLOW_DATA
storage.dataAllowed = 0x01;
#else
storage.dataAllowed = 0x00;
#endif
storage.contractDetails = 0x00;
storage.displayNonce = 0x00;
storage.initialized = 0x01;

View File

@@ -158,7 +158,9 @@ typedef struct txStringProperties_t {
char fullAddress[43];
char fullAmount[50];
char maxFee[50];
char nonce[8]; // 10M tx per account ought to be enough for everybody
char nonce[8]; // 10M tx per account ought to be enough for everybody
char chainID[8]; // 10M different chainID ought to be enough for people to find a unique
// chainID for their token / chain.
} txStringProperties_t;
typedef struct strDataTmp_t {

View File

@@ -53,22 +53,23 @@ int local_strchr(char *string, char ch) {
return -1;
}
uint32_t getV(txContent_t *txContent) {
uint32_t v = 0;
if (txContent->vLength == 1) {
v = txContent->v[0];
} else if (txContent->vLength == 2) {
v = (txContent->v[0] << 8) | txContent->v[1];
} else if (txContent->vLength == 3) {
v = (txContent->v[0] << 16) | (txContent->v[1] << 8) | txContent->v[2];
} else if (txContent->vLength == 4) {
v = (txContent->v[0] << 24) | (txContent->v[1] << 16) | (txContent->v[2] << 8) |
txContent->v[3];
} else if (txContent->vLength != 0) {
PRINTF("Unexpected v format\n");
// Almost like U4BE except that it takes `size` as a parameter.
// The `strict` parameter defines whether we should throw in case of a length > 4.
uint32_t u32_from_BE(uint8_t *in, uint8_t size, bool strict) {
uint32_t res = 0;
if (size == 1) {
res = in[0];
} else if (size == 2) {
res = (in[0] << 8) | in[1];
} else if (size == 3) {
res = (in[0] << 16) | (in[1] << 8) | in[2];
} else if (size == 4) {
res = (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3];
} else if (strict && size != 0) {
PRINTF("Unexpected format\n");
THROW(EXCEPTION);
}
return v;
return res;
}
void amountToString(uint8_t *amount,

View File

@@ -28,7 +28,9 @@ void convertUint256BE(uint8_t* data, uint32_t length, uint256_t* target);
int local_strchr(char* string, char ch);
uint32_t getV(txContent_t* txContent);
// Converts a list of bytes (in BE) of length `size` to a uint32_t. `strict` will make the function
// throw if the size is > 4.
uint32_t u32_from_BE(uint8_t* in, uint8_t size, bool strict);
void amountToString(uint8_t* amount,
uint8_t amount_len,