Skip to content

Commit

Permalink
Fix ethereum_client warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Sep 11, 2024
1 parent e16681a commit 3f1c1a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
33 changes: 21 additions & 12 deletions safe_eth/eth/ethereum_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Optional,
Sequence,
Tuple,
Type,
Union,
cast,
)
Expand Down Expand Up @@ -109,7 +110,7 @@ def tx_with_exception_handling(func):
:param func:
:return:
"""
error_with_exception: Dict[str, Exception] = {
error_with_exception: Dict[str, Type[Exception]] = {
"EIP-155": ChainIdIsRequired,
"Transaction with the same hash was already imported": TransactionAlreadyImported,
"replacement transaction underpriced": ReplacementTransactionUnderpriced,
Expand Down Expand Up @@ -466,17 +467,17 @@ def _decode_transfer_log(
elif topics_len == 3:
# ERC20 Transfer(address indexed from, address indexed to, uint256 value)
# 3 topics (transfer topic + from + to)
value_data = HexBytes(data)
try:
value_data = HexBytes(data)
value = eth_abi.decode(["uint256"], value_data)[0]
except DecodingError:
logger.warning(
"Cannot decode Transfer event `uint256 value` from data=%s",
value_data.hex(),
)
return None
from_to_data = b"".join(topics[1:])
try:
from_to_data = b"".join(topics[1:])
_from, to = (
fast_to_checksum_address(address)
for address in eth_abi.decode(
Expand All @@ -493,8 +494,8 @@ def _decode_transfer_log(
elif topics_len == 4:
# ERC712 Transfer(address indexed from, address indexed to, uint256 indexed tokenId)
# 4 topics (transfer topic + from + to + tokenId)
from_to_token_id_data = b"".join(topics[1:])
try:
from_to_token_id_data = b"".join(topics[1:])
_from, to, token_id = eth_abi.decode(
["address", "address", "uint256"], from_to_token_id_data
)
Expand Down Expand Up @@ -1473,7 +1474,7 @@ def deploy_and_initialize_contract(
initializer_data: Optional[Union[bytes, HexStr]] = None,
check_receipt: bool = True,
deterministic: bool = True,
) -> EthereumTxSent:
) -> Optional[EthereumTxSent]:
"""
:param deployer_account:
Expand All @@ -1484,11 +1485,16 @@ def deploy_and_initialize_contract(
:return:
"""
contract_address: Optional[ChecksumAddress] = None
assert (
constructor_data and initializer_data
), "At least constructor_data or initializer_data must be provided"
tx_hash: Optional[HexBytes] = None
tx: Optional[TxParams] = None
for data in (constructor_data, initializer_data):
# Because initializer_data is not mandatory
if data:
data = HexBytes(data)
tx: TxParams = {
tx = {
"from": deployer_account.address,
"data": data,
"gasPrice": self.w3.eth.gas_price,
Expand Down Expand Up @@ -1528,7 +1534,9 @@ def deploy_and_initialize_contract(
assert tx_receipt
assert tx_receipt["status"]

return EthereumTxSent(tx_hash, tx, contract_address)
if tx_hash and tx:
return EthereumTxSent(tx_hash, tx, contract_address)
return None

def get_nonce_for_account(
self,
Expand Down Expand Up @@ -1633,6 +1641,8 @@ def estimate_fee_eip1559(
percentile = 90
elif tx_speed == TxSpeed.FASTEST:
percentile = 100
else:
percentile = 50

result = self.w3.eth.fee_history(1, "latest", reward_percentiles=[percentile])
# Get next block `base_fee_per_gas`
Expand Down Expand Up @@ -1755,11 +1765,10 @@ def get_block(

def _parse_block_identifier(self, block_identifier: BlockIdentifier) -> str:
if isinstance(block_identifier, int):
return hex(block_identifier)
return HexStr(hex(block_identifier))
elif isinstance(block_identifier, bytes):
return HexBytes(block_identifier).hex()
else:
return block_identifier
return HexStr(HexBytes(block_identifier).hex())
return str(block_identifier)

def get_blocks(
self,
Expand Down Expand Up @@ -1820,7 +1829,7 @@ def build_tx_params(
:param gas_price:
:param nonce:
:param chain_id:
:param tx_params: An existing TxParams dictionary will be replaced by the providen values
:param tx_params: An existing TxParams dictionary will be replaced by the provided values
:return:
"""

Expand Down
2 changes: 2 additions & 0 deletions safe_eth/eth/multicall.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def deploy_contract(
ethereum_tx_sent = ethereum_client.deploy_and_initialize_contract(
deployer_account, constructor_data
)
if not ethereum_tx_sent:
return None

assert ethereum_tx_sent.contract_address is not None
contract_address = ethereum_tx_sent.contract_address
Expand Down

0 comments on commit 3f1c1a2

Please sign in to comment.