rework plugin start so name and icon can be passed to eth

This commit is contained in:
Clement Bouvet
2023-02-21 11:15:20 +01:00
committed by Alexandre Paillier
parent b5c58b59cf
commit 0414a043c8
5 changed files with 57 additions and 21 deletions

View File

@@ -77,10 +77,17 @@ typedef enum chain_kind_e {
CHAIN_KIND_OASYS CHAIN_KIND_OASYS
} chain_kind_t; } chain_kind_t;
#ifdef HAVE_NBGL
#include "nbgl_types.h"
#endif // HAVE_NBGL
typedef struct chain_config_s { typedef struct chain_config_s {
char coinName[10]; // ticker char coinName[10]; // ticker
uint64_t chainId; uint64_t chainId;
chain_kind_t kind; chain_kind_t kind;
#ifdef HAVE_NBGL
nbgl_icon_details_t coinIconDetails;
#endif // HAVE_NBGL
} chain_config_t; } chain_config_t;
#define ETHEREUM_MAINNET_CHAINID 1 #define ETHEREUM_MAINNET_CHAINID 1

View File

@@ -69,7 +69,8 @@ bolos_ux_params_t G_ux_params;
const internalStorage_t N_storage_real; const internalStorage_t N_storage_real;
chain_config_t *chainConfig; const char *plugin_name = NULL;
chain_config_t *chainConfig = NULL;
void reset_app_context() { void reset_app_context() {
// PRINTF("!!RESET_APP_CONTEXT\n"); // PRINTF("!!RESET_APP_CONTEXT\n");
@@ -950,14 +951,19 @@ void init_coin_config(chain_config_t *coin_config) {
coin_config->kind = CHAIN_KIND; coin_config->kind = CHAIN_KIND;
} }
void coin_main(chain_config_t *coin_config) { void coin_main(libargs_t *args) {
chain_config_t config; chain_config_t config;
if (coin_config == NULL) { if (args) {
if (args->chain_config != NULL) {
chainConfig = args->chain_config;
}
plugin_name = args->plugin_name;
}
if (chainConfig == NULL) {
init_coin_config(&config); init_coin_config(&config);
chainConfig = &config; chainConfig = &config;
} else {
chainConfig = coin_config;
} }
reset_app_context(); reset_app_context();
tmpCtx.transactionContext.currentItemIndex = 0; tmpCtx.transactionContext.currentItemIndex = 0;
@@ -1031,18 +1037,7 @@ void coin_main(chain_config_t *coin_config) {
app_exit(); app_exit();
} }
struct libargs_s { static void library_main_helper(libargs_t *args) {
unsigned int id;
unsigned int command;
chain_config_t *chain_config;
union {
check_address_parameters_t *check_address;
create_transaction_parameters_t *create_transaction;
get_printable_amount_parameters_t *get_printable_amount;
};
};
static void library_main_helper(struct libargs_s *args) {
check_api_level(CX_COMPAT_APILEVEL); check_api_level(CX_COMPAT_APILEVEL);
PRINTF("Inside a library \n"); PRINTF("Inside a library \n");
switch (args->command) { switch (args->command) {
@@ -1070,7 +1065,7 @@ static void library_main_helper(struct libargs_s *args) {
} }
} }
void library_main(struct libargs_s *args) { void library_main(libargs_t *args) {
chain_config_t coin_config; chain_config_t coin_config;
if (args->chain_config == NULL) { if (args->chain_config == NULL) {
init_coin_config(&coin_config); init_coin_config(&coin_config);
@@ -1102,6 +1097,13 @@ __attribute__((section(".boot"))) int main(int arg0) {
unsigned int libcall_params[5]; unsigned int libcall_params[5];
chain_config_t local_chainConfig; chain_config_t local_chainConfig;
init_coin_config(&local_chainConfig); init_coin_config(&local_chainConfig);
#ifdef HAVE_NBGL
uint8_t coinIcon[sizeof(ICONBITMAP)];
memcpy(coinIcon, &ICONBITMAP, sizeof(ICONBITMAP));
memcpy(&local_chainConfig.coinIconDetails, &ICONGLYPH, sizeof(ICONGLYPH));
local_chainConfig.coinIconDetails.bitmap = coinIcon;
#endif // HAVE_NBGL
PRINTF("Hello from Eth-clone\n"); PRINTF("Hello from Eth-clone\n");
check_api_level(CX_COMPAT_APILEVEL); check_api_level(CX_COMPAT_APILEVEL);
// delegate to Ethereum app/lib // delegate to Ethereum app/lib
@@ -1110,6 +1112,7 @@ __attribute__((section(".boot"))) int main(int arg0) {
libcall_params[2] = RUN_APPLICATION; libcall_params[2] = RUN_APPLICATION;
libcall_params[3] = (unsigned int) &local_chainConfig; libcall_params[3] = (unsigned int) &local_chainConfig;
libcall_params[4] = 0; libcall_params[4] = 0;
if (arg0) { if (arg0) {
// call as a library // call as a library
libcall_params[2] = ((unsigned int *) arg0)[1]; libcall_params[2] = ((unsigned int *) arg0)[1];
@@ -1141,7 +1144,7 @@ __attribute__((section(".boot"))) int main(int arg0) {
return 0; return 0;
} }
struct libargs_s *args = (struct libargs_s *) arg0; libargs_t *args = (libargs_t *) arg0;
if (args->id != 0x100) { if (args->id != 0x100) {
app_exit(); app_exit();
return 0; return 0;
@@ -1149,7 +1152,7 @@ __attribute__((section(".boot"))) int main(int arg0) {
switch (args->command) { switch (args->command) {
case RUN_APPLICATION: case RUN_APPLICATION:
// called as ethereum from altcoin or plugin // called as ethereum from altcoin or plugin
coin_main(args->chain_config); coin_main(args);
break; break;
default: default:
// called as ethereum or altcoin library // called as ethereum or altcoin library

View File

@@ -229,6 +229,8 @@ extern bool quantumSet;
extern uint32_t eth2WithdrawalIndex; extern uint32_t eth2WithdrawalIndex;
#endif #endif
extern const char *plugin_name;
void reset_app_context(void); void reset_app_context(void);
const uint8_t *parseBip32(const uint8_t *dataBuffer, uint8_t *dataLength, bip32_path_t *bip32); const uint8_t *parseBip32(const uint8_t *dataBuffer, uint8_t *dataLength, bip32_path_t *bip32);

View File

@@ -2,6 +2,7 @@
#define _SWAP_LIB_CALLS_H_ #define _SWAP_LIB_CALLS_H_
#include "stdbool.h" #include "stdbool.h"
#include "chainConfig.h"
#define RUN_APPLICATION 1 #define RUN_APPLICATION 1
@@ -52,4 +53,16 @@ typedef struct create_transaction_parameters_s {
const char* const destination_address_extra_id; const char* const destination_address_extra_id;
} create_transaction_parameters_t; } create_transaction_parameters_t;
typedef struct libargs_s {
unsigned int id;
unsigned int command;
chain_config_t* chain_config;
union {
check_address_parameters_t* check_address;
create_transaction_parameters_t* create_transaction;
get_printable_amount_parameters_t* get_printable_amount;
char* plugin_name;
};
} libargs_t;
#endif // _SWAP_LIB_CALLS_H_ #endif // _SWAP_LIB_CALLS_H_

View File

@@ -135,4 +135,15 @@ const char *get_app_network_ticker(void) {
const char *get_tx_network_ticker(void) { const char *get_tx_network_ticker(void) {
return get_network_ticker(TX); return get_network_ticker(TX);
} }
#ifdef HAVE_NBGL
#include "glyphs.h"
const nbgl_icon_details_t *get_app_chain_icon(void) {
if (chainConfig->coinIconDetails.bitmap) {
return &chainConfig->coinIconDetails; // if called from a clone, the bitmap is correct
} else {
return &ICONGLYPH; // else, jsu return the ETH icon
}
}
#endif // HAVE_NBGL