1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +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)
{
if (!shortcut) return 0;
int i;
for (i = 0; i < COINS_COUNT; i++) {
if (strcmp(shortcut, coins[i].coin_shortcut) == 0) {
@ -41,6 +42,7 @@ const CoinType *coinByShortcut(const char *shortcut)
const CoinType *coinByName(const char *name)
{
if (!name) return 0;
int i;
for (i = 0; i < COINS_COUNT; i++) {
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);
}
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)
{
static HDNode node;
if (!storage_getRootNode(&node)) {
layoutHome();
fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized or passphrase request cancelled");
layoutHome();
return 0;
}
return &node;
@ -351,14 +362,10 @@ void fsm_msgSignTx(SignTx *msg)
return;
}
const CoinType *coin = fsm_getCoin(msg->coin_name);
if (!coin) return;
HDNode *node = fsm_getRootNode();
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);
}
@ -495,14 +502,10 @@ void fsm_msgGetAddress(GetAddress *msg)
{
RESP_INIT(Address);
const CoinType *coin = fsm_getCoin(msg->coin_name);
if (!coin) return;
HDNode *node = fsm_getRootNode();
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 (msg->has_multisig) {
@ -563,14 +566,10 @@ void fsm_msgSignMessage(SignMessage *msg)
return;
}
const CoinType *coin = fsm_getCoin(msg->coin_name);
if (!coin) return;
HDNode *node = fsm_getRootNode();
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;
layoutProgressSwipe("Signing", 0);