Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Account.load updates #1099

Merged
merged 2 commits into from
Jun 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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