Update. My implementation has support for decoding multisig transactions but the way I was coming at encoding was - well let's not beat around the bush - completely wrong I'm disappointed to say.
I've gone back to basics and at least now understand where I had misunderstood things. The problem now is that it looks like bitcoind doesn't have sufficient functionality within the rawtransactions API to help me build the transaction. createrawtransaction only takes an array of addresses & values for the outputs so I believe the only thing I'm left with is building the transaction hex completely from scratch - I've burned more hours than I care to admit attempting to figure this out but I'm not making much progress.
I've gone through Tachikoma's source in an attempt to translate logic but that calls on bitcoin-ruby to build the transaction and looking through that (my ruby is non-existent) was making my eyes go square.
In a nutshell let's keep simple - note the below example vout - anyone know of a way this can be constructed using the bitcoind/qt API?
{
"value" : 0.00012000,
"n" : 3,
"scriptPubKey" : {
"asm" : "1 03e6da9c60084b43d28266243c636bcdaf4d8f17b5954e078d2dece7d4659e0dee 020100000000000000020000000007f819a0000000000000000 2 OP_CHECKMULTISIG",
"hex" : "512103e6da9c60084b43d28266243c636bcdaf4d8f17b5954e078d2dece7d4659e0dee210201000 00000000000020000000007f819a000000000000000052ae",
"reqSigs" : 1,
"type" : "multisig",
"addresses" : [
"1HyC1C8oRzoEqnwZnoLRwMXUE2p1y3nsh9",
"1Nb68WTMCNXQ6LbJEyJEGft3ztWwSFcWLE"
]
}
}
Again forgive the newbieness of the question if it comes across that way, I'm learning much of this from scratch.
Thanks!
I thought I should add some further info on my attempts to just create the raw transaction hex from scratch and see if I can get some help there (as I'm fairly confident it can't be done with the bitcoind/qt API and thus I doubt I'll get much of a response to that part).
I just can't seem to get my head around how to build it as a multisig transaction.
If we take the following transaction I've manually constructed for example:
0100000001a1a7ca5f86c8c5c1bdc367570b8714a75e4800cc97de5a0f47abb208a7eabd7f0100000000ffffffff03204e0000000000001976a914dd84a40b985e9cb1d6cff0a3ba810fb4bf74e23e88ac204e0000000000001976a914946cb2e08075bcbaf157e47bcb67eb2b2339d24288ac204e00000000000049010121021bfc32c40f01efd61535cae8b297257e536b140ee6c727f576698e70d24cf57521020100000000000000020000000007f819a00000000000000000000000000000000102ae00000000
This decodes to:
{
"txid" : "869f499746deb77019df8b9aedbaaa0fbdfb1317e0d5387c412fe3160bb89b81",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "7fbdeaa708b2ab470f5ade97cc00485ea714870b5767c3bdc1c5c8865fcaa7a1",
"vout" : 1,
"scriptSig" : {
"asm" : "",
"hex" : ""
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.00020000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 dd84a40b985e9cb1d6cff0a3ba810fb4bf74e23e OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914dd84a40b985e9cb1d6cff0a3ba810fb4bf74e23e88ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"1MCHESTptvd2LnNp7wmr2sGTpRomteAkq8"
]
}
},
{
"value" : 0.00020000,
"n" : 1,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 946cb2e08075bcbaf157e47bcb67eb2b2339d242 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914946cb2e08075bcbaf157e47bcb67eb2b2339d24288ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P"
]
}
},
{
"value" : 0.00020000,
"n" : 2,
"scriptPubKey" : {
"asm" : "1 021bfc32c40f01efd61535cae8b297257e536b140ee6c727f576698e70d24cf575 020100000000000000020000000007f819a0000000000000000000000000000000 2 OP_CHECKMULTISIG",
"hex" : "010121021bfc32c40f01efd61535cae8b297257e536b140ee6c727f576698e70d24cf57521020100000000000000020000000007f819a00000000000000000000000000000000102ae",
"type" : "nonstandard"
}
}
]
}
As you can see the last vout is a nonstandard tx type (not "multisig") and has no reqSigs value. I've obviously made a mess of building the transaction hex for the multisig part (vin & the other basic vouts are easy). Would anyone care to help out and let me know where I've gone wrong?
Thanks again
EDIT: Tachikoma I can't seem to get your code running to compare our transaction hex before signing:
Getting private key and public key for Mastercoin address
Getting raw transaction data
Found raw transaction; unpacking into tx
Setting fees
Total amount available from input: 0.06968
Paying 0.0001 network fees
Taking 0.00024 out of total for each mastercoin output
Sending 0.06934 back to mastercoin address
Using public key for data: 02010000000000000002000000003b9aca00000000000000000000000000000000
./wallet.rb:90:in `build_transaction': undefined method `build_tx' for # (NoMethodError)
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
from ./wallet.rb:169:in `'