diff --git a/x/registry/client/cli/query.go b/x/registry/client/cli/query.go index 462940a6..90d5eecc 100644 --- a/x/registry/client/cli/query.go +++ b/x/registry/client/cli/query.go @@ -161,7 +161,7 @@ $ %s query %s list } recordsList := res.GetRecords() - records := make([]types.RecordEncodable, len(recordsList)) + records := make([]types.ReadableRecord, len(recordsList)) for i, record := range res.GetRecords() { records[i] = record.ToReadableRecord() } diff --git a/x/registry/client/cli/tx.go b/x/registry/client/cli/tx.go index 477fe643..50981772 100644 --- a/x/registry/client/cli/tx.go +++ b/x/registry/client/cli/tx.go @@ -370,8 +370,8 @@ $ %s tx %s delete-name [crn] } // GetPayloadFromFile Load payload object from YAML file. -func GetPayloadFromFile(filePath string) (*types.PayloadEncodable, error) { - var payload types.PayloadEncodable +func GetPayloadFromFile(filePath string) (*types.ReadablePayload, error) { + var payload types.ReadablePayload data, err := os.ReadFile(filePath) // #nosec G304 if err != nil { diff --git a/x/registry/client/testutil/grpc.go b/x/registry/client/testutil/grpc.go index 835927fe..72eaa36f 100644 --- a/x/registry/client/testutil/grpc.go +++ b/x/registry/client/testutil/grpc.go @@ -433,7 +433,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryGetRecordByID() { } out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args) sr.NoError(err) - var records []nstypes.RecordEncodable + var records []nstypes.ReadableRecord err = json.Unmarshal(out.Bytes(), &records) sr.NoError(err) return records[0].ID diff --git a/x/registry/client/testutil/query.go b/x/registry/client/testutil/query.go index 9aaeab18..e0a433ff 100644 --- a/x/registry/client/testutil/query.go +++ b/x/registry/client/testutil/query.go @@ -114,7 +114,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryForRecords() { sr.Error(err) } else { sr.NoError(err) - var records []types.RecordEncodable + var records []types.ReadableRecord err := json.Unmarshal(out.Bytes(), &records) sr.NoError(err) sr.Equal(tc.noOfRecords, len(records)) diff --git a/x/registry/client/testutil/tx.go b/x/registry/client/testutil/tx.go index b85634ab..f7e2bea0 100644 --- a/x/registry/client/testutil/tx.go +++ b/x/registry/client/testutil/tx.go @@ -606,7 +606,7 @@ func (s *IntegrationTestSuite) TestGetCmdDissociateBond() { cmd = cli.GetCmdList() out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) sr.NoError(err) - var records []nstypes.RecordEncodable + var records []nstypes.ReadableRecord err = json.Unmarshal(out.Bytes(), &records) sr.NoError(err) return records[0].ID @@ -848,7 +848,7 @@ func (s *IntegrationTestSuite) TestGetCmdAssociateBond() { cmd = cli.GetCmdList() out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args) sr.NoError(err) - var records []nstypes.RecordEncodable + var records []nstypes.ReadableRecord err = json.Unmarshal(out.Bytes(), &records) sr.NoError(err) diff --git a/x/registry/keeper/keeper.go b/x/registry/keeper/keeper.go index 4eaac851..aab98ba7 100644 --- a/x/registry/keeper/keeper.go +++ b/x/registry/keeper/keeper.go @@ -267,9 +267,9 @@ func (k Keeper) GetRecordExpiryQueue(ctx sdk.Context) []*types.ExpiryQueueRecord } // ProcessSetRecord creates a record. -func (k Keeper) ProcessSetRecord(ctx sdk.Context, msg types.MsgSetRecord) (*types.RecordEncodable, error) { +func (k Keeper) ProcessSetRecord(ctx sdk.Context, msg types.MsgSetRecord) (*types.ReadableRecord, error) { payload := msg.Payload.ToReadablePayload() - record := types.RecordEncodable{Attributes: payload.RecordAttributes, BondID: msg.BondId} + record := types.ReadableRecord{Attributes: payload.RecordAttributes, BondID: msg.BondId} // Check signatures. resourceSignBytes, _ := record.GetSignBytes() @@ -308,7 +308,7 @@ func (k Keeper) ProcessSetRecord(ctx sdk.Context, msg types.MsgSetRecord) (*type return &record, nil } -func (k Keeper) processRecord(ctx sdk.Context, record *types.RecordEncodable, isRenewal bool) error { +func (k Keeper) processRecord(ctx sdk.Context, record *types.ReadableRecord, isRenewal bool) error { params := k.GetParams(ctx) rent := params.RecordRent diff --git a/x/registry/types/types.go b/x/registry/types/types.go index 9bb4fb71..b14a69f0 100644 --- a/x/registry/types/types.go +++ b/x/registry/types/types.go @@ -19,14 +19,14 @@ const ( type AttributeMap map[string]interface{} -// PayloadEncodable represents a signed record payload that can be serialized from/to YAML. -type PayloadEncodable struct { +// ReadablePayload represents a signed record payload that can be serialized from/to YAML. +type ReadablePayload struct { RecordAttributes AttributeMap `json:"record" yaml:"record"` Signatures []Signature `json:"signatures" yaml:"signatures"` } -// RecordEncodable represents a WNS record. -type RecordEncodable struct { +// ReadableRecord represents a WNS record. +type ReadableRecord struct { ID string `json:"id,omitempty"` Names []string `json:"names,omitempty"` BondID string `json:"bondId,omitempty"` @@ -39,7 +39,7 @@ type RecordEncodable struct { // ToPayload converts PayloadEncodable to Payload object. // Why? Because go-amino can't handle maps: https://github.com/tendermint/go-amino/issues/4. -func (payloadObj *PayloadEncodable) ToPayload() Payload { +func (payloadObj *ReadablePayload) ToPayload() Payload { // Note: record directly contains the attributes here attributes := payloadObj.RecordAttributes payload := Payload{ @@ -54,8 +54,8 @@ func (payloadObj *PayloadEncodable) ToPayload() Payload { } // ToReadablePayload converts Payload to a serializable object -func (payload Payload) ToReadablePayload() PayloadEncodable { - var encodable PayloadEncodable +func (payload Payload) ToReadablePayload() ReadablePayload { + var encodable ReadablePayload encodable.RecordAttributes = helpers.MustUnmarshalJSON[AttributeMap](payload.Record.Attributes) encodable.Signatures = payload.Signatures @@ -65,7 +65,7 @@ func (payload Payload) ToReadablePayload() PayloadEncodable { // ToRecordObj converts Record to RecordObj. // Why? Because go-amino can't handle maps: https://github.com/tendermint/go-amino/issues/4. -func (r *RecordEncodable) ToRecordObj() (Record, error) { +func (r *ReadableRecord) ToRecordObj() (Record, error) { var resourceObj Record resourceObj.Id = r.ID @@ -80,8 +80,8 @@ func (r *RecordEncodable) ToRecordObj() (Record, error) { } // ToReadableRecord converts Record to a serializable object -func (r *Record) ToReadableRecord() RecordEncodable { - var resourceObj RecordEncodable +func (r *Record) ToReadableRecord() ReadableRecord { + var resourceObj ReadableRecord resourceObj.ID = r.Id resourceObj.BondID = r.BondId @@ -96,7 +96,7 @@ func (r *Record) ToReadableRecord() RecordEncodable { } // CanonicalJSON returns the canonical JSON representation of the record. -func (r *RecordEncodable) CanonicalJSON() []byte { +func (r *ReadableRecord) CanonicalJSON() []byte { bytes, err := canonicaljson.Marshal(r.Attributes) if err != nil { panic("error marshalling record: " + err.Error()) @@ -106,7 +106,7 @@ func (r *RecordEncodable) CanonicalJSON() []byte { } // GetSignBytes generates a record hash to be signed. -func (r *RecordEncodable) GetSignBytes() ([]byte, []byte) { +func (r *ReadableRecord) GetSignBytes() ([]byte, []byte) { // Double SHA256 hash. // Input to the first round of hashing. @@ -126,7 +126,7 @@ func (r *RecordEncodable) GetSignBytes() ([]byte, []byte) { } // GetCID gets the record CID. -func (r *RecordEncodable) GetCID() (string, error) { +func (r *ReadableRecord) GetCID() (string, error) { id, err := helpers.GetCid(r.CanonicalJSON()) if err != nil { return "", err