-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashed-block2.py
More file actions
42 lines (36 loc) · 838 Bytes
/
hashed-block2.py
File metadata and controls
42 lines (36 loc) · 838 Bytes
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 hashlib, pickle
top_block = {
'transacion' : [
{
'from' : 'Jace',
'to' : 'Lucky',
'amount' : 10
},
{
'from' : 'Mula',
'to' : 'Jace',
'amount' : 10
},
{
'from' : 'Lucky',
'to' : 'Innocent',
'amount' : 10
},
]
}
pickle.dumps(top_block)
m = hashlib.sha3_256()
m.update(pickle.dumps(top_block))
m.digest()
m.hexdigest()
difficulty = 1
difficulty_string = ''.join(['0' for x in range(difficulty)])
nonce = 1
top_block['nonce'] = nonce
p = hashlib.sha3_256()
while p.hexdigest()[:difficulty] != difficulty_string:
nonce += 1
top_block['nonce'] = nonce
p = hashlib.sha3_256()
p.update(pickle.dumps(top_block))
print(nonce, m.hexdigest())