Skip to content

Use KnowHrp instead of Network#2387

Merged
apoelstra merged 1 commit into
rust-bitcoin:masterfrom
tcharding:01-23-known-hrp
Jan 23, 2024
Merged

Use KnowHrp instead of Network#2387
apoelstra merged 1 commit into
rust-bitcoin:masterfrom
tcharding:01-23-known-hrp

Conversation

@tcharding

Copy link
Copy Markdown
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
Copy Markdown

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

@Kixunil Kixunil left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ACK 20a5f1f

.parse::<CompressedPublicKey>()
.unwrap();
let addr = Address::p2wpkh(&key, Bitcoin);
let addr = Address::p2wpkh(&key, KnownHrp::Mainnet);

Copy link
Copy Markdown
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
Copy Markdown
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

Kixunil commented Jan 23, 2024

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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?

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Member

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
@Kixunil

Kixunil commented Jan 23, 2024

Copy link
Copy Markdown
Collaborator

Where else could they belong to?

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

@TheBlueMatt

Copy link
Copy Markdown
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

Kixunil commented Jan 23, 2024

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

Kixunil commented Jan 23, 2024

Copy link
Copy Markdown
Collaborator

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