Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.py
More file actions
Latest commit
129 lines (115 loc) · 2.48 KB
/
Copy pathBlock.py
File metadata and controls
129 lines (115 loc) · 2.48 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# global variable
fromClientimportClient
fromMinersimportMiner
fromTransactionimportTransaction
classBlock:
def__init__(self):
self.verified_transactions= []
self.previous_block_hash=""
self.Nonce=""
defdump_blockChain(self):
print("Number of blocks in the chain: "+str(len(self)))
forxinrange(len(TPCoins)):
block_temp=TPCoins[x]
print("block # "+str(x))
fortransactioninblock_temp.verified_transactions:
display_transaction(transaction)
print('--------------')
print('=====================================')
defdisplay_transaction(transaction):
# for transaction in transactions:
dict=transaction.to_dict()
print("sender: "+dict['sender'])
print('-----')
print("recipient: "+dict['recipient'])
print('-----')
print("value: "+str(dict['value']))
print('-----')
print("time: "+str(dict['time']))
print('-----')
# global variable
last_transaction_index=0
transactions= []
last_block_hash=""
TPCoins= []
Dinesh=Client()
Ramesh=Client()
Seema=Client()
Vijay=Client()
t2=Transaction(
Dinesh,
Seema.identity,
6.0
)
t2.sign_transaction()
transactions.append(t2)
t3=Transaction(
Ramesh,
Vijay.identity,
2.0
)
t3.sign_transaction()
transactions.append(t3)
t4=Transaction(
Seema,
Ramesh.identity,
4.0
)
t4.sign_transaction()
transactions.append(t4)
t5=Transaction(
Vijay,
Seema.identity,
7.0
)
t5.sign_transaction()
transactions.append(t5)
t6=Transaction(
Ramesh,
Seema.identity,
3.0
)
t6.sign_transaction()
transactions.append(t6)
t7=Transaction(
Seema,
Dinesh.identity,
8.0
)
t7.sign_transaction()
transactions.append(t7)
t8=Transaction(
Seema,
Ramesh.identity,
1.0
)
t8.sign_transaction()
transactions.append(t8)
t9=Transaction(
Vijay,
Dinesh.identity,
5.0
)
t9.sign_transaction()
transactions.append(t9)
t10=Transaction(
Vijay,
Ramesh.identity,
3.0
)
t10.sign_transaction()
transactions.append(t10)
block=Block()
foriinrange(3):
temp_transaction=transactions[last_transaction_index]
# validate transaction
# if valid
block.verified_transactions.append(temp_transaction)
last_transaction_index+=1
block.previous_block_hash=last_block_hash
miner=Miner()
block.Nonce=miner.main(block, 2)
digest=hash(block)
TPCoins.append(block)
last_block_hash=digest
dump_blockchain(TPCoins)