1+ import getpass
12import json
23import os
34
@@ -12,7 +13,7 @@ def setup(base_url=None, skip_ws=False, perp_dexs=None):
1213 config_path = os .path .join (os .path .dirname (__file__ ), "config.json" )
1314 with open (config_path ) as f :
1415 config = json .load (f )
15- account : LocalAccount = eth_account .Account .from_key (config [ "secret_key" ] )
16+ account : LocalAccount = eth_account .Account .from_key (get_secret_key ( config ) )
1617 address = config ["account_address" ]
1718 if address == "" :
1819 address = account .address
@@ -32,6 +33,25 @@ def setup(base_url=None, skip_ws=False, perp_dexs=None):
3233 return address , info , exchange
3334
3435
36+ def get_secret_key (config ):
37+ if config ["secret_key" ]:
38+ secret_key = config ["secret_key" ]
39+ else :
40+ keystore_path = config ["keystore_path" ]
41+ keystore_path = os .path .expanduser (keystore_path )
42+ if not os .path .isabs (keystore_path ):
43+ keystore_path = os .path .join (os .path .dirname (__file__ ), keystore_path )
44+ if not os .path .exists (keystore_path ):
45+ raise FileNotFoundError (f"Keystore file not found: { keystore_path } " )
46+ if not os .path .isfile (keystore_path ):
47+ raise ValueError (f"Keystore path is not a file: { keystore_path } " )
48+ with open (keystore_path ) as f :
49+ keystore = json .load (f )
50+ password = getpass .getpass ("Enter keystore password: " )
51+ secret_key = eth_account .Account .decrypt (keystore , password )
52+ return secret_key
53+
54+
3555def setup_multi_sig_wallets ():
3656 config_path = os .path .join (os .path .dirname (__file__ ), "config.json" )
3757 with open (config_path ) as f :
0 commit comments