Skip to content

Commit

Permalink
Merge pull request #268 from hypersign-protocol/hotfix/schema-query
Browse files Browse the repository at this point in the history
[Hotfix] Query Schema returns a singular Schema Document instead of a list of Documents
arnabghose997 authored Aug 29, 2022
2 parents 6cce5f6 + b188c45 commit ca0b22c
Showing 7 changed files with 4,251 additions and 1,068 deletions.
5,134 changes: 4,159 additions & 975 deletions docs/static/openapi.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ require (
github.com/tendermint/spm v0.1.9
github.com/tendermint/tendermint v0.34.20
github.com/tendermint/tm-db v0.6.7
google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc
google.golang.org/grpc v1.48.0
)

7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -2086,8 +2086,8 @@ google.golang.org/genproto v0.0.0-20220421151946-72621c1f0bd3/go.mod h1:8w6bsBMX
google.golang.org/genproto v0.0.0-20220429170224-98d788798c3e/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f h1:P8EiVSxZwC6xH2niv2N66aqwMtYFg+D54gbjpcqKJtM=
google.golang.org/genproto v0.0.0-20220719170305-83ca9fad585f/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE=
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc h1:Nf+EdcTLHR8qDNN/KfkQL0u0ssxt9OhbaWCl5C0ucEI=
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
@@ -2106,8 +2106,9 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2 changes: 1 addition & 1 deletion proto/ssi/v1/query.proto
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ message QueryGetSchemaRequest {
}

message QueryGetSchemaResponse {
repeated Schema schema = 1;
Schema schema = 1;
}

message QuerySchemaParamRequest {
7 changes: 5 additions & 2 deletions x/ssi/keeper/grpc_query_schema.go
Original file line number Diff line number Diff line change
@@ -17,10 +17,13 @@ func (k Keeper) GetSchema(goCtx context.Context, req *types.QueryGetSchemaReques
}
ctx := sdk.UnwrapSDKContext(goCtx)

var schemaList []*types.Schema = k.GetSchemaFromStore(ctx, req.SchemaId)
schema, err := k.GetSchemaFromStore(ctx, req.SchemaId)
if err != nil {
return nil, err
}

return &types.QueryGetSchemaResponse{
Schema: schemaList,
Schema: schema,
}, nil
}

17 changes: 7 additions & 10 deletions x/ssi/keeper/schema.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/hypersign-protocol/hid-node/x/ssi/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

func (k Keeper) GetSchemaCount(ctx sdk.Context) uint64 {
@@ -55,19 +56,15 @@ func (k Keeper) AppendSchema(ctx sdk.Context, schema types.Schema) uint64 {
}

// Get the schema from store
func (k Keeper) GetSchemaFromStore(ctx sdk.Context, querySchemaStr string) []*types.Schema {
func (k Keeper) GetSchemaFromStore(ctx sdk.Context, schemaId string) (*types.Schema, error) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.SchemaKey))
var schemas []*types.Schema
iterator := sdk.KVStorePrefixIterator(store, []byte{})
schemaBytes := store.Get([]byte(schemaId))

for ; iterator.Valid(); iterator.Next() {
var schema types.Schema
k.cdc.MustUnmarshal(iterator.Value(), &schema)
var schemaDoc types.Schema

if querySchemaStr == schema.Id[0:len(schema.Id)-12] || querySchemaStr == schema.Id {
schemas = append(schemas, &schema)
}
if err := k.cdc.Unmarshal(schemaBytes, &schemaDoc); err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidType, err.Error())
}

return schemas
return &schemaDoc, nil
}
150 changes: 74 additions & 76 deletions x/ssi/types/query.pb.go

0 comments on commit ca0b22c

Please sign in to comment.