I'm experimenting with multisig in clams. The first part worked (creating a p2sh and sending clams to it), but the second part (spending the funds) didn't do what I expected. I found a workaround, but it's possible there's a bug in signrawtransaction. Or I made a mistake, of course. Here's more detail:
1. I used "addmultisigaddress" and created a 2-of-2 address: 6WnV4Jhe7iNQLDekwr31h9zeoK1eaDMjAw
2. I sent 0.1 clams there (small enough that it's OK if I lose it). It's txout 0 of the transaction 21db92347e153a6afdddca7f96d444d81d7daa19674ed3101e50de72cb387b19. khashier shows this transaction, but is confused by the multisig address.
3. I used "createrawtransaction" to create an unsigned tx spending this back one of my ordinary addresses.
I had one private key in my wallet and the other on paper. Using "signrawtransaction" it would sign with the one in the wallet, as expected. But then if I tried to sign with "signrawtransaction" giving the other private key explicitly in the command line, it failed. (By "failed" I mean the partially signed transaction wasn't changed.)
I can reproduce the exact same behaviour. I'll investigate, and fix it if possible. It seems to not be using the private key provided in the signtransaction RPC call.
Thanks for the report.
The problem seems to be related to the fact that signrawtransaction decides whether to use information from the wallet, or from the RPC command arguments. It won't use both.
Here's an example where I make a transaction with two simple inputs. One's private key is in the wallet, and the other's is provided in the RPC command. signrawtransaction is unable to sign it fully:
$ cc signrawtransaction $(cc createrawtransaction '[{"txid":"dddf6ac41c281317aed6445196fc14db712f0cc5812880e45eb8e534ebffd8de","vout":0},{"txid":"5bbe0ca12578cb520266178b2d6413eb2597bc251e7343b03a9d42b8733ea961","vout":0}]' '{"xJDCLAMZtRD72TC31E8SJ4a6ycFtnQyuDH":0.1}') '[]' '["'$privkey'"]' | grep complete
"complete" : false
But if I call signrawtransaction twice, once providing the private key on the command line and once not, it is successful:
$ cc signrawtransaction $(cc signrawtransaction $(cc createrawtransaction '[{"txid":"dddf6ac41c281317aed6445196fc14db712f0cc5812880e45eb8e534ebffd8de","vout":0},{"txid":"5bbe0ca12578cb520266178b2d6413eb2597bc251e7343b03a9d42b8733ea961","vout":0}]' '{"xJDCLAMZtRD72TC31E8SJ4a6ycFtnQyuDH":0.1}') | grep hex | cut -d'"' -f4) '[]' '["'$privkey'"]' | grep complete
"complete" : true
Edit2: here I'm able to sign a transaction spending a multisig input (2 of 2) where one key is in the wallet and the other is in $privkey. I had to provide the scriptPubKey which isn't easy to get hold of:
$ cc signrawtransaction $(cc signrawtransaction $(cc createrawtransaction '[{"txid":"2db3324af1b8e5db5ec92b85ec68226e7b17664bdff34c8e73d303c6f7011907","vout":1}]' '{"xJDCLAMZtRD72TC31E8SJ4a6ycFtnQyuDH":0.1}') | grep hex | cut -d'"' -f4) '[{"txid":"2db3324af1b8e5db5ec92b85ec68226e7b17664bdff34c8e73d303c6f7011907","vout":1,"scriptPubKey":"a914810721c3f1790b5668dcd776d2df728cb9103b8f87","redeemScript":"522103145dbd6986ff283b26d88efc2d366ee3437e64fab8c084bc766bec0b5fc41a692103fb6c6 11bf45051b192077632d79b2201577231480165c8ecb45b34c4058e530b52ae"}]' '["'$privkey'"]' | grep complete
"complete" : true
To get the scriptPubKey, I started with the multisig address, 6SA5Wh49HnS12U3zZLvYGdFb9kDXUGx7ye, and did this:
$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append("/home/chris/Programs/python-bitcoinlib/") # from https://github.com/jgarzik/python-bitcoinlib.git
>>> import bitcoin.base58
>>> import binascii
>>> 'a9' + '14' + binascii.hexlify(bitcoin.base58.decode("6SA5Wh49HnS12U3zZLvYGdFb9kDXUGx7ye")[1:-4]) + '87'
'a914810721c3f1790b5668dcd776d2df728cb9103b8f87'
>>> 0xa9 is OP_HASH160
0x14 is 20, the length of the script hash in bytes
0x87 is OP_EQUAL
The redeemScript is from here:
$ cc validateaddress 6SA5Wh49HnS12U3zZLvYGdFb9kDXUGx7ye | grep hex
"hex" : "522103145dbd6986ff283b26d88efc2d366ee3437e64fab8c084bc766bec0b5fc41a692103fb6c6 11bf45051b192077632d79b2201577231480165c8ecb45b34c4058e530b52ae",
I made a pull request to fix this issue:
https://github.com/nochowderforyou/clams/pull/194Now I can sign a 2-of-2 transaction without having to look up the scriptPubKey or the redeemScript for the multisig address:
$ cc signrawtransaction $(cc signrawtransaction $(cc createrawtransaction '[{"txid":"2db3324af1b8e5db5ec92b85ec68226e7b17664bdff34c8e73d303c6f7011907","vout":1}]' '{"xJDCLAMZtRD72TC31E8SJ4a6ycFtnQyuDH":0.1}') | grep hex | cut -d'"' -f4) '[]' '["'$privkey'"]' | grep complete
"complete" : true
I do still need to run signrawtransaction twice, since it will still only take private keys from EITHER the wallet OR the RPC parameters, not both at the same time.
Edit3:
I thought I made this edit yesterday, but I don't see it now, so I'll make it again...I made a better pull request which lets signrawtransaction use all available private keys and multisig scripts:
https://github.com/nochowderforyou/clams/pull/195I also tagged a new release:
https://github.com/nochowderforyou/clams/releases/tag/v1.4.12And so now you can sign your 2-of-2 multisig transaction all at once, using 1 key from the wallet and one in WIF:
$ cc signrawtransaction $(cc createrawtransaction '[{"txid":"2db3324af1b8e5db5ec92b85ec68226e7b17664bdff34c8e73d303c6f7011907","vout":1}]' '{"xJDCLAMZtRD72TC31E8SJ4a6ycFtnQyuDH":0.1}') '[]' '["'$privkey'"]' | grep complete
"complete" : true