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

chainhash: add support to legacy-marshaled hashes #2025

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

Beerosagos
Copy link
Contributor

Recent commits 1d6e578 and 72ea23e introduced a change in the way Hashes are serialized and deserialized. This change could cause errors in downstream applications that persisted hashes serialized using the previous methods.

This introduces support for legacy-serialized hashes unmarshaling and restores the compatibility with previous versions.

@benma
Copy link
Contributor

benma commented Aug 28, 2023

cc @Roasbeef - this would be helpful as the BitBoxApp stores json-marshalled transactions, which contain the Hash type in the prevout info. The change in serialization format broke the BitBoxApp as it can't load persisted transactions anymore. This PR would fix it in an ergonomic way without needing a lot of custom boilerplate code.

@@ -118,6 +118,12 @@ func (hash Hash) MarshalJSON() ([]byte, error) {

// UnmarshalJSON parses the hash with JSON appropriate string value.
func (hash *Hash) UnmarshalJSON(input []byte) error {
// If the fist byte indicates an array, the hash could have been marshalled
Copy link
Contributor

Choose a reason for hiding this comment

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

typo first

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Makes sense, thanks for the fix. Should add a unit test case though.

chaincfg/chainhash/hash.go Show resolved Hide resolved
Recent commits 1d6e578 and 72ea23e introduced a change in the way Hashes
are serialized and deserialized. This change could cause errors in
downstream applications that persisted hashes serialized using the previous
methods.

This introduces support for legacy-serialized hashes unmarshaling and restores
the compatibility with previous versions.
@Beerosagos
Copy link
Contributor Author

@guggero @benma Thanks for the review! Pushed an update to fix the typo and add a test case PTAL 🙏

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 👑

@Roasbeef Roasbeef merged commit f12a0b3 into btcsuite:master Sep 1, 2023
Beerosagos added a commit to Beerosagos/bitbox-wallet-app that referenced this pull request Apr 29, 2024
Recent btcd updates changed the way hashes are serialized. We proposed a
fix (see btcsuite/btcd#2025) to restore backward
compatibility.

This commit adds a specific test case to ensure that the newer and the
legacy serialization methods work.
Beerosagos added a commit to Beerosagos/bitbox-wallet-app that referenced this pull request Apr 29, 2024
Recent btcd updates changed the way hashes are serialized. We proposed a
fix (see btcsuite/btcd#2025) to restore backward
compatibility.

This commit adds a specific test case to ensure that the newer and the
legacy serialization methods work.
Beerosagos added a commit to Beerosagos/bitbox-wallet-app that referenced this pull request Apr 29, 2024
Recent btcd updates changed the way hashes are serialized. We proposed a
fix (see btcsuite/btcd#2025) to restore backward
compatibility.

This commit adds a specific test case to ensure that the newer and the
legacy serialization methods work.
Beerosagos added a commit to Beerosagos/bitbox-wallet-app that referenced this pull request May 9, 2024
Recent btcd updates changed the way hashes are serialized. We proposed a
fix (see btcsuite/btcd#2025) to restore backward
compatibility.

This commit adds a specific test case to ensure that the newer and the
legacy serialization methods work.
Beerosagos added a commit to Beerosagos/bitbox-wallet-app that referenced this pull request May 16, 2024
Recent btcd updates changed the way hashes are serialized. We proposed a
fix (see btcsuite/btcd#2025) to restore backward
compatibility.

This commit adds a specific test case to ensure that the newer and the
legacy serialization methods work.
Beerosagos added a commit to Beerosagos/bitbox-wallet-app that referenced this pull request May 16, 2024
Recent btcd updates changed the way hashes are serialized. We proposed a
fix (see btcsuite/btcd#2025) to restore backward
compatibility.

This commit adds a specific test case to ensure that the newer and the
legacy serialization methods work.
NicolaLS pushed a commit to NicolaLS/bitbox-wallet-app that referenced this pull request Jun 4, 2024
Recent btcd updates changed the way hashes are serialized. We proposed a
fix (see btcsuite/btcd#2025) to restore backward
compatibility.

This commit adds a specific test case to ensure that the newer and the
legacy serialization methods work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants