-
Notifications
You must be signed in to change notification settings - Fork 586
/
grpc_query.go
46 lines (36 loc) · 1.43 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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
)
var _ types.QueryServer = Keeper{}
// InterchainAccount implements the Query/InterchainAccount gRPC method
func (k Keeper) InterchainAccount(goCtx context.Context, req *types.QueryInterchainAccountRequest) (*types.QueryInterchainAccountResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
portID, err := icatypes.NewControllerPortID(req.Owner)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to generate portID from owner address: %s", err)
}
ctx := sdk.UnwrapSDKContext(goCtx)
addr, found := k.GetInterchainAccountAddress(ctx, req.ConnectionId, portID)
if !found {
return nil, status.Errorf(codes.NotFound, "failed to retrieve account address for %s on connection %s", portID, req.ConnectionId)
}
return &types.QueryInterchainAccountResponse{
Address: addr,
}, nil
}
// Params implements the Query/Params gRPC method
func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := k.GetParams(ctx)
return &types.QueryParamsResponse{
Params: ¶ms,
}, nil
}