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

[Code Health] fix: proof module gRPC status error returns #956

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion x/proof/keeper/msg_server_create_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (k msgServer) CreateClaim(

// Basic validation of the CreateClaim message.
if err = msg.ValidateBasic(); err != nil {
return nil, err
return nil, status.Error(codes.InvalidArgument, err.Error())
}
logger.Info("validated the createClaim message")

Expand Down
19 changes: 16 additions & 3 deletions x/proof/keeper/msg_update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,33 @@ package keeper

import (
"context"
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/pokt-network/poktroll/x/proof/types"
)

func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
logger := k.Logger().With("method", "UpdateParams")

if err := req.ValidateBasic(); err != nil {
return nil, err
return nil, status.Error(codes.InvalidArgument, err.Error())
}
if k.GetAuthority() != req.Authority {
return nil, types.ErrProofInvalidSigner.Wrapf("invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority)
return nil, status.Error(
codes.PermissionDenied,
types.ErrProofInvalidSigner.Wrapf(
"invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority,
).Error(),
)
}

if err := k.SetParams(ctx, req.Params); err != nil {
return nil, err
err = fmt.Errorf("unable to set params: %w", err)
logger.Error(err.Error())
return nil, status.Error(codes.Internal, err.Error())
}

return &types.MsgUpdateParamsResponse{}, nil
Expand Down
7 changes: 6 additions & 1 deletion x/proof/keeper/query_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"encoding/binary"
"fmt"

"cosmossdk.io/store/prefix"
"github.com/cosmos/cosmos-sdk/runtime"
Expand All @@ -14,6 +15,8 @@ import (
)

func (k Keeper) AllClaims(ctx context.Context, req *types.QueryAllClaimsRequest) (*types.QueryAllClaimsResponse, error) {
logger := k.Logger().With("method", "AllClaims")

if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
Expand Down Expand Up @@ -65,7 +68,9 @@ func (k Keeper) AllClaims(ctx context.Context, req *types.QueryAllClaimsRequest)
// The value is the encoded claim.
var claim types.Claim
if err := k.cdc.Unmarshal(value, &claim); err != nil {
return err
err = fmt.Errorf("unable to unmarshal claim with key (hex): %x: %+v", key, err)
logger.Error(err.Error())
return status.Error(codes.Internal, err.Error())
}
claims = append(claims, claim)
}
Expand Down
6 changes: 5 additions & 1 deletion x/proof/keeper/query_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
)

func (k Keeper) AllProofs(ctx context.Context, req *types.QueryAllProofsRequest) (*types.QueryAllProofsResponse, error) {
logger := k.Logger().With("method", "AllProofs")

if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
Expand Down Expand Up @@ -63,7 +65,9 @@ func (k Keeper) AllProofs(ctx context.Context, req *types.QueryAllProofsRequest)
// The value is the encoded proof.
var proof types.Proof
if err := k.cdc.Unmarshal(value, &proof); err != nil {
return err
err = fmt.Errorf("unable to unmarshal proof with key (hex): %x: %+v", key, err)
logger.Error(err.Error())
return status.Error(codes.Internal, err.Error())
}

proofs = append(proofs, proof)
Expand Down
Loading