forked from C0mbustibll/Voting_snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
207 lines (181 loc) · 7.05 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
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
logger.add(f'log.log')
def forma(address, signature, space, proposal, choice, timestamp):
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": "uint32"
},
{
"name": "reason",
"type": "string"
},
{
"name": "app",
"type": "string"
},
{
"name": "metadata",
"type": "string"
}
]
},
"message": {
"space": space,
"proposal": proposal,
"choice": choice,
"app": "snapshot",
"reason": "",
"from": address,
"timestamp": timestamp,
'metadata': "{}"
}
}
}
return forma
def signature(address, space, proposal, choice, timestamp, key):
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": "uint32"
},
{
"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": 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
async def req(key, p):
tm = random.randint(1,TIMEMAX)
print(f'{w3.eth.account.from_key(key).address} Сплю -> {tm}')
await asyncio.sleep(tm)
global x
num_acc = x
for k,inf in enumerate(proposal_data):
if k == 0:
x += 1
SPACE, PROPOSAL, CHOICE = inf.split('@')[0], inf.split('@')[1], inf.split('@')[2]
headers = {'authority': 'hub.snapshot.org',
'sec-ch-ua': '"Google Chrome";v="101", "Chromium";v="101", ";Not A Brand";v="99"',
'accept': 'application/json', 'sec-ch-ua-mobile': '?0',
'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',
'origin': 'https://snapshot.org', 'sec-fetch-site': 'same-site', 'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty', 'referer': 'https://snapshot.org/', 'accept-language': 'ru', }
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://hub.snapshot.org/api/msg', json=forma(
address,
signature(address, SPACE, PROPOSAL, int(CHOICE), timestamp, key),
SPACE, PROPOSAL, int(CHOICE), timestamp
), 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())