Merged
Conversation
Remove unnecessary borrows when calling const_hex::encode_prefixed and const_hex::encode, since the arguments already implement AsRef<[u8]>. Also add serde feature to const-hex for deserialize support.
- Fix misleading doc comment on HashValue::from_hex that referenced UTF-8 validation no longer performed - Re-export const_hex from aptos-sdk (#[doc(hidden)]) so downstream crates using generated code don't need a direct const-hex dependency - Update codegen generator and proc macro to emit ::aptos_sdk::const_hex::encode() instead of const_hex::encode()
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates from the unmaintained hex crate to the actively maintained const-hex crate, providing faster hex encoding/decoding with const-compatible functions. The migration includes updating all hex encoding/decoding calls throughout the codebase and adding serde support for deserialization helpers.
Changes:
- Replace
hexcrate dependency withconst-hex(version 1.17.0 with serde feature) - Migrate all hex encoding from
format!("0x{}", hex::encode(...))toconst_hex::encode_prefixed(...) - Migrate all hex decoding from manual prefix stripping +
hex::decodetoconst_hex::decode(which handles prefixes automatically) - Add re-export of
const_hexfromaptos-sdkfor generated code compatibility
Reviewed changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Cargo.toml | Replace hex dependency with const-hex version 1.17.0 with serde feature |
| Cargo.lock | Update dependencies to include const-hex and remove hex crate |
| crates/aptos-sdk/CHANGELOG.md | Document the migration from hex to const-hex |
| crates/aptos-sdk/src/lib.rs | Re-export const_hex for use by generated code and proc macros |
| crates/aptos-sdk/src/error.rs | Update error type from hex::FromHexError to const_hex::FromHexError |
| crates/aptos-sdk/src/types/hash.rs | Simplify from_hex using const_hex::decode_to_slice, use encode_prefixed for to_hex, update documentation |
| crates/aptos-sdk/src/types/address.rs | Use const_hex for encoding with encode_prefixed for long strings and encode for short strings |
| crates/aptos-sdk/src/crypto/*.rs | Migrate all crypto modules to const_hex, remove manual 0x prefix stripping |
| crates/aptos-sdk/src/crypto/multi_*.rs | Update Display/Debug formatting to use encode_prefixed, migrate serde to const_hex::deserialize |
| crates/aptos-sdk/src/account/*.rs | Update all account types to use const_hex for hex operations |
| crates/aptos-sdk/src/api/fullnode.rs | Use encode_prefixed for hex formatting in API calls |
| crates/aptos-sdk/src/codegen/generator.rs | Update code generation to use ::aptos_sdk::const_hex::encode for vector types |
| crates/aptos-sdk-macros/src/codegen.rs | Update proc macro code generation to use ::aptos_sdk::const_hex::encode |
| crates/aptos-sdk/tests/*.rs | Update test code to use const_hex, fix needless borrow warnings |
| crates/aptos-sdk/examples/*.rs | Update examples to use const_hex |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hexcrate withconst-hexfor hex encoding/decoding (faster,const-compatible)serdefeature toconst-hexfor serde deserialization helpersconst_hexfromaptos-sdkso generated code (codegen + proc macros) works without downstream crates needing a directconst-hexdependencyneedless_borrows_for_generic_argswarningsSupersedes #35
Test plan
cargo test -p aptos-sdk --all-features— all 875 unit tests + 31 doctests passcargo clippy -p aptos-sdk --all-features -- -D warnings— zero warningscargo fmt -- --check— clean