Skip to content

Commit c6cbaff

Browse files
committed
eth: put network name 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 eb80872 commit c6cbaff

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/apps/eth/eth_params.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@
2121
static const app_eth_coin_params_t _params_eth = {
2222
.bip44_coin = 60 + BIP32_INITIAL_HARDENED_CHILD,
2323
.chain_id = 1,
24+
.name = "Ethereum",
2425
.unit = "ETH",
2526
};
2627

2728
static const app_eth_coin_params_t _params_ropsten_eth = {
2829
.bip44_coin = 1 + BIP32_INITIAL_HARDENED_CHILD,
2930
.chain_id = 3,
31+
.name = "Ropsten",
3032
.unit = "TETH",
3133
};
3234

3335
static const app_eth_coin_params_t _params_rinkeby_eth = {
3436
.bip44_coin = 1 + BIP32_INITIAL_HARDENED_CHILD,
3537
.chain_id = 4,
38+
.name = "Rinkeby",
3639
.unit = "TETH",
3740
};
3841

src/apps/eth/eth_params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef struct {
2121
uint32_t bip44_coin;
2222
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md#list-of-chain-ids
2323
uint8_t chain_id;
24+
const char* name;
2425
const char* unit;
2526
} app_eth_coin_params_t;
2627

src/rust/bitbox02-rust/src/hww/api/ethereum/pubrequest.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,7 @@ use bitbox02::keystore;
2424
extern crate alloc;
2525
use core::convert::TryInto;
2626

27-
fn coin_title(coin: pb::EthCoin) -> &'static str {
28-
match coin {
29-
pb::EthCoin::Eth => "Ethereum",
30-
pb::EthCoin::RopstenEth => "Ropsten",
31-
pb::EthCoin::RinkebyEth => "Rinkeby",
32-
}
33-
}
34-
3527
async fn process_address(request: &pb::EthPubRequest) -> Result<Response, Error> {
36-
let coin = pb::EthCoin::from_i32(request.coin).ok_or(Error::InvalidInput)?;
3728
let params = bitbox02::app_eth::params_get(request.coin as _).ok_or(Error::InvalidInput)?;
3829
// If a contract_address is provided, it has to be a supported ERC20-token.
3930
let erc20_params: Option<bitbox02::app_eth::ERC20Params> =
@@ -61,7 +52,7 @@ async fn process_address(request: &pb::EthPubRequest) -> Result<Response, Error>
6152
if request.display {
6253
let title = match erc20_params {
6354
Some(erc20_params) => erc20_params.name,
64-
None => coin_title(coin),
55+
None => params.name,
6556
};
6657
let params = confirm::Params {
6758
title,

src/rust/bitbox02/src/app_eth.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use bitbox02_sys::in_buffer_t;
1717
pub struct Params {
1818
pub bip44_coin: u32,
1919
pub chain_id: u8,
20+
pub name: &'static str,
2021
pub unit: &'static str,
2122
}
2223

@@ -25,6 +26,13 @@ pub fn params_get(coin: bitbox02_sys::ETHCoin) -> Option<Params> {
2526
Some(Params {
2627
bip44_coin: params.bip44_coin,
2728
chain_id: params.chain_id,
29+
name: {
30+
let s = unsafe {
31+
let len = crate::util::strlen_ptr(params.name);
32+
core::slice::from_raw_parts(params.name, len as _)
33+
};
34+
core::str::from_utf8(s).unwrap()
35+
},
2836
unit: {
2937
let s = unsafe {
3038
let len = crate::util::strlen_ptr(params.unit);

0 commit comments

Comments
 (0)