Skip to content

Commit

Permalink
add errcheck and do some lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Vritra4 committed Oct 23, 2023
1 parent af70176 commit 5c3967d
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 37 deletions.
5 changes: 4 additions & 1 deletion x/authz/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package authz
import (
"context"
"encoding/json"
"fmt"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
Expand Down Expand Up @@ -69,7 +70,9 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEn

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the authz module.
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) {
authz.RegisterQueryHandlerClient(context.Background(), mux, authz.NewQueryClient(clientCtx))
if err := authz.RegisterQueryHandlerClient(context.Background(), mux, authz.NewQueryClient(clientCtx)); err != nil {
panic(fmt.Sprintf("could not register gRPC query service: %v", err))
}
}

// GetQueryCmd returns the cli query commands for the authz module
Expand Down
3 changes: 3 additions & 0 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type BaseKeeper struct {
// GetPaginatedTotalSupply queries for the supply, ignoring 0 coins, with a given pagination
func (k BaseKeeper) GetPaginatedTotalSupply(ctx sdk.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error) {
issuers, err := k.mk.GetIssuers(ctx)
if err != nil {
return nil, nil, err
}

supply := sdk.NewCoins()

Expand Down
4 changes: 3 additions & 1 deletion x/distribution/keeper/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func (k Keeper) beforeAllocateTokens(ctx sdk.Context) error {
// bondedVotes is a list of (validator address, validator voted on last block flag) for all
// validators in the bonded set.
func (k Keeper) AllocateTokens(ctx sdk.Context, totalPreviousPower int64, bondedVotes []abci.VoteInfo) {
k.beforeAllocateTokens(ctx)
if err := k.beforeAllocateTokens(ctx); err != nil {
panic(err)
}

// fetch and clear the collected fees for distribution, since this is
// called in BeginBlock, collected fees will be from the previous block
Expand Down
4 changes: 3 additions & 1 deletion x/distribution/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ func (k Keeper) GetRewardWeights(ctx sdk.Context) []customtypes.RewardWeight {
func (k Keeper) SetRewardWeights(ctx sdk.Context, rewardWeights []customtypes.RewardWeight) {
params := k.GetParams(ctx)
params.RewardWeights = rewardWeights
k.SetParams(ctx, params)
if err := k.SetParams(ctx, params); err != nil {
panic(err)
}
}
4 changes: 3 additions & 1 deletion x/gov/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
// InitGenesis - store genesis parameters
func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, data *v1.GenesisState) {
k.SetProposalID(ctx, data.StartingProposalId)
k.SetParams(ctx, *data.Params)
if err := k.SetParams(ctx, *data.Params); err != nil {
panic(err)
}

// check if the deposits pool account exists
moduleAcc := k.GetGovernanceAccount(ctx)
Expand Down
4 changes: 3 additions & 1 deletion x/ibc/nft-transfer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
}
}

k.SetParams(ctx, state.Params)
if err := k.SetParams(ctx, state.Params); err != nil {
panic(err)
}
}

// ExportGenesis exports ibc-transfer module's portID and denom trace info into its genesis state.
Expand Down
4 changes: 3 additions & 1 deletion x/ibc/nft-transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc-transfer module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(fmt.Sprintf("could not register gRPC query service: %v", err))
}
}

// GetTxCmd implements AppModuleBasic interface
Expand Down
2 changes: 1 addition & 1 deletion x/ibc/nft-transfer/types/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func extractPathAndBaseFromFullClassId(fullClassIdItems []string) (string, strin

length := len(fullClassIdItems)
for i := 0; i < length; i = i + 2 {
// The IBC specification does not guarentee the expected format of the
// The IBC specification does not guarantee the expected format of the
// destination port or destination channel identifier. A short term solution
// to determine base class id is to expect the channel identifier to be the
// one ibc-go specifies. A longer term solution is to separate the path and base
Expand Down
4 changes: 3 additions & 1 deletion x/ibc/perm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc-transfer module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(fmt.Sprintf("could not register gRPC gateway routes: %v", err))
}
}

// GetTxCmd implements AppModuleBasic interface
Expand Down
12 changes: 6 additions & 6 deletions x/ibc/testing/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func ParseClientIDFromEvents(events sdk.Events) (string, error) {
for _, ev := range events {
if ev.Type == clienttypes.EventTypeCreateClient {
for _, attr := range ev.Attributes {
if string(attr.Key) == clienttypes.AttributeKeyClientID {
return string(attr.Value), nil
if attr.Key == clienttypes.AttributeKeyClientID {
return attr.Value, nil
}
}
}
Expand All @@ -33,8 +33,8 @@ func ParseConnectionIDFromEvents(events sdk.Events) (string, error) {
if ev.Type == connectiontypes.EventTypeConnectionOpenInit ||
ev.Type == connectiontypes.EventTypeConnectionOpenTry {
for _, attr := range ev.Attributes {
if string(attr.Key) == connectiontypes.AttributeKeyConnectionID {
return string(attr.Value), nil
if attr.Key == connectiontypes.AttributeKeyConnectionID {
return attr.Value, nil
}
}
}
Expand All @@ -48,8 +48,8 @@ func ParseChannelIDFromEvents(events sdk.Events) (string, error) {
for _, ev := range events {
if ev.Type == channeltypes.EventTypeChannelOpenInit || ev.Type == channeltypes.EventTypeChannelOpenTry {
for _, attr := range ev.Attributes {
if string(attr.Key) == channeltypes.AttributeKeyChannelID {
return string(attr.Value), nil
if attr.Key == channeltypes.AttributeKeyChannelID {
return attr.Value, nil
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion x/move/keeper/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ func (k MoveBankKeeper) BurnCoins(
}

// send tokens to 0x1
k.SendCoin(ctx, accAddr, types.StdAddr, coin.Denom, coin.Amount)
err := k.SendCoin(ctx, accAddr, types.StdAddr, coin.Denom, coin.Amount)
if err != nil {
return err
}

// execute burn
metadata, err := types.MetadataAddressFromDenom(coin.Denom)
Expand Down
3 changes: 3 additions & 0 deletions x/move/keeper/dex.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ func (k DexKeeper) getPoolWeights(

timestamp := sdk.NewInt(ctx.BlockTime().Unix())
weightA, weightB, err := types.ReadWeightsFromDexConfig(timestamp, bz)
if err != nil {
return math.LegacyDec{}, math.LegacyDec{}, err
}

if ok, err := k.isReverse(ctx, metadataLP); err != nil {
return math.LegacyZeroDec(), math.LegacyZeroDec(), err
Expand Down
4 changes: 3 additions & 1 deletion x/move/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) ([]abc
k.authKeeper.GetModuleAccount(ctx, types.MoveStakingModuleName)

params := genState.GetParams()
k.SetRawParams(ctx, params.ToRaw())
if err := k.SetRawParams(ctx, params.ToRaw()); err != nil {
return nil, err
}
k.SetExecutionCounter(ctx, genState.ExecutionCounter)

if len(genState.GetModules()) == 0 {
Expand Down
3 changes: 3 additions & 0 deletions x/move/keeper/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func (k Keeper) PublishModuleBundle(
}

codeBz, err := vmtypes.SerializeBytesVector(moduleCodeArr)
if err != nil {
return err
}

// ignore staking deltas and events
err = k.ExecuteEntryFunction(
Expand Down
9 changes: 7 additions & 2 deletions x/move/keeper/whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ func (k Keeper) Whitelist(ctx sdk.Context, msg types.MsgWhitelist) error {

// register denomLP as staking bond denom
bondDenoms = append(bondDenoms, denomLP)
k.StakingKeeper.SetBondDenoms(ctx, bondDenoms)
if err := k.StakingKeeper.SetBondDenoms(ctx, bondDenoms); err != nil {
return err
}

// append denomLP reward weight to distribution keeper
rewardWeights = append(rewardWeights, distrtypes.RewardWeight{Denom: denomLP, Weight: msg.RewardWeight})
Expand Down Expand Up @@ -213,7 +215,10 @@ func (k Keeper) Delist(ctx sdk.Context, msg types.MsgDelist) error {

// remove coinLP denom from the staking bond denoms
bondDenoms = append(bondDenoms[:bondDenomIndex], bondDenoms[bondDenomIndex+1:]...)
k.StakingKeeper.SetBondDenoms(ctx, bondDenoms)
err = k.StakingKeeper.SetBondDenoms(ctx, bondDenoms)
if err != nil {
return err
}

// remove coinLP reward weight from the distribution reward weights
rewardWeights = append(rewardWeights[:rewardWeightIndex], rewardWeights[rewardWeightIndex+1:]...)
Expand Down
6 changes: 3 additions & 3 deletions x/move/types/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func ReadStoresFromPool(bz []byte) (vmtypes.AccountAddress, vmtypes.AccountAddre
}

storeB := bz[cursor : cursor+AddressBytesLength]
cursor += AddressBytesLength
cursor += AddressBytesLength //nolint

storeBAddr, err := vmtypes.NewAccountAddressFromBytes(storeB)
if err != nil {
Expand Down Expand Up @@ -493,7 +493,7 @@ func ReadCollectionInfo(bz []byte) (
cursor += len

uri = string(bz[cursor : cursor+uriLen])
cursor += uriLen
cursor += uriLen //nolint

return
}
Expand Down Expand Up @@ -527,7 +527,7 @@ func ReadNftInfo(bz []byte) (name, uri, desc string) {
cursor += len

uri = string(bz[cursor : cursor+uriLen])
cursor += uriLen
cursor += uriLen //nolint

return
}
Expand Down
2 changes: 1 addition & 1 deletion x/move/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func GetDexPairKey(metadata vmtypes.AccountAddress) []byte {

// GetModulePrefix returns the prefix key of an account module store
func GetModulePrefix(addr vmtypes.AccountAddress) []byte {
return append([]byte(addr.Bytes()), ModuleSeparator)
return append(addr.Bytes(), ModuleSeparator)
}

// GetModuleKey returns the key of the published move module
Expand Down
59 changes: 47 additions & 12 deletions x/mstaking/types/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,101 @@ func NewMultiStakingHooks(hooks ...StakingHooks) MultiStakingHooks {
}

func (h MultiStakingHooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) error {
var err error
for i := range h {
h[i].AfterValidatorCreated(ctx, valAddr)
if err = h[i].AfterValidatorCreated(ctx, valAddr); err != nil {
return err
}
}
return nil
}
func (h MultiStakingHooks) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) error {
var err error
for i := range h {
h[i].BeforeValidatorModified(ctx, valAddr)
if err = h[i].BeforeValidatorModified(ctx, valAddr); err != nil {
return err
}
}
return nil
}
func (h MultiStakingHooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
var err error
for i := range h {
h[i].AfterValidatorRemoved(ctx, consAddr, valAddr)
if err = h[i].AfterValidatorRemoved(ctx, consAddr, valAddr); err != nil {
return err
}
}
return nil
}
func (h MultiStakingHooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
var err error
for i := range h {
h[i].AfterValidatorBonded(ctx, consAddr, valAddr)
if err = h[i].AfterValidatorBonded(ctx, consAddr, valAddr); err != nil {
return err
}
}
return nil
}

func (h MultiStakingHooks) AfterValidatorBeginUnbonding(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
var err error
for i := range h {
h[i].AfterValidatorBeginUnbonding(ctx, consAddr, valAddr)
if err = h[i].AfterValidatorBeginUnbonding(ctx, consAddr, valAddr); err != nil {
return err
}
}
return nil
}
func (h MultiStakingHooks) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
var err error
for i := range h {
h[i].BeforeDelegationCreated(ctx, delAddr, valAddr)
if err = h[i].BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
return err
}
}
return nil
}
func (h MultiStakingHooks) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
var err error
for i := range h {
h[i].BeforeDelegationSharesModified(ctx, delAddr, valAddr)
if err = h[i].BeforeDelegationSharesModified(ctx, delAddr, valAddr); err != nil {
return err
}
}
return nil
}
func (h MultiStakingHooks) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
var err error
for i := range h {
h[i].BeforeDelegationRemoved(ctx, delAddr, valAddr)
if err = h[i].BeforeDelegationRemoved(ctx, delAddr, valAddr); err != nil {
return err
}
}
return nil
}
func (h MultiStakingHooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
var err error
for i := range h {
h[i].AfterDelegationModified(ctx, delAddr, valAddr)
if err = h[i].AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
return err
}
}
return nil
}
func (h MultiStakingHooks) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fractions sdk.DecCoins) error {
var err error
for i := range h {
h[i].BeforeValidatorSlashed(ctx, valAddr, fractions)
if err = h[i].BeforeValidatorSlashed(ctx, valAddr, fractions); err != nil {
return err
}
}
return nil
}

func (h MultiStakingHooks) AfterUnbondingInitiated(ctx sdk.Context, id uint64) error {
var err error
for i := range h {
if err := h[i].AfterUnbondingInitiated(ctx, id); err != nil {
if err = h[i].AfterUnbondingInitiated(ctx, id); err != nil {
return err
}
}
Expand All @@ -93,8 +125,11 @@ func NewMultiSlashingHooks(hooks ...SlashingHooks) MultiSlashingHooks {
}

func (h MultiSlashingHooks) SlashUnbondingDelegations(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec) error {
var err error
for i := range h {
h[i].SlashUnbondingDelegations(ctx, valAddr, fraction)
if err = h[i].SlashUnbondingDelegations(ctx, valAddr, fraction); err != nil {
return err
}
}
return nil
}
4 changes: 3 additions & 1 deletion x/reward/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
releaseRate := params.ReleaseRate.Sub(params.ReleaseRate.Mul(params.DilutionRate))

// update store
k.SetReleaseRate(ctx, releaseRate)
if err := k.SetReleaseRate(ctx, releaseRate); err != nil {
panic(err)
}
k.SetLastDilutionTimestamp(ctx, ctx.BlockTime())
}

Expand Down
4 changes: 3 additions & 1 deletion x/reward/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
// InitGenesis new mint genesis
func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {

k.SetParams(ctx, data.Params)
if err := k.SetParams(ctx, data.Params); err != nil {
panic(err)
}
k.SetLastReleaseTimestamp(ctx, data.LastReleaseTimestamp)
k.SetLastDilutionTimestamp(ctx, data.LastDilutionTimestamp)

Expand Down
4 changes: 3 additions & 1 deletion x/slashing/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
if err != nil {
panic(err)
}
k.AddPubkey(ctx, consPk)
if err = k.AddPubkey(ctx, consPk); err != nil {
panic(err)
}
return false
},
)
Expand Down

0 comments on commit 5c3967d

Please sign in to comment.