forked from cerc-io/laconicd-deprecated
imporve insert attributes logic
This commit is contained in:
parent
bd04a6307e
commit
38c77c10f6
@ -5,10 +5,6 @@ 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 HashReference {
|
|
||||||
map<string,string> hash_reference=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message ServiceProviderRecord {
|
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\""];
|
||||||
@ -30,10 +26,10 @@ message ServiceProviderRecord {
|
|||||||
|
|
||||||
message WebsiteRegistrationRecord {
|
message WebsiteRegistrationRecord {
|
||||||
string url = 1 [(gogoproto.moretags) = "json:\"url\" yaml:\"url\""];
|
string url = 1 [(gogoproto.moretags) = "json:\"url\" yaml:\"url\""];
|
||||||
HashReference repo_hash_reference = 2
|
map<string,string> repo_reference = 2
|
||||||
[(gogoproto.moretags) = "json:\"repoHashReference\" yaml:\"repoHashReference\""];
|
[(gogoproto.moretags) = "json:\"repoReference\" yaml:\"repoReference\""];
|
||||||
HashReference build_artifact_ref = 3 [(gogoproto.moretags) = "json:\"buildArtifactHashRef\" yaml:\"buildArtifactHashRef\""];
|
map<string,string> build_artifact_ref = 3 [(gogoproto.moretags) = "json:\"buildArtifactRef\" yaml:\"buildArtifactRef\""];
|
||||||
HashReference tls_cert_ref = 4 [(gogoproto.moretags) = "json:\"tlsCertHashRef\" yaml:\"tlsCertHashRef\""];
|
map<string,string> 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\""];
|
||||||
}
|
}
|
||||||
@ -47,36 +43,36 @@ message GitRepository{
|
|||||||
}
|
}
|
||||||
|
|
||||||
message Binary{
|
message Binary{
|
||||||
HashReference hash_reference=1;
|
map<string,string> hash_reference=1;
|
||||||
string targeted_arch=2;
|
string targeted_arch=2;
|
||||||
string runtime_version=3;
|
string runtime_version=3;
|
||||||
HashReference repo_reference=4;
|
map<string,string> repo_reference=4;
|
||||||
string version=5;
|
string version=5;
|
||||||
string type=6;
|
string type=6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DockerImage{
|
message DockerImage{
|
||||||
string image_id=1;
|
string image_id=1;
|
||||||
HashReference binary_reference=2;
|
map<string,string> binary_reference=2;
|
||||||
HashReference repo_reference=3;
|
map<string,string> repo_reference=3;
|
||||||
string version=4;
|
string version=4;
|
||||||
string type=5;
|
string type=5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message WatcherRegistrationRecord{
|
message WatcherRegistrationRecord{
|
||||||
WatcherMetadata metadata =1;
|
WatcherMetadata metadata =1;
|
||||||
HashReference repo_reference=2;
|
map<string,string> repo_reference=2;
|
||||||
WASMBinary wasm=3;
|
WASMBinary wasm=3;
|
||||||
string version=4;
|
string version=4;
|
||||||
string type=5;
|
string type=5;
|
||||||
|
|
||||||
message WatcherMetadata{
|
message WatcherMetadata{
|
||||||
string version=1;
|
string version=1;
|
||||||
HashReference chain_reference=2;
|
map<string,string> chain_reference=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message WASMBinary{
|
message WASMBinary{
|
||||||
HashReference hash_reference=1;
|
map<string,string> hash_reference=1;
|
||||||
WASMBinaryMetadata metadata=2;
|
WASMBinaryMetadata metadata=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,16 +83,16 @@ message WatcherRegistrationRecord{
|
|||||||
}
|
}
|
||||||
|
|
||||||
message ResponderContract{
|
message ResponderContract{
|
||||||
HashReference service_provider_ref=1;
|
map<string,string> service_provider_ref=1;
|
||||||
HashReference auction_ref=2;
|
map<string,string> auction_ref=2;
|
||||||
HashReference watcher_ref=3;
|
map<string,string> watcher_ref=3;
|
||||||
string version=4;
|
string version=4;
|
||||||
string type=5;
|
string type=5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message JSPackage{
|
message JSPackage{
|
||||||
HashReference repo_reference=1;
|
map<string,string> repo_reference=1;
|
||||||
HashReference js_package_ref=2;
|
map<string,string> js_package_ref=2;
|
||||||
string version=3;
|
string version=3;
|
||||||
string type=4;
|
string type=4;
|
||||||
string name =5;
|
string name =5;
|
||||||
@ -109,5 +105,5 @@ message ChainRegistrationRecord{
|
|||||||
string version=4;
|
string version=4;
|
||||||
string chain_id=5;
|
string chain_id=5;
|
||||||
string network_id=6;
|
string network_id=6;
|
||||||
HashReference genesis_hash=7;
|
map<string,string> genesis_hash=7;
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ record:
|
|||||||
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
||||||
targeted_arch: x86_64
|
targeted_arch: x86_64
|
||||||
runtime_version: go 1.18
|
runtime_version: go 1.18
|
||||||
repo_hash_reference:
|
repo_reference:
|
||||||
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
type: Binary
|
type: Binary
|
@ -8,5 +8,6 @@ record:
|
|||||||
type: ChainRegistrationRecord
|
type: ChainRegistrationRecord
|
||||||
version: 0.11.2
|
version: 0.11.2
|
||||||
chain_id: laconic_9000-1
|
chain_id: laconic_9000-1
|
||||||
network_id: 1392
|
network_id: "1392"
|
||||||
genesis_hash: f6fbe71210275adc7c7ef585a72c065cdb85f0c8d13dea0f229fd7c22d445a26
|
genesis_hash:
|
||||||
|
/: f6fbe71210275adc7c7ef585a72c065cdb85f0c8d13dea0f229fd7c22d445a26
|
@ -1,8 +1,8 @@
|
|||||||
record:
|
record:
|
||||||
image_id: 77af4d6b9913
|
image_id: 77af4d6b9913
|
||||||
binary_hash_reference:
|
binary_reference:
|
||||||
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
||||||
repo_hash_reference:
|
repo_reference:
|
||||||
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
type: DockerImage
|
type: DockerImage
|
@ -1,7 +1,7 @@
|
|||||||
record:
|
record:
|
||||||
repo_hash_reference:
|
repo_reference:
|
||||||
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
||||||
js_package_hash_ref:
|
js_package_ref:
|
||||||
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
type: JSPackage
|
type: JSPackage
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
record:
|
record:
|
||||||
service_provider_hash_ref:
|
service_provider_ref:
|
||||||
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
||||||
auction_hash_ref:
|
auction_ref:
|
||||||
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
||||||
watcher_hash_ref:
|
watcher_ref:
|
||||||
/: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
|
/: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
type: ResponderContract
|
type: ResponderContract
|
@ -1,9 +1,9 @@
|
|||||||
record:
|
record:
|
||||||
metadata:
|
metadata:
|
||||||
version: 0.32.0
|
version: 0.32.0
|
||||||
chain_hash_reference:
|
chain_reference:
|
||||||
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
||||||
repo_hash_reference:
|
repo_reference:
|
||||||
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
||||||
wasm:
|
wasm:
|
||||||
hash_reference:
|
hash_reference:
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
record:
|
record:
|
||||||
type: WebsiteRegistrationRecord
|
type: WebsiteRegistrationRecord
|
||||||
url: https://cerc.io
|
url: https://cerc.io
|
||||||
repo_hash_reference:
|
repo_reference:
|
||||||
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
/: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
||||||
build_artifact_hash_ref:
|
build_artifact_ref:
|
||||||
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
/: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
||||||
tls_cert_hash_ref:
|
tls_cert_ref:
|
||||||
/: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
|
/: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
|
||||||
version: 1.0.0
|
version: 1.0.0
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -316,45 +317,33 @@ 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 "ServiceProviderRecord":
|
return err
|
||||||
{
|
}
|
||||||
// #nosec G705
|
|
||||||
for key := range record.Attributes {
|
expiryTimeKey := GetAttributesIndexKey(ExpiryTimeAttributeName, record.ExpiryTime)
|
||||||
if key == "x500" {
|
if err := k.setAttributeMapping(ctx, expiryTimeKey, record.ID); err != nil {
|
||||||
// #nosec G705
|
return err
|
||||||
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 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{})
|
||||||
|
for key := range val {
|
||||||
|
newKeyPrefix := fmt.Sprint(keyPrefix + key)
|
||||||
|
if err := k.insertAttributes(ctx, recordID, val[key], newKeyPrefix); 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
|
||||||
}
|
}
|
||||||
@ -364,7 +353,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) {
|
||||||
|
2646
x/registry/types/attributes.pb.go
generated
2646
x/registry/types/attributes.pb.go
generated
File diff suppressed because it is too large
Load Diff
@ -198,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")
|
||||||
|
Loading…
Reference in New Issue
Block a user