11from enum import Enum
2- from functools import lru_cache
3- from typing import Dict , List , Optional , Set , Tuple
2+ from functools import cache
43
54from eth_typing import ChecksumAddress
65from hexbytes import HexBytes
@@ -24,16 +23,16 @@ class HwWalletType(Enum):
2423 LEDGER = 1
2524
2625
27- @lru_cache ( maxsize = None )
26+ @cache
2827def get_hw_wallet_manager ():
2928 return HwWalletManager ()
3029
3130
3231class HwWalletManager :
3332 def __init__ (self ):
34- self .wallets : Set [HwWallet ] = set ()
35- self .supported_hw_wallet_types : Dict [str , HwWallet ] = {}
36- self .sender : Optional [ HwWallet ] = None
33+ self .wallets : set [HwWallet ] = set ()
34+ self .supported_hw_wallet_types : dict [str , HwWallet ] = {}
35+ self .sender : HwWallet | None = None
3736 try :
3837 from .ledger_wallet import LedgerWallet
3938
@@ -51,16 +50,16 @@ def __init__(self):
5150 def is_supported_hw_wallet (self , hw_wallet_type : HwWalletType ) -> bool :
5251 return hw_wallet_type in self .supported_hw_wallet_types
5352
54- def get_hw_wallet (self , hw_wallet_type : HwWalletType ) -> Optional [ HwWallet ] :
53+ def get_hw_wallet (self , hw_wallet_type : HwWalletType ) -> HwWallet | None :
5554 if hw_wallet_type in self .supported_hw_wallet_types :
5655 return self .supported_hw_wallet_types [hw_wallet_type ]
5756
5857 def get_accounts (
5958 self ,
6059 hw_wallet_type : HwWalletType ,
6160 template_derivation_path : str ,
62- number_accounts : Optional [ int ] = 5 ,
63- ) -> List [ Tuple [ChecksumAddress , str ]]:
61+ number_accounts : int | None = 5 ,
62+ ) -> list [ tuple [ChecksumAddress , str ]]:
6463 """
6564
6665 :param hw_wallet: Trezor or Ledger
@@ -101,7 +100,7 @@ def set_sender(self, hw_wallet_type: HwWalletType, derivation_path: str):
101100 hw_wallet = self .get_hw_wallet (hw_wallet_type )
102101 self .sender = hw_wallet (derivation_path )
103102
104- def delete_accounts (self , addresses : List [ChecksumAddress ]) -> Set :
103+ def delete_accounts (self , addresses : list [ChecksumAddress ]) -> set :
105104 """
106105 Remove ledger accounts from address
107106
@@ -119,8 +118,8 @@ def delete_accounts(self, addresses: List[ChecksumAddress]) -> Set:
119118 return accounts_to_remove
120119
121120 def sign_eip712 (
122- self , eip712_message : Dict , wallets : List [HwWallet ]
123- ) -> List [SafeSignature ]:
121+ self , eip712_message : dict , wallets : list [HwWallet ]
122+ ) -> list [SafeSignature ]:
124123 """
125124 Sign an EIP712 message
126125
@@ -130,7 +129,7 @@ def sign_eip712(
130129 """
131130 _ , domain_hash , message_hash = eip712_encode (eip712_message )
132131 eip712_message_hash = eip712_encode_hash (eip712_message )
133- safe_signatures : List [SafeSignature ] = []
132+ safe_signatures : list [SafeSignature ] = []
134133 for wallet in wallets :
135134 print_formatted_text (
136135 HTML (
@@ -148,7 +147,7 @@ def sign_eip712(
148147
149148 return safe_signatures
150149
151- def sign_safe_tx (self , safe_tx : SafeTx , wallets : List [HwWallet ]) -> SafeTx :
150+ def sign_safe_tx (self , safe_tx : SafeTx , wallets : list [HwWallet ]) -> SafeTx :
152151 """
153152 Sign a safe transaction with the provided hardware wallets
154153
@@ -169,11 +168,11 @@ def sign_safe_tx(self, safe_tx: SafeTx, wallets: List[HwWallet]) -> SafeTx:
169168 def execute_safe_tx (
170169 self ,
171170 safe_tx : SafeTx ,
172- tx_gas : Optional [ int ] = None ,
173- tx_gas_price : Optional [ int ] = None ,
174- tx_nonce : Optional [ int ] = None ,
175- eip1559_speed : Optional [ TxSpeed ] = None ,
176- ) -> Tuple [HexBytes , TxParams ]:
171+ tx_gas : int | None = None ,
172+ tx_gas_price : int | None = None ,
173+ tx_nonce : int | None = None ,
174+ eip1559_speed : TxSpeed | None = None ,
175+ ) -> tuple [HexBytes , TxParams ]:
177176 """
178177 Send multisig tx to the Safe
179178
@@ -223,16 +222,16 @@ def execute_safe_tx(
223222 return safe_tx .tx_hash , safe_tx .tx
224223
225224 def sign_message (
226- self , message : bytes , wallets : List [HwWallet ]
227- ) -> List [SafeSignature ]:
225+ self , message : bytes , wallets : list [HwWallet ]
226+ ) -> list [SafeSignature ]:
228227 """
229228 Sign a message for all the provided wallets
230229
231230 :param message:
232231 :param wallets:
233232 :return:
234233 """
235- signatures : List [SafeSignature ] = []
234+ signatures : list [SafeSignature ] = []
236235 for wallet in wallets :
237236 print_formatted_text (
238237 HTML (
0 commit comments