Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Script::new_p2pkh for creating P2PKH scriptPubKey #8

Merged
merged 1 commit into from Jan 14, 2021

Conversation

theStack
Copy link
Contributor

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's pubkey_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 of hashes::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 馃槑

@chris-belcher
Copy link
Contributor

Thanks for the PR, I'll review it shortly

@chris-belcher
Copy link
Contributor

Reviewed and tested. Looks good to me.

However please change the commit message. Use the body to explain what and why vs. how. I suggest something like "Replaced verbose code with call to rust-bitcoin"

@theStack
Copy link
Contributor Author

Thanks for reviewing. Forced-pushed with updated commit body.

@chris-belcher
Copy link
Contributor

I mean you should remove the text Use Script::new_p2pkh for creating P2PKH scriptPubKey because it explains how, rather than what and why. The first line should be Replaced verbose code with calls to rust-bitcoin (without the trailing period). Sorry to be like this about messages, but its surprisingly important.

For creating the P2PKH output script, the following methods from rust-bitcoin
are used (both available since version 0.25.1):
- `bitcoin::blockdata::script::Script::new_p2kh()`
- `bitcoin::util::key::PublicKey::pubkey_hash()`
@theStack
Copy link
Contributor Author

theStack commented Jan 14, 2021

Ah, got it, I was reading sloppily and thought the commit message body was not detailled enough. Force-pushed a new version. Note that I also considered to use the imperative mood in the subject line (i.e. "replace" instead of "replaced") ;)

@chris-belcher
Copy link
Contributor

Ah yes that's right, I forgot about the imperative mood.

@chris-belcher chris-belcher merged commit 3b06de2 into bitcoin-teleport:master Jan 14, 2021
@theStack theStack deleted the use-new_p2pkh branch January 14, 2021 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants