-
Notifications
You must be signed in to change notification settings - Fork 28
/
spam.py
42 lines (36 loc) · 1.01 KB
/
spam.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
import multiprocessing as mp
import requests
import json
import random
def get_block_number(hex_num):
random_id = random.randint(1, 1000000)
payload = {
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": [hex_num, False],
"id": random_id,
}
response = requests.post("http://127.0.0.1:3000", json=payload)
result = response.json()
try:
block_number = int(result["result"]["number"], 16)
except Exception as e:
return e
# block_number = result
# throw if id doesnt match
if result["id"] != random_id:
raise ValueError("Invalid response id: %s" % result["id"])
return block_number
def my_func(x):
for i in range(x):
block_number = get_block_number(hex(i+17975056))
# print(f"Block Number: {block_number}")
def main():
pool = mp.Pool(mp.cpu_count())
i = 0
while i < 10:
pool.map(my_func, range(0, 1000))
print("done: ", i)
i += 1
if __name__ == "__main__":
main()