Compare commits

...

35 Commits

Author SHA1 Message Date
0xmuralik
bbb6d2a7ab Merge branch 'main' of github.com:cerc-io/laconicd into murali/record-attributes 2023-03-16 10:39:40 +05:30
0xmuralik
656b8dc79b name tag for ref 2023-03-09 16:05:53 +05:30
0xmuralik
f827ea46b8 Revert "revert to '/' for hash ref"
This reverts commit beb1ad2df7.
2023-03-09 10:34:59 +05:30
0xmuralik
5cd07d9104 Revert "fix tests"
This reverts commit b90bb05b3f.
2023-03-09 10:34:47 +05:30
0xmuralik
30cbba44e7 Revert "cli test"
This reverts commit b59eb6878d.
2023-03-09 10:34:31 +05:30
0xmuralik
b59eb6878d cli test 2023-03-02 15:59:59 +05:30
0xmuralik
b90bb05b3f fix tests 2023-03-02 12:14:29 +05:30
0xmuralik
beb1ad2df7 revert to '/' for hash ref 2023-03-02 11:24:15 +05:30
0xmuralik
6025fadc71 Merge branch 'main' of github.com:cerc-io/laconicd into murali/record-attributes 2023-02-27 13:39:04 +05:30
0xmuralik
fa406be65f fix grpc query unit test 2023-01-30 17:34:43 +05:30
0xmuralik
e18541523d remove map and use HashRef obj 2023-01-30 15:46:12 +05:30
0xmuralik
4d5568bf83 gosec 2023-01-20 16:20:46 +05:30
0xmuralik
ff10aac7d7 unit tests 2023-01-20 15:06:13 +05:30
0xmuralik
38c77c10f6 imporve insert attributes logic 2023-01-20 12:14:33 +05:30
0xmuralik
bd04a6307e remove duplicate examples 2023-01-20 10:24:38 +05:30
0xmuralik
6e272334e4 edit variable names 2023-01-20 10:19:48 +05:30
0xmuralik
bf1670be78 payload to record attributes 2023-01-19 15:44:56 +05:30
0xmuralik
67208b08af type in git repo type 2023-01-19 15:31:08 +05:30
0xmuralik
2e986c4d5e fix serviceproviderrecord name 2023-01-19 13:05:56 +05:30
0xmuralik
e38ed67657 remove few types and proto-gen 2023-01-19 12:57:10 +05:30
0xmuralik
145d52f92e mock examples 2023-01-18 15:41:14 +05:30
0xmuralik
4ba723a384 WebsiteRegistrationRecord 2023-01-17 12:03:48 +05:30
0xmuralik
420042b9de hash reference 2023-01-17 11:55:08 +05:30
0xmuralik
d44ab22d87 delete duplicate code 2023-01-11 16:34:20 +05:30
0xmuralik
66cf0f758c proto for remaining record types 2023-01-11 16:23:29 +05:30
0xmuralik
c3774a3b96 merge from main 2023-01-11 15:14:05 +05:30
0xmuralik
39038980cc record names 2023-01-03 14:28:58 +05:30
0xmuralik
26300b0738 versioning record attributes and http post rules for rpc messages 2023-01-02 17:45:52 +05:30
0xmuralik
021ab7df1f patch typed data 2023-01-02 15:44:15 +05:30
0xmuralik
6eeed3de91 hardcode record attributes 2022-12-28 16:13:23 +05:30
0xmuralik
9e91a70f31 patch message types 2022-12-27 12:21:49 +05:30
0xmuralik
961f0f737a patch setRecord in WrapTxToTypedData 2022-12-26 10:59:36 +05:30
0xmuralik
930cca939f gofmpt 2022-12-21 14:56:05 +05:30
0xmuralik
e8fe95114a unpackInterfaces 2022-12-21 13:26:34 +05:30
0xmuralik
82b2c32575 unpack interface 2022-12-19 15:11:52 +05:30
20 changed files with 4449 additions and 260 deletions

View File

