From 74f58fe4f762ccc7ac3f3672cf463164483de6d6 Mon Sep 17 00:00:00 2001 From: wintercooled Date: Thu, 22 Mar 2018 13:39:10 +0000 Subject: [PATCH 01/10] Update 04_1_Sending_Coins_The_Easy_Way.md Fixed minor typos --- 04_1_Sending_Coins_The_Easy_Way.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/04_1_Sending_Coins_The_Easy_Way.md b/04_1_Sending_Coins_The_Easy_Way.md index 577ddad..cd18e38 100644 --- a/04_1_Sending_Coins_The_Easy_Way.md +++ b/04_1_Sending_Coins_The_Easy_Way.md @@ -76,7 +76,7 @@ $ bitcoin-cli gettransaction $txid "hex": "0200000001a8b61dba544525ad267644cb78f07c1ba58586ff9089aec3ac24d8764dc21dfb000000006a47304402204c38c2530d3283200e4fd3b2d22e609fc6dc941fd3ac4bc8b73ad5a86607e723022050056ae6cfc3233fb38459a6fd5e63d54e4c85e17b91d66fb915e3977a1c77dd0121027a313901f2ac34c87761513cabe69ca9ca61e2db3c7e6f89d7eccd7fc0a5917cfeffffff0280969800000000001976a914e7c1345fc8f87c68170b3aa798a956c2fe6a9eff88ac4082820b000000001976a914a091d978794d50e5caa3e5454cc8633240640d6688aca6de1000" } ``` -You can see now only the amount transferred (.1 BtC) but also a transaction fee (.000226 BTC), which is about a quarter of the .001 BC/kB minimum fee that was set, which suggests that the transaction was about a quarter of a kB in size. +You can see not only the amount transferred (.1 BTC) but also a transaction fee (.000226 BTC), which is about a quarter of the .001 BC/kB minimum fee that was set, which suggests that the transaction was about a quarter of a kB in size. While you are waiting for this transaction to clear, you'll note that `bitcoin-cli getbalance` shows that all of your money is gone (or, at least, all of your money from a single incoming transaction). Similarly, `bitcoin-cli listunspent` would show an appropriately sized blob of incoming money was gone. There's a reason for this: whenever you get money in, you have to send it _all_ out together, and you have to perform some gymnastics if you actually want to keep some of it! Once again, `sendtoaddress` takes care of this all for you, which means you don't have to worry about it in full until you use a raw transaction to send out money. From 034dc365cfc4fa5fe43cf843690aa57ce6a84bae Mon Sep 17 00:00:00 2001 From: wintercooled Date: Thu, 22 Mar 2018 13:56:01 +0000 Subject: [PATCH 02/10] Update 04_2_Creating_a_Raw_Transaction.md Fixed minor typo --- 04_2_Creating_a_Raw_Transaction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/04_2_Creating_a_Raw_Transaction.md b/04_2_Creating_a_Raw_Transaction.md index 310aff6..abfee35 100644 --- a/04_2_Creating_a_Raw_Transaction.md +++ b/04_2_Creating_a_Raw_Transaction.md @@ -2,7 +2,7 @@ > **NOTE:** This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning. -You're now ready to create Bitcoin raw transactions. This allows you to send money but to craft the transactions precisely as you want. This first section focuses on a simple one-input, one-output transaction. This sort of transaction _isn't_ actually that useful, because you're rarely going to want to send all of your money to one person (unless you're actually just forwarding it on, such as if you're moving things from one wallet to another). Thus, we don't label this section as a way to send money. It's just a foundational stepping stone to _actually_ sending money with a raw transaction. +You're now ready to create Bitcoin raw transactions. This allows you to send money but to craft the transactions as precisely as you want. This first section focuses on a simple one-input, one-output transaction. This sort of transaction _isn't_ actually that useful, because you're rarely going to want to send all of your money to one person (unless you're actually just forwarding it on, such as if you're moving things from one wallet to another). Thus, we don't label this section as a way to send money. It's just a foundational stepping stone to _actually_ sending money with a raw transaction. ## Understand the Bitcoin Transaction From 8602b7b71d98d59610719428c591c8769660a790 Mon Sep 17 00:00:00 2001 From: wintercooled Date: Thu, 22 Mar 2018 14:22:19 +0000 Subject: [PATCH 03/10] Update 04_2__Interlude_Using_JQ.md Fixed minor typos --- 04_2__Interlude_Using_JQ.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/04_2__Interlude_Using_JQ.md b/04_2__Interlude_Using_JQ.md index 1f42b7b..12d5348 100644 --- a/04_2__Interlude_Using_JQ.md +++ b/04_2__Interlude_Using_JQ.md @@ -362,12 +362,12 @@ Whew! **Usage Example:** _Calculate the fee for a transaction._ -To figure out the complete transaction fee at this point just requires one more bit of math: determining out how much money is going through the .vout. That's a simple use of JQ where you just use `awk` to sum up the `value` of all the `vout` information: +To figure out the complete transaction fee at this point just requires one more bit of math: determining how much money is going through the .vout. That's a simple use of JQ where you just use `awk` to sum up the `value` of all the `vout` information: ``` $ bitcoin-cli decoderawtransaction $rawtxhex | jq -r '.vout [] | .value' | awk '{s+=$1} END {print s}' 1.045 ``` -To complete the transaction fee calculation,, you subtract the .vout .amount (1.045) from the .vin .amount (1.3). +To complete the transaction fee calculation, you subtract the .vout .amount (1.045) from the .vin .amount (1.3). Putting it all together creates a complete calculator in just five lines of script: ``` From 1f5fef970ec961bcdcfa0cce5024e7953521ad91 Mon Sep 17 00:00:00 2001 From: wintercooled Date: Thu, 22 Mar 2018 14:42:53 +0000 Subject: [PATCH 04/10] Update 04_4_Sending_Coins_with_a_Raw_Transaction.md Fixed minor typo --- 04_4_Sending_Coins_with_a_Raw_Transaction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/04_4_Sending_Coins_with_a_Raw_Transaction.md b/04_4_Sending_Coins_with_a_Raw_Transaction.md index b20b4d7..dd652d3 100644 --- a/04_4_Sending_Coins_with_a_Raw_Transaction.md +++ b/04_4_Sending_Coins_with_a_Raw_Transaction.md @@ -26,7 +26,7 @@ Our sample raw transaction was simple in another way: it assumed that there was ## Write a Real Raw Transaction -To summarize: creating a real raw transaction to send coins will sometimes require multiple inputs and will almost always require multiple outputs, one of which is a change address. We'll be creating that saw of more realistic transaction here, in a new example that shows a real-life example of sending funds via Bitcoin's second methodology, raw transactions. +To summarize: creating a real raw transaction to send coins will sometimes require multiple inputs and will almost always require multiple outputs, one of which is a change address. We'll be creating that sort of more realistic transaction here, in a new example that shows a real-life example of sending funds via Bitcoin's second methodology, raw transactions. Here's the UTXOs we'll be using: ``` From f35521a1fbf2a8a2cfe27baee5aa68317f860f3b Mon Sep 17 00:00:00 2001 From: wintercooled Date: Thu, 22 Mar 2018 17:43:03 +0000 Subject: [PATCH 05/10] Update 05_1_Watching_for_Stuck_Transactions.md Fixed minor typo. --- 05_1_Watching_for_Stuck_Transactions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05_1_Watching_for_Stuck_Transactions.md b/05_1_Watching_for_Stuck_Transactions.md index 263ca51..d9b79ec 100644 --- a/05_1_Watching_for_Stuck_Transactions.md +++ b/05_1_Watching_for_Stuck_Transactions.md @@ -38,7 +38,7 @@ $ bitcoin-cli -named gettransaction txid=0f618e38efe887028a5dd04d0e12241431978b ``` A transaction can be considered stuck if it stays in this state for an extended amount of time. Not too many years ago, you could be sure that every transaction would go out _eventually_. But, that's no longer the case due to the increased usage of Bitcoin. Now, if a transaction is stuck too long, it will drop out of the mempool and then be lost from the Bitcoin network. -_What is the mempool?_ The Bitcoin mempool (or Memory Pool) is the pool of all unconfirmed transactions. When a miner makes a block, he uses transactions from his mempool. Then, when a block is verified, all the miners remove the transactions it contains from their pools. As of Bitcoin 0.12, unconfirmed transactions can also expire from mempools if they're old enough: typically, 72 hours or more. Mining pools might have their mempool-management mechanisms. Though the mempool should be largely the same across the Bitcoin network, there will be variations on each machine: different transactions might have propogated to a specific node or (more notably) it might have different limits on how much it's willing to store. +_What is the mempool?_ The Bitcoin mempool (or Memory Pool) is the pool of all unconfirmed transactions. When a miner makes a block, he uses transactions from his mempool. Then, when a block is verified, all the miners remove the transactions it contains from their pools. As of Bitcoin 0.12, unconfirmed transactions can also expire from mempools if they're old enough: typically, 72 hours or more. Mining pools might have their own mempool-management mechanisms. Though the mempool should be largely the same across the Bitcoin network, there will be variations on each machine: different transactions might have propogated to a specific node or (more notably) it might have different limits on how much it's willing to store. This list of all [unconfirmed transactions](https://blockchain.info/unconfirmed-transactions) might not match any individual machine's mempool, but it should (mostly) be a superset of them. From 89e3ff2f9e8e35e0deec2a3f4a08644e039e8461 Mon Sep 17 00:00:00 2001 From: wintercooled Date: Thu, 22 Mar 2018 18:00:50 +0000 Subject: [PATCH 06/10] Update 05_2_Resending_a_Transaction_with_RBF.md Fixed minor typo --- 05_2_Resending_a_Transaction_with_RBF.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05_2_Resending_a_Transaction_with_RBF.md b/05_2_Resending_a_Transaction_with_RBF.md index 3c45fdc..89998a0 100644 --- a/05_2_Resending_a_Transaction_with_RBF.md +++ b/05_2_Resending_a_Transaction_with_RBF.md @@ -52,7 +52,7 @@ The `bip125-replaceable` flag will stay `yes` until the transaction receives con _Should I trust transactions with no confirmations?_ No, never. This was true before RBF and it was true after RBF. Transactions must receive confirmations before they are trustworthy. This is especially true if a transaction is marked as `bip125-replaceable`, because then it can be ... replaced. -> **SEQUENCE NOTE (I):** This is the first use of the `nSequence` value in Bitcoin. You can set it between 1 and 0xffffffff-2 (4294967293) and enable RBF, but if you're not careful you can run up against the parallel use of `nSequence` for relative timelocks. We suggest always setting it to "1", which is what Bitcoin Core does, but the other option is to set it a value between 0xf0000000 (4026531840) and 0xffffffff-2 (4294967293). Setting it to "1" effectively makes relative timelocks irrelevent and setting it to 0xf0000000 or higher deactivates them. This is all explained further in [§9.3: Using CSV in Scripts](09_3_Using_CSV_in_Scripts.md). For now, just choose one of the non-conflicting values for `nSequence`. +> **SEQUENCE NOTE (I):** This is the first use of the `nSequence` value in Bitcoin. You can set it between 1 and 0xffffffff-2 (4294967293) and enable RBF, but if you're not careful you can run up against the parallel use of `nSequence` for relative timelocks. We suggest always setting it to "1", which is what Bitcoin Core does, but the other option is to set it to a value between 0xf0000000 (4026531840) and 0xffffffff-2 (4294967293). Setting it to "1" effectively makes relative timelocks irrelevent and setting it to 0xf0000000 or higher deactivates them. This is all explained further in [§9.3: Using CSV in Scripts](09_3_Using_CSV_in_Scripts.md). For now, just choose one of the non-conflicting values for `nSequence`. ### Optional: Always Opt-In for RBF From d3947b17117f2336a2ee57b7d0862a437acaacf8 Mon Sep 17 00:00:00 2001 From: wintercooled Date: Thu, 22 Mar 2018 18:07:38 +0000 Subject: [PATCH 07/10] Update 05_3_Funding_a_Transaction_with_CPFP.md fixed minor typo --- 05_3_Funding_a_Transaction_with_CPFP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05_3_Funding_a_Transaction_with_CPFP.md b/05_3_Funding_a_Transaction_with_CPFP.md index 32beaba..890af37 100644 --- a/05_3_Funding_a_Transaction_with_CPFP.md +++ b/05_3_Funding_a_Transaction_with_CPFP.md @@ -12,7 +12,7 @@ RBF was all about the sender. He messed up and needed to increase the fee, or he Basically, the idea of CPFP is that a recipient has a transaction that hasn't been confimed in a block that he wants to spend. So, he includes that unconfirmed transaction in a new transaction and pays a high-enough fee to encourage a miner to include both the original (parent) transaction and the new (child) transaction in a block. As a result, the parent and child transactions clear simultaneously. -It should be noted that CPFP is not a new protocol feature, like RBF. It's just a new incentivization scheme that can be used for transaction selection by miners. This also means that it's not as reliable as a protocol change like RBF: there might be reaosns that the parent is never put into a block, and that will prevent the child from ever bring put into a block. +It should be noted that CPFP is not a new protocol feature, like RBF. It's just a new incentivization scheme that can be used for transaction selection by miners. This also means that it's not as reliable as a protocol change like RBF: there might be reasons that the parent is never put into a block, and that will prevent the child from ever bring put into a block. ## Spend Unconfirmed UTXOs From 34372c037ed6b26bf9d6c138b1f7c18df334c51b Mon Sep 17 00:00:00 2001 From: wintercooled Date: Fri, 23 Mar 2018 11:02:41 +0000 Subject: [PATCH 08/10] Update 06_1_Sending_a_Transaction_to_a_Multisig.md fixed minor typo --- 06_1_Sending_a_Transaction_to_a_Multisig.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/06_1_Sending_a_Transaction_to_a_Multisig.md b/06_1_Sending_a_Transaction_to_a_Multisig.md index bcfa718..c95b8bc 100644 --- a/06_1_Sending_a_Transaction_to_a_Multisig.md +++ b/06_1_Sending_a_Transaction_to_a_Multisig.md @@ -84,7 +84,7 @@ The _address_ is what you'll give out to people who want to send funds. You'll n The _redeemScript_ is what you need to redeem the funds, along with the private keys for "m" of the "n" addresses. This script is another special feature of P2SH addresses and will be fully explained in [§8.1: Building a Bitcoin Script with P2SH](08_1_Building_a_Bitcoin_Script_with_P2SH.md). For now, just be aware that it's a bit of data that's required to get your money. -_What is a P2SH address?_ P2SH stands for Pay-to-script. It's a different type of receipient than a standard P2PKH address, used for funds whose redemption are based on more complex Bitcoin Scripts. `bitcoin-cli` uses P2SH encapsulation to help standardize and simplify its multisigs as "P2SH multisigs". +_What is a P2SH address?_ P2SH stands for Pay-to-script-hash. It's a different type of receipient than a standard P2PKH address, used for funds whose redemption are based on more complex Bitcoin Scripts. `bitcoin-cli` uses P2SH encapsulation to help standardize and simplify its multisigs as "P2SH multisigs". > **WARNING:** P2SH multisig addresses, like the ones created by `bitcoin-cli`, have a limit for "m" and "n" in multisigs based on the maximum size of the redeem script, which is currently 520 bytes. Pratically, you won't hit this unless you're doing something excessive. @@ -149,7 +149,7 @@ As you can see, there was nothing unusual in the creation of the transaction, an ## Summary: Sending a Transaction with a Multisig -Multisigs addresses lock funds to multiple private keys — possibly requiring all of those private keys for redemption, and possibly requiring just some from the set. They're easy enough to create with `bitcoin-cli` and they're entirely normal to send to. This ease is due in large part to the invisible use of P2SH (pay-to-script) addresses, a large topic that will get more coverage in the future. +Multisig addresses lock funds to multiple private keys — possibly requiring all of those private keys for redemption, and possibly requiring just some from the set. They're easy enough to create with `bitcoin-cli` and they're entirely normal to send to. This ease is due in large part to the invisible use of P2SH (pay-to-script-hash) addresses, a large topic that will get more coverage in the future. _What is the power of multisignatures?_ Multisignatures allow the modeling of a variety of financial arrangements such as corporations, partnerships, committees, and other groups. A 1-of-2 multisig might be a married couple's joint bank account, while a 2-of-2 multisig might be used for large expenditures by a Limited Liability Partnership. Multisignatures also form one of the bases of Smart Contracts. For example, a real estate deal could be closed with a 2-of-3 multisig, where the signatures are submitted by the buyer, the seller, and an escrow agent. Once the escrow agent agrees that all of the conditions have been met, he frees up the funds for the seller; or alternatively, the buyer and seller can jointly free the funds. From f273262cde18c3114e10d7ecd7c6c32da0bb630c Mon Sep 17 00:00:00 2001 From: wintercooled Date: Fri, 23 Mar 2018 11:12:04 +0000 Subject: [PATCH 09/10] Update 06_2_Spending_a_Transaction_to_a_Multisig.md fixed minor typo (I think have changed P2SH from pay-to-script to pay-to-scipt-hash. As I have changed this twice now I just want to check that it wasn't omitting the 'hash' deliberately. --- 06_2_Spending_a_Transaction_to_a_Multisig.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/06_2_Spending_a_Transaction_to_a_Multisig.md b/06_2_Spending_a_Transaction_to_a_Multisig.md index a2ea528..98f40ed 100644 --- a/06_2_Spending_a_Transaction_to_a_Multisig.md +++ b/06_2_Spending_a_Transaction_to_a_Multisig.md @@ -31,7 +31,7 @@ $ bitcoin-cli listunspent ## Set Up Your Variables -When you're ready to spend the funds received by a multisignature address, you're going need to collect a _lot_ of data: much more than you need when you spend a normal P2PKH UTXO. That's in part because the info on the multisig address isn't in your wallet, and in part because you're spending money that was sent to a P2SH (pay-to-script) address, and that's a lot more demanding. +When you're ready to spend the funds received by a multisignature address, you're going need to collect a _lot_ of data: much more than you need when you spend a normal P2PKH UTXO. That's in part because the info on the multisig address isn't in your wallet, and in part because you're spending money that was sent to a P2SH (pay-to-script-hash) address, and that's a lot more demanding. In total, you're going to need to collect three things: extended information about the UTXO; the redeemScript; and all the private keys involved. You'll of course need a new recipient address too. The private keys need to wait for the signing step, but everything else can be done now. From 527e52e74aadf0111459e6ac0f38d7baa9a2b567 Mon Sep 17 00:00:00 2001 From: wintercooled Date: Fri, 23 Mar 2018 11:18:52 +0000 Subject: [PATCH 10/10] Update 06_2_Spending_a_Transaction_to_a_Multisig.md made command convention consistent with previous usage. --- 06_2_Spending_a_Transaction_to_a_Multisig.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/06_2_Spending_a_Transaction_to_a_Multisig.md b/06_2_Spending_a_Transaction_to_a_Multisig.md index 98f40ed..c640162 100644 --- a/06_2_Spending_a_Transaction_to_a_Multisig.md +++ b/06_2_Spending_a_Transaction_to_a_Multisig.md @@ -132,7 +132,7 @@ In this case, we now see that the signature is `complete`! 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') -user1@blockstream2:~$ bitcoin-cli -named sendrawtransaction hexstring=$signedtx +$ bitcoin-cli -named sendrawtransaction hexstring=$signedtx 99d2b5717fed8875a1ed3b2827dd60ae3089f9caa7c7c23d47635f6f5b397c04 ```