diff --git a/x/nameservice/helpers/examples/service_provider_example.yml b/x/nameservice/helpers/examples/service_provider_example.yml new file mode 100644 index 00000000..b85862b4 --- /dev/null +++ b/x/nameservice/helpers/examples/service_provider_example.yml @@ -0,0 +1,11 @@ + +record: + type: ServiceProviderRegistration + bond_id: madeUpBondID + laconic_id: madeUpLaconicID + x500: + common_name: cerc-io + organization_unit: xyz + organization_name: abc + state_name: california + country: US \ No newline at end of file diff --git a/x/nameservice/helpers/examples/website_registration_example.yml b/x/nameservice/helpers/examples/website_registration_example.yml new file mode 100644 index 00000000..79c1de6a --- /dev/null +++ b/x/nameservice/helpers/examples/website_registration_example.yml @@ -0,0 +1,6 @@ +record: + type: WebsiteRegistrationRecord + url: https://cerc.io + repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D + build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9 + tls_cerc_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR \ No newline at end of file diff --git a/x/nameservice/keeper/grpc_query_test.go b/x/nameservice/keeper/grpc_query_test.go index 1387c507..4bbceeec 100644 --- a/x/nameservice/keeper/grpc_query_test.go +++ b/x/nameservice/keeper/grpc_query_test.go @@ -61,7 +61,7 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() { if test.createRecord { dir, err := os.Getwd() sr.NoError(err) - payloadType, err := cli.GetPayloadFromFile(dir + "/../helpers/examples/example1.yml") + payloadType, err := cli.GetPayloadFromFile(dir + "/../helpers/examples/service_provider_example.yml") sr.NoError(err) payload, err := payloadType.ToPayload() sr.NoError(err) diff --git a/x/nameservice/keeper/keeper.go b/x/nameservice/keeper/keeper.go index 4d3dd3b7..36c5c906 100644 --- a/x/nameservice/keeper/keeper.go +++ b/x/nameservice/keeper/keeper.go @@ -300,7 +300,7 @@ func (k Keeper) ProcessAttributes(ctx sdk.Context, record types.RecordType) erro for key := range record.Attributes { if key == "x500" { // #nosec G705 - for x500Key, x500Val := range record.Attributes[key].(map[string]string) { + for x500Key, x500Val := range record.Attributes[key].(map[string]interface{}) { indexKey := GetAttributesIndexKey(fmt.Sprintf("x500%s", x500Key), x500Val) if err := k.SetAttributeMapping(ctx, indexKey, record.ID); err != nil { return err diff --git a/x/nameservice/types/types.go b/x/nameservice/types/types.go index 8582a92b..2acd421f 100644 --- a/x/nameservice/types/types.go +++ b/x/nameservice/types/types.go @@ -4,10 +4,12 @@ import ( "crypto/sha256" "encoding/json" "fmt" + "strings" "github.com/cerc-io/laconicd/x/nameservice/helpers" codectypes "github.com/cosmos/cosmos-sdk/codec/types" canonicalJson "github.com/gibson042/canonicaljson-go" + "github.com/gogo/protobuf/proto" ) const ( @@ -41,7 +43,7 @@ func (payloadObj *PayloadType) ToPayload() (Payload, error) { } func payLoadAttributes(recordPayLoad map[string]interface{}) (*codectypes.Any, error) { - recordType, ok := recordPayLoad["Type"] + recordType, ok := recordPayLoad["type"] if !ok { return &codectypes.Any{}, fmt.Errorf("cannot get type from payload") } @@ -75,8 +77,38 @@ func payLoadAttributes(recordPayLoad map[string]interface{}) (*codectypes.Any, e // It will unmarshal with record attributes func (payload Payload) ToReadablePayload() PayloadType { var payloadType PayloadType - payloadType.Record = helpers.UnMarshalMapFromJSONBytes(payload.Record.Attributes.Value) + var bz []byte + s := strings.Split(payload.Record.Attributes.TypeUrl, ".") + switch s[len(s)-1] { + case "ServiceProviderRegistration": + { + var attributes ServiceProviderRegistration + err := proto.Unmarshal(payload.Record.Attributes.Value, &attributes) + if err != nil { + panic("Proto unmarshal error") + } + bz, err = json.Marshal(attributes) + if err != nil { + panic("JSON marshal error") + } + } + case "WebsiteRegistrationRecord": + { + var attributes WebsiteRegistrationRecord + err := proto.Unmarshal(payload.Record.Attributes.Value, &attributes) + if err != nil { + panic("Proto unmarshal error") + } + + bz, err = json.Marshal(attributes) + if err != nil { + panic("JSON marshal error") + } + } + } + + payloadType.Record = helpers.UnMarshalMapFromJSONBytes(bz) payloadType.Signatures = payload.Signatures return payloadType