/
validateproposeblock.py
116 lines (102 loc) · 3.14 KB
/
validateproposeblock.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
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
import transaction
import createnode
import proof_of_work
import block
import treestruct
# teacher1 -> student1 == 10
t = transaction.transaction(1,2)
t.sign = "teacher1sign"
t.hash = 12346
t.inlist[0].hash = "100"
t.inlist[0].n = 0
t.inlist[0].sign = "signghf"
t.inlist[0].pub = createnode.teacher1publickey
t.outlist[0].value = 10
t.outlist[0].addr = createnode.student1publickey
t.outlist[1].value = 90
t.outlist[1].addr = createnode.teacher1publickey
createnode.i_am.currentblock.add_trans_to_block(t)
# teacher2 -> student2 == 10
t = transaction.transaction(1,2)
t.sign = "teacher2sign"
t.hash = 12347
t.inlist[0].hash = "101"
t.inlist[0].n = 0
t.inlist[0].sign = "signghf"
t.inlist[0].pub = createnode.teacher2publickey
t.outlist[0].value = 10
t.outlist[0].addr = createnode.student2publickey
t.outlist[1].value = 90
t.outlist[1].addr = createnode.teacher2publickey
createnode.i_am.currentblock.add_trans_to_block(t)
# teacher3 -> student3 == 10
t = transaction.transaction(1,2)
t.sign = "teacher3sign"
t.hash = 12348
t.inlist[0].hash = "102"
t.inlist[0].n = 0
t.inlist[0].sign = "signghf"
t.inlist[0].pub = createnode.teacher3publickey
t.outlist[0].value = 10
t.outlist[0].addr = createnode.student3publickey
t.outlist[1].value = 90
t.outlist[1].addr = createnode.teacher3publickey
createnode.i_am.currentblock.add_trans_to_block(t)
# teacher4 -> student4 == 10
t = transaction.transaction(1,2)
t.sign = "teacher4sign"
t.hash = 12349
t.inlist[0].hash = "103"
t.inlist[0].n = 0
t.inlist[0].sign = "signghf"
t.inlist[0].pub = createnode.teacher4publickey
t.outlist[0].value = 10
t.outlist[0].addr = createnode.student4publickey
t.outlist[1].value = 90
t.outlist[1].addr = createnode.teacher4publickey
createnode.i_am.currentblock.add_trans_to_block(t)
# teacher5 -> student5 == 10
t = transaction.transaction(1,2)
t.sign = "teacher5sign"
t.hash = 12350
t.inlist[0].hash = "104"
t.inlist[0].n = 0
t.inlist[0].sign = "signghf"
t.inlist[0].pub = createnode.teacher5publickey
t.outlist[0].value = 10
t.outlist[0].addr = createnode.student5publickey
t.outlist[1].value = 90
t.outlist[1].addr = createnode.teacher5publickey
createnode.i_am.currentblock.add_trans_to_block(t)
#####################
for i in range(block.MAXTRANS) :
if createnode.i_am.currentblock.translist[i].hash == None:
print ""
print "not yet...."
break
# else we need to propose the current block after solving proof of work
proof_of_work.proofofwork(createnode.i_am.currentblock)
print ""
print "Proof of work has been solved!"
# convert the current block to file
block.blocktofile(createnode.i_am.currentblock,"blocktopropose.txt")
print ""
print "Current block is ready to be proposed!"
#####################
# to attach the block to the blockchain
treestruct.addblock(createnode.i_am.currentblock, createnode.i_am)
'''
t = transaction.transaction(1,2)
t.sign = "teacher1sign"
t.hash = 12360
t.inlist[0].hash = "12350"
t.inlist[0].n = 0
t.inlist[0].sign = "signghf"
t.inlist[0].pub = createnode.student5publickey
t.outlist[0].value = 4
t.outlist[0].addr = createnode.student5publickey
t.outlist[1].value = 6
t.outlist[1].addr = createnode.student3publickey
result = t.validatetrans(createnode.i_am)
#####################
'''