Skip to content

Commit

Permalink
Merge pull request realiotech#58 from faddat/linting
Browse files Browse the repository at this point in the history
linting
  • Loading branch information
jiujiteiro authored May 3, 2023
2 parents a1be4c6 + 87c8c1a commit afa09d4
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 89 deletions.
47 changes: 0 additions & 47 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,7 @@ linters:
- unparam
- unused

# TODO: fix the sdkerrors.Wrap deprecation warning and re-enable staticcheck
# TODO: fix the use of deprecated gov style

issues:
exclude-rules:
- text: "SA1019: sdkerrors.Register"
linters:
- staticcheck
- text: "sdkerrors.ABCIInfo is deprecated"
linters:
- staticcheck
- text: "sdkerrors.IsOf is deprecated"
linters:
- staticcheck
- text: "Use WeightedProposalMsg instead"
linters:
- staticcheck
- text: "Use MsgSimulatorFn instead"
linters:
- staticcheck
- text: "Error return value of `flagSet.Set` is not checked"
linters:
- errcheck
- text: "SA1019: sdkerrors.Wrapf is deprecated: functionality of this package has been moved to it's own module"
linters:
- staticcheck
- text: "sdkerrors.Error is deprecated: the type has been moved to cosmossdk.io/errors module"
linters:
- staticcheck
- text: "sdkerrors.Wrap is deprecated"
linters:
- staticcheck
- text: "Use of weak random number generator"
linters:
- gosec
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
linters:
- stylecheck
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck

max-issues-per-linter: 10000
max-same-issues: 10000

Expand Down
4 changes: 3 additions & 1 deletion x/asset/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package asset
import (
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/realiotech/realio-network/x/asset/keeper"
"github.com/realiotech/realio-network/x/asset/types"
)
Expand Down Expand Up @@ -35,7 +37,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
// this line is used by starport scaffolding # 1
default:
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
}
}
}
5 changes: 3 additions & 2 deletions x/asset/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"

errorsmod "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -39,7 +40,7 @@ func (k Keeper) Token(c context.Context, req *types.QueryTokenRequest) (*types.Q
ctx := sdk.UnwrapSDKContext(c)

if t, found := k.GetToken(ctx, req.Symbol); !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, "not found")
return nil, errorsmod.Wrap(sdkerrors.ErrKeyNotFound, "not found")
} else { //nolint:revive // fixing this causes t to be inaccessible, so let's leave all as is.
return &types.QueryTokenResponse{Token: t}, nil
}
Expand All @@ -52,7 +53,7 @@ func (k Keeper) IsAuthorized(c context.Context, req *types.QueryIsAuthorizedRequ
ctx := sdk.UnwrapSDKContext(c)

if t, found := k.GetToken(ctx, req.Symbol); !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, "not found")
return nil, errorsmod.Wrap(sdkerrors.ErrKeyNotFound, "not found")
} else { //nolint:revive // fixing this causes t to be inaccessible, so let's leave all as is.
accAddress, _ := sdk.AccAddressFromBech32(req.Address)
isAuthorized := t.AddressIsAuthorized(accAddress)
Expand Down
9 changes: 5 additions & 4 deletions x/asset/keeper/msg_server_authorize_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"

errorsmod "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -15,23 +16,23 @@ func (k msgServer) AuthorizeAddress(goCtx context.Context, msg *types.MsgAuthori
// Check if the value exists
token, isFound := k.GetToken(ctx, msg.Symbol)
if !isFound {
return nil, sdkerrors.Wrapf(sdkerrors.ErrKeyNotFound, "symbol %s does not exists", msg.Symbol)
return nil, errorsmod.Wrapf(sdkerrors.ErrKeyNotFound, "symbol %s does not exists", msg.Symbol)
}

// Checks if the token manager signed
signers := msg.GetSigners()
if len(signers) != 1 {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "invalid signers")
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "invalid signers")
}

// assert that the manager account is the only signer of the message
if signers[0].String() != token.Manager {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "caller not authorized")
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "caller not authorized")
}

