From 884a526abf602658e7e0ba0ebbf8398d7e4e3a7f Mon Sep 17 00:00:00 2001 From: skyge <18844062006@163.com> Date: Sun, 26 Apr 2020 20:09:08 +0800 Subject: [PATCH 1/3] F Fix importing key file error. --- brownie/_cli/accounts.py | 13 ++++++++++--- brownie/network/account.py | 22 +++++++++++++++------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/brownie/_cli/accounts.py b/brownie/_cli/accounts.py index b50504396..3a99882ee 100644 --- a/brownie/_cli/accounts.py +++ b/brownie/_cli/accounts.py @@ -80,12 +80,18 @@ def _generate(id_): def _import(id_, path): - source_path = Path(path).absolute() - if not source_path.suffix: - source_path = source_path.with_suffix(".json") dest_path = _get_data_folder().joinpath(f"accounts/{id_}.json") if dest_path.exists(): raise FileExistsError(f"A keystore file already exists with the id '{id_}'") + + source_path = Path(path).absolute() + if not source_path.exists(): + temp_source = source_path.with_suffix(".json") + if temp_source.exists(): + source_path = temp_source + else: + raise FileNotFoundError(f"Cannot find {source_path}") + accounts.load(source_path) shutil.copy(source_path, dest_path) notify( @@ -95,6 +101,7 @@ def _import(id_, path): ) + def _export(id_, path): source_path = _get_data_folder().joinpath(f"accounts/{id_}.json") if not source_path.exists(): diff --git a/brownie/network/account.py b/brownie/network/account.py index 6b2b0945a..88845e894 100644 --- a/brownie/network/account.py +++ b/brownie/network/account.py @@ -108,17 +108,25 @@ def load(self, filename: str = None) -> Union[List, "LocalAccount"]: Returns: Account instance.""" - project_path = _get_data_folder().joinpath("accounts") + base_accounts_path = _get_data_folder().joinpath("accounts") if not filename: - return [i.stem for i in project_path.glob("*.json")] + return [i.stem for i in base_accounts_path.glob("*.json")] + filename = str(filename) - if not filename.endswith(".json"): - filename += ".json" json_file = Path(filename).expanduser() + if not json_file.exists(): - json_file = project_path.joinpath(filename) - if not json_file.exists(): - raise FileNotFoundError(f"Cannot find {json_file}") + temp_json_file = json_file.with_suffix(".json") + if temp_json_file.exists(): + json_file = temp_json_file + else: + json_file_name = filename.split('/')[-1] + json_file = base_accounts_path.joinpath(json_file_name) + if not str(json_file).endswith(".json"): + json_file = json_file.with_suffix(".json") + if not json_file.exists(): + raise FileNotFoundError(f"Cannot find {json_file}") + with json_file.open() as fp: priv_key = web3.eth.account.decrypt( json.load(fp), getpass("Enter the password to unlock this account: ") From 5527e00f64f63307a30fdec941bd57a4039643f9 Mon Sep 17 00:00:00 2001 From: skyge <18844062006@163.com> Date: Sun, 26 Apr 2020 22:56:51 +0800 Subject: [PATCH 2/3] U Linting code. --- brownie/_cli/accounts.py | 1 - brownie/network/account.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/brownie/_cli/accounts.py b/brownie/_cli/accounts.py index 3a99882ee..4aa9d2ffe 100644 --- a/brownie/_cli/accounts.py +++ b/brownie/_cli/accounts.py @@ -101,7 +101,6 @@ def _import(id_, path): ) - def _export(id_, path): source_path = _get_data_folder().joinpath(f"accounts/{id_}.json") if not source_path.exists(): diff --git a/brownie/network/account.py b/brownie/network/account.py index 88845e894..28a337cb7 100644 --- a/brownie/network/account.py +++ b/brownie/network/account.py @@ -120,10 +120,10 @@ def load(self, filename: str = None) -> Union[List, "LocalAccount"]: if temp_json_file.exists(): json_file = temp_json_file else: - json_file_name = filename.split('/')[-1] + json_file_name = filename.split("/")[-1] json_file = base_accounts_path.joinpath(json_file_name) if not str(json_file).endswith(".json"): - json_file = json_file.with_suffix(".json") + json_file = json_file.with_suffix(".json") if not json_file.exists(): raise FileNotFoundError(f"Cannot find {json_file}") From 7276ec0ec46b81de6e8fb19038fa1ac8b8ae56e4 Mon Sep 17 00:00:00 2001 From: skyge <18844062006@163.com> Date: Sun, 26 Apr 2020 23:11:03 +0800 Subject: [PATCH 3/3] U Use existing method. --- brownie/network/account.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brownie/network/account.py b/brownie/network/account.py index 28a337cb7..3d5c86792 100644 --- a/brownie/network/account.py +++ b/brownie/network/account.py @@ -120,9 +120,9 @@ def load(self, filename: str = None) -> Union[List, "LocalAccount"]: if temp_json_file.exists(): json_file = temp_json_file else: - json_file_name = filename.split("/")[-1] + json_file_name = json_file.name json_file = base_accounts_path.joinpath(json_file_name) - if not str(json_file).endswith(".json"): + if json_file.suffix != ".json": json_file = json_file.with_suffix(".json") if not json_file.exists(): raise FileNotFoundError(f"Cannot find {json_file}")