Ejemplo n.º 1
0
	def test_TCDList(self):
		"Test the TCD list serialization"

		TCDlist = \
		[
		tcd.TCD(1, 2, 7, 'a'*20, 'b'*20, 'c'*20),
		tcd.TCD(3, 4, 8, 'd'*20, 'e'*20, 'f'*20),
		tcd.TCD(5, 6, 9, 'g'*20, 'h'*20, 'i'*20)
		]

		data = tcd.serializeList(TCDlist)
		self.assertEqual(data,
			TCDlist[0].serialize() +
			TCDlist[1].serialize() +
			TCDlist[2].serialize()
			)

		TCDlist2 = tcd.deserializeList(data)
		self.assertEqual(len(TCDlist2), 3)
		for i in range(3):
			self.assertEqual(TCDlist2[i].startTime, TCDlist[i].startTime)
			self.assertEqual(TCDlist2[i].endTime, TCDlist[i].endTime)
			self.assertEqual(TCDlist2[i].amount, TCDlist[i].amount)
			self.assertEqual(TCDlist2[i].tokenHash, TCDlist[i].tokenHash)
			self.assertEqual(TCDlist2[i].commitAddress, TCDlist[i].commitAddress)
			self.assertEqual(TCDlist2[i].rollbackAddress, TCDlist[i].rollbackAddress)

		self.assertRaises(Exception, tcd.deserializeList, data[:-1])
		self.assertRaises(Exception, tcd.deserializeList, data + '\x00')
Ejemplo n.º 2
0
print
WID = raw_input("Enter the withdraw transaction ID: ")
W = bitcoind.getTransaction(WID)

if W["confirmations"] < 6:
	print "Error: number of confirmations is %d < 6" % W["confirmations"]
	sys.exit()

W = binascii.unhexlify(W["hex"])
W = bitcointransaction.Transaction.deserialize(W)

#print "Reconstructed ID:", W.getTransactionID()[::-1].encode("hex")

#Ask for serialized list of TCDs (maybe get this from a file)
TCDlist_serialized = raw_input("Enter the serialized TCD list: ")
TCDlist = tcd.deserializeList(TCDlist_serialized)

#Check presence of list hash in W
listHash = crypto.RIPEMD160(crypto.SHA256(TCDlist_serialized))
#TODO

#TODO:
#Ask for index to be resolved
#Check whether W's output has our public key on it

#De-serialize TCD
#Get start(!) and end timestamps and token hash
#Check that end > start and last existing block time >> end
#Search in block range for token -> determine commit condition

#Make transaction