feat: remaining record content types to support #79

Closed
0xmuralik wants to merge 35 commits from murali/record-attributes into main
20 changed files with 4449 additions and 260 deletions

View File

@ -5,29 +5,109 @@ 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\""];
string organization_unit = 2 [(gogoproto.moretags) = "json:\"organizationUnit\" yaml:\"organizationUnit\""]; string organization_unit = 2 [(gogoproto.moretags) = "json:\"organizationUnit\" yaml:\"organizationUnit\""];
string organization_name = 3 [(gogoproto.moretags) = "json:\"organizationName\" yaml:\"organizationName\""]; string organization_name = 3 [(gogoproto.moretags) = "json:\"organizationName\" yaml:\"organizationName\""];
string locality_name = 4 [(gogoproto.moretags) = "json:\"localityName\" yaml:\"localityName\""]; string locality_name = 4 [(gogoproto.moretags) = "json:\"localityName\" yaml:\"localityName\""];
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 {
Review

This was underspecified on my part, instead of a raw_multicodec field and a raw_binary field, all we need is a hash_reference field. And this reference will be a CID or multihash which uses the raw mutliformat prefix and references the binary as an IPLD object.

This was underspecified on my part, instead of a `raw_multicodec` field and a `raw_binary` field, all we need is a `hash_reference` field. And this reference will be a CID or multihash which uses the [raw mutliformat prefix](https://github.com/multiformats/multicodec/blob/master/table.csv#L40) and references the binary as an IPLD object.
Review

Let's rename this to JSPackage and add a string name=5; field

Let's rename this to `JSPackage` and add a `string name=5;` field
Review

This will reference a registered GitRepository record by CID/multihash

GitRepository also has a repo_reference field which will contain a qualitative/non-content-hash-reference e.g. a github or gitea web url.

It might be helpful to signal in the naming of the various reference fields which references are content-hash => content references vs one's that are not. E.g. hash_reference vs reference.

This will reference a registered `GitRepository` record by CID/multihash `GitRepository` also has a `repo_reference` field which will contain a qualitative/non-content-hash-reference e.g. a github or gitea web url. It might be helpful to signal in the naming of the various `reference` fields which references are content-hash => content references vs one's that are not. E.g. `hash_reference` vs `reference`.
Review

Note: hash_reference to a GitRepository IPLD object

Note: `hash_reference` to a `GitRepository` IPLD object
Review

Note: hash_reference to binary IPLD object

Note: `hash_reference` to binary IPLD object
Review

Note: hash_reference to a GitRepository IPLD object

Note: `hash_reference` to a `GitRepository` IPLD object
Review

Note: hash_reference to a ChainRegistrationRecord IPLD object

Note: `hash_reference` to a `ChainRegistrationRecord` IPLD object
Review

Note: hash_reference to a WASM IPLD object

Note: `hash_reference` to a WASM IPLD object
Review

Note: hash_reference to ServiceProviderRecord IPLD object

Note: `hash_reference` to `ServiceProviderRecord` IPLD object
Review

Note: hash_reference to WatcherRegistrationRecord IPLD object

Note: `hash_reference` to `WatcherRegistrationRecord` IPLD object
Review

Note: hash_reference to auction result IPLD object

Note: `hash_reference` to auction result IPLD object
Review

Note: hash_reference to JSPackage IPLD object

Note: `hash_reference` to `JSPackage` IPLD object
0xmuralik commented 2023-01-17 05:43:47 +00:00 (Migrated from github.com)
Review

There is also a npm_package_reference (CID) in this message. Should we go with renaming repo_reference with repo_hash_reference and npm_package_reference with js_package_hash_ref?

There is also a npm_package_reference (CID) in this message. Should we go with renaming repo_reference with repo_hash_reference and npm_package_reference with js_package_hash_ref?
Review

We can avoid adding hash to the field names and instead we should revert to using a / sub-mapping to denote CID/link

We can avoid adding `hash` to the field names and instead we should revert to using a `/` sub-mapping to denote CID/link
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

@ -60,7 +60,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryParams() {
} }
} }
//nolint: all //nolint:all
func (s *IntegrationTestSuite) TestGRPCQueryWhoIs() { func (s *IntegrationTestSuite) TestGRPCQueryWhoIs() {
val := s.network.Validators[0] val := s.network.Validators[0]
sr := s.Require() sr := s.Require()
@ -180,7 +180,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryLookup() {
} }
} }
//nolint: all //nolint:all
func (s *IntegrationTestSuite) TestGRPCQueryRecordExpiryQueue() { func (s *IntegrationTestSuite) TestGRPCQueryRecordExpiryQueue() {
val := s.network.Validators[0] val := s.network.Validators[0]
sr := s.Require() sr := s.Require()
@ -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),
@ -252,7 +252,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryRecordExpiryQueue() {
} }
} }
//nolint: all //nolint:all
func (s *IntegrationTestSuite) TestGRPCQueryAuthorityExpiryQueue() { func (s *IntegrationTestSuite) TestGRPCQueryAuthorityExpiryQueue() {
val := s.network.Validators[0] val := s.network.Validators[0]
sr := s.Require() sr := s.Require()
@ -324,7 +324,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryAuthorityExpiryQueue() {
} }
} }
//nolint: all //nolint:all
func (s *IntegrationTestSuite) TestGRPCQueryListRecords() { func (s *IntegrationTestSuite) TestGRPCQueryListRecords() {
val := s.network.Validators[0] val := s.network.Validators[0]
sr := s.Require() sr := s.Require()
@ -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.
github-code-scanning[bot] commented 2023-01-20 11:11:55 +00:00 (Migrated from github.com)
Review

Sensitive package import

Certain system packages contain functions which may be a possible source of non-determinism

Show more details

## Sensitive package import Certain system packages contain functions which may be a possible source of non-determinism [Show more details](https://github.com/cerc-io/laconicd/security/code-scanning/599)
github-code-scanning[bot] commented 2023-03-16 05:25:52 +00:00 (Migrated from github.com)
Review

Sensitive package import

Certain system packages contain functions which may be a possible source of non-determinism

Show more details

## Sensitive package import Certain system packages contain functions which may be a possible source of non-determinism [Show more details](https://github.com/cerc-io/laconicd/security/code-scanning/1208)
"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")