From 2719d9baba56bf62277750f00e60694ac45cc8ca Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 7 Sep 2023 18:04:34 +0300 Subject: [PATCH] Add changes. --- moonstreamapi/moonstreamapi/actions.py | 25 ++++++++++++------- .../admin/migrations/add_selectors.py | 4 +-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/moonstreamapi/moonstreamapi/actions.py b/moonstreamapi/moonstreamapi/actions.py index e75e5654..cd0ccf26 100644 --- a/moonstreamapi/moonstreamapi/actions.py +++ b/moonstreamapi/moonstreamapi/actions.py @@ -538,6 +538,10 @@ def apply_moonworm_tasks( if "abi_method_hash" in tag ] + existing_selectors = [ + tag.split(":")[-1] for tag in chain(*existing_tags) if "abi_selector" in tag + ] + abi_hashes_dict = { hashlib.md5(json.dumps(method).encode("utf-8")).hexdigest(): method for method in abi @@ -545,17 +549,20 @@ def apply_moonworm_tasks( and (method.get("stateMutability", "") != "view") } + abi_selectors_dict = { + Web3.keccak( + text=abi_hashes_dict[hash]["name"] + + "(" + + ",".join(map(lambda x: x["type"], abi_hashes_dict[hash]["inputs"])) + + ")" + )[:4].hex(): method + for method in abi + if (method["type"] in ("event", "function")) + and (method.get("stateMutability", "") != "view") + } + for hash in abi_hashes_dict: if hash not in existing_hashes: - abi_selector = Web3.keccak( - text=abi_hashes_dict[hash]["name"] - + "(" - + ",".join( - map(lambda x: x["type"], abi_hashes_dict[hash]["inputs"]) - ) - + ")" - )[:4].hex() - moonworm_abi_tasks_entries_pack.append( { "title": address, diff --git a/moonstreamapi/moonstreamapi/admin/migrations/add_selectors.py b/moonstreamapi/moonstreamapi/admin/migrations/add_selectors.py index de0b96ea..daa79d90 100644 --- a/moonstreamapi/moonstreamapi/admin/migrations/add_selectors.py +++ b/moonstreamapi/moonstreamapi/admin/migrations/add_selectors.py @@ -51,7 +51,7 @@ def fill_missing_selectors_in_moonworm_tasks() -> None: logger.warn(f"Unable to parse abi from task: {task.id}") continue - if not any([tag.startswith("selector:") for tag in task.tags]): + if not any([tag.startswith("abi_selector:") for tag in task.tags]): ## generate selector abi_selector = Web3.keccak( @@ -61,7 +61,7 @@ def fill_missing_selectors_in_moonworm_tasks() -> None: + ")" )[:4].hex() - tags.append(f"#selector:{abi_selector}") + tags.append(f"abi_selector:{abi_selector}") entries_tags.append( {