-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.py
232 lines (197 loc) · 7.31 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
from web3.auto import w3
from eth_account.messages import encode_structured_data
import time
from loguru import logger
import aiohttp
import asyncio
from config import TIME, TIMEMAX, TIME_ERROR
import random
import ast
import json
logger.add(f'log.log')
def validation_type(type, choise):
if type == 'uint32':
return int(choise)
if type == 'string':
return json.dumps(dict(choise))
choise = [int(ch) for ch in choise]
return choise
# region form
def forma(address, signature, space, proposal, choice, timestamp, type_choice="uint32"):
forma = {
"address": address,
"sig": signature,
"data": {
"domain": {
"name": "snapshot",
"version": "0.1.4"
},
"types": {
"Vote": [{
"name": "from",
"type": "address"
},
{
"name": "space",
"type": "string"
},
{
"name": "timestamp",
"type": "uint64"
},
{
"name": "proposal",
"type": "bytes32"
},
{
"name": "choice",
"type": type_choice
},
{
"name": "reason",
"type": "string"
},
{
"name": "app",
"type": "string"
},
{
"name": "metadata",
"type": "string"
}
]
},
"message": {
"space": space,
"proposal": proposal,
"choice": validation_type(type_choice,choice),
"app": "snapshot",
"reason": "",
"from": address,
"timestamp": timestamp,
'metadata': "{}"
}
}
}
return forma
# endregion
# region signature
def signature(address, space, proposal, choice, timestamp, key, type_choice="uint32"):
sig_signature = {
"domain": {
"name": "snapshot",
"version": "0.1.4"
},
"types": {
"Vote": [
{
"name": "from",
"type": "address"
},
{
"name": "space",
"type": "string"
},
{
"name": "timestamp",
"type": "uint64"
},
{
"name": "proposal",
"type": "bytes32"
},
{
"name": "choice",
"type": type_choice
},
{
"name": "reason",
"type": "string"
},
{
"name": "app",
"type": "string"
},
{
"name": "metadata",
"type": "string"
}
],
'EIP712Domain': [{'name': 'name', 'type': 'string'}, {'name': 'version', 'type': 'string'}]
},
'primaryType': "Vote",
"message": {
"space": space,
"proposal": w3.toBytes(hexstr=proposal),
"choice": validation_type(type_choice,choice),
"app": "snapshot",
"reason": "",
"from": address,
"timestamp": timestamp,
'metadata': "{}"
}
}
signature = (w3.eth.account.sign_message(encode_structured_data(primitive=sig_signature), key))['signature'].hex()
return signature
# endregion
async def req(key, p):
tm = random.randint(1, TIMEMAX)
await asyncio.sleep(tm)
global x
num_acc = x
random.shuffle(proposal_data)
for k, inf in enumerate(proposal_data):
if k == 0:
x += 1
SPACE, PROPOSAL, CHOICE = inf.split('@')[0], inf.split('@')[1], inf.split('@')[2]
type_choise = "uint32"
if '[' in CHOICE:
CHOICE = ast.literal_eval(CHOICE)
type_choise = "uint32[]"
if '{' in CHOICE:
CHOICE = ast.literal_eval(CHOICE)
type_choise = "string"
headers = {'accept': 'application/json',
'user-agent': 'Mozilla/5.0 (Windows NT 6.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36'}
STATUS = True
while STATUS:
timestamp = int(time.time())
address = w3.eth.account.from_key(key).address
async with aiohttp.ClientSession(headers=headers) as ses:
async with ses.post('https://seq.snapshot.org/', json=forma(
address,
signature(address, SPACE, PROPOSAL, CHOICE, timestamp, key, type_choise),
SPACE, PROPOSAL, CHOICE, timestamp, type_choise
), proxy=f'http://{p}', headers=headers) as r:
try:
data = await r.json()
if data.get('id') == None:
if data.get('error_description') == 'no voting power':
logger.info(
f"[{num_acc}/{len(keys)}][{k + 1}/{len(proposal_data)}] {address} PROPOSAL -> {PROPOSAL[:10]} Error-> {data.get('error_description')}")
STATUS = False
elif data.get('error_description') == 'failed to check voting power':
await asyncio.sleep(TIME_ERROR)
else:
logger.error(
f"[{num_acc}/{len(keys)}][{k + 1}/{len(proposal_data)}] {address} PROPOSAL -> {PROPOSAL[:10]} Error-> {data.get('error_description')}")
await asyncio.sleep(TIME_ERROR)
else:
logger.success(
f"[{num_acc}/{len(keys)}][{k + 1}/{len(proposal_data)}] {address} PROPOSAL -> {PROPOSAL[:10]} Success")
STATUS = False
except Exception as e:
# logger.error(f'{address} -> failed check json')
await asyncio.sleep(TIME_ERROR)
await asyncio.sleep(random.randint(1, TIME))
with open('key.txt', 'r') as f:
keys = [i for i in [k.strip() for k in f] if i != '']
with open('proxy.txt', 'r') as f:
prox = [i for i in [pr.strip() for pr in f] if i != '']
with open('data.txt', 'r') as f:
proposal_data = [i for i in [d.strip() for d in f] if i != '']
x = 1
async def main():
await asyncio.gather(*[req(k, prox[v]) for v, k in enumerate(keys)])
if __name__ == '__main__':
asyncio.run(main())