From d9663325760933a9cf49c823b244a5b7d95f221a Mon Sep 17 00:00:00 2001 From: Venticello <1232990+venticello@users.noreply.github.com> Date: Mon, 19 Sep 2022 16:44:14 +0300 Subject: [PATCH] Whitelisted methods from ABI Transaction processing only with the functions that are in the ABI. Others are ignored and a message is printed with the method ID and transaction hash. --- moonworm/crawler/function_call_crawler.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/moonworm/crawler/function_call_crawler.py b/moonworm/crawler/function_call_crawler.py index 50940dd..1f21ac4 100644 --- a/moonworm/crawler/function_call_crawler.py +++ b/moonworm/crawler/function_call_crawler.py @@ -6,6 +6,7 @@ from logging import error from typing import Any, Callable, Dict, List, Optional from eth_typing.evm import ChecksumAddress +from eth_utils import function_abi_to_4byte_selector from web3 import Web3 from web3.contract import Contract from web3.types import ABI @@ -146,6 +147,7 @@ class FunctionCallCrawler: self.contract_addresses = contract_addresses self.contract = Web3().eth.contract(abi=self.contract_abi) self.on_decode_error = on_decode_error + self.whitelisted_methods = [Web3().toHex(function_abi_to_4byte_selector(a)) for a in self.contract_abi] def process_transaction(self, transaction: Dict[str, Any]): try: @@ -189,7 +191,11 @@ class FunctionCallCrawler: address, block_number ) for transaction in transactions: - self.process_transaction(transaction) + method_id = transaction.get('input')[:10] + if method_id in self.whitelisted_methods: + self.process_transaction(transaction) + else: + print(f"Function not in ABI, MethodID: {method_id} tx: {transaction['hash'].hex()}. Ignored.") self.state.state if flush_state: self.state.flush()