예제 #1
0
def filetoblock(filename) :				
	f = open(filename, 'r')
	prevhash = readword(f.readline())
	B = block(prevhash)
	B.max_trans_num = int(readword(f.readline()))
	B.nonce = int(readword(f.readline()))
	#B.translist = [transaction.transaction(0,0) for i in range (B.max_trans_num)] 	
	for i in range(B.max_trans_num) :		
		incount = int(readword(f.readline()))
		outcount = int(readword(f.readline()))
		T = transaction.transaction(incount,outcount)
		T.inlist = [transaction.inputtrans() for i1 in range (T.incount)]	#Create an array of type inlist[incount]
		T.sign = readword(f.readline())
		T.hash = readword(f.readline())
		for j in range(T.incount) :	# iterating through each input and adding them to the transaction's inlist
			I = transaction.inputtrans()
			I.hash = readword(f.readline())
			I.n = readword(f.readline())
			I.sign = readword(f.readline())
			I.pub = readword(f.readline())
			T.inlist[j] = I
	
		T.outlist = [transaction.outputtrans() for i2 in range (T.outcount)]	   #Create an array of type outlist[outcount] 
		for j in range(T.outcount) :	# iterating through each output and adding them to the transaction's outlist
			O = transaction.outputtrans()
			O.value = int(readword(f.readline()))
			O.addr = readword(f.readline())
			T.outlist[j] = O
	 	B.translist[i] = T	# adding the transaction to the block's translist
	return B
예제 #2
0
t1.hash = 12341
# no input trans but has two outputs
t1.outlist = [transaction.outputtrans() for i in range (t1.outcount)]
t1.outlist[0].value = 1
t1.outlist[0].addr = node1.publickey
t1.outlist[1].value = 19
t1.outlist[1].addr = node0.publickey
# adding trans1 to the block
block1.translist[0] = t1

#transaction 2 in the block sent by node0 with address 1000
t1 = transaction.transaction(1,2)
t1.sign = "sign2"
t1.hash = 12342
# input trans
t1.inlist = [transaction.inputtrans() for i in range (t1.incount)]
t1.inlist[0].hash = 12341
t1.inlist[0].n = 1
t1.inlist[0].sign = "signofnode0"
t1.inlist[0].pub = node0.publickey	# public key of node 0
# output trans
t1.outlist = [transaction.outputtrans() for i in range (t1.outcount)]
t1.outlist[0].value = 2
t1.outlist[0].addr = node2.publickey
t1.outlist[1].value = 17
t1.outlist[1].addr = node0.publickey
# adding trans1 to the block
block1.translist[1] = t1

#transaction 3 in the block sent by node0 with address 1000
t1 = transaction.transaction(1,2)