Beispiel #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
Beispiel #2
0
# adding the block to the blockchain kept by node1, assuming this test is run from the node1's machine
node0 = node.node()
node1 = node.node()
node2 = node.node()
node3 = node.node()
node4 = node.node()

block1 = block.block(9999)	#genesis hash

#transaction 1 in the block sent by node0 with address 1000
t1 = transaction.transaction(0,2)
t1.sign = "sign1"
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