Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: changed chainID handling #3

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/app/src/tx_parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/tx_display.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/tx_validate.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/coin.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/tinykeccak/keccak-tiny.c
)

Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=4
# This is the patch version of this release
APPVERSION_P=1
APPVERSION_P=2
16 changes: 16 additions & 0 deletions app/src/coin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "coin.h"
#include <stdint.h>
#include <stddef.h>

#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];
}
7 changes: 5 additions & 2 deletions app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
extern "C" {
#endif

#include <stdint.h>
#define CLA 0x55u

#define HDPATH_LEN_DEFAULT 5
Expand Down Expand Up @@ -53,8 +54,6 @@ typedef enum {
#define APPVERSION_LINE1 "Version:"
#define APPVERSION_LINE2 ("v" APPVERSION)

#define COIN_DEFAULT_CHAINID "thorchain"

#define COIN_DEFAULT_DENOM_BASE "rune"
#define COIN_DEFAULT_DENOM_REPR "RUNE"
#define COIN_DEFAULT_DENOM_REPR_2 "THOR.RUNE"
Expand All @@ -80,6 +79,10 @@ typedef enum {
#define INS_SIGN_SECP256K1 0x02u
#define INS_GET_ADDR_SECP256K1 0x04u

#define SUPPORTED_CHAIN_COUNT 3

const char* get_supported_chain(uint8_t index);

#ifdef __cplusplus
}
#endif
22 changes: 14 additions & 8 deletions app/src/tx_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,25 @@ __Z_INLINE parser_error_t calculate_is_default_chainid() {
0, &pageCount))

zemu_log_stack(outVal);
zemu_log_stack(COIN_DEFAULT_CHAINID);

if (strcmp(outVal, COIN_DEFAULT_CHAINID) == 0) {
// If we don't match the default chainid, switch to expert mode
display_cache.is_default_chain = true;
zemu_log_stack("DEFAULT Chain ");
} else if ((outVal[0] == 0x30 || outVal[0] == 0x31) && strlen(outVal) == 1) {
// Check if chain ID matches any of the supported ones
for (uint8_t i = 0; i < SUPPORTED_CHAIN_COUNT; i++) {
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;
}
}
if ((outVal[0] == 0x30 || outVal[0] == 0x31) && strlen(outVal) == 1) {
zemu_log_stack("Not Allowed chain");
return parser_unexpected_chain;
} else {
zemu_log_stack("Chain is NOT DEFAULT");
}

zemu_log_stack("Chain is NOT supported");
return parser_ok;
}

Expand Down
Loading