def test_makeSpendMultiSigTransaction(self): "Test the makeSpendMultiSigTransaction function" with DummyTransaction(): tx = bitcoinutils.makeSpendMultiSigTransaction( "txid", 4, 40, "toHash", 3) self.assertEqual(len(tx.trace), 1) #Constructor, with tx_in and tx_out: self.assertEqual(tx.trace[0][0], "__init__") self.assertEqual(tx.trace[0][1], tuple()) self.assertEqual(len(tx.trace[0][2]), 2) self.assertEqual(len(tx.trace[0][2]["tx_in"]), 1) self.assertEqual(len(tx.trace[0][2]["tx_out"]), 1) tx_in = tx.trace[0][2]["tx_in"][0] self.assertEqual(tx_in.trace, [('__init__', ('txid', 4), {})]) tx_out = tx.trace[0][2]["tx_out"][0] self.assertEqual(len(tx_out.trace), 1) self.assertEqual(tx_out.trace[0][0], "__init__") self.assertEqual(len(tx_out.trace[0][1]), 2) self.assertEqual(tx_out.trace[0][1][0], 37) script = tx_out.trace[0][1][1] self.assertEqual(script.elements, (OP.DUP, OP.HASH160, "toHash", OP.EQUALVERIFY, OP.CHECKSIG))
def test_makeSpendMultiSigTransaction(self): "Test the makeSpendMultiSigTransaction function" with DummyTransaction(): tx = bitcoinutils.makeSpendMultiSigTransaction( "txid", 4, 40, "toHash", 3) self.assertEqual(len(tx.trace), 1) #Constructor, with tx_in and tx_out: self.assertEqual(tx.trace[0][0], "__init__") self.assertEqual(tx.trace[0][1], tuple()) self.assertEqual(len(tx.trace[0][2]), 2) self.assertEqual(len(tx.trace[0][2]["tx_in"]), 1) self.assertEqual(len(tx.trace[0][2]["tx_out"]), 1) tx_in = tx.trace[0][2]["tx_in"][0] self.assertEqual(tx_in.trace, [('__init__', ('txid', 4), {})]) tx_out = tx.trace[0][2]["tx_out"][0] self.assertEqual(len(tx_out.trace), 1) self.assertEqual(tx_out.trace[0][0], "__init__") self.assertEqual(len(tx_out.trace[0][1]), 2) self.assertEqual(tx_out.trace[0][1][0], 37) script = tx_out.trace[0][1][1] self.assertEqual( script.elements, (OP.DUP, OP.HASH160, "toHash", OP.EQUALVERIFY, OP.CHECKSIG))
amount = int(100000 * float(raw_input("Amount to be transferred (mBTC): "))) fee = 10000 #0.1 mBTC outputHash = binascii.unhexlify(raw_input("Input hash (empty: create multisig): "))[::-1] if outputHash == "": tx = sendToMultiSigPubKey(d, amount, key1.getPublicKey(), key2.getPublicKey(), keyHash2, fee=fee) else: outputIndex = 0 tx = makeSpendMultiSigTransaction(outputHash, outputIndex, amount, keyHash1, fee) sig1 = signMultiSigTransaction( tx, outputIndex, [key1.getPublicKey(), key2.getPublicKey()], key1) sig2 = signMultiSigTransaction( tx, outputIndex, [key1.getPublicKey(), key2.getPublicKey()], key2) applyMultiSigSignatures(tx, sig1, sig2) print "Tx:", tx.serialize().encode("hex") print "Tx ID:", tx.getTransactionID()[::-1].encode("hex") tx_s = tx.serialize() #d.sendRawTransaction(tx_s)