Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/Slashing: gRPC query service #6597

Merged
merged 13 commits into from
Jul 6, 2020
Prev Previous commit
Next Next commit
Add signing infos
  • Loading branch information
sahith-narahari committed Jul 3, 2020
commit 9dbd901e93905feaeb9a69c831f44e777b4a8b93
2 changes: 1 addition & 1 deletion proto/cosmos/slashing/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ message QuerySigningInfosRequest{
// QuerySigningInfosResponse is the response type for the Query/SigningInfos RPC method
message QuerySigningInfosResponse{
// info is the signing info of all validators
repeated cosmos.slashing.ValidatorSigningInfo info = 1;
repeated cosmos.slashing.ValidatorSigningInfo info = 1[(gogoproto.nullable)= false];
cosmos.query.PageResponse res =2;
}
26 changes: 24 additions & 2 deletions x/slashing/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
)

Expand All @@ -28,6 +30,10 @@ func (k Keeper) SigningInfo(c context.Context, req *types.QuerySigningInfoReques
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

if req.ConsAddress == nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(c)
signingInfo, found := k.GetValidatorSigningInfo(ctx, req.ConsAddress)
if !found {
Expand All @@ -42,6 +48,22 @@ func (k Keeper) SigningInfos(c context.Context, req *types.QuerySigningInfosRequ
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

_ = sdk.UnwrapSDKContext(c)
return nil, nil
ctx := sdk.UnwrapSDKContext(c)
store := ctx.KVStore(k.storeKey)
var signInfos []types.ValidatorSigningInfo

sigInfoStore := prefix.NewStore(store, types.ValidatorSigningInfoKeyPrefix)
res, err := query.Paginate(sigInfoStore, req.Req, func(key []byte, value []byte) error {
var info types.ValidatorSigningInfo
err := k.cdc.UnmarshalBinaryBare(value, &info)
if err != nil {
return err
}
signInfos = append(signInfos, info)
return nil
})
if err != nil {
return nil, err
}
return &types.QuerySigningInfosResponse{Info: signInfos, Res: res}, nil
}
64 changes: 32 additions & 32 deletions x/slashing/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.