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

Fix wrong newtype APIs #1503

Merged
merged 1 commit into from Dec 30, 2022
Merged

Conversation

Kixunil
Copy link
Collaborator

@Kixunil Kixunil commented Dec 23, 2022

This fixes several API bugs:

  • Use TryFrom instead of From for fallible conversions
  • Move byte conversion methods from impl_array_newtype to impl_bytes_newtype
  • Add missing trait impls like AsRef, Borrow, their mutable versions and infallible conversions from arrays

Closes #1336

Notably this change is much less bad than even I expected and some places actually get cleaner than before.

This fixes several API bugs:

* Use `TryFrom` instead of `From` for fallible conversions
* Move byte conversion methods from `impl_array_newtype` to
  `impl_bytes_newtype`
* Add missing trait impls like `AsRef`, `Borrow`, their mutable versions
  and infallible conversions from arrays

Closes rust-bitcoin#1336
@Kixunil Kixunil added bug API break This PR requires a version bump for the next release labels Dec 23, 2022
@@ -149,7 +149,7 @@ impl PartiallySignedTransaction {
}
let derivation = DerivationPath::from(path);
// Keys, according to BIP-174, must be unique
if xpub_map.insert(xpub, (Fingerprint::from(&fingerprint[..]), derivation)).is_some() {
if xpub_map.insert(xpub, (Fingerprint::from(fingerprint), derivation)).is_some() {
return Err(encode::Error::ParseFailed("Repeated global xpub key"))

Choose a reason for hiding this comment

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

I think there are two missing tests that need to be checked

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unrelated but which ones? Why do you think?

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 64f7d25

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

code review ACK 64f7d25

@Kixunil Kixunil added this to the 0.30.0 milestone Dec 30, 2022
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 64f7d25

@apoelstra apoelstra merged commit 3a867ee into rust-bitcoin:master Dec 30, 2022
@Kixunil Kixunil deleted the fix-terrible-from-impl branch December 31, 2022 20:02
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 bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Completely wrong implementation of From in impl_array_newtype
5 participants