polkadart
polkadart copied to clipboard
Fix Runtime V14 scale codec parser
User description
- [x] Fix Runtime V14 codec parser based on the official frame-metadata format.
- [x] Parser and Encode metadata from bytes.
- [x] Encode metadata as JSON
- [ ] Update polkadart-cli generator to use the new metadata format. (in progress)
PR Type
enhancement, other
Description
- Implemented a new
RuntimeMetadataV14class to handle runtime metadata version 14. - Added comprehensive codec implementations for metadata components.
- Introduced new libraries for scale info and metadata handling.
- Updated
StateApito useRuntimeMetadataPrefixedfor metadata operations. - Added a new script for fetching and processing chain metadata.
- Updated dependencies to include
substrate_metadata.
Changes walkthrough 📝
| Relevant files | |||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Enhancement | 20 files
| ||||||||||||||||||||||||||||||||||||||||
| Dependencies | 1 files
|
💡 PR-Agent usage: Comment
/help "your question"on any pull request to receive relevant information
PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
| ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪ |
| 🧪 No relevant tests |
| 🔒 No security concerns identified |
| ⚡ Recommended focus areas for review Code Complexity Possible Redundancy Inconsistent Naming |
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Score |
| Possible bug |
Correct the method call to pass the output stream in encodingIn the packages/substrate_metadata/lib/scale_info/type_definition.dart [115]
Suggestion importance[1-10]: 9Why: This suggestion corrects a potential bug by ensuring the correct method is called with the necessary parameters, which is crucial for the proper functioning of the encoding process. | 9 |
Improve error handling during hex string decodingAdd error handling for potential decoding failures when parsing the hex string to packages/substrate_metadata/lib/metadata/common.dart [18-26]
Suggestion importance[1-10]: 8Why: Adding error handling for hex string decoding is crucial for preventing application crashes and providing meaningful error messages. This suggestion significantly enhances the robustness of the code by handling potential exceptions. | 8 | |
Improve error handling for empty or invalid JSON maps in deserializationConsider handling the case where the 'json' map is empty or does not contain packages/substrate_metadata/lib/scale_info/type_definition.dart [11]
Suggestion importance[1-10]: 8Why: This suggestion improves error handling by checking if the JSON map is empty, which prevents runtime errors and provides a clear exception message. It addresses a potential bug effectively. | 8 | |
Ensure safe casting of
| 7 | |
Prevent potential null dereference by adding null checks or assertionsAdd null checks or assertions for the packages/substrate_metadata/lib/metadata/v14.dart [44-54]
Suggestion importance[1-10]: 7Why: Adding an assertion to check for null input is a good practice to prevent runtime errors. This change enhances the robustness of the code by ensuring that the input is not null before proceeding with the decode operation. | 7 | |
Ensure non-null JSON input in deserialization methods to prevent errorsAdd null checks for the 'json' parameter in the packages/substrate_metadata/lib/scale_info/type_definition.dart [10]
Suggestion importance[1-10]: 7Why: Adding a null check for the JSON parameter is a good practice to prevent null pointer exceptions. It enhances the robustness of the code by ensuring that the input is valid. | 7 | |
| Maintainability |
Refactor duplicated metadata fetching logic into a separate methodRefactor the repeated logic for fetching and validating packages/polkadart_cli/bin/get_metadata.dart [19-32]
Suggestion importance[1-10]: 6Why: The suggestion promotes code maintainability by refactoring repeated logic into a separate method. This reduces code duplication and makes future updates easier, although it does not address any critical issues. | 6 |
| Enhancement |
Enhance error handling in
| 5 |
Improve error handling by providing more descriptive error messagesConsider handling the case where packages/substrate_metadata/lib/metadata/v14.dart [160-178]
Suggestion importance[1-10]: 5Why: The suggestion provides a slightly more descriptive error message, which can help with debugging. However, the improvement is marginal as it only adds a generic suggestion to check input source or data integrity. | 5 |
Also please bump substrate_metadata to v2.0.0 as that will be a breaking change from what we talked about
Ok, I've add support to metadata v15, I think this one is ready now.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 69.81%. Comparing base (
f087b3a) to head (124bba9).
Additional details and impacted files
@@ Coverage Diff @@
## main #487 +/- ##
===========================================
+ Coverage 50.05% 69.81% +19.75%
===========================================
Files 203 22 -181
Lines 10408 805 -9603
===========================================
- Hits 5210 562 -4648
+ Misses 5198 243 -4955
| Flag | Coverage Δ | |
|---|---|---|
| ink_abi | 69.81% <ø> (ø) |
|
| polkadart | ? |
|
| polkadart_cli | ? |
|
| polkadart_keyring | ? |
|
| polkadart_scale_codec | ? |
|
| secp256k1_ecdsa | ? |
|
| sr25519 | ? |
|
| ss58 | ? |
|
| substrate_bip39 | ? |
|
| substrate_metadata | ? |
Flags with carried forward coverage won't be shown. Click here to find out more.