Skip to content

Commit

Permalink
Destination address now stored as u8 array
Browse files Browse the repository at this point in the history
  • Loading branch information
kingofpayne committed Nov 22, 2023
1 parent fca7177 commit 9e23213
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ledger_secure_sdk_sys = "1.0.0"
include_gif = "1.0.0"
serde = {version="1.0.192", default_features = false, features = ["derive"]}
serde-json-core = { git = "https://github.com/rust-embedded-community/serde-json-core"}

hex = { version = "0.4.3", default-features = false, features = ["serde"] }

[profile.release]
opt-level = 'z'
Expand Down
7 changes: 6 additions & 1 deletion src/app_ui/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ use ledger_device_ui_sdk::bitmaps::{CROSSMARK, EYE, VALIDATE_14};
use ledger_device_ui_sdk::ui::{Field, MultiFieldReview};

pub fn ui_display_tx(tx: &Tx) -> bool {
// Generate destination address string in hexadecimal format.
let mut to_str = [0u8; 42];
to_str[..2].copy_from_slice("0x".as_bytes());
hex::encode_to_slice(tx.to, &mut to_str[2..]).unwrap();

// Define transaction review fields
let my_fields = [
Field {
Expand All @@ -28,7 +33,7 @@ pub fn ui_display_tx(tx: &Tx) -> bool {
},
Field {
name: "Destination",
value: tx.to,
value: core::str::from_utf8(&to_str).unwrap(),
},
Field {
name: "Memo",
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/sign_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const MAX_TRANSACTION_LEN: usize = 510;
pub struct Tx<'a> {
nonce: u64,
pub value: &'a str,
pub to: &'a str,
#[serde(with = "hex::serde")]
pub to: [u8; 20],
pub memo: &'a str,
}

Expand Down
2 changes: 1 addition & 1 deletion tests/application_client/boilerplate_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self,
if not 0 <= self.nonce <= UINT64_MAX:
raise TransactionError(f"Bad nonce: '{self.nonce}'!")

if len(self.to) != 42:
if len(self.to) != 40:
raise TransactionError(f"Bad address: '{self.to}'!")

def serialize(self) -> bytes:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_sign_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_sign_tx_short_tx(firmware, backend, navigator, test_name):
transaction = Transaction(
nonce=1,
value=0.777,
to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
to="de0b295669a9fd93d5f28d9ec85e40f4cb697bae",
memo="For u EthDev"
).serialize()

Expand Down Expand Up @@ -70,7 +70,7 @@ def test_sign_tx_long_tx(firmware, backend, navigator, test_name):

transaction = Transaction(
nonce=1,
to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
to="de0b295669a9fd93d5f28d9ec85e40f4cb697bae",
value=666,
memo=("This is a very long memo. "
"It will force the app client to send the serialized transaction to be sent in chunk. "
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_sign_tx_refused(firmware, backend, navigator, test_name):

transaction = Transaction(
nonce=1,
to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
to="de0b295669a9fd93d5f28d9ec85e40f4cb697bae",
value=666,
memo="This transaction will be refused by the user"
).serialize()
Expand Down

0 comments on commit 9e23213

Please sign in to comment.