commit 243ec11321d4fec9754d6308694b87972fca19ea
parent c4e2dc37f36c99de0da3d985d3251162aa8d1b76
Author: lash <dev@holbrook.no>
Date: Tue, 5 Apr 2022 14:02:18 +0000
Add data-i
Diffstat:
5 files changed, 60 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,5 @@
+- 0.3.2
+ * Add data-in filter
- 0.3.1
* Add data filter
- 0.3.0
diff --git a/eth_monitor/filters/out.py b/eth_monitor/filters/out.py
@@ -69,7 +69,7 @@ class OutFilter(RuledFilter):
data = 'data {}'.format(data)
#s = '{} {} {} {}'.format(self.c, block, tx, data)
tx_count = len(block.txs)
- s = '{} {} block {} {} tx {}/{} {} {}'.format(
+ s = '{} {} block {} {} tx {}/{} {} {} {}'.format(
self.c,
datetime.datetime.fromtimestamp(block.timestamp),
block.number,
@@ -77,6 +77,7 @@ class OutFilter(RuledFilter):
tx.index,
tx_count,
strip_0x(tx.hash),
+ tx.status,
data,
)
diff --git a/eth_monitor/rules.py b/eth_monitor/rules.py
@@ -8,6 +8,37 @@ from chainlib.eth.address import is_same_address
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:
def __init__(self, methods, description=None):
diff --git a/eth_monitor/runnable/sync.py b/eth_monitor/runnable/sync.py
@@ -31,6 +31,7 @@ from eth_monitor.rules import (
AddressRules,
RuleSimple,
RuleMethod,
+ RuleData,
)
from eth_monitor.filters import RuledFilter
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('--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('--data', default=[], action='append', type=str, help='Add data 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', default=[], action='append', type=str, help='Add data prefix strings to include 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('--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')
@@ -168,8 +171,12 @@ def setup_address_arg_rules(rules, args):
def setup_data_arg_rules(rules, args):
- include_data = args.data
- exclude_data = args.xdata
+ include_data = []
+ 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')
rules.include(includes)
@@ -177,6 +184,19 @@ def setup_data_arg_rules(rules, args):
excludes = RuleMethod(exclude_data, description='EXCLUDE')
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
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = eth-monitor
-version = 0.3.1
+version = 0.3.2
description = Monitor and cache transactions using match filters
author = Louis Holbrook
author_email = dev@holbrook.no