-
Notifications
You must be signed in to change notification settings - Fork 0
/
searcher.py
99 lines (90 loc) · 2.97 KB
/
searcher.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from elasticsearch import Elasticsearch
from conf import Config
class Searcher:
def __init__(self, index_prefix):
self.index_prefix = index_prefix
self.es = Elasticsearch(hosts=[{'host': Config.es_host, 'port': Config.es_port}], timeout=360)
def sql(self, query):
query = query.lower().strip()
if query.startswith('select') or query.startswith('desc') or query.startswith('show'):
return self.es.sql.query(body={'query': query}, format='json')
else:
return {}
def aio_search(self, query, size, start):
body = {
"track_total_hits": 10000,
"query": {
"query_string": {
"query": query,
"default_field": "aio"
}
},
"size": size,
"from": start
}
return self.es.search(index=self.index_prefix + '_flat', body=body)
def get_by_height(self, height, index):
if index == 'flat':
field = 'utxo_block_height'
elif index == 'utxo':
field = 'result.block.header.height'
elif index == 'web3':
field = 'number'
else:
return {}
body = {
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"term": {
field: {
"value": height
}
}
}
}
}
}
return self.es.search(index=self.index_prefix + '_' + index, body=body)
def evm_tx_by_hash(self, tx_hash):
return self.es.get(index=self.index_prefix + '_tx', id=tx_hash)
def utxo_by_proposer(self, proposer, size, start):
body = {
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"term": {
"result.block.header.proposer_address.keyword": {
"value": proposer
}
}
}
}
},
"size": size,
"from": start
}
return self.es.search(index=self.index_prefix + '_utxo', body=body)
def top_proposers(self, num):
body = {
"track_total_hits": 10000,
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"group_by_proposer": {
"terms": {
"field": "result.block.header.proposer_address.keyword",
"size": num
}
}
}
}
return self.es.search(index=self.index_prefix + '_utxo', body=body)