13
13
import eth_account
14
14
import eth_keys
15
15
import rlp
16
- from eip712 .messages import EIP712Message , _hash_eip191_message
16
+ from eip712 .messages import EIP712Message
17
17
from eth_account ._utils .signing import sign_message_hash
18
18
from eth_account .datastructures import SignedMessage
19
- from eth_account .messages import defunct_hash_message
19
+ from eth_account .messages import _hash_eip191_message , defunct_hash_message
20
20
from eth_utils import keccak
21
21
from eth_utils .applicators import apply_formatters_to_dict
22
22
from hexbytes import HexBytes
@@ -233,7 +233,7 @@ def load(
233
233
break
234
234
except ValueError as e :
235
235
if allow_retry :
236
- prompt = f "Incorrect password, try again: "
236
+ prompt = "Incorrect password, try again: "
237
237
password = None
238
238
continue
239
239
raise e
@@ -404,7 +404,6 @@ def get_deployment_address(self, nonce: Optional[int] = None) -> EthAddress:
404
404
405
405
406
406
class _PrivateKeyAccount (PublicKeyAccount ):
407
-
408
407
"""Base class for Account and LocalAccount"""
409
408
410
409
def __init__ (self , addr : str ) -> None :
@@ -482,8 +481,8 @@ def _check_for_revert(self, tx: Dict) -> None:
482
481
except ValueError as exc :
483
482
exc = VirtualMachineError (exc )
484
483
raise ValueError (
485
- f"Execution reverted during call: '{ exc .revert_msg } '. This transaction will likely revert. "
486
- "If you wish to broadcast, include `allow_revert:True` as a transaction parameter." ,
484
+ f"Execution reverted during call: '{ exc .revert_msg } '. This transaction will likely "
485
+ "revert. If you wish to broadcast, include `allow_revert:True` as a parameter." ,
487
486
) from None
488
487
489
488
def deploy (
@@ -606,7 +605,7 @@ def estimate_gas(
606
605
"data" : HexBytes (data or "" ),
607
606
}
608
607
if gas_price is not None :
609
- tx ["gasPrice" ] = web3 .toHex (gas_price )
608
+ tx ["gasPrice" ] = web3 .to_hex (gas_price )
610
609
try :
611
610
return web3 .eth .estimate_gas (tx )
612
611
except ValueError as exc :
@@ -753,7 +752,7 @@ def _make_transaction(
753
752
"from" : self .address ,
754
753
"value" : Wei (amount ),
755
754
"nonce" : nonce if nonce is not None else self ._pending_nonce (),
756
- "gas" : web3 .toHex (gas_limit ),
755
+ "gas" : web3 .to_hex (gas_limit ),
757
756
"data" : HexBytes (data ),
758
757
}
759
758
if to :
@@ -865,7 +864,6 @@ def _await_confirmation(
865
864
866
865
867
866
class Account (_PrivateKeyAccount ):
868
-
869
867
"""Class for interacting with an Ethereum account.
870
868
871
869
Attributes:
@@ -881,7 +879,6 @@ def _transact(self, tx: Dict, allow_revert: bool) -> Any:
881
879
882
880
883
881
class LocalAccount (_PrivateKeyAccount ):
884
-
885
882
"""Class for interacting with an Ethereum account.
886
883
887
884
Attributes:
@@ -925,6 +922,7 @@ def save(self, filename: str, overwrite: bool = False, password: Optional[str] =
925
922
password = getpass ("Enter the password to encrypt this account with: " )
926
923
927
924
encrypted = web3 .eth .account .encrypt (self .private_key , password )
925
+ encrypted ["address" ] = encrypted ["address" ].lower ()
928
926
with json_file .open ("w" ) as fp :
929
927
json .dump (encrypted , fp )
930
928
return str (json_file )
@@ -984,7 +982,6 @@ def _transact(self, tx: Dict, allow_revert: bool) -> None:
984
982
985
983
986
984
class ClefAccount (_PrivateKeyAccount ):
987
-
988
985
"""
989
986
Class for interacting with an Ethereum account where signing is handled in Clef.
990
987
"""
@@ -1000,10 +997,10 @@ def _transact(self, tx: Dict, allow_revert: bool) -> None:
1000
997
self ._check_for_revert (tx )
1001
998
1002
999
formatters = {
1003
- "nonce" : web3 .toHex ,
1004
- "value" : web3 .toHex ,
1005
- "chainId" : web3 .toHex ,
1006
- "data" : web3 .toHex ,
1000
+ "nonce" : web3 .to_hex ,
1001
+ "value" : web3 .to_hex ,
1002
+ "chainId" : web3 .to_hex ,
1003
+ "data" : web3 .to_hex ,
1007
1004
"from" : to_address ,
1008
1005
}
1009
1006
if "to" in tx :
@@ -1029,7 +1026,7 @@ def _apply_fee_to_tx(
1029
1026
if gas_price is not None :
1030
1027
if max_fee or priority_fee :
1031
1028
raise ValueError ("gas_price and (max_fee, priority_fee) are mutually exclusive" )
1032
- tx ["gasPrice" ] = web3 .toHex (gas_price )
1029
+ tx ["gasPrice" ] = web3 .to_hex (gas_price )
1033
1030
return tx
1034
1031
1035
1032
if priority_fee is None :
@@ -1046,7 +1043,7 @@ def _apply_fee_to_tx(
1046
1043
if priority_fee > max_fee :
1047
1044
raise InvalidTransaction ("priority_fee must not exceed max_fee" )
1048
1045
1049
- tx ["maxFeePerGas" ] = web3 .toHex (max_fee )
1050
- tx ["maxPriorityFeePerGas" ] = web3 .toHex (priority_fee )
1051
- tx ["type" ] = web3 .toHex (2 )
1046
+ tx ["maxFeePerGas" ] = web3 .to_hex (max_fee )
1047
+ tx ["maxPriorityFeePerGas" ] = web3 .to_hex (priority_fee )
1048
+ tx ["type" ] = web3 .to_hex (2 )
1052
1049
return tx
0 commit comments