Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

add ibc client/consensus/connection/channel queries to lens #164

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions client/query/ibc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package query

import (
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v3/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
)

// ibc_ParamsRPC returns the distribution params
func ibc_ClientParamsRPC(q *Query) (*clienttypes.QueryClientParamsResponse, error) {
req := &clienttypes.QueryClientParamsRequest{}
queryClient := clienttypes.NewQueryClient(q.Client)
ctx, cancel := q.GetQueryContext()
defer cancel()
res, err := queryClient.ClientParams(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

// ibc_ClientStateRPC returns the state of the specified IBC client.
func ibc_ClientStateRPC(q *Query, clientId string) (*clienttypes.QueryClientStateResponse, error) {
req := &clienttypes.QueryClientStateRequest{ClientId: clientId}
queryClient := clienttypes.NewQueryClient(q.Client)
ctx, cancel := q.GetQueryContext()
defer cancel()
res, err := queryClient.ClientState(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

// ibc_ClientStatesRPC returns the state of the all IBC clients.
func ibc_ClientStatesRPC(q *Query) (*clienttypes.QueryClientStatesResponse, error) {
req := &clienttypes.QueryClientStatesRequest{Pagination: q.Options.Pagination}
queryClient := clienttypes.NewQueryClient(q.Client)
ctx, cancel := q.GetQueryContext()
defer cancel()
res, err := queryClient.ClientStates(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

// ibc_ConsensusStateRPC returns the consensus state of the specified IBC client.
func ibc_ConsensusStateRPC(q *Query, clientId string, height clienttypes.Height) (*clienttypes.QueryConsensusStateResponse, error) {
req := &clienttypes.QueryConsensusStateRequest{ClientId: clientId}
if (height.RevisionHeight == 0) && (height.RevisionNumber == 0) {
req.LatestHeight = true
} else {
req.RevisionNumber = height.RevisionNumber
req.RevisionHeight = height.RevisionHeight
}

queryClient := clienttypes.NewQueryClient(q.Client)
ctx, cancel := q.GetQueryContext()
defer cancel()
res, err := queryClient.ConsensusState(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

// ibc_ConsensusStatesRPC returns the consensus states of given IBC client.
func ibc_ConsensusStatesRPC(q *Query, clientId string) (*clienttypes.QueryConsensusStatesResponse, error) {
req := &clienttypes.QueryConsensusStatesRequest{ClientId: clientId, Pagination: q.Options.Pagination}

queryClient := clienttypes.NewQueryClient(q.Client)
ctx, cancel := q.GetQueryContext()
defer cancel()
res, err := queryClient.ConsensusStates(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

// ibc_ConnectionRPC returns the state of the specified IBC connection.
func ibc_ConnectionRPC(q *Query, connectionId string) (*connectiontypes.QueryConnectionResponse, error) {
req := &connectiontypes.QueryConnectionRequest{ConnectionId: connectionId}

queryClient := connectiontypes.NewQueryClient(q.Client)
ctx, cancel := q.GetQueryContext()
defer cancel()
res, err := queryClient.Connection(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

// ibc_ConnectionsRPC returns the state of all IBC connections.
func ibc_ConnectionsRPC(q *Query) (*connectiontypes.QueryConnectionsResponse, error) {
req := &connectiontypes.QueryConnectionsRequest{Pagination: q.Options.Pagination}

queryClient := connectiontypes.NewQueryClient(q.Client)
ctx, cancel := q.GetQueryContext()
defer cancel()
res, err := queryClient.Connections(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

// ibc_ChannelRPC returns the state of the specified IBC channel.
func ibc_ChannelRPC(q *Query, channelId string, portId string) (*channeltypes.QueryChannelResponse, error) {
req := &channeltypes.QueryChannelRequest{PortId: portId, ChannelId: channelId}

queryClient := channeltypes.NewQueryClient(q.Client)
ctx, cancel := q.GetQueryContext()
defer cancel()
res, err := queryClient.Channel(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

// ibc_ChannelsRPC returns the state of all IBC channels.
func ibc_ChannelsRPC(q *Query) (*channeltypes.QueryChannelsResponse, error) {
req := &channeltypes.QueryChannelsRequest{Pagination: q.Options.Pagination}

queryClient := channeltypes.NewQueryClient(q.Client)
ctx, cancel := q.GetQueryContext()
defer cancel()
res, err := queryClient.Channels(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}
59 changes: 59 additions & 0 deletions client/query/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distributionTypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v3/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
"github.com/strangelove-ventures/lens/client"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
)
Expand Down Expand Up @@ -236,3 +239,59 @@ func (q *Query) ABCIQuery(path string, data string, prove bool) (*coretypes.Resu
/// TODO: In the future have some logic to route the query to the appropriate client (gRPC or RPC)
return ABCIQueryRPC(q, path, data, prove)
}

// IBC Queries

// IBCQuery returns parameters for the IBC client submodule.
func (q *Query) Ibc_ClientParams() (*clienttypes.QueryClientParamsResponse, error) {
/// TODO: In the future have some logic to route the query to the appropriate client (gRPC or RPC)
return ibc_ClientParamsRPC(q)
}

// Ibc_ClientState returns the client state for the specified IBC client.
func (q *Query) Ibc_ClientState(clientId string) (*clienttypes.QueryClientStateResponse, error) {
/// TODO: In the future have some logic to route the query to the appropriate client (gRPC or RPC)
return ibc_ClientStateRPC(q, clientId)
}

// Ibc_ClientStates returns the client state for all IBC clients.
func (q *Query) Ibc_ClientStates() (*clienttypes.QueryClientStatesResponse, error) {
/// TODO: In the future have some logic to route the query to the appropriate client (gRPC or RPC)
return ibc_ClientStatesRPC(q)
}

// Ibc_ConsensusState returns the consensus state for the specified IBC client and the given height.
func (q *Query) Ibc_ConsensusState(clientId string, height clienttypes.Height) (*clienttypes.QueryConsensusStateResponse, error) {
/// TODO: In the future have some logic to route the query to the appropriate client (gRPC or RPC)
return ibc_ConsensusStateRPC(q, clientId, height)
}

// Ibc_ConsensusState returns all consensus states for the specified IBC client.
func (q *Query) Ibc_ConsensusStates(clientId string) (*clienttypes.QueryConsensusStatesResponse, error) {
/// TODO: In the future have some logic to route the query to the appropriate client (gRPC or RPC)
return ibc_ConsensusStatesRPC(q, clientId)
}

// Ibc_Connection returns the connection state for the specified IBC connection.
func (q *Query) Ibc_Connection(connectionId string) (*connectiontypes.QueryConnectionResponse, error) {
/// TODO: In the future have some logic to route the query to the appropriate client (gRPC or RPC)
return ibc_ConnectionRPC(q, connectionId)
}

// Ibc_Connections returns the connection state for all IBC connections.
func (q *Query) Ibc_Connections() (*connectiontypes.QueryConnectionsResponse, error) {
/// TODO: In the future have some logic to route the query to the appropriate client (gRPC or RPC)
return ibc_ConnectionsRPC(q)
}

// Ibc_Channel returns the channel state for the specified IBC channel and port.
func (q *Query) Ibc_Channel(channelId string, portId string) (*channeltypes.QueryChannelResponse, error) {
/// TODO: In the future have some logic to route the query to the appropriate client (gRPC or RPC)
return ibc_ChannelRPC(q, channelId, portId)
}

// Ibc_Channels returns the channel state for all IBC channels.
func (q *Query) Ibc_Channels() (*channeltypes.QueryChannelsResponse, error) {
/// TODO: In the future have some logic to route the query to the appropriate client (gRPC or RPC)
return ibc_ChannelsRPC(q)
}