1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-15 11:08:08 +00:00

extract fsm_getCoin

This commit is contained in:
Pavol Rusnak 2015-01-26 12:51:56 +01:00
parent 0981ed98b6
commit 8f48ffe63c
2 changed files with 20 additions and 19 deletions

View File

@ -30,6 +30,7 @@ const CoinType coins[COINS_COUNT] = {
const CoinType *coinByShortcut(const char *shortcut) const CoinType *coinByShortcut(const char *shortcut)
{ {
if (!shortcut) return 0;
int i; int i;
for (i = 0; i < COINS_COUNT; i++) { for (i = 0; i < COINS_COUNT; i++) {
if (strcmp(shortcut, coins[i].coin_shortcut) == 0) { if (strcmp(shortcut, coins[i].coin_shortcut) == 0) {
@ -41,6 +42,7 @@ const CoinType *coinByShortcut(const char *shortcut)
const CoinType *coinByName(const char *name) const CoinType *coinByName(const char *name)
{ {
if (!name) return 0;
int i; int i;
for (i = 0; i < COINS_COUNT; i++) { for (i = 0; i < COINS_COUNT; i++) {
if (strcmp(name, coins[i].coin_name) == 0) { if (strcmp(name, coins[i].coin_name) == 0) {

View File

@ -78,12 +78,23 @@ void fsm_sendFailure(FailureType code, const char *text)
msg_write(MessageType_MessageType_Failure, resp); msg_write(MessageType_MessageType_Failure, resp);
} }
const CoinType *fsm_getCoin(const char *name)
{
const CoinType *coin = coinByName(name);
if (!coin) {
fsm_sendFailure(FailureType_Failure_Other, "Invalid coin name");
layoutHome();
return 0;
}
return coin;
}
HDNode *fsm_getRootNode(void) HDNode *fsm_getRootNode(void)
{ {
static HDNode node; static HDNode node;
if (!storage_getRootNode(&node)) { if (!storage_getRootNode(&node)) {
layoutHome();
fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized or passphrase request cancelled"); fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized or passphrase request cancelled");
layoutHome();
return 0; return 0;
} }
return &node; return &node;
@ -351,14 +362,10 @@ void fsm_msgSignTx(SignTx *msg)
return; return;
} }
const CoinType *coin = fsm_getCoin(msg->coin_name);
if (!coin) return;
HDNode *node = fsm_getRootNode(); HDNode *node = fsm_getRootNode();
if (!node) return; if (!node) return;
const CoinType *coin = coinByName(msg->coin_name);
if (!coin) {
fsm_sendFailure(FailureType_Failure_Other, "Invalid coin name");
layoutHome();
return;
}
signing_init(msg->inputs_count, msg->outputs_count, coin, node); signing_init(msg->inputs_count, msg->outputs_count, coin, node);
} }
@ -495,14 +502,10 @@ void fsm_msgGetAddress(GetAddress *msg)
{ {
RESP_INIT(Address); RESP_INIT(Address);
const CoinType *coin = fsm_getCoin(msg->coin_name);
if (!coin) return;
HDNode *node = fsm_getRootNode(); HDNode *node = fsm_getRootNode();
if (!node) return; if (!node) return;
const CoinType *coin = coinByName(msg->coin_name);
if (!coin) {
fsm_sendFailure(FailureType_Failure_Other, "Invalid coin name");
layoutHome();
return;
}
if (fsm_deriveKey(node, msg->address_n, msg->address_n_count) == 0) return; if (fsm_deriveKey(node, msg->address_n, msg->address_n_count) == 0) return;
if (msg->has_multisig) { if (msg->has_multisig) {
@ -563,14 +566,10 @@ void fsm_msgSignMessage(SignMessage *msg)
return; return;
} }
const CoinType *coin = fsm_getCoin(msg->coin_name);
if (!coin) return;
HDNode *node = fsm_getRootNode(); HDNode *node = fsm_getRootNode();
if (!node) return; if (!node) return;
const CoinType *coin = coinByName(msg->coin_name);
if (!coin) {
fsm_sendFailure(FailureType_Failure_Other, "Invalid coin name");
layoutHome();
return;
}
if (fsm_deriveKey(node, msg->address_n, msg->address_n_count) == 0) return; if (fsm_deriveKey(node, msg->address_n, msg->address_n_count) == 0) return;
layoutProgressSwipe("Signing", 0); layoutProgressSwipe("Signing", 0);