Skip to content

Commit 5f2876b

Browse files
committed
btc: put network name and coin into params
Put it into the params like the rest of the params - no need to have special mapping functions just for the name.
1 parent c6cbaff commit 5f2876b

File tree

13 files changed

+42
-65
lines changed

13 files changed

+42
-65
lines changed

src/apps/btc/btc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ app_btc_result_t app_btc_address_multisig(
9090

9191
const char* title = "Receive to";
9292

93-
if (!apps_btc_confirm_multisig_basic(title, coin, multisig_registered_name, multisig)) {
93+
if (!apps_btc_confirm_multisig_basic(title, params, multisig_registered_name, multisig)) {
9494
return APP_BTC_ERR_USER_ABORT;
9595
}
9696

@@ -209,7 +209,7 @@ app_btc_result_t app_btc_register_script_config(
209209
}
210210

211211
if (!apps_btc_confirm_multisig_extended(
212-
"Register", coin, name, multisig, xpub_type, keypath, keypath_len)) {
212+
"Register", params, name, multisig, xpub_type, keypath, keypath_len)) {
213213
return APP_BTC_ERR_USER_ABORT;
214214
}
215215

src/apps/btc/btc_common.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,6 @@
2727

2828
#define MULTISIG_P2WSH_MAX_SIGNERS 15
2929

30-
const char* btc_common_coin_name(BTCCoin coin)
31-
{
32-
static const char* _coin_btc = "Bitcoin";
33-
static const char* _coin_tbtc = "BTC Testnet";
34-
static const char* _coin_ltc = "Litecoin";
35-
static const char* _coin_tltc = "LTC Testnet";
36-
37-
switch (coin) {
38-
case BTCCoin_BTC:
39-
return _coin_btc;
40-
case BTCCoin_TBTC:
41-
return _coin_tbtc;
42-
case BTCCoin_LTC:
43-
return _coin_ltc;
44-
case BTCCoin_TLTC:
45-
return _coin_tltc;
46-
default:
47-
Abort("btc_common_coin_name");
48-
}
49-
}
50-
5130
bool btc_common_is_valid_keypath_account_simple(
5231
BTCScriptConfig_SimpleType script_type,
5332
const uint32_t* keypath,

src/apps/btc/btc_common.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
// is technically possible to extend to if needed.
3737
#define MAX_PK_SCRIPT_SIZE (700)
3838

39-
/**
40-
* Returns the coin name to be used in confirm dialogs ("Bitcoin", "Litecoin", etc.). Aborts for an
41-
* invalid coin.
42-
*/
43-
USE_RESULT const char* btc_common_coin_name(BTCCoin coin);
44-
4539
/**
4640
* Does limit checks the keypath, whitelisting bip44 purposes and accounts.
4741
* @return true if the keypath is valid, false if it is invalid.

src/apps/btc/btc_params.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,45 @@
1818
// Keep these in sync with hww/api/bitcoin/params.rs
1919

2020
static const app_btc_coin_params_t _params_btc = {
21+
.coin = BTCCoin_BTC,
2122
.bip44_coin = 0 + BIP32_INITIAL_HARDENED_CHILD,
2223
.base58_version_p2pkh = 0x00, // starts with 1
2324
.base58_version_p2sh = 0x05, // starts with 3
2425
.bech32_hrp = "bc",
26+
.name = "Bitcoin",
2527
.unit = "BTC",
2628
.rbf_support = true,
2729
};
2830

2931
static const app_btc_coin_params_t _params_tbtc = {
32+
.coin = BTCCoin_TBTC,
3033
.bip44_coin = 1 + BIP32_INITIAL_HARDENED_CHILD,
3134
.base58_version_p2pkh = 0x6f, // starts with m or n
3235
.base58_version_p2sh = 0xc4, // starts with 2
3336
.bech32_hrp = "tb",
37+
.name = "BTC Testnet",
3438
.unit = "TBTC",
3539
.rbf_support = true,
3640
};
3741

3842
static const app_btc_coin_params_t _params_ltc = {
43+
.coin = BTCCoin_LTC,
3944
.bip44_coin = 2 + BIP32_INITIAL_HARDENED_CHILD,
4045
.base58_version_p2pkh = 0x30, // starts with L
4146
.base58_version_p2sh = 0x32, // starts with M
4247
.bech32_hrp = "ltc",
48+
.name = "Litecoin",
4349
.unit = "LTC",
4450
.rbf_support = false,
4551
};
4652

4753
static const app_btc_coin_params_t _params_tltc = {
54+
.coin = BTCCoin_TLTC,
4855
.bip44_coin = 1 + BIP32_INITIAL_HARDENED_CHILD,
4956
.base58_version_p2pkh = 0x6f, // starts with m or n
5057
.base58_version_p2sh = 0xc4, // starts with 2
5158
.bech32_hrp = "tltc",
59+
.name = "LTC testnet",
5260
.unit = "TLTC",
5361
.rbf_support = false,
5462
};

src/apps/btc/btc_params.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#include <hww.pb.h>
1919

2020
typedef struct {
21+
BTCCoin coin;
2122
uint32_t bip44_coin;
2223
uint8_t base58_version_p2pkh;
2324
uint8_t base58_version_p2sh;
2425
const char* bech32_hrp;
26+
const char* name;
2527
// unit to use in formatted amounts, e.g. "BTC".
2628
const char* unit;
2729
bool rbf_support;

src/apps/btc/btc_sign_validate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ app_btc_result_t app_btc_sign_validate_init_script_configs(
6262
return APP_BTC_ERR_INVALID_INPUT;
6363
}
6464
if (!apps_btc_confirm_multisig_basic(
65-
"Spend from", coin, multisig_registered_name, multisig)) {
65+
"Spend from", coin_params, multisig_registered_name, multisig)) {
6666
return APP_BTC_ERR_USER_ABORT;
6767
}
6868
return APP_BTC_OK;

src/apps/btc/confirm_multisig.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
bool apps_btc_confirm_multisig_basic(
2727
const char* title,
28-
BTCCoin coin,
28+
const app_btc_coin_params_t* params,
2929
const char* name,
3030
const BTCScriptConfig_Multisig* multisig)
3131
{
@@ -36,7 +36,7 @@ bool apps_btc_confirm_multisig_basic(
3636
"%lu-of-%lu\n%s multisig",
3737
(unsigned long)multisig->threshold,
3838
(unsigned long)multisig->xpubs_count,
39-
btc_common_coin_name(coin));
39+
params->name);
4040
if (snprintf_result < 0 || snprintf_result >= (int)sizeof(basic_info)) {
4141
Abort("apps_btc_confirm_multisig/0");
4242
}
@@ -60,7 +60,7 @@ bool apps_btc_confirm_multisig_basic(
6060

6161
bool apps_btc_confirm_multisig_extended(
6262
const char* title,
63-
BTCCoin coin,
63+
const app_btc_coin_params_t* params,
6464
const char* name,
6565
const BTCScriptConfig_Multisig* multisig,
6666
BTCRegisterScriptConfigRequest_XPubType xpub_type,
@@ -82,7 +82,7 @@ bool apps_btc_confirm_multisig_extended(
8282
rust_bip32_to_string(
8383
keypath, keypath_len, rust_util_cstr_mut(keypath_string, sizeof(keypath_string)));
8484

85-
if (!apps_btc_confirm_multisig_basic(title, coin, name, multisig)) {
85+
if (!apps_btc_confirm_multisig_basic(title, params, name, multisig)) {
8686
return false;
8787
}
8888

@@ -92,19 +92,19 @@ bool apps_btc_confirm_multisig_extended(
9292
if (snprintf_result < 0 || snprintf_result >= (int)sizeof(info)) {
9393
Abort("apps_btc_confirm_multisig/0");
9494
}
95-
const confirm_params_t params = {
95+
const confirm_params_t confirm_params = {
9696
.title = title,
9797
.body = info,
9898
.accept_is_nextarrow = true,
9999
};
100-
if (!workflow_confirm_blocking(&params)) {
100+
if (!workflow_confirm_blocking(&confirm_params)) {
101101
return false;
102102
}
103103

104104
xpub_type_t output_xpub_type;
105105
switch (xpub_type) {
106106
case BTCRegisterScriptConfigRequest_XPubType_AUTO_ELECTRUM:
107-
switch (coin) {
107+
switch (params->coin) {
108108
case BTCCoin_BTC:
109109
case BTCCoin_LTC:
110110
switch (multisig->script_type) {
@@ -136,7 +136,7 @@ bool apps_btc_confirm_multisig_extended(
136136
}
137137
break;
138138
case BTCRegisterScriptConfigRequest_XPubType_AUTO_XPUB_TPUB:
139-
switch (coin) {
139+
switch (params->coin) {
140140
case BTCCoin_BTC:
141141
case BTCCoin_LTC:
142142
output_xpub_type = XPUB;

src/apps/btc/confirm_multisig.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#ifndef _APPS_BTC_CONFIRM_MULTISIG_H_
1616
#define _APPS_BTC_CONFIRM_MULTISIG_H_
1717

18+
#include "btc_params.h"
19+
1820
#include <btc.pb.h>
1921
#include <compiler_util.h>
2022
#include <stdbool.h>
@@ -26,13 +28,13 @@
2628
* - multisig type (m-of-n)
2729
* - name given by the user
2830
* @param[in] title the title shown in each confirmation screen
29-
* @param[in] coin coin to be confirmed
31+
* @param[in] params Coin params of the coin to be confirmed.
3032
* @param[in] name User given name of the multisig account.
3133
* @param[in] multisig multisig details
3234
*/
3335
USE_RESULT bool apps_btc_confirm_multisig_basic(
3436
const char* title,
35-
BTCCoin coin,
37+
const app_btc_coin_params_t* params,
3638
const char* name,
3739
const BTCScriptConfig_Multisig* multisig);
3840

@@ -46,7 +48,7 @@ USE_RESULT bool apps_btc_confirm_multisig_basic(
4648
* - account keypath
4749
* - all xpubs (formatted according to `xpub_type`).
4850
* @param[in] title the title shown in each confirmation screen
49-
* @param[in] coin coin to be confirmed
51+
* @param[in] params Coin params of the coin to be confirmed.
5052
* @param[in] name User given name of the multisig account.
5153
* @param[in] multisig multisig details
5254
* @param[in] xpub_type: if AUTO_ELECTRUM, will automatically format xpubs as `Zpub/Vpub`,
@@ -56,7 +58,7 @@ USE_RESULT bool apps_btc_confirm_multisig_basic(
5658
*/
5759
USE_RESULT bool apps_btc_confirm_multisig_extended(
5860
const char* title,
59-
BTCCoin coin,
61+
const app_btc_coin_params_t* params,
6062
const char* name,
6163
const BTCScriptConfig_Multisig* multisig,
6264
BTCRegisterScriptConfigRequest_XPubType xpub_type,

src/rust/bitbox02-rust/src/hww/api/bitcoin.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,6 @@ fn coin_enabled(coin: pb::BtcCoin) -> Result<(), Error> {
8888
Err(Error::Disabled)
8989
}
9090

91-
pub fn coin_name(coin: pb::BtcCoin) -> &'static str {
92-
use pb::BtcCoin::*;
93-
match coin {
94-
Btc => "Bitcoin",
95-
Tbtc => "BTC Testnet",
96-
Ltc => "Litecoin",
97-
Tltc => "LTC Testnet",
98-
}
99-
}
100-
10191
/// Processes an xpub api call.
10292
async fn xpub(
10393
coin: BtcCoin,
@@ -121,11 +111,7 @@ async fn xpub(
121111
};
122112
let xpub = encode_xpub_at_keypath(keypath, xpub_type).or(Err(Error::InvalidInput))?;
123113
if display {
124-
let title = format!(
125-
"{}\naccount #{}",
126-
coin_name(coin),
127-
keypath[2] - HARDENED + 1,
128-
);
114+
let title = format!("{}\naccount #{}", params.name, keypath[2] - HARDENED + 1,);
129115
let confirm_params = confirm::Params {
130116
title: &title,
131117
body: &xpub,
@@ -147,7 +133,7 @@ async fn address_simple(
147133
let address = bitbox02::app_btc::address_simple(coin as _, simple_type as _, keypath)?;
148134
if display {
149135
let confirm_params = confirm::Params {
150-
title: coin_name(coin),
136+
title: params::get(coin).name,
151137
body: &address,
152138
scrollable: true,
153139
..Default::default()

src/rust/bitbox02-rust/src/hww/api/bitcoin/params.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct Params {
2525
pub base58_version_p2pkh: u8,
2626
pub base58_version_p2sh: u8,
2727
pub bech32_hrp: &'static str,
28+
pub name: &'static str,
2829
pub unit: &'static str,
2930
pub rbf_support: bool,
3031
}
@@ -36,6 +37,7 @@ const PARAMS_BTC: Params = Params {
3637
base58_version_p2pkh: 0x00, // starts with 1
3738
base58_version_p2sh: 0x05, // starts with 3
3839
bech32_hrp: "bc",
40+
name: "Bitcoin",
3941
unit: "BTC",
4042
rbf_support: true,
4143
};
@@ -45,6 +47,7 @@ const PARAMS_TBTC: Params = Params {
4547
base58_version_p2pkh: 0x6f, // starts with m or n
4648
base58_version_p2sh: 0xc4, // starts with 2
4749
bech32_hrp: "tb",
50+
name: "BTC Testnet",
4851
unit: "TBTC",
4952
rbf_support: true,
5053
};
@@ -54,6 +57,7 @@ const PARAMS_LTC: Params = Params {
5457
base58_version_p2pkh: 0x30, // starts with L
5558
base58_version_p2sh: 0x32, // starts with M
5659
bech32_hrp: "ltc",
60+
name: "Litecoin",
5761
unit: "LTC",
5862
rbf_support: false,
5963
};
@@ -63,6 +67,7 @@ const PARAMS_TLTC: Params = Params {
6367
base58_version_p2pkh: 0x6f, // starts with m or n
6468
base58_version_p2sh: 0xc4, // starts with 2
6569
bech32_hrp: "tltc",
70+
name: "LTC Testnet",
6671
unit: "TLTC",
6772
rbf_support: false,
6873
};

0 commit comments

Comments
 (0)