From cc0896c33451d308a51c2fefe2e8939c8a93fb94 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 16 Nov 2017 18:34:50 +0100 Subject: [PATCH] add bip44 coin_type to CoinInfo --- firmware/coins-gen.py | 3 ++- firmware/coins.c | 10 ++++++++++ firmware/coins.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/firmware/coins-gen.py b/firmware/coins-gen.py index 75bbe63522..0cf4bbc987 100755 --- a/firmware/coins-gen.py +++ b/firmware/coins-gen.py @@ -27,7 +27,8 @@ def get_fields(coin): '0x%s' % coin['xpub_magic'] if coin['xpub_magic'] is not None else '0x00000000', '0x%s' % coin['xprv_magic'] if coin['xprv_magic'] is not None else '0x00000000', '%d' % coin['forkid'] if coin['forkid'] else '0', - '"%s"' % coin['bech32_prefix'] if coin.get('bech32_prefix') is not None else 'NULL' + '"%s"' % coin['bech32_prefix'] if coin.get('bech32_prefix') is not None else 'NULL', + '0x%08x' % (0x80000000 + coin['bip44']), ] diff --git a/firmware/coins.c b/firmware/coins.c index 3af074b535..1d62abca98 100644 --- a/firmware/coins.c +++ b/firmware/coins.c @@ -49,6 +49,16 @@ const CoinInfo *coinByAddressType(uint32_t address_type) return 0; } +const CoinInfo *coinByCoinType(uint32_t coin_type) +{ + for (int i = 0; i < COINS_COUNT; i++) { + if (coin_type == coins[i].coin_type) { + return &(coins[i]); + } + } + return 0; +} + bool coinExtractAddressType(const CoinInfo *coin, const char *addr, uint32_t *address_type) { if (!addr) return false; diff --git a/firmware/coins.h b/firmware/coins.h index 953520d5b8..bf9cd2e09d 100644 --- a/firmware/coins.h +++ b/firmware/coins.h @@ -42,12 +42,14 @@ typedef struct _CoinInfo { uint32_t xprv_magic; uint32_t forkid; const char *bech32_prefix; + uint32_t coin_type; } CoinInfo; extern const CoinInfo coins[COINS_COUNT]; const CoinInfo *coinByName(const char *name); const CoinInfo *coinByAddressType(uint32_t address_type); +const CoinInfo *coinByCoinType(uint32_t coin_type); bool coinExtractAddressType(const CoinInfo *coin, const char *addr, uint32_t *address_type); bool coinExtractAddressTypeRaw(const CoinInfo *coin, const uint8_t *addr_raw, uint32_t *address_type);