1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

fix(python): bump web3 dependency (fixes #3136)

This commit is contained in:
matejcik 2023-10-18 15:34:27 +02:00
parent a945de85a5
commit e590efaddd
3 changed files with 25 additions and 19 deletions

View File

@ -1,5 +1,5 @@
hidapi >= 0.7.99.post20 hidapi>=0.7.99.post20
web3 >= 4.8 web3>=5
Pillow Pillow
stellar-sdk>=6 stellar-sdk>=6
rlp>=1.1.0 ; python_version<'3.7' rlp>=1.1.0 ; python_version<'3.7'

View File

@ -27,10 +27,10 @@ install_requires = (CWD / "requirements.txt").read_text().splitlines()
extras_require = { extras_require = {
"hidapi": ["hidapi>=0.7.99.post20"], "hidapi": ["hidapi>=0.7.99.post20"],
"ethereum": ["rlp>=1.1.0 ; python_version<'3.7'", "web3>=4.8"], "ethereum": ["rlp>=1.1.0 ; python_version<'3.7'", "web3>=5"],
"qt-widgets": ["PyQt5"], "qt-widgets": ["PyQt5"],
"extra": ["Pillow"], "extra": ["Pillow"],
"stellar": ["stellar-sdk>=4.0.0,<6.0.0"], "stellar": ["stellar-sdk>=6"],
} }
extras_require["full"] = sum(extras_require.values(), []) extras_require["full"] = sum(extras_require.values(), [])

View File

@ -20,7 +20,7 @@ import sys
import tarfile import tarfile
from decimal import Decimal from decimal import Decimal
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, List, NoReturn, Optional, TextIO from typing import TYPE_CHECKING, Any, Dict, List, NoReturn, Optional, TextIO, cast
import click import click
@ -30,6 +30,8 @@ from . import with_client
if TYPE_CHECKING: if TYPE_CHECKING:
import web3 import web3
from eth_typing import ChecksumAddress # noqa: I900
from web3.types import Wei
from ..client import TrezorClient from ..client import TrezorClient
@ -133,7 +135,9 @@ def _list_units(ctx: click.Context, param: Any, value: bool) -> None:
ctx.exit() ctx.exit()
def _erc20_contract(token_address: str, to_address: str, amount: int) -> str: def _erc20_contract(
token_address: "ChecksumAddress", to_address: str, amount: int
) -> str:
min_abi = [ min_abi = [
{ {
"name": "transfer", "name": "transfer",
@ -381,7 +385,7 @@ def sign_tx(
(not is_eip1559 and gas_price is None) (not is_eip1559 and gas_price is None)
or any(x is None for x in (gas_limit, nonce)) or any(x is None for x in (gas_limit, nonce))
or publish or publish
) and not _get_web3().isConnected(): ) and not _get_web3().is_connected():
click.echo("Failed to connect to Ethereum node.") click.echo("Failed to connect to Ethereum node.")
click.echo( click.echo(
"If you want to sign offline, make sure you provide --gas-price, " "If you want to sign offline, make sure you provide --gas-price, "
@ -400,7 +404,7 @@ def sign_tx(
) )
if token: if token:
data = _erc20_contract(token, to_address, amount) data = _erc20_contract(cast("ChecksumAddress", token), to_address, amount)
to_address = token to_address = token
amount = 0 amount = 0
@ -416,17 +420,19 @@ def sign_tx(
data_bytes = b"" data_bytes = b""
if gas_limit is None: if gas_limit is None:
gas_limit = _get_web3().eth.estimateGas( gas_limit = _get_web3().eth.estimate_gas(
{ {
"to": to_address, "to": to_address,
"from": from_address, "from": from_address,
"value": amount, "value": cast("Wei", amount),
"data": f"0x{data_bytes.hex()}", "data": data_bytes,
} }
) )
if nonce is None: if nonce is None:
nonce = _get_web3().eth.getTransactionCount(from_address) nonce = _get_web3().eth.get_transaction_count(
cast("ChecksumAddress", from_address)
)
assert gas_limit is not None assert gas_limit is not None
assert nonce is not None assert nonce is not None
@ -456,7 +462,7 @@ def sign_tx(
) )
else: else:
if gas_price is None: if gas_price is None:
gas_price = _get_web3().eth.gasPrice gas_price = _get_web3().eth.gas_price
assert gas_price is not None assert gas_price is not None
sig = ethereum.sign_tx( sig = ethereum.sign_tx(
client, client,
@ -504,16 +510,16 @@ def sign_tx(
transaction = _rlp.encode(transaction_items) transaction = _rlp.encode(transaction_items)
if eip2718_type is not None: if eip2718_type is not None:
eip2718_prefix = f"{eip2718_type:02x}" eip2718_prefix = eip2718_type.to_bytes(1, "big")
else: else:
eip2718_prefix = "" eip2718_prefix = b""
tx_hex = f"0x{eip2718_prefix}{transaction.hex()}" tx_bytes = eip2718_prefix + transaction
if publish: if publish:
tx_hash = _get_web3().eth.sendRawTransaction(tx_hex).hex() tx_hash = _get_web3().eth.send_raw_transaction(tx_bytes).hex()
return f"Transaction published with ID: {tx_hash}" return f"Transaction published with ID: 0x{tx_hash}"
else: else:
return f"Signed raw transaction:\n{tx_hex}" return f"Signed raw transaction:\n0x{tx_bytes.hex()}"
@cli.command() @cli.command()