forked from ton-society/the-open-league
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmc_interaction.py
61 lines (55 loc) · 2.69 KB
/
smc_interaction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from models.metric import Metric, CalculationContext, RedoubtMetricImpl
class SmartContractInteractionRedoubtImpl(RedoubtMetricImpl):
def calculate(self, context: CalculationContext, metric):
if len(metric.op_codes) > 0:
op_codes_filter = " OR ".join(map(lambda op: f"op = {op}", metric.op_codes))
else:
op_codes_filter = "TRUE"
if metric.comment_regexp:
comment_regexp_filter = f"and comment like '{metric.comment_regexp}'"
else:
comment_regexp_filter = ""
if metric.address:
address_filter = f"destination ='{metric.address}'"
else:
assert len(metric.addresses) > 0, f"You should provide either address or addresses non empty list " \
f"({context.project.name}: {metric.description})"
address_filter = " OR ".join(map(lambda a: f"destination ='{a}'", metric.addresses))
if len(metric.comment_not_equals) > 0:
comment_not_equals_filter = "and " + " and ".join(map(lambda v: f"comment != '{v}'", metric.comment_not_equals))
else:
comment_not_equals_filter = ""
return f"""
select
msg_id as id, '{context.project.name}' as project, {0.5 if metric.is_custodial else 1} as weight,
source as user_address, ts from messages_local m
where ({address_filter}) {'and length("comment") > 0' if metric.comment_required else ''}
{comment_regexp_filter} {comment_not_equals_filter}
AND (
{op_codes_filter}
)
"""
"""
Simple smart contract interaction - any message (but resulted in successful transaction) to the address provided
Options:
* address - single address
* addresses - list of addresses
* is_custodial - custodial flag
* comment_required - comment required flag
* op_codes - list of op codes (please use signed decimal notation, not hex!)
* comment_regexp - comment regexp to filter with
* comment_not_equals - list of strings from comment to exclude
"""
class SmartContractInteraction(Metric):
def __init__(self, description, address=None, addresses=[], is_custodial=False,
comment_required=False, op_codes=[], comment_regexp=None, comment_not_equals=[]):
Metric.__init__(self, description, [SmartContractInteractionRedoubtImpl()])
assert type(addresses) == list
assert type(op_codes) == list
self.address = address
self.addresses = addresses
self.is_custodial = is_custodial
self.comment_required = comment_required
self.op_codes = op_codes
self.comment_regexp = comment_regexp
self.comment_not_equals = comment_not_equals