forked from f-prime/zCoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminer.py
More file actions
71 lines (66 loc) · 1.95 KB
/
Copy pathminer.py
File metadata and controls
71 lines (66 loc) · 1.95 KB
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
import socket
import hashlib
import json
import random
import string
import sqlite3
import threading
def check_difficulty():
db = sqlite3.connect("nodes.db")
find = db.execute("SELECT ip, port FROM data WHERE relay=?", [True])
find = find.fetchall()
random.shuffle(find)
for x in find:
s = socket.socket()
try:
s.settimeout(1)
s.connect(x)
except:
s.close()
continue
else:
s.send(json.dumps({"cmd":"get_raw_difficulty"}))
data = s.recv(1024)
if data:
s.close()
return {"difficulty":int(data)}
def check_coin(data):
node = sqlite3.connect("nodes.db")
node = node.execute("SELECT ip, port FROM data WHERE relay=?", [True])
node = node.fetchall()
random.shuffle(node)
for x in node:
s = socket.socket()
try:
s.settimeout(1)
s.connect((x[0], x[1]))
except:
s.close()
continue
else:
data['cmd'] = "check_coin"
print data
s.send(json.dumps(data))
s.close()
def mine():
while True:
check = check_difficulty()
starter = ''.join([random.choice(string.uppercase+string.lowercase+string.digits) for x in range(5)])
on = 0
print check
while True:
print starter+str(on)
c = hashlib.sha512(starter+str(on)).hexdigest()
startswith = "1"*check['difficulty']
if c.startswith(startswith):
print c
wall = sqlite3.connect("wallet.db")
address = wall.execute("SELECT address FROM data")
address = address.fetchall()[0][0]
check_coin({"starter":starter+str(on), "hash":c, "address":address})
break
else:
on += 1
#for x in range(5):
# threading.Thread(target=mine).start()
mine()