Skip to content

Commit

Permalink
changed q's to k and Repositioned UnWrapSDKContext (cosmos#3424)
Browse files Browse the repository at this point in the history
* changed q's to k and repositioned UnWrapSDKContext

* add new lines

* address review comment

* add missing nil message/request check to rpc handlers

* Update modules/core/04-channel/keeper/grpc_query.go

Co-authored-by: Jim Fasarakis-Hilliard <[email protected]>

---------

Co-authored-by: Carlos Rodriguez <[email protected]>
Co-authored-by: Jim Fasarakis-Hilliard <[email protected]>
  • Loading branch information
3 people authored Apr 18, 2023
1 parent b64f942 commit 9e4b0d2
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ func (k Keeper) InterchainAccount(goCtx context.Context, req *types.QueryInterch
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

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)
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/host/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
var _ types.QueryServer = (*Keeper)(nil)

// Params implements the Query/Params gRPC method
func (q Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := q.GetParams(ctx)
params := k.GetParams(ctx)

return &types.QueryParamsResponse{
Params: &params,
Expand Down
20 changes: 10 additions & 10 deletions modules/apps/transfer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
var _ types.QueryServer = (*Keeper)(nil)

// DenomTrace implements the Query/DenomTrace gRPC method
func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest) (*types.QueryDenomTraceResponse, error) {
func (k Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest) (*types.QueryDenomTraceResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -29,7 +29,7 @@ func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest)
}

ctx := sdk.UnwrapSDKContext(c)
denomTrace, found := q.GetDenomTrace(ctx, hash)
denomTrace, found := k.GetDenomTrace(ctx, hash)
if !found {
return nil, status.Error(
codes.NotFound,
Expand All @@ -43,18 +43,18 @@ func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest)
}

// DenomTraces implements the Query/DenomTraces gRPC method
func (q Keeper) DenomTraces(c context.Context, req *types.QueryDenomTracesRequest) (*types.QueryDenomTracesResponse, error) {
func (k Keeper) DenomTraces(c context.Context, req *types.QueryDenomTracesRequest) (*types.QueryDenomTracesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(c)

traces := types.Traces{}
store := prefix.NewStore(ctx.KVStore(q.storeKey), types.DenomTraceKey)
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.DenomTraceKey)

pageRes, err := query.Paginate(store, req.Pagination, func(_, value []byte) error {
result, err := q.UnmarshalDenomTrace(value)
result, err := k.UnmarshalDenomTrace(value)
if err != nil {
return err
}
Expand All @@ -73,17 +73,17 @@ func (q Keeper) DenomTraces(c context.Context, req *types.QueryDenomTracesReques
}

// Params implements the Query/Params gRPC method
func (q Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := q.GetParams(ctx)
params := k.GetParams(ctx)

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

// DenomHash implements the Query/DenomHash gRPC method
func (q Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) (*types.QueryDenomHashResponse, error) {
func (k Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) (*types.QueryDenomHashResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -96,7 +96,7 @@ func (q Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) (

ctx := sdk.UnwrapSDKContext(c)
denomHash := denomTrace.Hash()
found := q.HasDenomTrace(ctx, denomHash)
found := k.HasDenomTrace(ctx, denomHash)
if !found {
return nil, status.Error(
codes.NotFound,
Expand All @@ -110,7 +110,7 @@ func (q Keeper) DenomHash(c context.Context, req *types.QueryDenomHashRequest) (
}

// EscrowAddress implements the EscrowAddress gRPC method
func (q Keeper) EscrowAddress(c context.Context, req *types.QueryEscrowAddressRequest) (*types.QueryEscrowAddressResponse, error) {
func (k Keeper) EscrowAddress(c context.Context, req *types.QueryEscrowAddressRequest) (*types.QueryEscrowAddressResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand Down
50 changes: 25 additions & 25 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
var _ types.QueryServer = (*Keeper)(nil)

// ClientState implements the Query/ClientState gRPC method
func (q Keeper) ClientState(c context.Context, req *types.QueryClientStateRequest) (*types.QueryClientStateResponse, error) {
func (k Keeper) ClientState(c context.Context, req *types.QueryClientStateRequest) (*types.QueryClientStateResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -32,7 +32,7 @@ func (q Keeper) ClientState(c context.Context, req *types.QueryClientStateReques
}

ctx := sdk.UnwrapSDKContext(c)
clientState, found := q.GetClientState(ctx, req.ClientId)
clientState, found := k.GetClientState(ctx, req.ClientId)
if !found {
return nil, status.Error(
codes.NotFound,
Expand All @@ -53,15 +53,15 @@ func (q Keeper) ClientState(c context.Context, req *types.QueryClientStateReques
}

// ClientStates implements the Query/ClientStates gRPC method
func (q Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequest) (*types.QueryClientStatesResponse, error) {
func (k Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequest) (*types.QueryClientStatesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(c)

clientStates := types.IdentifiedClientStates{}
store := prefix.NewStore(ctx.KVStore(q.storeKey), host.KeyClientStorePrefix)
store := prefix.NewStore(ctx.KVStore(k.storeKey), host.KeyClientStorePrefix)

pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) {
// filter any metadata stored under client state key
Expand All @@ -70,7 +70,7 @@ func (q Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequ
return false, nil
}

clientState, err := q.UnmarshalClientState(value)
clientState, err := k.UnmarshalClientState(value)
if err != nil {
return false, err
}
Expand All @@ -97,7 +97,7 @@ func (q Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequ
}

// ConsensusState implements the Query/ConsensusState gRPC method
func (q Keeper) ConsensusState(c context.Context, req *types.QueryConsensusStateRequest) (*types.QueryConsensusStateResponse, error) {
func (k Keeper) ConsensusState(c context.Context, req *types.QueryConsensusStateRequest) (*types.QueryConsensusStateResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -115,13 +115,13 @@ func (q Keeper) ConsensusState(c context.Context, req *types.QueryConsensusState

height := types.NewHeight(req.RevisionNumber, req.RevisionHeight)
if req.LatestHeight {
consensusState, found = q.GetLatestClientConsensusState(ctx, req.ClientId)
consensusState, found = k.GetLatestClientConsensusState(ctx, req.ClientId)
} else {
if req.RevisionHeight == 0 {
return nil, status.Error(codes.InvalidArgument, "consensus state height cannot be 0")
}

consensusState, found = q.GetClientConsensusState(ctx, req.ClientId, height)
consensusState, found = k.GetClientConsensusState(ctx, req.ClientId, height)
}

if !found {
Expand All @@ -144,7 +144,7 @@ func (q Keeper) ConsensusState(c context.Context, req *types.QueryConsensusState
}

// ConsensusStates implements the Query/ConsensusStates gRPC method
func (q Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStatesRequest) (*types.QueryConsensusStatesResponse, error) {
func (k Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStatesRequest) (*types.QueryConsensusStatesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -156,7 +156,7 @@ func (q Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStat
ctx := sdk.UnwrapSDKContext(c)

consensusStates := []types.ConsensusStateWithHeight{}
store := prefix.NewStore(ctx.KVStore(q.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix))))
store := prefix.NewStore(ctx.KVStore(k.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix))))

pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) {
// filter any metadata stored under consensus state key
Expand All @@ -169,7 +169,7 @@ func (q Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStat
return false, err
}

consensusState, err := q.UnmarshalConsensusState(value)
consensusState, err := k.UnmarshalConsensusState(value)
if err != nil {
return false, err
}
Expand All @@ -188,7 +188,7 @@ func (q Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStat
}

// ConsensusStateHeights implements the Query/ConsensusStateHeights gRPC method
func (q Keeper) ConsensusStateHeights(c context.Context, req *types.QueryConsensusStateHeightsRequest) (*types.QueryConsensusStateHeightsResponse, error) {
func (k Keeper) ConsensusStateHeights(c context.Context, req *types.QueryConsensusStateHeightsRequest) (*types.QueryConsensusStateHeightsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -200,7 +200,7 @@ func (q Keeper) ConsensusStateHeights(c context.Context, req *types.QueryConsens
ctx := sdk.UnwrapSDKContext(c)

var consensusStateHeights []types.Height
store := prefix.NewStore(ctx.KVStore(q.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix))))
store := prefix.NewStore(ctx.KVStore(k.storeKey), host.FullClientKey(req.ClientId, []byte(fmt.Sprintf("%s/", host.KeyConsensusStatePrefix))))

pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, _ []byte, accumulate bool) (bool, error) {
// filter any metadata stored under consensus state key
Expand All @@ -227,7 +227,7 @@ func (q Keeper) ConsensusStateHeights(c context.Context, req *types.QueryConsens
}

// ClientStatus implements the Query/ClientStatus gRPC method
func (q Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequest) (*types.QueryClientStatusResponse, error) {
func (k Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequest) (*types.QueryClientStatusResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -237,52 +237,52 @@ func (q Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequ
}

ctx := sdk.UnwrapSDKContext(c)
clientState, found := q.GetClientState(ctx, req.ClientId)
clientState, found := k.GetClientState(ctx, req.ClientId)
if !found {
return nil, status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrClientNotFound, req.ClientId).Error(),
)
}

status := q.GetClientStatus(ctx, clientState, req.ClientId)
status := k.GetClientStatus(ctx, clientState, req.ClientId)

return &types.QueryClientStatusResponse{
Status: status.String(),
}, nil
}

// ClientParams implements the Query/ClientParams gRPC method
func (q Keeper) ClientParams(c context.Context, _ *types.QueryClientParamsRequest) (*types.QueryClientParamsResponse, error) {
func (k Keeper) ClientParams(c context.Context, _ *types.QueryClientParamsRequest) (*types.QueryClientParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := q.GetParams(ctx)
params := k.GetParams(ctx)

return &types.QueryClientParamsResponse{
Params: &params,
}, nil
}

// UpgradedClientState implements the Query/UpgradedClientState gRPC method
func (q Keeper) UpgradedClientState(c context.Context, req *types.QueryUpgradedClientStateRequest) (*types.QueryUpgradedClientStateResponse, error) {
func (k Keeper) UpgradedClientState(c context.Context, req *types.QueryUpgradedClientStateRequest) (*types.QueryUpgradedClientStateResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(c)

plan, found := q.GetUpgradePlan(ctx)
plan, found := k.GetUpgradePlan(ctx)
if !found {
return nil, status.Error(
codes.NotFound, "upgrade plan not found",
)
}

bz, found := q.GetUpgradedClient(ctx, plan.Height)
bz, found := k.GetUpgradedClient(ctx, plan.Height)
if !found {
return nil, status.Error(codes.NotFound, types.ErrClientNotFound.Error())
}

clientState, err := types.UnmarshalClientState(q.cdc, bz)
clientState, err := types.UnmarshalClientState(k.cdc, bz)
if err != nil {
return nil, status.Error(
codes.Internal, err.Error(),
Expand All @@ -300,19 +300,19 @@ func (q Keeper) UpgradedClientState(c context.Context, req *types.QueryUpgradedC
}

// UpgradedConsensusState implements the Query/UpgradedConsensusState gRPC method
func (q Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) {
func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(c)

bz, found := q.GetUpgradedConsensusState(ctx, ctx.BlockHeight())
bz, found := k.GetUpgradedConsensusState(ctx, ctx.BlockHeight())
if !found {
return nil, status.Errorf(codes.NotFound, "%s, height %d", types.ErrConsensusStateNotFound.Error(), ctx.BlockHeight())
}

consensusState, err := types.UnmarshalConsensusState(q.cdc, bz)
consensusState, err := types.UnmarshalConsensusState(k.cdc, bz)
if err != nil {
return nil, status.Error(
codes.Internal, err.Error(),
Expand Down
Loading

0 comments on commit 9e4b0d2

Please sign in to comment.