Safer check for pool_list in config (#9810)

* Safer check for pool_list in config

* safer pool_list check
This commit is contained in:
Earle Lowe 2022-01-19 11:35:24 -08:00 committed by GitHub
parent a673bd4b61
commit 142b0c5c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -584,10 +584,12 @@ class Farmer:
if launcher_id == pool_state_dict["pool_config"].launcher_id:
config = load_config(self._root_path, "config.yaml")
new_list = []
for list_element in config["pool"]["pool_list"]:
if hexstr_to_bytes(list_element["launcher_id"]) == bytes(launcher_id):
list_element["payout_instructions"] = payout_instructions
new_list.append(list_element)
pool_list = config["pool"].get("pool_list", [])
if pool_list is not None:
for list_element in pool_list:
if hexstr_to_bytes(list_element["launcher_id"]) == bytes(launcher_id):
list_element["payout_instructions"] = payout_instructions
new_list.append(list_element)
config["pool"]["pool_list"] = new_list
save_config(self._root_path, "config.yaml", config)

View File

@ -41,8 +41,9 @@ class PoolWalletConfig(Streamable):
def load_pool_config(root_path: Path) -> List[PoolWalletConfig]:
config = load_config(root_path, "config.yaml")
ret_list: List[PoolWalletConfig] = []
if "pool_list" in config["pool"]:
for pool_config_dict in config["pool"]["pool_list"]:
pool_list = config["pool"].get("pool_list", [])
if pool_list is not None:
for pool_config_dict in pool_list:
try:
pool_config = PoolWalletConfig(
bytes32.from_hexstr(pool_config_dict["launcher_id"]),