Skip to content

Commit

Permalink
feat: add provider info query
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaru Wang committed Jul 21, 2023
1 parent 7484dbc commit ee5c6f6
Show file tree
Hide file tree
Showing 4 changed files with 464 additions and 35 deletions.
10 changes: 10 additions & 0 deletions proto/interchain_security/ccv/consumer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ service Query {
rpc QueryParams(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/interchain_security/ccv/consumer/params";
}

rpc QueryProviderChainInfo(QueryProviderInfoRequest) returns (QueryProviderInfoResponse) {
option (google.api.http).get = "/interchain_security/ccv/consumer/provider-info";
}
}

// NextFeeDistributionEstimate holds information about next fee distribution
Expand Down Expand Up @@ -52,3 +56,9 @@ message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [ (gogoproto.nullable) = false ];
}

message QueryProviderInfoRequest {}

message QueryProviderInfoResponse {
string ChainID = 1;
}
26 changes: 25 additions & 1 deletion x/ccv/consumer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"google.golang.org/grpc/status"

sdk "github.com/cosmos/cosmos-sdk/types"

ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
)

Expand Down Expand Up @@ -40,3 +40,27 @@ func (k Keeper) QueryParams(c context.Context,

return &types.QueryParamsResponse{Params: p}, nil
}

func (k Keeper) QueryProviderChainInfo(c context.Context,
req *types.QueryProviderInfoRequest,
) (*types.QueryProviderInfoResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

providerClientID, found := k.GetProviderClientID(ctx)
if !found {
return nil, nil
}
clientState, found := k.clientKeeper.GetClientState(ctx, providerClientID)
if !found {
return nil, nil
}
providerChainID := clientState.(*ibctm.ClientState).ChainId
resp := types.QueryProviderInfoResponse{
ChainID: providerChainID,
}

return &resp, nil
}
Loading

0 comments on commit ee5c6f6

Please sign in to comment.