-
Notifications
You must be signed in to change notification settings - Fork 104
/
provider_info.go
54 lines (44 loc) · 1.67 KB
/
provider_info.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
package keeper
import (
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" //nolint:golint
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/v4/x/ccv/types"
)
func (k Keeper) GetProviderInfo(ctx sdk.Context) (*types.QueryProviderInfoResponse, error) { //nolint:golint
consumerChannelID, found := k.GetProviderChannel(ctx)
if !found {
return nil, ccvtypes.ErrChannelNotFound
}
consumerChannel, found := k.channelKeeper.GetChannel(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
if !found {
return nil, ccvtypes.ErrChannelNotFound
}
// from channel get connection
consumerConnectionID, consumerConnection, err := k.channelKeeper.GetChannelConnection(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
if err != nil {
return nil, err
}
providerChannelID := consumerChannel.GetCounterparty().GetChannelID()
providerConnection := consumerConnection.GetCounterparty()
consumerClientState, found := k.clientKeeper.GetClientState(ctx, consumerConnection.GetClientID())
if !found {
return nil, ccvtypes.ErrClientNotFound
}
providerChainID := consumerClientState.(*ibctm.ClientState).ChainId
resp := types.QueryProviderInfoResponse{
Consumer: types.ChainInfo{
ChainID: ctx.ChainID(),
ClientID: consumerConnection.GetClientID(),
ConnectionID: consumerConnectionID,
ChannelID: consumerChannelID,
},
Provider: types.ChainInfo{
ChainID: providerChainID,
ClientID: providerConnection.GetClientID(),
ConnectionID: providerConnection.GetConnectionID(),
ChannelID: providerChannelID,
},
}
return &resp, nil
}