-
Notifications
You must be signed in to change notification settings - Fork 110
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
enhancement(lib/genesis): Create struct of Runtime field of the Genesis struct. #2808
enhancement(lib/genesis): Create struct of Runtime field of the Genesis struct. #2808
Conversation
Closes 2766
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## development #2808 +/- ##
===============================================
+ Coverage 51.30% 51.45% +0.15%
===============================================
Files 226 227 +1
Lines 28228 28370 +142
===============================================
+ Hits 14481 14599 +118
- Misses 12351 12372 +21
- Partials 1396 1399 +3 |
MarshalJSON
/UnmarshalJSON
methods for Runtime field of the Genesis struct.MarshalJSON
/UnmarshalJSON
methods for Runtime field of the Genesis struct.
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.
#2766 is not totally explicit/clear on what's expected to be done, sorry about that, but let me clarify! 😉
We need a Runtime
struct
type Runtime struct {
System System `json:"system"`
Babe Babe `json:"babe"`
// ... other fields ...
}
You can check the runtime child JSON fields in chain/**/*-spec.json files. For example:
gossamer/chain/dev/genesis-spec.json
Line 11 in 78a1dbd
"runtime": { |
You will need to define other child structs such as for "babe"
with the right json struct field tags.
Start with implementing these structs;
We don't need a custom MarshalJSON
(json.Marshal
will take care of it correctly using the json:"fieldname"
struct field tag), but we will need a custom UnmarshalJSON
only on Runtime
since some genesis-spec.json files have the system json key as "system"
and some older ones as "System"
. Note however you can and should unmarshal within this custom UnmarshalJSON
with json.Unmarshal(data, r)
(where r
is the *Runtime
), and if the System
struct field is still empty try to extract the "System"
key as a fall back.
You might also want to add a unit test (I can help just tag me @qdm12) for the custom UnmarshalJSON
since it's tricky to get right without testing it.
@qdm12
|
@danforbes any idea? By the way where is the 'latest' JSON structure documented? We could use the latest official doc at least to encode from our Go struct to JSON (and thus set the json struct field tags). At least, the 'structure' didn't change it seems, it's just the field names that changed over time. As a consequence, we can still use the same Go struct for all JSON decoding, but we will need to support decoding using different JSON field keys (trying the latest naming format first, then the older ones) using custom Until this is resolved, you can still add Go |
You can define the Go structs for the genesis (even if the json keys differ), and we will just focus on the latest format, so that means no custom The latest format can be found by digging into https://paritytech.github.io/substrate/master/src/sc_chain_spec/chain_spec.rs.html#205 (parity uses |
MarshalJSON
/UnmarshalJSON
methods for Runtime field of the Genesis struct.modified Runtime struct fields to use the fields given in local/westend-local file.
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.
LGTM, just a tiny comment over the scale.Uint128
MarshalJSON method
Co-authored-by: Eclésio Junior <eclesiomelo.1@gmail.com>
This reverts commit d894a2c.
🎉 This PR is included in version 0.8.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Changes
Created struct for Runtime field of Genesis struct.
Created structs for all the fields of Runtime struct.
Wrote Marshal and Unmarshal methods for
Wrote Marshal method for Uint128.
added empty string check for function argument of
PublicAddressToByteArray
function in lib/crypto/keypair.goTests
go test -tags integration github.com/ChainSafe/gossamer
Issues
fixes #2766
Primary Reviewer
@timwu20