-
Notifications
You must be signed in to change notification settings - Fork 33
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
[Genesis and Config] Replace the placeholders with mvp implementations #154
Comments
@andrewnguyen22 Since you plan on tackling this later this week, wanted to add something I've been wanting to fix here. Partially, I'm leaving it as a comment so I don't forget either. Inside of shared/types/genesis/validator.go, I added the code snippet below, which was a hack I'm a bit ashamed of. It was needed in order to be able to use the same type (generated strcut from protobuf) in both our business logic and when loading a type from a json file. However, per the comment from @deblasis here, there is an opportunity to leverage package genesis
import (
"encoding/hex"
"encoding/json"
"google.golang.org/protobuf/encoding/protojson"
)
// HACK: Since the protocol actor protobufs (e.g. validator, fisherman, etc) use `bytes` for some
// fields (e.g. `address`, `output`, `publicKey`), we need to use a helper struct to unmarshal the
// the types when they are defined via json (e.g. genesis file, testing configurations, etc...).
// Alternative solutions could include whole wrapper structs (i.e. duplication of schema definition),
// using strings instead of bytes (i.e. major change with downstream effects) or avoid defining these
// types in json altogether (i.e. limitation of usability).
type JsonBytesLoaderHelper struct {
Address HexData `json:"address,omitempty"`
PublicKey HexData `json:"public_key,omitempty"`
Output HexData `json:"output,omitempty"`
}
type HexData []byte
func (h *HexData) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
decoded, err := hex.DecodeString(s)
if err != nil {
return err
}
*h = HexData(decoded)
return nil
}
func (v *Validator) UnmarshalJSON(data []byte) error {
var jh JsonBytesLoaderHelper
json.Unmarshal(data, &jh)
protojson.Unmarshal(data, v)
v.Address = jh.Address
v.PublicKey = jh.PublicKey
v.Output = jh.Output
return nil
} |
Objective
Origin Document
The current implementation is a POC that enables the mvp. In order to achieve a successful M1, true genesis and configuration processing is (P0) required.
Goals / Deliverables
General issue checklist
Creator: @andrewnguyen22
The text was updated successfully, but these errors were encountered: