chainsyncer/chainsyncer/filter.py

35 lines
789 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# standard imports
import logging
logg = logging.getLogger(__name__)
class SyncFilter:
def __init__(self, safe=True):
self.safe = safe
self.filters = []
def add(self, fltr):
if getattr(fltr, 'filter') == None:
raise ValueError('filter object must implement have method filter')
logg.debug('added filter {}'.format(str(fltr)))
self.filters.append(fltr)
def apply(self, conn, block, tx):
for f in self.filters:
logg.debug('applying filter {}'.format(str(f)))
f.filter(conn, block, tx)
class NoopFilter(SyncFilter):
def filter(self, conn, block, tx):
logg.debug('noop filter :received\n{} {}'.format(block, tx))
def __str__(self):
return 'noopfilter'