accAddress, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid address")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid address")
}

token.AuthorizeAddress(accAddress)
Expand Down
5 changes: 3 additions & 2 deletions x/asset/keeper/msg_server_create_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

errorsmod "cosmossdk.io/errors"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"

realionetworktypes "github.com/realiotech/realio-network/types"
Expand All @@ -29,12 +30,12 @@ func (k msgServer) CreateToken(goCtx context.Context, msg *types.MsgCreateToken)
msg.Symbol,
)
if isFound {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "symbol %s already set", msg.Symbol)
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "symbol %s already set", msg.Symbol)
}

managerAccAddress, err := sdk.AccAddressFromBech32(msg.Manager)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid manager address")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid manager address")
}

token := types.NewToken(lowerCaseName, lowerCaseSymbol, msg.Total, msg.Manager, msg.AuthorizationRequired)
Expand Down
7 changes: 4 additions & 3 deletions x/asset/keeper/msg_server_transfer_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -28,7 +29,7 @@ func (k msgServer) TransferToken(goCtx context.Context, msg *types.MsgTransferTo
msg.Symbol,
)
if !isFound {
return nil, sdkerrors.Wrapf(sdkerrors.ErrKeyNotFound, "token %s not found", msg.Symbol)
return nil, errorsmod.Wrapf(sdkerrors.ErrKeyNotFound, "token %s not found", msg.Symbol)
}

if token.AuthorizationRequired {
Expand All @@ -39,7 +40,7 @@ func (k msgServer) TransferToken(goCtx context.Context, msg *types.MsgTransferTo
if isAuthorizedFrom && isAuthorizedTo {
totalInt, totalIsValid := math.NewIntFromString(msg.Amount)
if !totalIsValid {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "invalid coin amount %s", msg.Amount)
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "invalid coin amount %s", msg.Amount)
}

baseDenom := fmt.Sprintf("a%s", strings.ToLower(msg.Symbol))
Expand All @@ -49,7 +50,7 @@ func (k msgServer) TransferToken(goCtx context.Context, msg *types.MsgTransferTo
return nil, err
}
} else {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s transfer not authorized", msg.Symbol)
return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s transfer not authorized", msg.Symbol)
}

return &types.MsgTransferTokenResponse{}, nil
Expand Down
9 changes: 5 additions & 4 deletions x/asset/keeper/msg_server_un_authorize_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/realiotech/realio-network/x/asset/types"
Expand All @@ -14,23 +15,23 @@ func (k msgServer) UnAuthorizeAddress(goCtx context.Context, msg *types.MsgUnAut
// Check if the value exists
token, isFound := k.GetToken(ctx, msg.Symbol)
if !isFound {
return nil, sdkerrors.Wrapf(sdkerrors.ErrKeyNotFound, "symbol %s does not exists", msg.Symbol)
return nil, errorsmod.Wrapf(sdkerrors.ErrKeyNotFound, "symbol %s does not exists", msg.Symbol)
}

// Checks if the token manager signed
signers := msg.GetSigners()
if len(signers) != 1 {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "invalid signers")
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "invalid signers")
}

// assert that the manager account is the only signer of the message
if signers[0].String() != token.Manager {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "caller not authorized")
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "caller not authorized")
}

accAddress, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid address")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid address")
}

token.UnAuthorizeAddress(accAddress)
Expand Down
8 changes: 5 additions & 3 deletions x/asset/keeper/msg_server_update_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
"context"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/realiotech/realio-network/x/asset/types"
Expand All @@ -13,18 +15,18 @@ func (k msgServer) UpdateToken(goCtx context.Context, msg *types.MsgUpdateToken)

existing, isFound := k.GetToken(ctx, msg.Symbol)
if !isFound {
return nil, sdkerrors.Wrapf(sdkerrors.ErrKeyNotFound, "symbol %s does not exists", msg.Symbol)
return nil, errorsmod.Wrapf(sdkerrors.ErrKeyNotFound, "symbol %s does not exists", msg.Symbol)
}

