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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WitnessVersion type #562

Closed
wants to merge 2 commits into from
Closed

WitnessVersion type #562

wants to merge 2 commits into from

Conversation

dr-orlovsky
Copy link
Collaborator

Part of Taproot epic (should be listed in #503)

@dr-orlovsky dr-orlovsky added the API break This PR requires a version bump for the next release label Jan 30, 2021
@dr-orlovsky dr-orlovsky mentioned this pull request Jan 30, 2021
@dr-orlovsky dr-orlovsky added this to Ready for Review in Taproot Jan 30, 2021
Copy link
Contributor

@sgeisler sgeisler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and improves the API quite a bit imo. I left a few nits regarding some expects and comments.

impl From<WitnessVersion> for ::bech32::u5 {
/// Converts `WitnessVersion` instance into corresponding Bech32 u5-value
fn from(ver: WitnessVersion) -> Self {
::bech32::u5::try_from_u8(ver.into_version_no()).expect("WitnessVersion is broken")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this error text could be more descriptive, e.g. "WitnessVersion is always in 0..=16"

@@ -168,22 +337,19 @@ impl Payload {
/// Get a [Payload] from an output script (scriptPubkey).
pub fn from_script(script: &script::Script) -> Option<Payload> {
Some(if script.is_p2pkh() {
Payload::PubkeyHash(PubkeyHash::from_slice(&script.as_bytes()[3..23]).unwrap())
Payload::PubkeyHash(PubkeyHash::from_slice(&script.as_bytes()[3..23]).expect("hash engine broken"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure has nothing to do with the hash engine but with supplying a byte slice of a wrong length.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed expect at all by using infallible from_inner

}


impl FromStr for WitnessVersion {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually useful? Where do we directly (de)serialize a witness version? Isn't it always part of some other data structure with its own encoding?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could imagine it being useful somewhere, and it's not much extra code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not too bad now that I noticed even without it the UnparsableWitnessVersion error variant can't be made more expressive.

} else if script.is_witness_program() {
// We can unwrap the u5 check and assume script length
// We can unwrap assume script length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the and has to stay in the comment for it to make any sense.

@dr-orlovsky
Copy link
Collaborator Author

Fixed @sgeisler suggestions & force-pushed. Ready for re-review

@sgeisler
Copy link
Contributor

Does this really still have to be its own PR? Afaik it's included in #563 (idk if based on an up to date version) and fits in there quite well. It's a breaking change anyway.

@sanket1729
Copy link
Member

I have left some feedback on #563 for this commit.

@dr-orlovsky
Copy link
Collaborator Author

Updated with review suggestions from #563

@sgeisler
Copy link
Contributor

sgeisler commented Apr 8, 2021

Again, would anyone be opposed to closing this in favor of merging it with #563? It's just so related and reviewing #563 together with the #562 changes seemed easy enough. #563 is also close to merge ready imo, maybe a third review would be nice and we need to decide if we want to release 0.26.1 before that, but there's nothing fundamentally blocking just merging #563 all at once after that.

@dr-orlovsky
Copy link
Collaborator Author

Agree, closing this now

Taproot automation moved this from Ready for Review to Done Apr 12, 2021
@dr-orlovsky dr-orlovsky mentioned this pull request Jun 13, 2021
@dr-orlovsky
Copy link
Collaborator Author

Reopened as #617

@dr-orlovsky dr-orlovsky moved this from Done to Rejected in Taproot Sep 25, 2021
Davidson-Souza pushed a commit to Davidson-Souza/rust-bitcoin that referenced this pull request Jul 12, 2023
Davidson-Souza pushed a commit to Davidson-Souza/rust-bitcoin that referenced this pull request Jul 12, 2023
…gates to bitcoin_hashes

1d6a46e change bitcoin-hashes feature gates to bitcoin_hashes (Andrew Poelstra)

Pull request description:

  This leaves `bitcoin-hashes` in place everywhere in the documentation, but changes it to `bitcoin_hashes` on the actual feature gates, to ensure that both flags work.

  It's unfortunately a bit hard to test this because the library will be self-consistent pretty-much no matter what we do ... the issue is if the user enables the wrong flag we want to make sure that all the APIs we intend to be visible are actually visible.

  Fixes rust-bitcoin#562.

ACKs for top commit:
  tcharding:
    ACK 1d6a46e

Tree-SHA512: 1e060aeb2810ef1e23cf5c956023aca586550ba0287bbf7bc1108dc14091e17d7601aac3f057d0313fafd21351cdda1b08b4250f34ecde917be686d0b739e65a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API break This PR requires a version bump for the next release
Projects
Taproot
Rejected
Development

Successfully merging this pull request may close these issues.

None yet

4 participants