Created
August 2, 2016 07:54
-
-
Save muzhig/1d94b659c5a0d76bdd63f4a694d8187d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bitcoinrpc.connection import BitcoinConnection | |
con = BitcoinConnection(host='127.0.0.1', port=18332, user='u', password='p') | |
destination_addr = 'mh5YsB8cSLT2NxLKkdaZANBqhLSDgMFgGj' | |
num_signatures = 2 | |
signer_addr = 'mfcWQhBtWGPcSBPiPDeUJZ5n1Ud7XF2hSK' | |
additional_signer_addr = 'mr37a4xtZZByapa9neEPC3oYLxbEaFyCkP' | |
amount = 20.0 | |
fees = 5e-5 | |
multisig = con.proxy.createmultisig( | |
num_signatures, | |
[signer_addr, additional_signer_addr, con.validateaddress(destination_addr).pubkey] | |
) | |
UTX0_txid = con.sendtoaddress(multisig[u'address'], amount) | |
raw = con.getrawtransaction(UTX0_txid) | |
print raw.vout | |
# [{u'scriptPubKey': {u'reqSigs': 1, u'hex': u'76a9146fc86f9c973a9b9391627f30f63cc0e2c192105a88ac', u'addresses': [u'mqi1QtCCDb6FCa8fWXLQwMYEpYQD4fVpy1'], u'asm': u'OP_DUP OP_HASH160 6fc86f9c973a9b9391627f30f63cc0e2c192105a OP_EQUALVERIFY OP_CHECKSIG', u'type': u'pubkeyhash'}, u'value': Decimal('28.99991680'), u'n': 0}, {u'scriptPubKey': {u'reqSigs': 1, u'hex': u'a914489dc590a651425da845d81e66f23fc5cd4b04f487', u'addresses': [u'2MysBeGWqqewwYGTtBt19cQ3DZQ7aTkMCFZ'], u'asm': u'OP_HASH160 489dc590a651425da845d81e66f23fc5cd4b04f4 OP_EQUAL', u'type': u'scripthash'}, u'value': Decimal('20.00000000'), u'n': 1}] | |
for UTX0_vout, vout in enumerate(raw.vout): | |
if vout['scriptPubKey']['addresses'] == [multisig[u'address']]: | |
UTX0_scriptPubKey = vout['scriptPubKey']['hex'] | |
break | |
else: | |
raise ValueError('valid vout not found') | |
print UTX0_vout | |
print UTX0_scriptPubKey | |
withdraw_tx = con.createrawtransaction( | |
[{"txid": UTX0_txid, "vout": UTX0_vout}], | |
{destination_addr: amount - fees} | |
) | |
print withdraw_tx | |
partially_signed_tx = con.signrawtransaction( | |
withdraw_tx, | |
[{"txid": UTX0_txid, "vout": UTX0_vout, 'scriptPubKey': UTX0_scriptPubKey, 'redeemScript': multisig['redeemScript']}], | |
[con.proxy.dumpprivkey(signer_addr)] | |
) | |
print partially_signed_tx | |
finally_signed = con.signrawtransaction( | |
partially_signed_tx['hex'], | |
[{"txid": UTX0_txid, "vout": UTX0_vout, 'scriptPubKey': UTX0_scriptPubKey, 'redeemScript': multisig['redeemScript']}], | |
[con.proxy.dumpprivkey(destination_addr)] | |
) | |
print finally_signed | |
sent = con.proxy.sendrawtransaction(finally_signed['hex']) | |
print sent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment