mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-03 03:11:17 +00:00
38fa9197ca
Initial EIP1559 implementation Fix a few small issues Progress on Python lib implementation and firmware Fix RLP length Start fixing tests Fix legacy transactions Simplify API and logic Add EIP1559 tests Fix access list formatting Fix UI visiblity issue Fix commented out code fix: correct linting issues Fix access_list protobuf formatting Remove unneeded code Remove dead code Check tx_type bounds for EIP 2718 Reduce code duplication Prefer eip2718_type over re-using tx_type Add more tests Simplify format_access_list Simplify sign_tx slightly Change Access List format and add logic to encode it Fix a bunch of small PR comments Fix a linting issue Move tests out of class and regenerate Remove copy-pasted comments Add access list to CLI Simplify _parse_access_list_item Fix small mistakes following rebase Fix linting Refactor to use a separate message for EIP 1559 tx Simplify changed legacy code Fix a few small PR comments Fix linting fix(legacy): recognize SignTxEIP1559 on legacy build Fix PR comments
108 lines
3.0 KiB
Python
108 lines
3.0 KiB
Python
from ubinascii import hexlify
|
|
|
|
from trezor import ui
|
|
from trezor.enums import ButtonRequestType
|
|
from trezor.strings import format_amount
|
|
from trezor.ui.layouts import (
|
|
confirm_address,
|
|
confirm_amount,
|
|
confirm_blob,
|
|
confirm_output,
|
|
)
|
|
from trezor.ui.layouts.tt.altcoin import confirm_total_ethereum
|
|
|
|
from . import networks, tokens
|
|
from .address import address_from_bytes
|
|
|
|
|
|
async def require_confirm_tx(ctx, to_bytes, value, chain_id, token=None, tx_type=None):
|
|
if to_bytes:
|
|
to_str = address_from_bytes(to_bytes, networks.by_chain_id(chain_id))
|
|
else:
|
|
to_str = "new contract?"
|
|
await confirm_output(
|
|
ctx,
|
|
address=to_str,
|
|
amount=format_ethereum_amount(value, token, chain_id, tx_type),
|
|
font_amount=ui.BOLD,
|
|
color_to=ui.GREY,
|
|
br_code=ButtonRequestType.SignTx,
|
|
)
|
|
|
|
|
|
async def require_confirm_fee(
|
|
ctx, spending, gas_price, gas_limit, chain_id, token=None, tx_type=None
|
|
):
|
|
await confirm_total_ethereum(
|
|
ctx,
|
|
format_ethereum_amount(spending, token, chain_id, tx_type),
|
|
format_ethereum_amount(gas_price, None, chain_id, tx_type),
|
|
format_ethereum_amount(gas_price * gas_limit, None, chain_id, tx_type),
|
|
)
|
|
|
|
|
|
async def require_confirm_eip1559_fee(
|
|
ctx, max_priority_fee, max_gas_fee, gas_limit, chain_id
|
|
):
|
|
await confirm_amount(
|
|
ctx,
|
|
title="Confirm fee",
|
|
description="Maximum fee per gas",
|
|
amount=format_ethereum_amount(max_gas_fee, None, chain_id),
|
|
)
|
|
await confirm_amount(
|
|
ctx,
|
|
title="Confirm fee",
|
|
description="Priority fee per gas",
|
|
amount=format_ethereum_amount(max_priority_fee, None, chain_id),
|
|
)
|
|
await confirm_amount(
|
|
ctx,
|
|
title="Confirm fee",
|
|
description="Maximum fee",
|
|
amount=format_ethereum_amount(max_gas_fee * gas_limit, None, chain_id),
|
|
)
|
|
|
|
|
|
async def require_confirm_unknown_token(ctx, address_bytes):
|
|
contract_address_hex = "0x" + hexlify(address_bytes).decode()
|
|
await confirm_address(
|
|
ctx,
|
|
"Unknown token",
|
|
contract_address_hex,
|
|
description="Contract:",
|
|
br_type="unknown_token",
|
|
icon_color=ui.ORANGE,
|
|
br_code=ButtonRequestType.SignTx,
|
|
)
|
|
|
|
|
|
async def require_confirm_data(ctx, data, data_total):
|
|
await confirm_blob(
|
|
ctx,
|
|
"confirm_data",
|
|
title="Confirm data",
|
|
description="Size: %d bytes" % data_total,
|
|
data=data,
|
|
br_code=ButtonRequestType.SignTx,
|
|
)
|
|
|
|
|
|
def format_ethereum_amount(value: int, token, chain_id: int, tx_type=None):
|
|
if token is tokens.UNKNOWN_TOKEN:
|
|
suffix = "Wei UNKN"
|
|
decimals = 0
|
|
elif token:
|
|
suffix = token[2]
|
|
decimals = token[3]
|
|
else:
|
|
suffix = networks.shortcut_by_chain_id(chain_id, tx_type)
|
|
decimals = 18
|
|
|
|
# Don't want to display wei values for tokens with small decimal numbers
|
|
if decimals > 9 and value < 10 ** (decimals - 9):
|
|
suffix = "Wei " + suffix
|
|
decimals = 0
|
|
|
|
return "%s %s" % (format_amount(value, decimals), suffix)
|