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

Use KnowHrp instead of Network #2387

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

tcharding
Copy link
Member

We have a bunch of functions that take Network when what they really want is something that can be converted to a KnownHrp.

Make KnownHrp public and accept impl Into<KnownHrp>.

We have a bunch of functions that take `Network` when what they really
want is something that can be converted to a `KnownHrp`.

Make `KnownHrp` public and accept `impl Into<KnownHrp>`.
@github-actions github-actions bot added the C-bitcoin PRs modifying the bitcoin crate label Jan 23, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 7621632788

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 84.262%

Totals Coverage Status
Change from base Build 7616194895: 0.004%
Covered Lines: 19221
Relevant Lines: 22811

💛 - Coveralls

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 20a5f1f

@@ -874,7 +875,7 @@ mod tests {
let key = "033bc8c83c52df5712229a2f72206d90192366c36428cb0c12b6af98324d97bfbc"
.parse::<CompressedPublicKey>()
.unwrap();
let addr = Address::p2wpkh(&key, Bitcoin);
let addr = Address::p2wpkh(&key, KnownHrp::Mainnet);
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO these tests could've stayed but whatever...

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, you are right. I did the change before I used impl Into.

@Kixunil
Copy link
Collaborator

Kixunil commented Jan 23, 2024

Note that I've just realized we'll have to make Hrp public at some point too. But I'm still not convinced it belongs to bech32 and there's likely a cleaner way. But that's for far future, units and primitives are more important now.

@apoelstra
Copy link
Member

But I'm still not convinced it belongs to bech32 and there's likely a cleaner way.

HRPs are an integral part of bech32. Where else could they belong to?

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 20a5f1f

@apoelstra apoelstra merged commit e003336 into rust-bitcoin:master Jan 23, 2024
31 checks passed
@Kixunil
Copy link
Collaborator

Kixunil commented Jan 23, 2024

Where else could they belong to?

Something like bech32-hrp which can get stabilized sooner than the rest for instance. :)

@TheBlueMatt
Copy link
Member

As discussed rather extensively on #2225 I don't think we should do this. Users being forced to move between two different Network enums that have the same purpose isn't a cleaner API, its just more fluff and crap to go have to read in the docs. If we add a new Network, we'll clearly want a KnownHrp for it, and vice versa. Until that changes, I don't see a reason to have two separate enums here.

@Kixunil
Copy link
Collaborator

Kixunil commented Jan 23, 2024

This has nothing to do with #2225 but funnily enough it adds argument for application-specific enums.

KnownHrp already doesn't exist for signet which broke roundtrip. I guess this actually proves my point that Network is not universally implemented. The idea is dead, we might as well rename Network to CoreNetwork to indicate the point.

@TheBlueMatt
Copy link
Member

That, rather, implies KnownHrp should be defined for signet, and shouldn't match existing ones. That ship may have sailed by now, but its ultimately a bug in the spec for signet, and not something general that implies Network can't be general in most cases :).

@Kixunil
Copy link
Collaborator

Kixunil commented Jan 23, 2024

Yes, it's a bug in signet but we're already screwed and have to live with what we have. The other possibilities are remove Address support, make Address not roundtrip, return error when parsing signet Address. Each is absolutely terrible.

@tcharding tcharding deleted the 01-23-known-hrp branch January 25, 2024 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bitcoin PRs modifying the bitcoin crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants