forked from hclivess/Bismuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
difficulty_calculator.py
44 lines (29 loc) · 1020 Bytes
/
difficulty_calculator.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
import sqlite3, hashlib
f = open('difficulty.log', 'w')
conn = sqlite3.connect('static/hyper.db')
c = conn.cursor()
c.execute("select * from transactions where reward != 0 and block_height != 0 order by block_height asc")
result = c.fetchall()
def bin_convert(string):
return ''.join(format(ord(x), '8b').replace(' ', '0') for x in string)
db_block_hash = "init"
for x in result:
miner_address = x[2]
nonce = x[11]
diff_broke = 0
diff = 0
while diff_broke == 0:
mining_hash = bin_convert(hashlib.sha224((miner_address + nonce + db_block_hash).encode("utf-8")).hexdigest())
mining_condition = bin_convert(db_block_hash)[0:diff]
if mining_condition in mining_hash:
diff_result = diff
diff = diff + 1
else:
diff_broke = 1
try:
f.write(str(x[0]) + " " + str(diff_result) + "\n")
print (x[0],diff_result)
except:
pass
db_block_hash = x[7] #current for next run as previous
f.close()