diff --git a/src/eth_plugin_handler.c b/src/eth_plugin_handler.c index ddeeabc..4343150 100644 --- a/src/eth_plugin_handler.c +++ b/src/eth_plugin_handler.c @@ -52,17 +52,17 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI, memset((uint8_t *) queryContractUI, 0, sizeof(ethQueryContractUI_t)); // If no extra information was found, set the pointer to NULL - if (NO_EXTRA_INFO(tmpCtx, 1)) { + if (NO_EXTRA_INFO(tmpCtx, 0)) { queryContractUI->item1 = NULL; } else { - queryContractUI->item1 = &tmpCtx.transactionContext.extraInfo[1]; + queryContractUI->item1 = &tmpCtx.transactionContext.extraInfo[0]; } // If no extra information was found, set the pointer to NULL - if (NO_EXTRA_INFO(tmpCtx, 0)) { + if (NO_EXTRA_INFO(tmpCtx, 1)) { queryContractUI->item2 = NULL; } else { - queryContractUI->item2 = &tmpCtx.transactionContext.extraInfo[0]; + queryContractUI->item2 = &tmpCtx.transactionContext.extraInfo[1]; } queryContractUI->screenIndex = screenIndex; diff --git a/src/eth_plugin_handler.h b/src/eth_plugin_handler.h index dab8ea4..1acaea0 100644 --- a/src/eth_plugin_handler.h +++ b/src/eth_plugin_handler.h @@ -6,7 +6,7 @@ #define NO_EXTRA_INFO(ctx, idx) \ (allzeroes(&(ctx.transactionContext.extraInfo[idx]), sizeof(extraInfo_t))) -#define NO_NFT_METADATA (NO_EXTRA_INFO(tmpCtx, 1)) +#define NO_NFT_METADATA (NO_EXTRA_INFO(tmpCtx, 0)) void eth_plugin_prepare_init(ethPluginInitContract_t *init, const uint8_t *selector, diff --git a/src/main.c b/src/main.c index c566b5d..f76cae8 100644 --- a/src/main.c +++ b/src/main.c @@ -533,7 +533,6 @@ __attribute__((noreturn)) void coin_main(libargs_t *args) { } reset_app_context(); - tmpCtx.transactionContext.currentItemIndex = 0; for (;;) { UX_INIT(); diff --git a/src/manage_asset_info.c b/src/manage_asset_info.c index bfaa589..6c915e2 100644 --- a/src/manage_asset_info.c +++ b/src/manage_asset_info.c @@ -2,6 +2,7 @@ void reset_known_tokens(void) { memset(tmpCtx.transactionContext.tokenSet, 0, MAX_ITEMS); + tmpCtx.transactionContext.currentItemIndex = 0; } static extraInfo_t *get_asset_info(uint8_t index) { diff --git a/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c b/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c index 94bf4e2..f9b3bf5 100644 --- a/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c +++ b/src_features/provideErc20TokenInformation/cmd_provideTokenInfo.c @@ -5,6 +5,7 @@ #include "os_io_seproxyhal.h" #include "extra_tokens.h" #include "network.h" +#include "manage_asset_info.h" #ifdef HAVE_CONTRACT_NAME_IN_DESCRIPTOR @@ -26,10 +27,7 @@ void handleProvideErc20TokenInformation(uint8_t p1, cx_sha256_init(&sha256); - tmpCtx.transactionContext.currentItemIndex = - (tmpCtx.transactionContext.currentItemIndex + 1) % MAX_ITEMS; - tokenDefinition_t *token = - &tmpCtx.transactionContext.tokens[tmpCtx.transactionContext.currentItemIndex]; + tokenDefinition_t *token = &get_current_asset_info()->token; if (dataLength < 1) { THROW(0x6A80); @@ -95,7 +93,7 @@ void handleProvideErc20TokenInformation(uint8_t p1, THROW(0x6A80); #endif } - tmpCtx.transactionContext.tokenSet[tmpCtx.transactionContext.currentItemIndex] = 1; + validate_current_asset_info(); THROW(0x9000); } @@ -117,10 +115,7 @@ void handleProvideErc20TokenInformation(uint8_t p1, uint8_t hash[INT256_LENGTH]; cx_ecfp_public_key_t tokenKey; - tmpCtx.transactionContext.currentItemIndex = - (tmpCtx.transactionContext.currentItemIndex + 1) % MAX_ITEMS; - tokenDefinition_t *token = - &tmpCtx.transactionContext.extraInfo[tmpCtx.transactionContext.currentItemIndex].token; + tokenDefinition_t *token = &get_current_asset_info()->token; PRINTF("Provisioning currentItemIndex %d\n", tmpCtx.transactionContext.currentItemIndex); @@ -183,7 +178,7 @@ void handleProvideErc20TokenInformation(uint8_t p1, } } - tmpCtx.transactionContext.tokenSet[tmpCtx.transactionContext.currentItemIndex] = 1; + validate_current_asset_info(); THROW(0x9000); } diff --git a/src_features/provideNFTInformation/cmd_provideNFTInfo.c b/src_features/provideNFTInformation/cmd_provideNFTInfo.c index 61889d6..147887c 100644 --- a/src_features/provideNFTInformation/cmd_provideNFTInfo.c +++ b/src_features/provideNFTInformation/cmd_provideNFTInfo.c @@ -8,6 +8,7 @@ #include "os_io_seproxyhal.h" #include "network.h" #include "public_keys.h" +#include "manage_asset_info.h" #define TYPE_SIZE 1 #define VERSION_SIZE 1 @@ -56,10 +57,7 @@ void handleProvideNFTInformation(uint8_t p1, PRINTF("NFT metadata provided without proper plugin loaded!\n"); THROW(0x6985); } - tmpCtx.transactionContext.currentItemIndex = - (tmpCtx.transactionContext.currentItemIndex + 1) % MAX_ITEMS; - nftInfo_t *nft = - &tmpCtx.transactionContext.extraInfo[tmpCtx.transactionContext.currentItemIndex].nft; + nftInfo_t *nft = &get_current_asset_info()->nft; PRINTF("Provisioning currentItemIndex %d\n", tmpCtx.transactionContext.currentItemIndex); @@ -201,7 +199,7 @@ void handleProvideNFTInformation(uint8_t p1, #endif } - tmpCtx.transactionContext.tokenSet[tmpCtx.transactionContext.currentItemIndex] = 1; + validate_current_asset_info(); THROW(0x9000); }