Skip to content

Commit 81daa8e

Browse files
committed
eth: move erc20_params into new crate
The plan is to auto-generate the Rust list of tokens from a txt/json file in build.rs, so it's cleaner to have that separated out into its own crate.
1 parent 94de92a commit 81daa8e

File tree

9 files changed

+35
-6
lines changed

9 files changed

+35
-6
lines changed

src/rust/Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ members = [
2121
"bitbox02-noise",
2222
"bitbox02",
2323
"bitbox02-sys",
24+
"erc20_params",
2425
]
2526

2627
resolver = "2"

src/rust/bitbox02-rust/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ doctest = false
2828

2929
[dependencies]
3030
bitbox02 = {path = "../bitbox02"}
31-
util = {path = "../util"}
31+
util = { path = "../util" }
32+
erc20_params = { path = "../erc20_params", optional = true }
3233
binascii = { version = "0.1.4", default-features = false, features = ["encode"] }
3334
bitbox02-noise = {path = "../bitbox02-noise"}
3435
hex = { workspace = true }
@@ -70,6 +71,7 @@ ed25519 = [
7071

7172
app-ethereum = [
7273
# enable these dependencies
74+
"erc20_params",
7375
"sha3",
7476
"num-bigint",
7577
"num-traits",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ compile_error!(
1919

2020
mod address;
2121
mod amount;
22-
mod erc20_params;
2322
mod keypath;
2423
mod params;
2524
mod pubrequest;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ async fn process_address(request: &pb::EthPubRequest) -> Result<Response, Error>
2727

2828
let params = super::params::get_and_warn_unknown(Some(coin), request.chain_id).await?;
2929
// If a contract_address is provided, it has to be a supported ERC20-token.
30-
let erc20_params: Option<super::erc20_params::Params> = if request.contract_address.is_empty() {
30+
let erc20_params: Option<erc20_params::Params> = if request.contract_address.is_empty() {
3131
None
3232
} else {
3333
let address: [u8; 20] = request
3434
.contract_address
3535
.as_slice()
3636
.try_into()
3737
.or(Err(Error::InvalidInput))?;
38-
Some(super::erc20_params::get(params.chain_id, address).ok_or(Error::InvalidInput)?)
38+
Some(erc20_params::get(params.chain_id, address).ok_or(Error::InvalidInput)?)
3939
};
4040

4141
if !super::keypath::is_valid_keypath_address(&request.keypath) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ async fn verify_erc20_transaction(
201201
erc20_recipient: [u8; 20],
202202
erc20_value: BigUint,
203203
) -> Result<(), Error> {
204-
let erc20_params =
205-
super::erc20_params::get(params.chain_id, parse_recipient(request.recipient())?);
204+
let erc20_params = erc20_params::get(params.chain_id, parse_recipient(request.recipient())?);
206205
let formatted_fee = parse_fee(request, params).format();
207206
let recipient_address = super::address::from_pubkey_hash(&erc20_recipient);
208207
let (formatted_value, formatted_total) = match erc20_params {

src/rust/erc20_params/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

src/rust/erc20_params/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2024 Shift Cryptos AG
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
[package]
16+
name = "erc20_params"
17+
version = "0.1.0"
18+
authors = ["Shift Crypto AG <[email protected]>"]
19+
edition = "2021"
20+
license = "Apache-2.0"

src/rust/bitbox02-rust/src/hww/api/ethereum/erc20_params.rs renamed to src/rust/erc20_params/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#![no_std]
16+
1517
#[repr(packed)]
1618
struct P {
1719
pub unit: *const u8,

0 commit comments

Comments
 (0)