@ -5,13 +5,16 @@ import "gogoproto/gogo.proto";
option go_package = "github.com/cerc-io/laconicd/x/registry/types"; option go_package = "github.com/cerc-io/laconicd/x/registry/types";
message ServiceProviderRegistration { message HashReference{
string ref =1 [(gogoproto.jsontag) = "/"];
}
message ServiceProviderRecord {
string bond_id = 1 [(gogoproto.moretags) = "json:\"bondId\" yaml:\"bondId\""]; string bond_id = 1 [(gogoproto.moretags) = "json:\"bondId\" yaml:\"bondId\""];
string laconic_id = 2 [(gogoproto.moretags) = "json:\"laconicId\" yaml:\"laconicId\""]; string laconic_id = 2 [(gogoproto.moretags) = "json:\"laconicId\" yaml:\"laconicId\""];
X500 x500 = 3 [(gogoproto.moretags) = "json:\"x500\" yaml:\"x500\""]; X500 x500 = 3 [(gogoproto.moretags) = "json:\"x500\" yaml:\"x500\""];
string type = 4 [(gogoproto.moretags) = "json:\"type\" yaml:\"type\""]; string type = 4 [(gogoproto.moretags) = "json:\"type\" yaml:\"type\""];
string version = 6 [(gogoproto.moretags) = "json:\"version\" yaml:\"version\""]; string version = 6 [(gogoproto.moretags) = "json:\"version\" yaml:\"version\""];
}
message X500 { message X500 {
string common_name = 1 [(gogoproto.moretags) = "json:\"commonName\" yaml:\"commonName\""]; string common_name = 1 [(gogoproto.moretags) = "json:\"commonName\" yaml:\"commonName\""];
@ -21,13 +24,90 @@ message X500 {
string state_name = 5 [(gogoproto.moretags) = "json:\"stateName\" yaml:\"stateName\""]; string state_name = 5 [(gogoproto.moretags) = "json:\"stateName\" yaml:\"stateName\""];
string country = 6 [(gogoproto.moretags) = "json:\"country\" yaml:\"country\""]; string country = 6 [(gogoproto.moretags) = "json:\"country\" yaml:\"country\""];
} }
}
message WebsiteRegistrationRecord { message WebsiteRegistrationRecord {
string url = 1 [(gogoproto.moretags) = "json:\"url\" yaml:\"url\""]; string url = 1 [(gogoproto.moretags) = "json:\"url\" yaml:\"url\""];
string repo_registration_record_cid = 2 HashReference repo_reference = 2
[(gogoproto.moretags) = "json:\"repoRegistrationRecordCID\" yaml:\"repoRegistrationRecordCID\""]; [(gogoproto.moretags) = "json:\"repoReference\" yaml:\"repoReference\""];
string build_artifact_cid = 3 [(gogoproto.moretags) = "json:\"buildArtifactCID\" yaml:\"buildArtifactCID\""]; HashReference build_artifact_ref = 3 [(gogoproto.moretags) = "json:\"buildArtifactRef\" yaml:\"buildArtifactRef\""];
string tls_cert_cid = 4 [(gogoproto.moretags) = "json:\"TLSCertCID\" yaml:\"TLSCertCID\""]; HashReference tls_cert_ref = 4 [(gogoproto.moretags) = "json:\"tlsCertRef\" yaml:\"tlsCertRef\""];
string type = 5 [(gogoproto.moretags) = "json:\"type\" yaml:\"type\""]; string type = 5 [(gogoproto.moretags) = "json:\"type\" yaml:\"type\""];
string version = 6 [(gogoproto.moretags) = "json:\"version\" yaml:\"version\""]; string version = 6 [(gogoproto.moretags) = "json:\"version\" yaml:\"version\""];
} }
message GitRepository{
string name =1 [(gogoproto.moretags) = "json:\"name\" yaml:\"name\""];
string repo_reference=2 [(gogoproto.moretags) = "json:\"repo_reference\" yaml:\"repo_reference\""];
string description=3 [(gogoproto.moretags) = "json:\"description\" yaml:\"description\""];
string version = 4 [(gogoproto.moretags) = "json:\"version\" yaml:\"version\""];
string type =5 [(gogoproto.moretags) = "json:\"type\" yaml:\"type\""];
}
message Binary{
HashReference hash_reference=1;
string targeted_arch=2;
string runtime_version=3;
HashReference repo_reference=4;
string version=5;
string type=6;
}
message DockerImage{
string image_id=1;
HashReference binary_reference=2;
HashReference repo_reference=3;
string version=4;
string type=5;
}
message WatcherRegistrationRecord{
WatcherMetadata metadata =1;
HashReference repo_reference=2;
WASMBinary wasm=3;
string version=4;
string type=5;
message WatcherMetadata{
string version=1;
HashReference chain_reference=2;
}
message WASMBinary{
HashReference hash_reference=1;
WASMBinaryMetadata metadata=2;
}
message WASMBinaryMetadata{
string compiler_version=1;
string execution_engine_version=2;
}
}
message ResponderContract{
HashReference service_provider_ref=1;
HashReference auction_ref=2;
HashReference watcher_ref=3;
string version=4;
string type=5;
}
message JSPackage{
HashReference repo_reference=1;
HashReference js_package_ref=2;
string version=3;
string type=4;
string name =5;
}
message ChainRegistrationRecord{
string name=1;
repeated string ipld_types=2;
string type=3;
string version=4;
string chain_id=5;
string network_id=6;
HashReference genesis_hash=7;
}

View File

@ -209,7 +209,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryRecordExpiryQueue() {
func(bondId string) { func(bondId string) {
dir, err := os.Getwd() dir, err := os.Getwd()
sr.NoError(err) sr.NoError(err)
payloadPath := dir + "/service_provider_example.yml" payloadPath := dir + "/../../helpers/examples/service_provider_example.yml"
args := []string{ args := []string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName), fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
@ -353,7 +353,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryListRecords() {
func(bondId string) { func(bondId string) {
dir, err := os.Getwd() dir, err := os.Getwd()
sr.NoError(err) sr.NoError(err)
payloadPath := dir + "/service_provider_example.yml" payloadPath := dir + "/../../helpers/examples/service_provider_example.yml"
args := []string{ args := []string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName), fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
@ -626,7 +626,7 @@ func createRecord(bondID string, s *IntegrationTestSuite) {
dir, err := os.Getwd() dir, err := os.Getwd()
sr.NoError(err) sr.NoError(err)
payloadPath := dir + "/service_provider_example.yml" payloadPath := dir + "/../../helpers/examples/service_provider_example.yml"
args := []string{ args := []string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName), fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),

View File

@ -79,7 +79,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryForRecords() {
bondID := GetBondID(s) bondID := GetBondID(s)
dir, err := os.Getwd() dir, err := os.Getwd()
sr.NoError(err) sr.NoError(err)
payloadPath := dir + "/service_provider_example.yml" payloadPath := dir + "/../../helpers/examples/service_provider_example.yml"
args := []string{ args := []string{
payloadPath, bondID, payloadPath, bondID,
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName), fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),

View File

@ -1,13 +0,0 @@
record:
type: ServiceProviderRegistration
bond_id: madeUpBondID
laconic_id: madeUpLaconicID
version: 1.0.0
x500:
common_name: cerc-io
organization_unit: xyz
organization_name: abc
state_name: california
country: US
locality_name: local

View File

@ -198,7 +198,7 @@ func (s *IntegrationTestSuite) TestGetCmdSetRecord() {
bondID := GetBondID(s) bondID := GetBondID(s)
dir, err := os.Getwd() dir, err := os.Getwd()
sr.NoError(err) sr.NoError(err)
payloadPath := dir + "/service_provider_example.yml" payloadPath := dir + "/../../helpers/examples/watcher_registration_example.yml"
tc.args = append([]string{payloadPath, bondID}, tc.args...) tc.args = append([]string{payloadPath, bondID}, tc.args...)
} }
@ -580,7 +580,7 @@ func (s *IntegrationTestSuite) TestGetCmdDissociateBond() {
bondID := GetBondID(s) bondID := GetBondID(s)
dir, err := os.Getwd() dir, err := os.Getwd()
sr.NoError(err) sr.NoError(err)
payloadPath := dir + "/service_provider_example.yml" payloadPath := dir + "/../../helpers/examples/service_provider_example.yml"
args := []string{ args := []string{
payloadPath, bondID, payloadPath, bondID,
@ -822,7 +822,7 @@ func (s *IntegrationTestSuite) TestGetCmdAssociateBond() {
bondID := GetBondID(s) bondID := GetBondID(s)
dir, err := os.Getwd() dir, err := os.Getwd()
sr.NoError(err) sr.NoError(err)
payloadPath := dir + "/service_provider_example.yml" payloadPath := dir + "/../../helpers/examples/service_provider_example.yml"
txArgs := []string{ txArgs := []string{
payloadPath, bondID, payloadPath, bondID,

View File

@ -1,7 +0,0 @@
record:
type: WebsiteRegistrationRecord
url: https://cerc.io
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
version: 1.0.0

View File

@ -0,0 +1,9 @@
record:
hash_reference:
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
targeted_arch: x86_64
runtime_version: go 1.18
repo_reference:
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
version: 1.0.0
type: Binary

View File

@ -0,0 +1,13 @@
record:
name: Laconic
ipld_types:
- type3
- type11
- schema2
- codec5
type: ChainRegistrationRecord
version: 0.11.2
chain_id: laconic_9000-1
network_id: "1392"
genesis_hash:
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D

View File

@ -0,0 +1,8 @@
record:
image_id: 77af4d6b9913
binary_reference:
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
repo_reference:
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
version: 1.0.0
type: DockerImage

View File

@ -0,0 +1,6 @@
record:
name: cosmos-sdk
repo_reference: https://github.com/cosmos/cosmos-sdk
description: This is a description string
version: 0.46.7
type: GitRepository

View File

@ -1,7 +1,8 @@
record: record:
attr1: value1 repo_reference:
attr2: value2
link1:
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
link2:
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9 /: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
js_package_ref:
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
version: 1.0.0
type: JSPackage
name: test-JSPackage

View File

@ -0,0 +1,9 @@
record:
service_provider_ref:
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
auction_ref:
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
watcher_ref:
/: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
version: 1.0.0
type: ResponderContract

View File

@ -1,6 +1,6 @@
record: record:
type: ServiceProviderRegistration type: ServiceProviderRecord
bond_id: madeUpBondID bond_id: madeUpBondID
laconic_id: madeUpLaconicID laconic_id: madeUpLaconicID
version: 1.0.0 version: 1.0.0

View File

@ -0,0 +1,15 @@
record:
metadata:
version: 0.32.0
chain_reference:
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
repo_reference:
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
wasm:
hash_reference:
/: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
metadata:
compiler_version: 1.15.0
execution_engine_version: 0.16.1
version: 1.0.0
type: WatcherRegistrationRecord

View File

@ -1,7 +1,10 @@
record: record:
type: WebsiteRegistrationRecord type: WebsiteRegistrationRecord
url: https://cerc.io url: https://cerc.io
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D repo_reference:
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9 /: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
tls_cerc_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR build_artifact_ref:
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
tls_cert_ref:
/: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
version: 1.0.0 version: 1.0.0

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"os" "os"
"strings"
"github.com/cerc-io/laconicd/x/registry/client/cli" "github.com/cerc-io/laconicd/x/registry/client/cli"
"github.com/cerc-io/laconicd/x/registry/helpers" "github.com/cerc-io/laconicd/x/registry/helpers"
@ -37,7 +38,14 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
sr := suite.Require() sr := suite.Require()
var recordId string var recordId string
examples := []string{ examples := []string{
"/../helpers/examples/binary_example.yml",
"/../helpers/examples/chain_registration_example.yml",
"/../helpers/examples/docker_image_example.yml",
"/../helpers/examples/git_repo_example.yml",
"/../helpers/examples/js_package_example.yml",
"/../helpers/examples/responder_contract_example.yml",
"/../helpers/examples/service_provider_example.yml", "/../helpers/examples/service_provider_example.yml",
"/../helpers/examples/watcher_registration_example.yml",
"/../helpers/examples/website_registration_example.yml", "/../helpers/examples/website_registration_example.yml",
} }
testCases := []struct { testCases := []struct {
@ -59,14 +67,14 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
&registrytypes.QueryListRecordsRequest{}, &registrytypes.QueryListRecordsRequest{},
true, true,
false, false,
2, len(examples),
}, },
{ {
"Filter with type", "Filter with type",
&registrytypes.QueryListRecordsRequest{ &registrytypes.QueryListRecordsRequest{
Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{ Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{
{ {
Key: "type", Key: "type---",
Value: &registrytypes.QueryListRecordsRequest_ValueInput{ Value: &registrytypes.QueryListRecordsRequest_ValueInput{
Type: "string", Type: "string",
String_: "WebsiteRegistrationRecord", String_: "WebsiteRegistrationRecord",
@ -80,11 +88,11 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
1, 1,
}, },
{ {
"Filter with attributes ServiceProviderRegistration", "Filter with attributes ServiceProviderRecord",
&registrytypes.QueryListRecordsRequest{ &registrytypes.QueryListRecordsRequest{
Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{ Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{
{ {
Key: "x500state_name", Key: "x500---state_name---",
Value: &registrytypes.QueryListRecordsRequest_ValueInput{ Value: &registrytypes.QueryListRecordsRequest_ValueInput{
Type: "string", Type: "string",
String_: "california", String_: "california",
@ -97,6 +105,42 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
false, false,
1, 1,
}, },
{
"Filter with attributes WatcherRegistrationRecord",
&registrytypes.QueryListRecordsRequest{
Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{
{
Key: "metadata---chain_reference---/---",
Value: &registrytypes.QueryListRecordsRequest_ValueInput{
Type: "string",
String_: "QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9",
},
},
},
All: true,
},
true,
false,
1,
},
{
"Filter with attributes version",
&registrytypes.QueryListRecordsRequest{
Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{
{
Key: "version---",
Value: &registrytypes.QueryListRecordsRequest_ValueInput{
Type: "string",
String_: "1.0.0",
},
},
},
All: true,
},
true,
false,
7,
},
} }
for _, test := range testCases { for _, test := range testCases {
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() { suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
@ -133,11 +177,7 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
sr.NoError(err) sr.NoError(err)
recAttr := helpers.UnMarshalMapFromJSONBytes(bz) recAttr := helpers.UnMarshalMapFromJSONBytes(bz)
for _, attr := range test.req.GetAttributes() { for _, attr := range test.req.GetAttributes() {
if attr.Key[:4] == "x500" { sr.Equal(keeper.GetAttributeValue(attr.Value), getAttributesFromRecord(recAttr, attr.Key))
sr.Equal(keeper.GetAttributeValue(attr.Value), recAttr["x500"].(map[string]interface{})[attr.Key[4:]])
} else {
sr.Equal(keeper.GetAttributeValue(attr.Value), recAttr[attr.Key])
}
} }
} }
} }
@ -228,6 +268,17 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
} }
} }
func getAttributesFromRecord(recordAttr map[string]interface{}, key string) interface{} {
keys := strings.Split(key, "---")
for i, str := range keys {
if i == len(keys)-2 {
return recordAttr[str].(string)
}
recordAttr = recordAttr[str].(map[string]interface{})
}
return nil
}
func (suite *KeeperTestSuite) TestGrpcQueryRegistryModuleBalance() { func (suite *KeeperTestSuite) TestGrpcQueryRegistryModuleBalance() {
grpcClient, ctx := suite.queryClient, suite.ctx grpcClient, ctx := suite.queryClient, suite.ctx
sr := suite.Require() sr := suite.Require()

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"reflect" // #nosec G702 This is also used in eip712 antehandler code. No new risk introduced.
"sort" "sort"
"time" "time"
@ -317,45 +318,34 @@ func (k Keeper) PutRecord(ctx sdk.Context, record types.Record) {
} }
func (k Keeper) ProcessAttributes(ctx sdk.Context, record types.RecordType) error { func (k Keeper) ProcessAttributes(ctx sdk.Context, record types.RecordType) error {
switch record.Attributes["type"] { if err := k.insertAttributes(ctx, record.ID, record.Attributes, ""); err != nil {
case "ServiceProviderRegistration": return err
{ }
expiryTimeKey := GetAttributesIndexKey(ExpiryTimeAttributeName, record.ExpiryTime)
if err := k.setAttributeMapping(ctx, expiryTimeKey, record.ID); err != nil {
return err
}
return nil
}
func (k Keeper) insertAttributes(ctx sdk.Context, recordID string, attr interface{}, keyPrefix string) error {
if reflect.TypeOf(attr).Kind() == reflect.Map {
val := attr.(map[string]interface{})
// #nosec G705 // #nosec G705
for key := range record.Attributes { for key := range val {
if key == "x500" { newKeyPrefix := fmt.Sprint(keyPrefix + key + "---")
// #nosec G705 if err := k.insertAttributes(ctx, recordID, val[key], newKeyPrefix); err != nil {
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 return err
} }
} }
} else { } else {
indexKey := GetAttributesIndexKey(key, record.Attributes[key]) indexKey := GetAttributesIndexKey(keyPrefix, attr)
if err := k.SetAttributeMapping(ctx, indexKey, record.ID); err != nil { if err := k.setAttributeMapping(ctx, indexKey, recordID); err != nil {
return err return err
} }
} }
}
}
case "WebsiteRegistrationRecord":
{
// #nosec G705
for key := range record.Attributes {
indexKey := GetAttributesIndexKey(key, record.Attributes[key])
if err := k.SetAttributeMapping(ctx, indexKey, record.ID); err != nil {
return err
}
}
}
default:
return fmt.Errorf("unsupported record type %s", record.Attributes["type"])
}
expiryTimeKey := GetAttributesIndexKey(ExpiryTimeAttributeName, record.ExpiryTime)
if err := k.SetAttributeMapping(ctx, expiryTimeKey, record.ID); err != nil {
return err
}
return nil return nil
} }
@ -365,7 +355,7 @@ func GetAttributesIndexKey(key string, value interface{}) []byte {
return append(PrefixAttributesIndex, []byte(keyString)...) return append(PrefixAttributesIndex, []byte(keyString)...)
} }
func (k Keeper) SetAttributeMapping(ctx sdk.Context, key []byte, recordID string) error { func (k Keeper) setAttributeMapping(ctx sdk.Context, key []byte, recordID string) error {
store := ctx.KVStore(k.storeKey) store := ctx.KVStore(k.storeKey)
var recordIds []string var recordIds []string
if store.Has(key) { if store.Has(key) {

File diff suppressed because it is too large Load Diff

View File

@ -40,9 +40,9 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
) )
registry.RegisterInterface( registry.RegisterInterface(
"vulcanize.registry.v1beta1.ServiceProvideRegistration", "vulcanize.registry.v1beta1.ServiceProviderRecord",
(*Attributes)(nil), (*Attributes)(nil),
&ServiceProviderRegistration{}, &ServiceProviderRecord{},
) )
registry.RegisterInterface( registry.RegisterInterface(
@ -50,6 +50,48 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
(*Attributes)(nil), (*Attributes)(nil),
&WebsiteRegistrationRecord{}, &WebsiteRegistrationRecord{},
) )
registry.RegisterInterface(
"vulcanize.registry.v1beta1.GitRepository",
(*Attributes)(nil),
&GitRepository{},
)
registry.RegisterInterface(
"vulcanize.registry.v1beta1.Binary",
(*Attributes)(nil),
&Binary{},
)
registry.RegisterInterface(
"vulcanize.registry.v1beta1.DockerImage",
(*Attributes)(nil),
&DockerImage{},
)
registry.RegisterInterface(
"vulcanize.registry.v1beta1.WatcherRegistrationRecord",
(*Attributes)(nil),
&WatcherRegistrationRecord{},
)
registry.RegisterInterface(
"vulcanize.registry.v1beta1.ResponderContract",
(*Attributes)(nil),
&ResponderContract{},
)
registry.RegisterInterface(
"vulcanize.registry.v1beta1.JSPackage",
(*Attributes)(nil),
&JSPackage{},
)
registry.RegisterInterface(
"vulcanize.registry.v1beta1.ChainRegistrationRecord",
(*Attributes)(nil),
&ChainRegistrationRecord{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
} }

View File

@ -50,9 +50,9 @@ func payLoadAttributes(recordPayLoad map[string]interface{}) (*codectypes.Any, e
bz := helpers.MarshalMapToJSONBytes(recordPayLoad) bz := helpers.MarshalMapToJSONBytes(recordPayLoad)
switch recordType.(string) { switch recordType.(string) {
case "ServiceProviderRegistration": case "ServiceProviderRecord":
{ {
var attributes ServiceProviderRegistration var attributes ServiceProviderRecord
err := json.Unmarshal(bz, &attributes) err := json.Unmarshal(bz, &attributes)
if err != nil { if err != nil {
return &codectypes.Any{}, err return &codectypes.Any{}, err
@ -68,6 +68,69 @@ func payLoadAttributes(recordPayLoad map[string]interface{}) (*codectypes.Any, e
} }
return codectypes.NewAnyWithValue(&attributes) return codectypes.NewAnyWithValue(&attributes)
} }
case "GitRepository":
{
var attributes GitRepository
err := json.Unmarshal(bz, &attributes)
if err != nil {
return &codectypes.Any{}, err
}
return codectypes.NewAnyWithValue(&attributes)
}
case "Binary":
{
var attributes Binary
err := json.Unmarshal(bz, &attributes)
if err != nil {
return &codectypes.Any{}, err
}
return codectypes.NewAnyWithValue(&attributes)
}
case "DockerImage":
{
var attributes DockerImage
err := json.Unmarshal(bz, &attributes)
if err != nil {
return &codectypes.Any{}, err
}
return codectypes.NewAnyWithValue(&attributes)
}
case "WatcherRegistrationRecord":
{
var attributes WatcherRegistrationRecord
err := json.Unmarshal(bz, &attributes)
if err != nil {
return &codectypes.Any{}, err
}
return codectypes.NewAnyWithValue(&attributes)
}
case "ResponderContract":
{
var attributes ResponderContract
err := json.Unmarshal(bz, &attributes)
if err != nil {
return &codectypes.Any{}, err
}
return codectypes.NewAnyWithValue(&attributes)
}
case "JSPackage":
{
var attributes JSPackage
err := json.Unmarshal(bz, &attributes)
if err != nil {
return &codectypes.Any{}, err
}
return codectypes.NewAnyWithValue(&attributes)
}
case "ChainRegistrationRecord":
{
var attributes ChainRegistrationRecord
err := json.Unmarshal(bz, &attributes)
if err != nil {
return &codectypes.Any{}, err
}
return codectypes.NewAnyWithValue(&attributes)
}
default: default:
return &codectypes.Any{}, fmt.Errorf("unsupported record type %s", recordType.(string)) return &codectypes.Any{}, fmt.Errorf("unsupported record type %s", recordType.(string))
} }
@ -114,9 +177,9 @@ func GetJSONBytesFromAny(any codectypes.Any) ([]byte, error) {
var bz []byte var bz []byte
s := strings.Split(any.TypeUrl, ".") s := strings.Split(any.TypeUrl, ".")
switch s[len(s)-1] { switch s[len(s)-1] {
case "ServiceProviderRegistration": case "ServiceProviderRecord":
{ {
var attributes ServiceProviderRegistration var attributes ServiceProviderRecord
err := proto.Unmarshal(any.Value, &attributes) err := proto.Unmarshal(any.Value, &attributes)
if err != nil { if err != nil {
panic("Proto unmarshal error") panic("Proto unmarshal error")
@ -135,6 +198,97 @@ func GetJSONBytesFromAny(any codectypes.Any) ([]byte, error) {
panic("Proto unmarshal error") panic("Proto unmarshal error")
} }
bz, err = json.Marshal(attributes)
if err != nil {
panic("JSON marshal error")
}
}
case "GitRepository":
{
var attributes GitRepository
err := proto.Unmarshal(any.Value, &attributes)
if err != nil {
panic("Proto unmarshal error")
}
bz, err = json.Marshal(attributes)
if err != nil {
panic("JSON marshal error")
}
}
case "Binary":
{
var attributes Binary
err := proto.Unmarshal(any.Value, &attributes)
if err != nil {
panic("Proto unmarshal error")
}
bz, err = json.Marshal(attributes)
if err != nil {
panic("JSON marshal error")
}
}
case "DockerImage":
{
var attributes DockerImage
err := proto.Unmarshal(any.Value, &attributes)
if err != nil {
panic("Proto unmarshal error")
}
bz, err = json.Marshal(attributes)
if err != nil {
panic("JSON marshal error")
}
}
case "WatcherRegistrationRecord":
{
var attributes WatcherRegistrationRecord
err := proto.Unmarshal(any.Value, &attributes)
if err != nil {
panic("Proto unmarshal error")
}
bz, err = json.Marshal(attributes)
if err != nil {
panic("JSON marshal error")
}
}
case "ResponderContract":
{
var attributes ResponderContract
err := proto.Unmarshal(any.Value, &attributes)
if err != nil {
panic("Proto unmarshal error")
}
bz, err = json.Marshal(attributes)
if err != nil {
panic("JSON marshal error")
}
}
case "JSPackage":
{
var attributes JSPackage
err := proto.Unmarshal(any.Value, &attributes)
if err != nil {
panic("Proto unmarshal error")
}
bz, err = json.Marshal(attributes)
if err != nil {
panic("JSON marshal error")
}
}
case "ChainRegistrationRecord":
{
var attributes ChainRegistrationRecord
err := proto.Unmarshal(any.Value, &attributes)
if err != nil {
panic("Proto unmarshal error")
}
bz, err = json.Marshal(attributes) bz, err = json.Marshal(attributes)
if err != nil { if err != nil {
panic("JSON marshal error") panic("JSON marshal error")