-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBLOCKCHAIN+DEMO.py
75 lines (35 loc) · 1.3 KB
/
BLOCKCHAIN+DEMO.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
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
72
73
74
# coding: utf-8
# # BLOCKCHAIN DEMO
# ## Class Block to create objects for all the class
# In[176]:
import hashlib
class Block():
def __init__(self,previousHash,transactions):
self.previousHash = previousHash
self.transactions = transactions
def getBlockHash(self):
Hash = hashlib.sha1()
Hash.update(str.encode(self.transactions) + str.encode(self.previousHash))
return Hash.hexdigest()
#def transactions(self):
#print(Block.transactions)
#def previoushash(self):
#print(Block.previousHash)
# In[168]:
GenesysBlock = Block(previousHash="0",transactions = "rohit gives manvi 1000 coins")
# In[169]:
Block_1 = Block(GenesysBlock.getBlockHash(),transactions = "manvi gives rohit 50 coins")
Block_2 = Block(Block_1.getBlockHash(),transactions = "shivam gives manvi 10 coins")
Block_3 = Block(Block_2.getBlockHash(),transactions = "vaibhav gives shivam 50 coins")
Block_4 = Block(Block_3.getBlockHash(),transactions = "rohin gives rohit 20 coins")
Block_5 = Block(Block_4.getBlockHash(),transactions = "raunak gives manvi 90 coins")
# In[170]:
GenesysBlock.getBlockHash()
# In[171]:
Block_1.getBlockHash()
# In[172]:
Block_2.getBlockHash()
# In[173]:
Block_3.getBlockHash()
# In[174]:
Block_4.getBlockHash()