Update 6_2_Spending_a_Transaction_to_a_Multisig.md

This commit is contained in:
Shannon Appelcline 2017-05-19 14:20:18 -07:00 committed by GitHub
parent 7db6f1e63e
commit 182fca3348

View File

@ -61,9 +61,9 @@ $ recipient=$(bitcoin-cli getrawchangeaddress)
``` ```
## Create Your Transaction ## Create Your Transaction
You can now create your transaction. To do so you add new `inputs` variables for the `scriptPubKey` and the `redeemScript`: You can now create your transaction. This is no different than usual.
``` ```
$ rawtxhex=$(bitcoin-cli -named createrawtransaction inputs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout', "scriptPubKey": "'$utxo_spk'", "redeemScript": "'$redeem_script'" } ]''' outputs='''{ "'$recipient'": 1.299}''') $ rawtxhex=$(bitcoin-cli -named createrawtransaction inputs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout' } ]''' outputs='''{ "'$recipient'": 1.299}''')
``` ```
## Sign Your Transaction ## Sign Your Transaction
@ -81,7 +81,11 @@ cMgb3KM8hPATCtgMKarKMiFesLft6eEw3DY6BB8d97fkeXeqQagw
### Make Your First Signature ### Make Your First Signature
You can now make your first signature with the `signrawtransaction` command. This time you must add two new variables: `prevtxs` should be a list of all the `inputs` from your raw transaction, which can just be cut-and-paste; while `privkeys` should be a list of all the private keys you dumped on this machine. You can now make your first signature with the `signrawtransaction` command. Here's where things are different: you're going to need to coach the command on how to sign. You do these by adding the following new information:
* Include a `prevtxs` argument that includes the `txid`, the `vout`, the `scriptPubKey`, and the `redeemScript` that you recorded, each of them an individual key-value pair in the JSON object.
* Include a `privkeys` argument that lists the private keys you dumped on this machine.
``` ```
machine1$ bitcoin-cli -named signrawtransaction hexstring=$rawtxhex prevtxs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout', "scriptPubKey": "'$utxo_spk'", "redeemScript": "'$redeem_script'" } ]''' privkeys='["cMgb3KM8hPATCtgMKarKMiFesLft6eEw3DY6BB8d97fkeXeqQagw"]' machine1$ bitcoin-cli -named signrawtransaction hexstring=$rawtxhex prevtxs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout', "scriptPubKey": "'$utxo_spk'", "redeemScript": "'$redeem_script'" } ]''' privkeys='["cMgb3KM8hPATCtgMKarKMiFesLft6eEw3DY6BB8d97fkeXeqQagw"]'
{ {
@ -98,7 +102,7 @@ machine1$ bitcoin-cli -named signrawtransaction hexstring=$rawtxhex prevtxs='''[
] ]
} }
``` ```
That produces scary errors and says that it's not `complete`. This is all all correct. You can see that the signature has been partially successfully because the `hex` has gotten longer. The transaction has been partially signed but is not done because it needs more signatures. That produces scary errors and says that it's not `complete`. This is all correct. You can see that the signature has been partially successfully because the `hex` has gotten longer. Though the transaction has been partially signed, it's not done because it needs more signatures.
### Repeat for Other Signers ### Repeat for Other Signers
@ -106,9 +110,7 @@ You can now pass the transaction on, to be signed again by anyone else required
> **M-OF-N VS N-OF-N:** Obviously, if you have an n-of-n signature (like the 2-of-2 multisignature in this example), then everyone has to sign, but if you hae a m-of-n multisignature where "m < n", then the signature will be complete when only some ("m") of the signers have signed. > **M-OF-N VS N-OF-N:** Obviously, if you have an n-of-n signature (like the 2-of-2 multisignature in this example), then everyone has to sign, but if you hae a m-of-n multisignature where "m < n", then the signature will be complete when only some ("m") of the signers have signed.
Each of the signers follow the same procedure. To do so first they access their private keys:
First, they access their private keys:
``` ```
$ bitcoin-cli -named dumpprivkey address=$address2 $ bitcoin-cli -named dumpprivkey address=$address2
cTi1Muvj24vG159R8orFjtqsPygCxhu8mJt2GLDQv7bNBGYoav4B cTi1Muvj24vG159R8orFjtqsPygCxhu8mJt2GLDQv7bNBGYoav4B
@ -121,30 +123,31 @@ $ bitcoin-cli -named signrawtransaction hexstring=020000000128e3b6f901705be0730e
"complete": true "complete": true
} }
``` ```
You'll note that this now says signature is `complete`! Third, they may need to send on the even longer `hexstring` they produce to additional signers.
In this case, we now see that the signature is `complete`!
## Send Your Transaction ## Send Your Transaction
You should now fall back on the standard JQ methodology to save your `hexstring` and then to send it: When done, you should fall back on the standard JQ methodology to save your `hexstring` and then to send it:
``` ```
$ signedtx = $(bitcoin-cli -named signrawtransaction hexstring=020000000128e3b6f901705be0730e8a1345cf893e3cc38f0598e38bc56e9d43ac1ae11b62000000009200483045022100a9fe6ed0dbe14c0c4c7c89cee0aef2770f0b2bdcd6b3e8d71fe91e91c4bb765e02200cfba27a59b584a0cc8e70fb4438be94da417ee77eff28deb70449e012b6d6fa014752210307fd375ed7cced0f50723e3e1a97bbe7ccff7318c815df4e99a59bc94dbcd819210367c4f666f18279009c941e57fab3e42653c6553e5ca092c104d1db279e328a2852aeffffffff01e01dbe07000000001976a914cd1b2ba4fa8ae3e62bc4fc6be467a63228ceeedf88ac00000000 prevtxs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout', "scriptPubKey": "'$utxo_spk'", "redeemScript": "'$redeem_script'" } ]''' privkeys='["cTi1Muvj24vG159R8orFjtqsPygCxhu8mJt2GLDQv7bNBGYoav4B"]' | jq -r '.hex') $ signedtx = $(bitcoin-cli -named signrawtransaction hexstring=020000000128e3b6f901705be0730e8a1345cf893e3cc38f0598e38bc56e9d43ac1ae11b62000000009200483045022100a9fe6ed0dbe14c0c4c7c89cee0aef2770f0b2bdcd6b3e8d71fe91e91c4bb765e02200cfba27a59b584a0cc8e70fb4438be94da417ee77eff28deb70449e012b6d6fa014752210307fd375ed7cced0f50723e3e1a97bbe7ccff7318c815df4e99a59bc94dbcd819210367c4f666f18279009c941e57fab3e42653c6553e5ca092c104d1db279e328a2852aeffffffff01e01dbe07000000001976a914cd1b2ba4fa8ae3e62bc4fc6be467a63228ceeedf88ac00000000 prevtxs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout', "scriptPubKey": "'$utxo_spk'", "redeemScript": "'$redeem_script'" } ]''' privkeys='["cTi1Muvj24vG159R8orFjtqsPygCxhu8mJt2GLDQv7bNBGYoav4B"]' | jq -r '.hex')
user1@blockstream2:~$ bitcoin-cli -named sendrawtransaction hexstring=$signedtx user1@blockstream2:~$ bitcoin-cli -named sendrawtransaction hexstring=$signedtx
99d2b5717fed8875a1ed3b2827dd60ae3089f9caa7c7c23d47635f6f5b397c04 99d2b5717fed8875a1ed3b2827dd60ae3089f9caa7c7c23d47635f6f5b397c04
``` ```
Whew! That took some work, but the multisignature transaction was successfully reused!
## Understand the Importance of This Expanded Signing Methodology ## Understand the Importance of This Expanded Signing Methodology
This took some work, and as you'll soon learn, the foolishness with the private keys, the redeem script, and the scriptpubkey isn't actually required to redeem from multisignature addresses using newer versions of Bitcoin Core. So, what was the point? This took some work, and as you'll soon learn, the foolishness with the private keys, the redeem script, and the scriptpubkey isn't actually required to redeem from multisignature addresses using newer versions of Bitcoin Core. So, what was the point?
This redemption methodology shows a standard methodology for signing and reusing P2SH transactions. In short, your `signrawtransaction` needs to: This redemption methodology shows a standard way to sign and reuse P2SH transactions. In short, to redeem P2SH funds, a `signrawtransaction` needs to:
1. Include the `scriptPubKey`, which explains the P2SH cryptographic puzzle. 1. Include the `scriptPubKey`, which explains the P2SH cryptographic puzzle.
2. Include the `redeemScript`, which solves the P2SH cryptographic puzzle, and introduces a new puzzle of its own. 2. Include the `redeemScript`, which solves the P2SH cryptographic puzzle, and introduces a new puzzle of its own.
3. Be run on each machine holding required signatures. 3. Be run on each machine holding required signatures.
4. Include the relevant signatures, which solve the redeemScript puzzle. 4. Include the relevant signatures, which solve the redeemScript puzzle.
So, here it's offered as a way to redeem multisig funds. In the future you can also use this methodology to redeem funds that were locked with other, more complex P2SH scripts, as explained starting in Chapter 9. Here, we saw this methodology used to redeem multisig funds. In the future you can also use it to redeem funds that were locked with other, more complex P2SH scripts, as explained starting in Chapter 9.
## Summary: Spending a Transaction with a Multisig ## Summary: Spending a Transaction with a Multisig