eth-monitor/eth_monitor/filters/base.py

40 lines
1.1 KiB
Python
Raw Normal View History

# standard imports
import os
import logging
2022-01-23 23:07:59 +01:00
import json
# external imports
from hexathon import strip_0x
from chainsyncer.filter import SyncFilter
logg = logging.getLogger(__name__)
class RuledFilter(SyncFilter):
def __init__(self, rules_filter=None):
2022-01-23 23:44:31 +01:00
if self.store.chain_dir == None:
raise RuntimeError('store must be initialized. call RuledFilter.init() first')
self.rules_filter = rules_filter
@staticmethod
2022-01-23 23:44:31 +01:00
def init(store, include_block_data=False, include_tx_data=False):
RuledFilter.store = store
2022-01-23 23:07:59 +01:00
RuledFilter.include_block_data = include_block_data
RuledFilter.include_tx_data = include_tx_data
@classmethod
def block_callback(cls, block, extra=None):
2022-01-30 15:43:53 +01:00
logg.info('processing {}'.format(block))
2022-01-23 23:44:31 +01:00
cls.store.put_block(block, include_data=cls.include_block_data)
def filter(self, conn, block, tx, db_session=None):
if self.rules_filter != None:
if not self.rules_filter.apply_rules(tx):
logg.debug('rule match failed for tx {}'.format(tx.hash))
return True
return False