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

add errcheck and do some lint #2

Merged
merged 2 commits into from
Oct 26, 2023
Merged
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
// we also need to update `LIBINITIAVM_VERSION` of images/private/Dockerfile#5
github.com/initia-labs/initiavm v0.1.2-beta.0.0.20231019083945-cfd3e33ab691
github.com/initia-labs/initiavm v0.1.2-beta.0.0.20231019090616-843ae36c29c4
github.com/novifinancial/serde-reflection/serde-generate/runtime/golang v0.0.0-20220519162058-e5cd3c3b3f3a
github.com/pelletier/go-toml v1.9.5
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,8 @@ github.com/influxdata/promql/v2 v2.12.0/go.mod h1:fxOPu+DY0bqCTCECchSRtWfc+0X19y
github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bSgUQ7q5ZLSO+bKBGqJiCBGAl+9DxyW63zLTujjUlOE=
github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0=
github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po=
github.com/initia-labs/initiavm v0.1.2-beta.0.0.20231019083945-cfd3e33ab691 h1:lesZoXLcVxXk2zBTAqwHd89EtNVoGyib99B76JIajdE=
github.com/initia-labs/initiavm v0.1.2-beta.0.0.20231019083945-cfd3e33ab691/go.mod h1:aQt4lImZWF9xj7Fm978n0IoeDdKWXTg1CSq6O4WoSD8=
github.com/initia-labs/initiavm v0.1.2-beta.0.0.20231019090616-843ae36c29c4 h1:ecTAJQ2eeT+73L5VUBwT4hoj0e9MV3q0U4qoK8rgT0c=
github.com/initia-labs/initiavm v0.1.2-beta.0.0.20231019090616-843ae36c29c4/go.mod h1:aQt4lImZWF9xj7Fm978n0IoeDdKWXTg1CSq6O4WoSD8=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down
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
Loading
Loading