From 6bf5576f49a2be3c698205c40fbf25891ca84053 Mon Sep 17 00:00:00 2001 From: Z4karia Date: Wed, 8 Jan 2025 19:46:23 +0100 Subject: [PATCH] fix chainID handling --- app/src/coin.c | 16 ++++++++++++++++ app/src/coin.h | 8 +++----- app/src/tx_display.c | 6 +++++- 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 app/src/coin.c diff --git a/app/src/coin.c b/app/src/coin.c new file mode 100644 index 0000000..1144def --- /dev/null +++ b/app/src/coin.c @@ -0,0 +1,16 @@ +#include "coin.h" +#include +#include + +#define MAX_CHAIN_ID_LEN 20 + +static const char SUPPORTED_CHAIN_IDS[SUPPORTED_CHAIN_COUNT][MAX_CHAIN_ID_LEN] = { + "thorchain", + "thorchain-1", + "thorchain-stagenet-2" +}; + +const char* get_supported_chain(uint8_t index) { + if (index >= SUPPORTED_CHAIN_COUNT) return NULL; + return SUPPORTED_CHAIN_IDS[index]; +} diff --git a/app/src/coin.h b/app/src/coin.h index 550817f..142b684 100644 --- a/app/src/coin.h +++ b/app/src/coin.h @@ -19,6 +19,7 @@ extern "C" { #endif +#include #define CLA 0x55u #define HDPATH_LEN_DEFAULT 5 @@ -79,11 +80,8 @@ typedef enum { #define INS_GET_ADDR_SECP256K1 0x04u #define SUPPORTED_CHAIN_COUNT 3 -static const char* const SUPPORTED_CHAIN_IDS[SUPPORTED_CHAIN_COUNT] = { - "thorchain", - "thorchain-1", - "thorchain-stagenet-2" -}; + +const char* get_supported_chain(uint8_t index); #ifdef __cplusplus } diff --git a/app/src/tx_display.c b/app/src/tx_display.c index 2c2c150..f258a00 100644 --- a/app/src/tx_display.c +++ b/app/src/tx_display.c @@ -126,7 +126,11 @@ __Z_INLINE parser_error_t calculate_is_default_chainid() { // Check if chain ID matches any of the supported ones for (uint8_t i = 0; i < SUPPORTED_CHAIN_COUNT; i++) { - if (strcmp(outVal, SUPPORTED_CHAIN_IDS[i]) == 0) { + const char* supported_chain = get_supported_chain(i); + if (supported_chain == NULL) { + return parser_unexpected_value; + } + if (strcmp(outVal, supported_chain) == 0) { display_cache.is_default_chain = true; zemu_log_stack("Supported Chain"); return parser_ok;