mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
Eckelj/cid queries (#90)
* get_assets_by_pubkey * having the APIs up and running and with tests * renamed Transactions object to CIDs * renamed files * fixed formatting issue --------- Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
f64a9832f7
commit
6718f289a9
211
docs/static/openapi.yml
vendored
211
docs/static/openapi.yml
vendored
@ -46473,6 +46473,175 @@ paths:
|
||||
additionalProperties: {}
|
||||
tags:
|
||||
- Query
|
||||
/planetmint/planetmint-go/asset/get_cids_by_pub_key/{extPubKey}/{lookupPeriodInMin}:
|
||||
get:
|
||||
summary: Queries a list of GetCIDsByPubKey items.
|
||||
operationId: PlanetmintgoAssetGetCIDsByPubKey
|
||||
responses:
|
||||
'200':
|
||||
description: A successful response.
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
cids:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
pagination:
|
||||
type: object
|
||||
properties:
|
||||
next_key:
|
||||
type: string
|
||||
format: byte
|
||||
description: |-
|
||||
next_key is the key to be passed to PageRequest.key to
|
||||
query the next page most efficiently. It will be empty if
|
||||
there are no more results.
|
||||
total:
|
||||
type: string
|
||||
format: uint64
|
||||
title: >-
|
||||
total is total number of results available if
|
||||
PageRequest.count_total
|
||||
|
||||
was set, its value is undefined otherwise
|
||||
description: >-
|
||||
PageResponse is to be embedded in gRPC response messages where
|
||||
the
|
||||
|
||||
corresponding request message has used PageRequest.
|
||||
|
||||
message SomeResponse {
|
||||
repeated Bar results = 1;
|
||||
PageResponse page = 2;
|
||||
}
|
||||
default:
|
||||
description: An unexpected error response.
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
details:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
'@type':
|
||||
type: string
|
||||
additionalProperties: {}
|
||||
parameters:
|
||||
- name: extPubKey
|
||||
in: path
|
||||
required: true
|
||||
type: string
|
||||
- name: lookupPeriodInMin
|
||||
in: path
|
||||
required: true
|
||||
type: string
|
||||
format: uint64
|
||||
- name: pagination.key
|
||||
description: |-
|
||||
key is a value returned in PageResponse.next_key to begin
|
||||
querying the next page most efficiently. Only one of offset or key
|
||||
should be set.
|
||||
in: query
|
||||
required: false
|
||||
type: string
|
||||
format: byte
|
||||
- name: pagination.offset
|
||||
description: >-
|
||||
offset is a numeric offset that can be used when key is unavailable.
|
||||
|
||||
It is less efficient than using key. Only one of offset or key
|
||||
should
|
||||
|
||||
be set.
|
||||
in: query
|
||||
required: false
|
||||
type: string
|
||||
format: uint64
|
||||
- name: pagination.limit
|
||||
description: >-
|
||||
limit is the total number of results to be returned in the result
|
||||
page.
|
||||
|
||||
If left empty it will default to a value to be set by each app.
|
||||
in: query
|
||||
required: false
|
||||
type: string
|
||||
format: uint64
|
||||
- name: pagination.count_total
|
||||
description: >-
|
||||
count_total is set to true to indicate that the result set should
|
||||
include
|
||||
|
||||
a count of the total number of items available for pagination in
|
||||
UIs.
|
||||
|
||||
count_total is only respected when offset is used. It is ignored
|
||||
when key
|
||||
|
||||
is set.
|
||||
in: query
|
||||
required: false
|
||||
type: boolean
|
||||
- name: pagination.reverse
|
||||
description: >-
|
||||
reverse is set to true if results are to be returned in the
|
||||
descending order.
|
||||
|
||||
|
||||
Since: cosmos-sdk 0.43
|
||||
in: query
|
||||
required: false
|
||||
type: boolean
|
||||
tags:
|
||||
- Query
|
||||
/planetmint/planetmint-go/asset/get_notarized_asset/{cid}:
|
||||
get:
|
||||
summary: Queries a list of GetNotarizedAsset items.
|
||||
operationId: PlanetmintgoAssetGetNotarizedAsset
|
||||
responses:
|
||||
'200':
|
||||
description: A successful response.
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
cid:
|
||||
type: string
|
||||
signature:
|
||||
type: string
|
||||
pubkey:
|
||||
type: string
|
||||
default:
|
||||
description: An unexpected error response.
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
details:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
'@type':
|
||||
type: string
|
||||
additionalProperties: {}
|
||||
parameters:
|
||||
- name: cid
|
||||
in: path
|
||||
required: true
|
||||
type: string
|
||||
tags:
|
||||
- Query
|
||||
/github.com/planetmint/planetmint-go/dao/params:
|
||||
get:
|
||||
summary: Parameters queries the parameters of the module.
|
||||
@ -75480,6 +75649,48 @@ definitions:
|
||||
planetmintgo.asset.Params:
|
||||
type: object
|
||||
description: Params defines the parameters for the module.
|
||||
planetmintgo.asset.QueryGetCIDsByPubKeyResponse:
|
||||
type: object
|
||||
properties:
|
||||
cids:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
pagination:
|
||||
type: object
|
||||
properties:
|
||||
next_key:
|
||||
type: string
|
||||
format: byte
|
||||
description: |-
|
||||
next_key is the key to be passed to PageRequest.key to
|
||||
query the next page most efficiently. It will be empty if
|
||||
there are no more results.
|
||||
total:
|
||||
type: string
|
||||
format: uint64
|
||||
title: >-
|
||||
total is total number of results available if
|
||||
PageRequest.count_total
|
||||
|
||||
was set, its value is undefined otherwise
|
||||
description: |-
|
||||
PageResponse is to be embedded in gRPC response messages where the
|
||||
corresponding request message has used PageRequest.
|
||||
|
||||
message SomeResponse {
|
||||
repeated Bar results = 1;
|
||||
PageResponse page = 2;
|
||||
}
|
||||
planetmintgo.asset.QueryGetNotarizedAssetResponse:
|
||||
type: object
|
||||
properties:
|
||||
cid:
|
||||
type: string
|
||||
signature:
|
||||
type: string
|
||||
pubkey:
|
||||
type: string
|
||||
planetmintgo.asset.QueryParamsResponse:
|
||||
type: object
|
||||
properties:
|
||||
|
@ -1,4 +1,5 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package planetmintgo.asset;
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
@ -10,17 +11,53 @@ option go_package = "github.com/planetmint/planetmint-go/x/asset/types";
|
||||
|
||||
// Query defines the gRPC querier service.
|
||||
service Query {
|
||||
|
||||
// Parameters queries the parameters of the module.
|
||||
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
|
||||
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) {
|
||||
option (google.api.http).get = "/github.com/planetmint/planetmint-go/asset/params";
|
||||
|
||||
}
|
||||
|
||||
// Queries a list of GetCIDsByPubKey items.
|
||||
rpc GetCIDsByPubKey (QueryGetCIDsByPubKeyRequest) returns (QueryGetCIDsByPubKeyResponse) {
|
||||
option (google.api.http).get = "/planetmint/planetmint-go/asset/get_cids_by_pub_key/{extPubKey}/{lookupPeriodInMin}";
|
||||
|
||||
}
|
||||
|
||||
// Queries a list of GetNotarizedAsset items.
|
||||
rpc GetNotarizedAsset (QueryGetNotarizedAssetRequest) returns (QueryGetNotarizedAssetResponse) {
|
||||
option (google.api.http).get = "/planetmint/planetmint-go/asset/get_notarized_asset/{cid}";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// QueryParamsRequest is request type for the Query/Params RPC method.
|
||||
message QueryParamsRequest {}
|
||||
|
||||
// QueryParamsResponse is response type for the Query/Params RPC method.
|
||||
message QueryParamsResponse {
|
||||
|
||||
// params holds all the parameters of this module.
|
||||
Params params = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
}
|
||||
|
||||
message QueryGetCIDsByPubKeyRequest {
|
||||
string extPubKey = 1;
|
||||
uint64 lookupPeriodInMin = 2;
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 3;
|
||||
}
|
||||
|
||||
message QueryGetCIDsByPubKeyResponse {
|
||||
repeated string cids = 1;
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
|
||||
message QueryGetNotarizedAssetRequest {
|
||||
string cid = 1;
|
||||
}
|
||||
|
||||
message QueryGetNotarizedAssetResponse {
|
||||
string cid = 1;
|
||||
string signature = 2;
|
||||
string pubkey = 3;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,10 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
|
||||
}
|
||||
|
||||
cmd.AddCommand(CmdQueryParams())
|
||||
cmd.AddCommand(CmdGetCIDsByPubKey())
|
||||
|
||||
cmd.AddCommand(CmdGetNotarizedAsset())
|
||||
|
||||
// this line is used by starport scaffolding # 1
|
||||
|
||||
return cmd
|
||||
|
58
x/asset/client/cli/query_get_assets_by_pub_key.go
Normal file
58
x/asset/client/cli/query_get_assets_by_pub_key.go
Normal file
@ -0,0 +1,58 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/planetmint/planetmint-go/x/asset/types"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var _ = strconv.Itoa(0)
|
||||
|
||||
func CmdGetCIDsByPubKey() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "get-assets-by-pub-key [ext-pub-key] [lookup-period-in-min]",
|
||||
Short: "Query get_cids_by_pub_key",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
reqExtPubKey := args[0]
|
||||
reqLookupPeriodInMin, err := cast.ToUint64E(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
|
||||
params := &types.QueryGetCIDsByPubKeyRequest{
|
||||
|
||||
ExtPubKey: reqExtPubKey,
|
||||
LookupPeriodInMin: reqLookupPeriodInMin,
|
||||
}
|
||||
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params.Pagination = pageReq
|
||||
|
||||
res, err := queryClient.GetCIDsByPubKey(cmd.Context(), params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
46
x/asset/client/cli/query_get_notarized_asset.go
Normal file
46
x/asset/client/cli/query_get_notarized_asset.go
Normal file
@ -0,0 +1,46 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/planetmint/planetmint-go/x/asset/types"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var _ = strconv.Itoa(0)
|
||||
|
||||
func CmdGetNotarizedAsset() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "get-notarized-asset [cid]",
|
||||
Short: "Query get_notarized_asset",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
reqCid := args[0]
|
||||
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
|
||||
params := &types.QueryGetNotarizedAssetRequest{
|
||||
|
||||
Cid: reqCid,
|
||||
}
|
||||
|
||||
res, err := queryClient.GetNotarizedAsset(cmd.Context(), params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
@ -23,6 +23,40 @@ func (k Keeper) GetAsset(ctx sdk.Context, hash string) (val types.Asset, found b
|
||||
return val, true
|
||||
}
|
||||
|
||||
func (k Keeper) GetCIDsByPublicKey(ctx sdk.Context, pubkey string) (assetArray []types.Asset, found bool) {
|
||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
|
||||
|
||||
reverseIterator := store.ReverseIterator(nil, nil)
|
||||
defer reverseIterator.Close()
|
||||
var asset types.Asset
|
||||
for ; reverseIterator.Valid(); reverseIterator.Next() {
|
||||
lastValue := reverseIterator.Value()
|
||||
|
||||
k.cdc.MustUnmarshal(lastValue, &asset)
|
||||
if asset.GetPubkey() == pubkey {
|
||||
assetArray = append(assetArray, asset)
|
||||
}
|
||||
}
|
||||
return assetArray, len(assetArray) > 0
|
||||
}
|
||||
|
||||
func (k Keeper) GetCidsByPublicKey(ctx sdk.Context, pubkey string) (cids []string, found bool) {
|
||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
|
||||
|
||||
reverseIterator := store.ReverseIterator(nil, nil)
|
||||
defer reverseIterator.Close()
|
||||
var asset types.Asset
|
||||
for ; reverseIterator.Valid(); reverseIterator.Next() {
|
||||
lastValue := reverseIterator.Value()
|
||||
|
||||
k.cdc.MustUnmarshal(lastValue, &asset)
|
||||
if asset.GetPubkey() == pubkey {
|
||||
cids = append(cids, asset.GetHash())
|
||||
}
|
||||
}
|
||||
return cids, len(cids) > 0
|
||||
}
|
||||
|
||||
func GetAssetHashBytes(hash string) []byte {
|
||||
bz := []byte(hash)
|
||||
return bz
|
||||
|
@ -18,9 +18,13 @@ func createNAsset(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Asset {
|
||||
for i := range items {
|
||||
hash := sha256.Sum256([]byte(strconv.FormatInt(int64(i), 2)))
|
||||
hashStr := string(hash[:])
|
||||
|
||||
items[i].Hash = hashStr
|
||||
items[i].Pubkey = "pubkey"
|
||||
items[i].Signature = "sign"
|
||||
if i%2 == 1 {
|
||||
items[i].Pubkey = "pubkey_search"
|
||||
}
|
||||
keeper.StoreAsset(ctx, items[i])
|
||||
}
|
||||
return items
|
||||
@ -35,3 +39,34 @@ func TestGetAsset(t *testing.T) {
|
||||
assert.Equal(t, item, asset)
|
||||
}
|
||||
}
|
||||
func TestGetCids(t *testing.T) {
|
||||
keeper, ctx := keepertest.AssetKeeper(t)
|
||||
items := createNAsset(keeper, ctx, 10)
|
||||
for _, item := range items {
|
||||
asset, found := keeper.GetAsset(ctx, item.Hash)
|
||||
assert.True(t, found)
|
||||
assert.Equal(t, item, asset)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAssetByPubKeys(t *testing.T) {
|
||||
keeper, ctx := keepertest.AssetKeeper(t)
|
||||
_ = createNAsset(keeper, ctx, 10)
|
||||
assets, found := keeper.GetCIDsByPublicKey(ctx, "pubkey_search")
|
||||
assert.True(t, found)
|
||||
assert.Equal(t, len(assets), 5)
|
||||
assets, found = keeper.GetCIDsByPublicKey(ctx, "pubkey")
|
||||
assert.True(t, found)
|
||||
assert.Equal(t, len(assets), 5)
|
||||
}
|
||||
|
||||
func TestGetCidsByPubKeys(t *testing.T) {
|
||||
keeper, ctx := keepertest.AssetKeeper(t)
|
||||
_ = createNAsset(keeper, ctx, 10)
|
||||
assets, found := keeper.GetCidsByPublicKey(ctx, "pubkey_search")
|
||||
assert.True(t, found)
|
||||
assert.Equal(t, len(assets), 5)
|
||||
assets, found = keeper.GetCidsByPublicKey(ctx, "pubkey")
|
||||
assert.True(t, found)
|
||||
assert.Equal(t, len(assets), 5)
|
||||
}
|
||||
|
25
x/asset/keeper/query_get_cids_by_pub_key.go
Normal file
25
x/asset/keeper/query_get_cids_by_pub_key.go
Normal file
@ -0,0 +1,25 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/planetmint/planetmint-go/x/asset/types"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (k Keeper) GetCIDsByPubKey(goCtx context.Context, req *types.QueryGetCIDsByPubKeyRequest) (*types.QueryGetCIDsByPubKeyResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
cids, found := k.GetCidsByPublicKey(ctx, req.GetExtPubKey())
|
||||
if !found {
|
||||
return nil, status.Error(codes.NotFound, "no CIDs found")
|
||||
}
|
||||
|
||||
return &types.QueryGetCIDsByPubKeyResponse{CIDs: cids}, nil
|
||||
}
|
47
x/asset/keeper/query_get_cids_by_pub_key_test.go
Normal file
47
x/asset/keeper/query_get_cids_by_pub_key_test.go
Normal file
@ -0,0 +1,47 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
||||
"github.com/planetmint/planetmint-go/x/asset/types"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetNotarizedAssetByPubKey(t *testing.T) {
|
||||
keeper, ctx := keepertest.AssetKeeper(t)
|
||||
wctx := sdk.WrapSDKContext(ctx)
|
||||
_ = createNAsset(keeper, ctx, 10)
|
||||
assets, _ := keeper.GetCidsByPublicKey(ctx, "pubkey_search")
|
||||
for _, tc := range []struct {
|
||||
desc string
|
||||
request *types.QueryGetCIDsByPubKeyRequest
|
||||
response *types.QueryGetCIDsByPubKeyResponse
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "cid found",
|
||||
request: &types.QueryGetCIDsByPubKeyRequest{ExtPubKey: "pubkey_search"},
|
||||
response: &types.QueryGetCIDsByPubKeyResponse{CIDs: assets},
|
||||
},
|
||||
{
|
||||
desc: "cid not found",
|
||||
request: &types.QueryGetCIDsByPubKeyRequest{ExtPubKey: "invalid key"},
|
||||
err: status.Error(codes.NotFound, "no CIDs found"),
|
||||
},
|
||||
} {
|
||||
tc := tc
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
response, err := keeper.GetCIDsByPubKey(wctx, tc.request)
|
||||
if tc.err != nil {
|
||||
require.ErrorIs(t, err, tc.err)
|
||||
} else {
|
||||
require.Equal(t, tc.response, response)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
25
x/asset/keeper/query_get_notarized_asset.go
Normal file
25
x/asset/keeper/query_get_notarized_asset.go
Normal file
@ -0,0 +1,25 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/planetmint/planetmint-go/x/asset/types"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (k Keeper) GetNotarizedAsset(goCtx context.Context, req *types.QueryGetNotarizedAssetRequest) (*types.QueryGetNotarizedAssetResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
asset, found := k.GetAsset(ctx, req.GetCid())
|
||||
if !found {
|
||||
return nil, status.Error(codes.NotFound, "cid not found")
|
||||
}
|
||||
|
||||
return &types.QueryGetNotarizedAssetResponse{Cid: asset.GetHash(), Signature: asset.GetSignature(), Pubkey: asset.GetPubkey()}, nil
|
||||
}
|
46
x/asset/keeper/query_get_notarized_asset_test.go
Normal file
46
x/asset/keeper/query_get_notarized_asset_test.go
Normal file
@ -0,0 +1,46 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
||||
"github.com/planetmint/planetmint-go/x/asset/types"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetNotarizedAsset(t *testing.T) {
|
||||
keeper, ctx := keepertest.AssetKeeper(t)
|
||||
wctx := sdk.WrapSDKContext(ctx)
|
||||
msgs := createNAsset(keeper, ctx, 1)
|
||||
for _, tc := range []struct {
|
||||
desc string
|
||||
request *types.QueryGetNotarizedAssetRequest
|
||||
response *types.QueryGetNotarizedAssetResponse
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "cid found",
|
||||
request: &types.QueryGetNotarizedAssetRequest{Cid: msgs[0].GetHash()},
|
||||
response: &types.QueryGetNotarizedAssetResponse{Cid: msgs[0].GetHash(), Signature: msgs[0].GetSignature(), Pubkey: msgs[0].GetPubkey()},
|
||||
},
|
||||
{
|
||||
desc: "cid not found",
|
||||
request: &types.QueryGetNotarizedAssetRequest{Cid: "invalid key"},
|
||||
err: status.Error(codes.NotFound, "cid not found"),
|
||||
},
|
||||
} {
|
||||
tc := tc
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
response, err := keeper.GetNotarizedAsset(wctx, tc.request)
|
||||
if tc.err != nil {
|
||||
require.ErrorIs(t, err, tc.err)
|
||||
} else {
|
||||
require.Equal(t, tc.response, response)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -51,6 +51,154 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_GetCIDsByPubKey_0 = &utilities.DoubleArray{Encoding: map[string]int{"extPubKey": 0, "lookupPeriodInMin": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
|
||||
)
|
||||
|
||||
func request_Query_GetCIDsByPubKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryGetCIDsByPubKeyRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["extPubKey"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "extPubKey")
|
||||
}
|
||||
|
||||
protoReq.ExtPubKey, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "extPubKey", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["lookupPeriodInMin"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "lookupPeriodInMin")
|
||||
}
|
||||
|
||||
protoReq.LookupPeriodInMin, err = runtime.Uint64(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "lookupPeriodInMin", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetCIDsByPubKey_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.GetCIDsByPubKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_GetCIDsByPubKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryGetCIDsByPubKeyRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["extPubKey"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "extPubKey")
|
||||
}
|
||||
|
||||
protoReq.ExtPubKey, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "extPubKey", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["lookupPeriodInMin"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "lookupPeriodInMin")
|
||||
}
|
||||
|
||||
protoReq.LookupPeriodInMin, err = runtime.Uint64(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "lookupPeriodInMin", err)
|
||||
}
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetCIDsByPubKey_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.GetCIDsByPubKey(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Query_GetNotarizedAsset_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryGetNotarizedAssetRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["cid"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "cid")
|
||||
}
|
||||
|
||||
protoReq.Cid, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "cid", err)
|
||||
}
|
||||
|
||||
msg, err := client.GetNotarizedAsset(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_GetNotarizedAsset_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryGetNotarizedAssetRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["cid"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "cid")
|
||||
}
|
||||
|
||||
protoReq.Cid, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "cid", err)
|
||||
}
|
||||
|
||||
msg, err := server.GetNotarizedAsset(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerServer registers the http handlers for service Query to "mux".
|
||||
// UnaryRPC :call QueryServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
@ -80,6 +228,52 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_GetCIDsByPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_GetCIDsByPubKey_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_GetCIDsByPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_GetNotarizedAsset_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_GetNotarizedAsset_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_GetNotarizedAsset_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -141,13 +335,61 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_GetCIDsByPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_GetCIDsByPubKey_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_GetCIDsByPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_GetNotarizedAsset_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_GetNotarizedAsset_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_GetNotarizedAsset_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"github.com", "planetmint", "planetmint-go", "asset", "params"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Query_GetCIDsByPubKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"planetmint", "planetmint-go", "asset", "get_cids_by_pub_key", "extPubKey", "lookupPeriodInMin"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
|
||||
pattern_Query_GetNotarizedAsset_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"planetmint", "planetmint-go", "asset", "get_notarized_asset", "cid"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_Query_Params_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_GetCIDsByPubKey_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_GetNotarizedAsset_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user