-
Notifications
You must be signed in to change notification settings - Fork 635
/
grpc_query.go
83 lines (66 loc) · 2.13 KB
/
grpc_query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package keeper
import (
"context"
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/ibc-go/modules/apps/transfer/types"
)
var _ types.QueryServer = Keeper{}
// DenomTrace implements the Query/DenomTrace gRPC method
func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest) (*types.QueryDenomTraceResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
hash, err := types.ParseHexHash(req.Hash)
if err != nil {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom trace hash %s, %s", req.Hash, err))
}
ctx := sdk.UnwrapSDKContext(c)
denomTrace, found := q.GetDenomTrace(ctx, hash)
if !found {
return nil, status.Error(
codes.NotFound,
sdkerrors.Wrap(types.ErrTraceNotFound, req.Hash).Error(),
)
}
return &types.QueryDenomTraceResponse{
DenomTrace: &denomTrace,
}, nil
}
// DenomTraces implements the Query/DenomTraces gRPC method
func (q Keeper) DenomTraces(c context.Context, req *types.QueryDenomTracesRequest) (*types.QueryDenomTracesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
traces := types.Traces{}
store := prefix.NewStore(ctx.KVStore(q.storeKey), types.DenomTraceKey)
pageRes, err := query.Paginate(store, req.Pagination, func(_, value []byte) error {
result, err := q.UnmarshalDenomTrace(value)
if err != nil {
return err
}
traces = append(traces, result)
return nil
})
if err != nil {
return nil, err
}
return &types.QueryDenomTracesResponse{
DenomTraces: traces.Sort(),
Pagination: pageRes,
}, nil
}
// Params implements the Query/Params gRPC method
func (q Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := q.GetParams(ctx)
return &types.QueryParamsResponse{
Params: ¶ms,
}, nil
}