Skip to content

Commit

Permalink
Merge pull request #1099 from eth-brownie/feat/password-kwarg
Browse files Browse the repository at this point in the history
Minor `Account.load` updates
  • Loading branch information
iamdefinitelyahuman authored Jun 2, 2021
2 parents 337f990 + 5306d37 commit 607c0a5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions brownie/network/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,17 @@ def from_mnemonic(
return new_accounts[0]
return new_accounts

def load(self, filename: str = None) -> Union[List, "LocalAccount"]:
def load(self, filename: str = None, password: str = None) -> Union[List, "LocalAccount"]:
"""
Load a local account from a keystore file.
Arguments
---------
filename: str
Keystore filename. If `None`, returns a list of available keystores.
password: str
Password to unlock the keystore. If `None`, password is entered via
a getpass prompt.
Returns
-------
Expand All @@ -192,7 +195,7 @@ def load(self, filename: str = None) -> Union[List, "LocalAccount"]:
filename = str(filename)
json_file = Path(filename).expanduser()

if not json_file.exists():
if not json_file.exists() or json_file.is_dir():
temp_json_file = json_file.with_suffix(".json")
if temp_json_file.exists():
json_file = temp_json_file
Expand All @@ -206,7 +209,8 @@ def load(self, filename: str = None) -> Union[List, "LocalAccount"]:

with json_file.open() as fp:
priv_key = web3.eth.account.decrypt(
json.load(fp), getpass("Enter the password to unlock this account: ")
json.load(fp),
password or getpass(f'Enter password for "{json_file.stem}": '),
)
return self.add(priv_key)

Expand Down

0 comments on commit 607c0a5

Please sign in to comment.