Skip to content

Commit 536871e

Browse files
committed
Merge #25: cookbook: Upgrade to latest bitcoin 0.32.0
54b68a5 cookbook: Upgrade to latest bitcoin 0.32.0 (Tobin C. Harding) Pull request description: Upgrade the cookbook to use the latest release of `rust-bitcoin`. ACKs for top commit: apoelstra: utACK 54b68a5 Tree-SHA512: 543ccfe120da784c9731d5a45f165cd4e7d4873de8f51236d2fe9bb74d14007de236d488603df8cfe7e61e1b6e4f6a0c4b081028e55924039c45fd45d0251fee
2 parents adda3c3 + 54b68a5 commit 536871e

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

cookbook/src/tx_segwit-v0.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn dummy_unspent_transaction_output(wpkh: &WPubkeyHash) -> (OutPoint, TxOut) {
108108
```
109109

110110
`dummy_unspent_transaction_output` generates a dummy unspent transaction output (UTXO).
111-
This is a SegWit V0 P2WPKH (`ScriptBuf::new_v0_p2wpkh`) UTXO with a dummy invalid transaction ID (`txid: Txid::all_zeros()`),
111+
This is a SegWit V0 P2WPKH (`ScriptBuf::new_p2wpkh`) UTXO with a dummy invalid transaction ID (`txid: Txid::all_zeros()`),
112112
and a value of the `const DUMMY_UTXO_AMOUNT` that we defined earlier.
113113
We are using the [`OutPoint`](https://docs.rs/bitcoin/0.31.1/bitcoin/blockdata/transaction/struct.OutPoint.html) struct to represent the transaction output.
114114
Finally, we return the tuple `(out_point, utxo)`.
@@ -209,10 +209,10 @@ fn main() {
209209

210210
// Sign the sighash using the secp256k1 library (exported by rust-bitcoin).
211211
let msg = Message::from(sighash);
212-
let sig = secp.sign_ecdsa(&msg, &sk);
212+
let signature = secp.sign_ecdsa(&msg, &sk);
213213

214214
// Update the witness stack.
215-
let signature = bitcoin::ecdsa::Signature { sig, hash_ty: EcdsaSighashType::All };
215+
let signature = bitcoin::ecdsa::Signature { signature, sighash_type };
216216
let pk = sk.public_key(&secp);
217217
*sighasher.witness_mut(input_index).unwrap() = Witness::p2wpkh(&signature, &pk);
218218

@@ -264,7 +264,7 @@ Inside the [`TxOut`](https://docs.rs/bitcoin/0.31.1/bitcoin/blockdata/transactio
264264

265265
In `let change = TxOut {...}` we are instantiating the change output.
266266
It is very similar to the `spend` output, but we are now using the `const CHANGE_AMOUNT` that we defined earlier[^spend].
267-
This is done by setting the `script_pubkey` field to [`ScriptBuf::new_v0_p2wpkh(&wpkh)`](https://docs.rs/bitcoin/0.31.1/bitcoin/blockdata/script/struct.ScriptBuf.html#method.new_v0_p2wpkh),
267+
This is done by setting the `script_pubkey` field to [`ScriptBuf::new_p2wpkh(&wpkh)`](https://docs.rs/bitcoin/0.31.1/bitcoin/blockdata/script/struct.ScriptBuf.html#method.new_p2wpkh),
268268
which generates P2WPKH-type of script pubkey.
269269

270270
In `let unsigned_tx = Transaction {...}` we are instantiating the transaction we want to sign and broadcast using the [`Transaction`](https://docs.rs/bitcoin/0.31.1/bitcoin/blockdata/transaction/struct.Transaction.html) struct.

cookbook/src/tx_taproot.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn dummy_unspent_transaction_output<C: Verification>(
9797
secp: &Secp256k1<C>,
9898
internal_key: UntweakedPublicKey,
9999
) -> (OutPoint, TxOut) {
100-
let script_pubkey = ScriptBuf::new_v1_p2tr(secp, internal_key, None);
100+
let script_pubkey = ScriptBuf::new_p2tr(secp, internal_key, None);
101101

102102
let out_point = OutPoint {
103103
txid: Txid::all_zeros(), // Obviously invalid.
@@ -111,7 +111,7 @@ fn dummy_unspent_transaction_output<C: Verification>(
111111
```
112112

113113
`dummy_unspent_transaction_output` generates a dummy unspent transaction output (UTXO).
114-
This is a P2TR (`ScriptBuf::new_v1_p2tr`) UTXO.
114+
This is a P2TR (`ScriptBuf::new_p2tr`) UTXO.
115115
It takes the following arguments:
116116

117117
- `secp` is a reference to a [`Secp256k1`](https://docs.rs/secp256k1/0.27.0/secp256k1/struct.Secp256k1.html) type.
@@ -167,7 +167,7 @@ Now we are ready for our main function that will sign a transaction that spends
167167
# secp: &Secp256k1<C>,
168168
# internal_key: UntweakedPublicKey,
169169
# ) -> (OutPoint, TxOut) {
170-
# let script_pubkey = ScriptBuf::new_v1_p2tr(secp, internal_key, None);
170+
# let script_pubkey = ScriptBuf::new_p2tr(secp, internal_key, None);
171171
#
172172
# let out_point = OutPoint {
173173
# txid: Txid::all_zeros(), // Obviously invalid.
@@ -233,10 +233,10 @@ fn main() {
233233
// Sign the sighash using the secp256k1 library (exported by rust-bitcoin).
234234
let tweaked: TweakedKeypair = keypair.tap_tweak(&secp, None);
235235
let msg = Message::from_digest(sighash.to_byte_array());
236-
let sig = secp.sign_schnorr(&msg, &tweaked.to_inner());
236+
let signature = secp.sign_schnorr(&msg, &tweaked.to_inner());
237237

238238
// Update the witness stack.
239-
let signature = bitcoin::taproot::Signature { sig, hash_ty: sighash_type };
239+
let signature = bitcoin::taproot::Signature { signature, sighash_type };
240240
sighasher.witness_mut(input_index).unwrap().push(&signature.to_vec());
241241

242242
// Get the signed transaction.
@@ -283,7 +283,7 @@ Inside the [`TxOut`](https://docs.rs/bitcoin/0.31.1/bitcoin/blockdata/transactio
283283

284284
In `let change = TxOut {...}` we are instantiating the change output.
285285
It is very similar to the `spend` output, but we are now using the `const CHANGE_AMOUNT` that we defined earlier[^spend].
286-
This is done by setting the `script_pubkey` field to [`ScriptBuf::new_v1_p2tr(...)`](https://docs.rs/bitcoin/0.31.1/bitcoin/blockdata/script/struct.ScriptBuf.html#method.new_v1_p2tr),
286+
This is done by setting the `script_pubkey` field to [`ScriptBuf::new_p2tr(...)`](https://docs.rs/bitcoin/0.31.1/bitcoin/blockdata/script/struct.ScriptBuf.html#method.new_p2tr),
287287
which generates P2TR-type of script pubkey.
288288

289289
In `let unsigned_tx = Transaction {...}` we are instantiating the transaction we want to sign and broadcast using the [`Transaction`](https://docs.rs/bitcoin/0.31.1/bitcoin/blockdata/transaction/struct.Transaction.html) struct.

cookbook/tests/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ publish = false
66

77
[dependencies]
88
doc-comment = "0.3"
9-
bitcoin = { version = "0.31", features = ["std", "rand-std"] }
9+
bitcoin = { version = "0.32", features = ["std", "rand-std"] }

0 commit comments

Comments
 (0)