Exemple #1
0
def makeSpendMultiSigTransaction(outputHash, outputIndex, amount, toHash, fee):
    """
	Make an (non-signed) transaction to send funds from a 2-of-2 multi-signature
	output to a standard Bitcoin scriptPubKey ("send to Bitcoin address").
	The transaction is returned, and is NOT published on the Bitcoin network by
	this function.

	Arguments:
	outputHash: str; the transaction ID of the previous output transaction
	            Note that the byte order is the reverse as shown in Bitcoin.
	outputIndex: int; the index of the output in the previous output transaction
	amount: int; the amount to be sent, including the fee (in Satoshi).
	        This must be equal to the amount in the input.
	toHash: str; the SHA256- and RIPEMD160-hashed public key of the receiver
	        (equivalent to the bitcoin address)
	fee: int; the transaction fee (in Satoshi)

	Return value:
	Transaction; the transaction that sends funds as specified.
	"""

    tx = Transaction(
        tx_in=[TxIn(outputHash, outputIndex)],
        tx_out=[TxOut(amount - fee, Script.standardPubKey(toHash))])

    return tx
def sendToMultiSigPubKey(bitcoind, amount, toPubKey1, toPubKey2, changeHash, fee):
	"""
	Make a transaction to send funds from ourself to a 2-of-2 multi-signature
	scriptPubKey. The transaction is returned, and is NOT published on the
	Bitcoin network by this function.

	Arguments:
	bitcoind: Bitcoind; the bitcoin daemon from which to retrieve this information
	amount: int; the amount to be sent, not including the fee (in Satoshi)
	toPubKey1: str; the first public key
	toPubKey2: str; the second public key
	changeHash: str; the SHA256- and RIPEMD160-hashed public key to which any
	            change should be sent (equivalent to the bitcoin address)
	fee: int; the transaction fee (in Satoshi)

	Return value:
	Transaction; the transaction that sends funds as specified.

	Exceptions:
	Exception: insufficient funds
	"""

	totalIn, inputs = getInputsForAmount(bitcoind, amount+fee)
	change = totalIn - fee - amount

	#print "%d -> %d, %d, %d" % (totalIn, amount, change, fee)

	tx = Transaction(
		tx_in = [
			TxIn(x[0], x[1])
			for x in inputs
			],
		tx_out = [
			TxOut(amount, Script.multiSigPubKey([toPubKey1, toPubKey2])),
			TxOut(change, Script.standardPubKey(changeHash))
			]
		)

	for i in range(len(inputs)):
		scriptPubKey = Script.deserialize(inputs[i][2])
		key = Key()
		key.setPrivateKey(inputs[i][3])
		tx.signInput(i, scriptPubKey, [None, key.getPublicKey()], [key])

	return tx
def sendToDataPubKey(bitcoind, data, changeHash, fee):
	"""
	Make a transaction to publish data on the block chain with an OP_RETURN
	output. No funds are sent to the OP_RETURN output: everything goes to fee
	and to the change address. The transaction is returned, and
	is NOT published on the Bitcoin network by this function.

	Arguments:
	bitcoind: Bitcoind; the bitcoin daemon from which to retrieve this information
	data: str; the data to be included in the scriptPubKey (max. 40 bytes)
	changeHash: str; the SHA256- and RIPEMD160-hashed public key to which any
	            change should be sent (equivalent to the bitcoin address)
	fee: int; the transaction fee (in Satoshi)

	Return value:
	Transaction; the transaction that sends funds as specified.

	Exceptions:
	Exception: insufficient funds
	"""

	totalIn, inputs = getInputsForAmount(bitcoind, fee)
	change = totalIn - fee

	print "%d -> %d, %d" % (totalIn, change, fee)

	tx = Transaction(
		tx_in = [
			TxIn(x[0], x[1])
			for x in inputs
			],
		tx_out = [
			TxOut(0, Script.dataPubKey(data)),
			TxOut(change, Script.standardPubKey(changeHash))
			]
		)

	for i in range(len(inputs)):
		scriptPubKey = Script.deserialize(inputs[i][2])
		key = Key()
		key.setPrivateKey(inputs[i][3])
		tx.signInput(i, scriptPubKey, [None, key.getPublicKey()], [key])

	return tx
Exemple #4
0
def sendToMultiSigPubKey(bitcoind, amount, toPubKey1, toPubKey2, changeHash,
                         fee):
    """
	Make a transaction to send funds from ourself to a 2-of-2 multi-signature
	scriptPubKey. The transaction is returned, and is NOT published on the
	Bitcoin network by this function.

	Arguments:
	bitcoind: Bitcoind; the bitcoin daemon from which to retrieve this information
	amount: int; the amount to be sent, not including the fee (in Satoshi)
	toPubKey1: str; the first public key
	toPubKey2: str; the second public key
	changeHash: str; the SHA256- and RIPEMD160-hashed public key to which any
	            change should be sent (equivalent to the bitcoin address)
	fee: int; the transaction fee (in Satoshi)

	Return value:
	Transaction; the transaction that sends funds as specified.

	Exceptions:
	Exception: insufficient funds
	"""

    totalIn, inputs = getInputsForAmount(bitcoind, amount + fee)
    change = totalIn - fee - amount

    #print "%d -> %d, %d, %d" % (totalIn, amount, change, fee)

    tx = Transaction(tx_in=[TxIn(x[0], x[1]) for x in inputs],
                     tx_out=[
                         TxOut(amount,
                               Script.multiSigPubKey([toPubKey1, toPubKey2])),
                         TxOut(change, Script.standardPubKey(changeHash))
                     ])

    for i in range(len(inputs)):
        scriptPubKey = Script.deserialize(inputs[i][2])
        key = Key()
        key.setPrivateKey(inputs[i][3])
        tx.signInput(i, scriptPubKey, [None, key.getPublicKey()], [key])

    return tx
Exemple #5
0
def sendToDataPubKey(bitcoind, data, changeHash, fee):
    """
	Make a transaction to publish data on the block chain with an OP_RETURN
	output. No funds are sent to the OP_RETURN output: everything goes to fee
	and to the change address. The transaction is returned, and
	is NOT published on the Bitcoin network by this function.

	Arguments:
	bitcoind: Bitcoind; the bitcoin daemon from which to retrieve this information
	data: str; the data to be included in the scriptPubKey (max. 40 bytes)
	changeHash: str; the SHA256- and RIPEMD160-hashed public key to which any
	            change should be sent (equivalent to the bitcoin address)
	fee: int; the transaction fee (in Satoshi)

	Return value:
	Transaction; the transaction that sends funds as specified.

	Exceptions:
	Exception: insufficient funds
	"""

    totalIn, inputs = getInputsForAmount(bitcoind, fee)
    change = totalIn - fee

    print "%d -> %d, %d" % (totalIn, change, fee)

    tx = Transaction(tx_in=[TxIn(x[0], x[1]) for x in inputs],
                     tx_out=[
                         TxOut(0, Script.dataPubKey(data)),
                         TxOut(change, Script.standardPubKey(changeHash))
                     ])

    for i in range(len(inputs)):
        scriptPubKey = Script.deserialize(inputs[i][2])
        key = Key()
        key.setPrivateKey(inputs[i][3])
        tx.signInput(i, scriptPubKey, [None, key.getPublicKey()], [key])

    return tx