Skip to content

Commit

Permalink
refactor: renamed query rpcs of didDoc and schema
Browse files Browse the repository at this point in the history
  • Loading branch information
arnabghose997 committed Sep 1, 2022
1 parent 2e6eae3 commit cd6b57f
Show file tree
Hide file tree
Showing 10 changed files with 836 additions and 1,183 deletions.
14 changes: 7 additions & 7 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20251,7 +20251,7 @@ paths:
- Query
'/hypersign-protocol/hidnode/ssi/credential/{credId}':
get:
summary: Get the Credential Status for a given credential Id
summary: Get the Credential Status for a given credential id
operationId: HypersignprotocolHidnodeSsiQueryCredential
responses:
'200':
Expand Down Expand Up @@ -20322,7 +20322,7 @@ paths:
/hypersign-protocol/hidnode/ssi/did:
get:
summary: Get the list of registered Did Documents and count
operationId: HypersignprotocolHidnodeSsiDidParam
operationId: HypersignprotocolHidnodeSsiQueryDidDocuments
responses:
'200':
description: A successful response.
Expand Down Expand Up @@ -20492,8 +20492,8 @@ paths:
- Query
'/hypersign-protocol/hidnode/ssi/did/{didId}':
get:
summary: Get the Did Document for a specified Did Id
operationId: HypersignprotocolHidnodeSsiResolveDid
summary: Get the Did Document for a specified Did id
operationId: HypersignprotocolHidnodeSsiQueryDidDocument
responses:
'200':
description: A successful response.
Expand Down Expand Up @@ -20599,8 +20599,8 @@ paths:
- Query
/hypersign-protocol/hidnode/ssi/schema:
get:
summary: Get the list of Schemas and count
operationId: HypersignprotocolHidnodeSsiSchemaParam
summary: Get the list of registered Schemas and count
operationId: HypersignprotocolHidnodeSsiQuerySchemas
responses:
'200':
description: A successful response.
Expand Down Expand Up @@ -20737,7 +20737,7 @@ paths:
'/hypersign-protocol/hidnode/ssi/schema/{schemaId}':
get:
summary: Get the Schema for a specified Schema Id
operationId: HypersignprotocolHidnodeSsiGetSchema
operationId: HypersignprotocolHidnodeSsiQuerySchema
responses:
'200':
description: A successful response.
Expand Down
74 changes: 36 additions & 38 deletions proto/ssi/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ option go_package = "github.com/hypersign-protocol/hid-node/x/ssi/types";

