forked from moguli/20180225_Tibame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmining_bitcoin.py
31 lines (26 loc) · 898 Bytes
/
mining_bitcoin.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
#coding=utf-8
import struct
import binascii
import hashlib
#Block 286819
ver = 2
prev_block = "000000000000000117c80378b8da0e33559b5997f2ad55e2f7d18ec1975b9717"
mrkl_root = "871714dcbae6c8193a2bb9b2a69fe1c0440399f38d94b3a0f1b447275a29978a"
time_ = 1392872245 # 2014-02-20 04:57:25 (1392872245)
bits = 419520339
# https://en.bitcoin.it/wiki/Difficulty
exp = bits >> 24
mant = bits & 0xffffff
target_hexstr = '%064x' % (mant * (1<<(8*(exp - 3))))
target_str = target_hexstr.decode('hex')
nonce = 856000000
while nonce < 0x10000000000:
header = ( struct.pack("<L", ver) + prev_block.decode('hex')[::-1] +
mrkl_root.decode('hex')[::-1] + struct.pack("<LLL", time_,
bits, nonce))
hash = hashlib.sha256(hashlib.sha256(header).digest()).digest()
print nonce, hash[::-1].encode('hex')
if hash[::-1] < target_str:
print 'success'
break
nonce += 1