Add support for EIP2718 (enveloppe) and EIP2930 (acess list tx); Display chain ID when different from 1 (ethereum mainnet)

This commit is contained in:
pscott
2021-04-21 16:56:17 +02:00
parent 5dd99c3d48
commit 970f0355dd
14 changed files with 419 additions and 146 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

@@ -59,6 +59,7 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
int eth_plugin_perform_init(uint8_t *contractAddress, ethPluginInitContract_t *init) {
uint8_t i;
const uint8_t **selectors;
return 0;
dataContext.tokenContext.pluginAvailable = 0;
// Handle hardcoded plugin list
PRINTF("Selector %.*H\n", 4, init->selector);

View File

@@ -714,7 +714,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,58 @@ 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");
THROW(EXCEPTION);
// Almost like U4BE except that it takes `size` as a parameter.
uint32_t u32_from_BE(uint8_t *in, uint8_t size) {
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 {
res = (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3];
}
return res;
}
// Converts a uint32_t to a string.
void u32_to_str(char *dest, uint32_t in, uint8_t dest_size) {
uint8_t i = 0;
// Get the first digit (in case it's 0).
dest[i] = in % 10 + '0';
in /= 10;
i++;
// Get every digit.
while (in != 0) {
if (i >= dest_size) {
THROW(6502);
}
dest[i] = in % 10 + '0';
in /= 10;
i++;
}
// Null terminate the string.
dest[i] = '\0';
i--;
// Reverse the string
uint8_t end = i;
char tmp;
i = 0;
while (i < end) {
// Swap the first and last elements.
tmp = dest[i];
dest[i] = dest[end];
dest[end] = tmp;
// Decrease the interval size.
i++;
end--;
}
return v;
}
void amountToString(uint8_t *amount,

View File

@@ -28,7 +28,11 @@ void convertUint256BE(uint8_t* data, uint32_t length, uint256_t* target);
int local_strchr(char* string, char ch);
uint32_t getV(txContent_t* txContent);
// `itoa` for uint32_t.
void u32_to_str(char* dest, uint8_t dest_size, uint32_t in);
// Converts a list of bytes (in BE) of length `size` to a uint32_t.
uint32_t u32_from_BE(uint8_t* in, uint8_t size);
void amountToString(uint8_t* amount,
uint8_t amount_len,