// Query defines the gRPC querier service.
service Query {
// Get the Schema for a specified Schema Id
rpc GetSchema(QueryGetSchemaRequest) returns (QueryGetSchemaResponse) {
// Get the Schema Document for a specified schema id
rpc QuerySchema(QuerySchemaRequest) returns (QuerySchemaResponse) {
option (google.api.http).get = "/hypersign-protocol/hidnode/ssi/schema/{schemaId}";
}

// Get the list of Schemas and count
rpc SchemaParam(QuerySchemaParamRequest) returns (QuerySchemaParamResponse) {
// Get the count and list of registered Schemas
rpc QuerySchemas(QuerySchemasRequest) returns (QuerySchemasResponse) {
option (google.api.http).get = "/hypersign-protocol/hidnode/ssi/schema";
}

// Get the Did Document for a specified Did Id
rpc ResolveDid(QueryGetDidDocByIdRequest) returns (DidResolutionResponse) {
// Get the Did Document for a specified DID id
rpc QueryDidDocument(QueryDidDocumentRequest) returns (QueryDidDocumentResponse) {
option (google.api.http).get = "/hypersign-protocol/hidnode/ssi/did/{didId}";
}

// Get the list of registered Did Documents and count
rpc DidParam(QueryDidParamRequest) returns (QueryDidParamResponse) {
// Get the count and list of registered Did Documents
rpc QueryDidDocuments(QueryDidDocumentsRequest) returns (QueryDidDocumentsResponse) {
option (google.api.http).get = "/hypersign-protocol/hidnode/ssi/did";
}

// Get the Credential Status for a given credential Id
// Get the Credential Status for a given credential id
rpc QueryCredential(QueryCredentialRequest) returns (QueryCredentialResponse) {
option (google.api.http).get = "/hypersign-protocol/hidnode/ssi/credential/{credId}";
}
Expand All @@ -48,48 +48,33 @@ service Query {
// this line is used by starport scaffolding # 2
}

message QueryCredentialRequest {
string credId = 1;
}

message QueryCredentialResponse {
Credential credStatus = 1;
}
// Schema Messages

message QueryGetSchemaRequest {
message QuerySchemaRequest {
string schemaId = 1;
}

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

message QuerySchemaParamRequest {
message QuerySchemasRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QuerySchemaParamResponse {
message QuerySchemasResponse {
uint64 totalCount = 1;
repeated Schema schemaList = 2;
}

message QueryGetDidDocByIdRequest {
string didId = 1;
}

message QueryDidParamRequest {
bool count = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// Credential Messages

message QueryDidParamResponse {
uint64 totalDidCount = 1;
repeated DidResolutionResponse didDocList = 2;
message QueryCredentialRequest {
string credId = 1;
}

message DidResolutionResponse {
Did didDocument = 1;
Metadata didDocumentMetadata = 2;
message QueryCredentialResponse {
Credential credStatus = 1;
}

message QueryCredentialsRequest {
Expand All @@ -101,12 +86,25 @@ message QueryCredentialsResponse {
repeated Credential credentials = 2;
}

message MarshalInput {
string stringInput = 1;
// Did Document Messages

message QueryDidDocumentRequest {
string didId = 1;
}

message MarshalOutput {
string unmarshalOutput = 1;
message QueryDidDocumentResponse {
Did didDocument = 1;
Metadata didDocumentMetadata = 2;
}

message QueryDidDocumentsRequest {
bool count = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

message QueryDidDocumentsResponse {
uint64 totalDidCount = 1;
repeated QueryDidDocumentResponse didDocList = 2;
}

// this line is used by starport scaffolding # 3
8 changes: 4 additions & 4 deletions x/ssi/client/cli/query_ssi.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func CmdGetSchema() *cobra.Command {

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryGetSchemaRequest{SchemaId: argSchemaId}
params := &types.QuerySchemaRequest{SchemaId: argSchemaId}

res, err := queryClient.GetSchema(cmd.Context(), params)
res, err := queryClient.QuerySchema(cmd.Context(), params)
if err != nil {
return err
}
Expand Down Expand Up @@ -57,9 +57,9 @@ func CmdResolveDID() *cobra.Command {

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryGetDidDocByIdRequest{DidId: argDidDocId}
params := &types.QueryDidDocumentRequest{DidId: argDidDocId}

res, err := queryClient.ResolveDid(cmd.Context(), params)
res, err := queryClient.QueryDidDocument(cmd.Context(), params)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions x/ssi/client/cli/tx_ssi.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ func CmdDeactivateDID() *cobra.Command {

// Query Did Document from store using Did Id
queryClient := types.NewQueryClient(clientCtx)
requestParams := &types.QueryGetDidDocByIdRequest{DidId: argDidId}
resolvedDidDocument, err := queryClient.ResolveDid(cmd.Context(), requestParams)
requestParams := &types.QueryDidDocumentRequest{DidId: argDidId}
resolvedDidDocument, err := queryClient.QueryDidDocument(cmd.Context(), requestParams)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions x/ssi/keeper/grpc_query_did.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import (
"google.golang.org/grpc/status"
)

func (k Keeper) DidParam(goCtx context.Context, req *types.QueryDidParamRequest) (*types.QueryDidParamResponse, error) {
func (k Keeper) QueryDidDocuments(goCtx context.Context, req *types.QueryDidDocumentsRequest) (*types.QueryDidDocumentsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DidKey))

var didResolveList []*types.DidResolutionResponse
var didResolveList []*types.QueryDidDocumentResponse
_, err := query.Paginate(store, req.Pagination, func(key []byte, value []byte) error {
var (
didResolve types.DidResolutionResponse
didResolve types.QueryDidDocumentResponse
didDoc types.DidDocument
)
if err := k.cdc.Unmarshal(value, &didDoc); err != nil {
Expand All @@ -44,13 +44,13 @@ func (k Keeper) DidParam(goCtx context.Context, req *types.QueryDidParamRequest)

var didDocCount uint64 = k.GetDidCount(ctx)
if req.Count {
return &types.QueryDidParamResponse{TotalDidCount: didDocCount}, nil
return &types.QueryDidDocumentsResponse{TotalDidCount: didDocCount}, nil
}
return &types.QueryDidParamResponse{TotalDidCount: didDocCount, DidDocList: didResolveList}, nil
return &types.QueryDidDocumentsResponse{TotalDidCount: didDocCount, DidDocList: didResolveList}, nil
}

// Ref: https://w3c-ccg.github.io/did-resolution/#resolving-algorithm
func (k Keeper) ResolveDid(goCtx context.Context, req *types.QueryGetDidDocByIdRequest) (*types.DidResolutionResponse, error) {
func (k Keeper) QueryDidDocument(goCtx context.Context, req *types.QueryDidDocumentRequest) (*types.QueryDidDocumentResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
Expand All @@ -63,7 +63,7 @@ func (k Keeper) ResolveDid(goCtx context.Context, req *types.QueryGetDidDocByIdR
return nil, err
}

return &types.DidResolutionResponse{
return &types.QueryDidDocumentResponse{
DidDocument: didDoc.GetDid(),
DidDocumentMetadata: didDoc.GetMetadata(),
}, nil
Expand Down
8 changes: 4 additions & 4 deletions x/ssi/keeper/grpc_query_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (
"google.golang.org/grpc/status"
)

func (k Keeper) GetSchema(goCtx context.Context, req *types.QueryGetSchemaRequest) (*types.QueryGetSchemaResponse, error) {
func (k Keeper) QuerySchema(goCtx context.Context, req *types.QuerySchemaRequest) (*types.QuerySchemaResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)

var schema []*types.Schema = k.GetSchemaFromStore(ctx, req.SchemaId)

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

func (k Keeper) SchemaParam(goCtx context.Context, req *types.QuerySchemaParamRequest) (*types.QuerySchemaParamResponse, error) {
func (k Keeper) QuerySchemas(goCtx context.Context, req *types.QuerySchemasRequest) (*types.QuerySchemasResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
Expand All @@ -50,5 +50,5 @@ func (k Keeper) SchemaParam(goCtx context.Context, req *types.QuerySchemaParamRe
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.QuerySchemaParamResponse{SchemaList: schemas, TotalCount: k.GetSchemaCount(ctx)}, nil
return &types.QuerySchemasResponse{SchemaList: schemas, TotalCount: k.GetSchemaCount(ctx)}, nil
}
16 changes: 8 additions & 8 deletions x/ssi/tests/query_did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/assert"
)

func TestDidResolve(t *testing.T) {
t.Log("Running test for DidResolve (Query)")
func TestQueryDidDocument(t *testing.T) {
t.Log("Running test for QueryDidDocument (Query)")
k, ctx := TestKeeper(t)
msgServer := keeper.NewMsgServerImpl(*k)
goCtx := sdk.WrapSDKContext(ctx)
Expand Down Expand Up @@ -39,11 +39,11 @@ func TestDidResolve(t *testing.T) {
t.Log("Did Registeration Successful")
t.Log("Querying the DID from store")

req := &types.QueryGetDidDocByIdRequest{
req := &types.QueryDidDocumentRequest{
DidId: didId,
}

res, errResponse := k.ResolveDid(goCtx, req)
res, errResponse := k.QueryDidDocument(goCtx, req)
if errResponse != nil {
t.Error("Did Resolve Failed")
t.Error(errResponse)
Expand All @@ -55,8 +55,8 @@ func TestDidResolve(t *testing.T) {
t.Log("Did Resolve Test Completed")
}

func TestDidParam(t *testing.T) {
t.Log("Running test for DidParam (Query)")
func TestQueryDidDocuments(t *testing.T) {
t.Log("Running test for QueryDocuments (Query)")
k, ctx := TestKeeper(t)
msgServer := keeper.NewMsgServerImpl(*k)
goCtx := sdk.WrapSDKContext(ctx)
Expand Down Expand Up @@ -85,9 +85,9 @@ func TestDidParam(t *testing.T) {
t.Log("Did Registeration Successful")
t.Log("Querying the list of Did Documents")

req := &types.QueryDidParamRequest{}
req := &types.QueryDidDocumentsRequest{}

res, errResponse := k.DidParam(goCtx, req)
res, errResponse := k.QueryDidDocuments(goCtx, req)
if errResponse != nil {
t.Error("Did Resolve Failed")
t.Error(errResponse)
Expand Down
16 changes: 8 additions & 8 deletions x/ssi/tests/query_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/assert"
)

func TestGetSchema(t *testing.T) {
t.Log("Running test for GetSchema (Query)")
func TestQuerySchema(t *testing.T) {
t.Log("Running test for QuerySchema (Query)")
k, ctx := TestKeeper(t)
msgServer := keeper.NewMsgServerImpl(*k)
goCtx := sdk.WrapSDKContext(ctx)
Expand Down Expand Up @@ -61,11 +61,11 @@ func TestGetSchema(t *testing.T) {

t.Log("Querying the Schema from store")

req := &types.QueryGetSchemaRequest{
req := &types.QuerySchemaRequest{
SchemaId: schemaRpcElements.SchemaDocument.GetId(),
}

res, errResponse := k.GetSchema(goCtx, req)
res, errResponse := k.QuerySchema(goCtx, req)
if errResponse != nil {
t.Error("Schema Resolve Failed")
t.Error(errResponse)
Expand All @@ -79,8 +79,8 @@ func TestGetSchema(t *testing.T) {
t.Log("GetSchema Test Completed")
}

func TestSchemaParam(t *testing.T) {
t.Log("Running test for SchemaParam (Query)")
func TestQuerySchemas(t *testing.T) {
t.Log("Running test for QuerySchemas (Query)")
k, ctx := TestKeeper(t)
msgServer := keeper.NewMsgServerImpl(*k)
goCtx := sdk.WrapSDKContext(ctx)
Expand Down Expand Up @@ -130,9 +130,9 @@ func TestSchemaParam(t *testing.T) {

t.Log("Querying the list of Schema Documents")

req := &types.QuerySchemaParamRequest{}
req := &types.QuerySchemasRequest{}

res, errResponse := k.SchemaParam(goCtx, req)
res, errResponse := k.QuerySchemas(goCtx, req)
if errResponse != nil {
t.Error("Schema List Resolve Failed")
t.Error(errResponse)
Expand Down
Loading

0 comments on commit cd6b57f

Please sign in to comment.