mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-27 08:38:07 +00:00
extract fsm_getCoin
This commit is contained in:
parent
0981ed98b6
commit
8f48ffe63c
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user