pull/919/head
Andrey 2023-09-19 12:48:44 +03:00
rodzic 80efa41b79
commit 827823ab7a
1 zmienionych plików z 13 dodań i 22 usunięć

Wyświetl plik

@ -526,34 +526,19 @@ def apply_moonworm_tasks(
token=MOONSTREAM_ADMIN_ACCESS_TOKEN, token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
) )
# create historical crawl task in journal
# will use create_entries_pack for creating entries in journal # will use create_entries_pack for creating entries in journal
existing_tags = [entry.tags for entry in entries] existing_tags = [entry.tags for entry in entries]
existing_hashes = [
tag.split(":")[-1]
for tag in chain(*existing_tags)
if "abi_method_hash" in tag
]
existing_selectors = [ existing_selectors = [
tag.split(":")[-1] for tag in chain(*existing_tags) if "abi_selector" in tag 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
if (method["type"] in ("event", "function"))
and (method.get("stateMutability", "") != "view")
}
abi_selectors_dict = { abi_selectors_dict = {
Web3.keccak( Web3.keccak(
text=abi_hashes_dict[hash]["name"] text=method["name"]
+ "(" + "("
+ ",".join(map(lambda x: x["type"], abi_hashes_dict[hash]["inputs"])) + ",".join(map(lambda x: x["type"], method["inputs"]))
+ ")" + ")"
)[:4].hex(): method )[:4].hex(): method
for method in abi for method in abi
@ -561,19 +546,25 @@ def apply_moonworm_tasks(
and (method.get("stateMutability", "") != "view") and (method.get("stateMutability", "") != "view")
} }
for hash in abi_hashes_dict: for abi_selector in abi_selectors_dict:
if hash not in existing_hashes: if abi_selector not in existing_selectors:
hash = hashlib.md5(
json.dumps(abi_selectors_dict[abi_selector]).encode("utf-8")
).hexdigest()
moonworm_abi_tasks_entries_pack.append( moonworm_abi_tasks_entries_pack.append(
{ {
"title": address, "title": address,
"content": json.dumps(abi_hashes_dict[hash], indent=4), "content": json.dumps(
abi_selectors_dict[abi_selector], indent=4
),
"tags": [ "tags": [
f"address:{address}", f"address:{address}",
f"type:{abi_hashes_dict[hash]['type']}", f"type:{abi_selectors_dict[abi_selector]['type']}",
f"abi_method_hash:{hash}", f"abi_method_hash:{hash}",
f"abi_selector:{abi_selector}", f"abi_selector:{abi_selector}",
f"subscription_type:{subscription_type}", f"subscription_type:{subscription_type}",
f"abi_name:{abi_hashes_dict[hash]['name']}", f"abi_name:{abi_selectors_dict[abi_selector]['name']}",
f"status:active", f"status:active",
f"task_type:moonworm", f"task_type:moonworm",
f"moonworm_task_pickedup:False", # True if task picked up by moonworm-crawler(default each 120 sec) f"moonworm_task_pickedup:False", # True if task picked up by moonworm-crawler(default each 120 sec)