-
Notifications
You must be signed in to change notification settings - Fork 879
Enable getting the network kind from an address #4251
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
Conversation
This patch can be trivially backported to the 0.32.x branch with |
Users may wish to ask of an address 'what kind of address is this?' We have the `NetworkKind` struct that abstracts over the answer but currently no API to ask the question. The address may have been parsed or constructed and weather the network has been checked already is immaterial. Hence we add the function for both `NetworkChecked` and `NetworkUnchecked` addresses. Fix: rust-bitcoin#4247
147afd8
to
f4f79f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK f4f79f8; successfully ran local tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK f4f79f8
KnownHrp::Regtest => NetworkKind::Test, | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel somewhat uneasy about this conversion since it's lossy. But not really wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KnownHrp
is a larger type than NetworkKind
so it's in the type signature that it'll be lossy.
P2sh { hash: _, ref network } => *network, | ||
Segwit { program: _, ref hrp } => NetworkKind::from(*hrp), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth also having is_mainnet
method (and possibly also is_a_test
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaning toward not because these methods are one-liners (once this method is in) and it's extra API surface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, these are common in Rust libraries. But maybe it's enough to have them on NetworkKind
so once can call network_kind().is_mainnet()
.
Users may wish to ask of an address 'what kind of address is this?' We have the
NetworkKind
struct that abstracts over the answer but currently no API to ask the question.The address may have been parsed or constructed and weather the network has been checked already is immaterial. Hence we add the function for both
NetworkChecked
andNetworkUnchecked
addresses.Fix: #4247