use Script::new_p2pkh for creating P2PKH scriptPubKey #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a simple refactor PR that takes advantage of
Script::new_p2pkh()
from the bitcoin crate (see https://docs.rs/bitcoin/0.25.2/bitcoin/blockdata/script/struct.Script.html#method.new_p2pkh, avilable since 0.25.1) for creating a P2PKH output script rather than crafting it by hand. Also, for calculating the hash from the pubkey, it'spubkey_hash()
method (https://docs.rs/bitcoin/0.25.2/bitcoin/util/key/struct.PublicKey.html#method.pubkey_hash -- available since 0.25.1) is used instead ofhashes::hash160
.The implementation of
Script::new_p2pkh()
actually looks quite similar to what is replaced:https://github.com/rust-bitcoin/rust-bitcoin/blob/b48f374c2cd6127aaa5e8b2ffbed80c3aa03245c/src/blockdata/script.rs#L238-L247
Note that I'm a total Rust noob, but at least the silent output of
cargo build
gives me some confidence that the change works 😎