-
Notifications
You must be signed in to change notification settings - Fork 81
/
grpc_query_interchainaccount.go
37 lines (28 loc) · 1.27 KB
/
grpc_query_interchainaccount.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
package keeper
import (
"context"
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
"github.com/neutron-org/neutron/v3/x/interchaintxs/types"
)
func (k Keeper) InterchainAccountAddress(c context.Context, req *types.QueryInterchainAccountAddressRequest) (*types.QueryInterchainAccountAddressResponse, error) {
if req == nil {
return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)
icaOwner, err := types.NewICAOwner(req.OwnerAddress, req.InterchainAccountId)
if err != nil {
return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to create ica owner: %s", err)
}
portID, err := icatypes.NewControllerPortID(icaOwner.String())
if err != nil {
return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to get controller portID: %s", err)
}
addr, found := k.icaControllerKeeper.GetInterchainAccountAddress(ctx, req.ConnectionId, portID)
if !found {
return nil, errors.Wrapf(types.ErrInterchainAccountNotFound, "no interchain account found for portID %s", portID)
}
return &types.QueryInterchainAccountAddressResponse{InterchainAccountAddress: addr}, nil
}