// Checks if the token manager signed
signers := msg.GetSigners()
if len(signers) != 1 {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "invalid signers")
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "invalid signers")
}

// assert that the manager account is the only signer of the message
if signers[0].String() != existing.Manager {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "caller not authorized")
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "caller not authorized")
}

// only Authorization Flag is updatable at this time
Expand Down
4 changes: 2 additions & 2 deletions x/asset/keeper/restrictions.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package keeper

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/realiotech/realio-network/x/asset/types"
)

Expand Down Expand Up @@ -42,7 +42,7 @@ func (k Keeper) AssetSendRestriction(ctx sdk.Context, fromAddr, toAddr sdk.AccAd
if isAuthorizedFrom && isAuthorizedTo {
continue
} else { //nolint:revive // superfluous else, could fix, but not worth it?
err = sdkerrors.Wrapf(types.ErrNotAuthorized, "%s is not authorized to transact with %s", fromAddr, coin.Denom)
err = errorsmod.Wrapf(types.ErrNotAuthorized, "%s is not authorized to transact with %s", fromAddr, coin.Denom)
break
}
}
Expand Down
14 changes: 7 additions & 7 deletions x/asset/types/errors.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package types

// DONTCOVER

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
errorsmod "cosmossdk.io/errors"
)

// DONTCOVER

// x/asset module sentinel errors
var (
ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error")
ErrInvalidPacketTimeout = sdkerrors.Register(ModuleName, 1500, "invalid packet timeout")
ErrInvalidVersion = sdkerrors.Register(ModuleName, 1501, "invalid version")
ErrNotAuthorized = sdkerrors.Register(ModuleName, 1502, "transaction not authorized")
ErrSample = errorsmod.Register(ModuleName, 1100, "sample error")
ErrInvalidPacketTimeout = errorsmod.Register(ModuleName, 1500, "invalid packet timeout")
ErrInvalidVersion = errorsmod.Register(ModuleName, 1501, "invalid version")
ErrNotAuthorized = errorsmod.Register(ModuleName, 1502, "transaction not authorized")
)
3 changes: 2 additions & 1 deletion x/asset/types/message_authorize_address.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -41,7 +42,7 @@ func (msg *MsgAuthorizeAddress) GetSignBytes() []byte {
func (msg *MsgAuthorizeAddress) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Manager)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid manager address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid manager address (%s)", err)
}
return nil
}
3 changes: 2 additions & 1 deletion x/asset/types/message_create_token.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -43,7 +44,7 @@ func (msg *MsgCreateToken) GetSignBytes() []byte {
func (msg *MsgCreateToken) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Manager)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid manager address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid manager address (%s)", err)
}
return nil
}
3 changes: 2 additions & 1 deletion x/asset/types/message_update_token.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -41,7 +42,7 @@ func (msg *MsgUpdateToken) GetSignBytes() []byte {
func (msg *MsgUpdateToken) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Manager)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid manager address (%s)", err)
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid manager address (%s)", err)
}
return nil
}
12 changes: 6 additions & 6 deletions x/mint/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

// InitGenesis new mint genesis
func (keeper Keeper) InitGenesis(ctx sdk.Context, ak types.AccountKeeper, data *types.GenesisState) {
keeper.SetMinter(ctx, data.Minter)
keeper.SetParams(ctx, data.Params)
func (k Keeper) InitGenesis(ctx sdk.Context, ak types.AccountKeeper, data *types.GenesisState) {
k.SetMinter(ctx, data.Minter)
k.SetParams(ctx, data.Params)
ak.GetModuleAccount(ctx, types.ModuleName)
}

// ExportGenesis returns a GenesisState for a given context and keeper.
func (keeper Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
minter := keeper.GetMinter(ctx)
params := keeper.GetParams(ctx)
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
minter := k.GetMinter(ctx)
params := k.GetParams(ctx)
return types.NewGenesisState(minter, params)
}
Loading

0 comments on commit afa09d4

Please sign in to comment.