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.
pull/96/head
Venticello 2022-09-19 16:44:14 +03:00 zatwierdzone przez GitHub
rodzic 04d2860481
commit d966332576
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -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()