4
0
mirror of git://holbrook.no/eth-monitor.git synced 2024-11-23 20:26:45 +01:00

Add data-i

This commit is contained in:
lash 2022-04-05 14:02:18 +00:00
parent c4e2dc37f3
commit 243ec11321
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 60 additions and 6 deletions

View File

@ -1,3 +1,5 @@
- 0.3.2
* Add data-in filter
- 0.3.1 - 0.3.1
* Add data filter * Add data filter
- 0.3.0 - 0.3.0

View File

@ -69,7 +69,7 @@ class OutFilter(RuledFilter):
data = 'data {}'.format(data) data = 'data {}'.format(data)
#s = '{} {} {} {}'.format(self.c, block, tx, data) #s = '{} {} {} {}'.format(self.c, block, tx, data)
tx_count = len(block.txs) tx_count = len(block.txs)
s = '{} {} block {} {} tx {}/{} {} {}'.format( s = '{} {} block {} {} tx {}/{} {} {} {}'.format(
self.c, self.c,
datetime.datetime.fromtimestamp(block.timestamp), datetime.datetime.fromtimestamp(block.timestamp),
block.number, block.number,
@ -77,6 +77,7 @@ class OutFilter(RuledFilter):
tx.index, tx.index,
tx_count, tx_count,
strip_0x(tx.hash), strip_0x(tx.hash),
tx.status,
data, data,
) )

View File

@ -8,6 +8,37 @@ from chainlib.eth.address import is_same_address
logg = logging.getLogger() logg = logging.getLogger()
class RuleData:
def __init__(self, fragments, description=None):
self.fragments = fragments
self.description = description
if self.description == None:
self.description = str(uuid.uuid4())
def check(self, sender, recipient, data, tx_hash):
if len(self.fragments) == 0:
return False
for fragment in self.fragments:
l = len(fragment)
if len(fragment) > len(data):
continue
if fragment in data:
logg.debug('tx {} rule {} match in DATA FRAGMENT {}'.format(tx_hash, self.description, fragment))
return True
return False
def __str__(self):
return 'Fragment ' + self.description + ' {}'.format(
self.fragments,
)
class RuleMethod: class RuleMethod:
def __init__(self, methods, description=None): def __init__(self, methods, description=None):

View File

@ -31,6 +31,7 @@ from eth_monitor.rules import (
AddressRules, AddressRules,
RuleSimple, RuleSimple,
RuleMethod, RuleMethod,
RuleData,
) )
from eth_monitor.filters import RuledFilter from eth_monitor.filters import RuledFilter
from eth_monitor.filters.out import OutFilter from eth_monitor.filters.out import OutFilter
@ -62,8 +63,10 @@ argparser.add_argument('--keep-alive', action='store_true', dest='keep_alive', h
argparser.add_argument('--input', default=[], action='append', type=str, help='Add input (recipient) addresses to includes list') argparser.add_argument('--input', default=[], action='append', type=str, help='Add input (recipient) addresses to includes list')
argparser.add_argument('--output', default=[], action='append', type=str, help='Add output (sender) addresses to includes list') argparser.add_argument('--output', default=[], action='append', type=str, help='Add output (sender) addresses to includes list')
argparser.add_argument('--exec', default=[], action='append', type=str, help='Add exec (contract) addresses to includes list') argparser.add_argument('--exec', default=[], action='append', type=str, help='Add exec (contract) addresses to includes list')
argparser.add_argument('--data', default=[], action='append', type=str, help='Add data strings to include list') argparser.add_argument('--data', default=[], action='append', type=str, help='Add data prefix strings to include list')
argparser.add_argument('--x-data', default=[], action='append', dest='xdata', type=str, help='Add data strings to exclude list') argparser.add_argument('--data-in', default=[], action='append', dest='data_in', type=str, help='Add data contain strings to include list')
argparser.add_argument('--x-data', default=[], action='append', dest='xdata', type=str, help='Add data prefix string to exclude list')
argparser.add_argument('--x-data-in', default=[], action='append', dest='xdata_in', type=str, help='Add data contain string to exclude list')
argparser.add_argument('--address', default=[], action='append', type=str, help='Add addresses as input, output and exec to includes list') argparser.add_argument('--address', default=[], action='append', type=str, help='Add addresses as input, output and exec to includes list')
argparser.add_argument('--x-input', default=[], action='append', type=str, dest='xinput', help='Add input (recipient) addresses to excludes list') argparser.add_argument('--x-input', default=[], action='append', type=str, dest='xinput', help='Add input (recipient) addresses to excludes list')
argparser.add_argument('--x-output', default=[], action='append', type=str, dest='xoutput', help='Add output (sender) addresses to excludes list') argparser.add_argument('--x-output', default=[], action='append', type=str, dest='xoutput', help='Add output (sender) addresses to excludes list')
@ -168,8 +171,12 @@ def setup_address_arg_rules(rules, args):
def setup_data_arg_rules(rules, args): def setup_data_arg_rules(rules, args):
include_data = args.data include_data = []
exclude_data = args.xdata for v in args.data:
include_data.append(v.lower())
exclude_data = []
for v in args.xdata:
exclude_data.append(v.lower())
includes = RuleMethod(include_data, description='INCLUDE') includes = RuleMethod(include_data, description='INCLUDE')
rules.include(includes) rules.include(includes)
@ -177,6 +184,19 @@ def setup_data_arg_rules(rules, args):
excludes = RuleMethod(exclude_data, description='EXCLUDE') excludes = RuleMethod(exclude_data, description='EXCLUDE')
rules.exclude(excludes) rules.exclude(excludes)
include_data = []
for v in args.data_in:
include_data.append(v.lower())
exclude_data = []
for v in args.xdata_in:
exclude_data.append(v.lower())
includes = RuleData(include_data, description='INCLUDE')
rules.include(includes)
excludes = RuleData(exclude_data, description='EXCLUDE')
rules.exclude(excludes)
return rules return rules

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = eth-monitor name = eth-monitor
version = 0.3.1 version = 0.3.2
description = Monitor and cache transactions using match filters description = Monitor and cache transactions using match filters
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no