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

Fix golint #135

Merged
merged 7 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 1 addition & 2 deletions x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, ic types.InflationCalculatio

// send the minted coins to the fee collector account
err := k.AddCollectedFees(ctx, mintedCoins)

if err != nil {
return
panic(err)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
}

if mintedCoin.Amount.IsInt64() {
Expand Down
5 changes: 3 additions & 2 deletions x/mint/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand All @@ -10,10 +11,10 @@ import (
// bondedRatio and returns the newly calculated inflation rate.
// It can be used to specify a custom inflation calculation logic, instead of relying on the
// default logic provided by the sdk.
type InflationCalculationFn func(ctx sdk.Context, minter Minter, params Params, bondedRatio sdk.Dec, totalStakingSupply sdk.Int) sdk.Dec
type InflationCalculationFn func(ctx sdk.Context, minter Minter, params Params, bondedRatio sdk.Dec, totalStakingSupply math.Int) sdk.Dec

// DefaultInflationCalculationFn is the default function used to calculate inflation.
func DefaultInflationCalculationFn(_ sdk.Context, minter Minter, params Params, bondedRatio sdk.Dec, totalStakingSupply sdk.Int) sdk.Dec {
func DefaultInflationCalculationFn(_ sdk.Context, minter Minter, params Params, bondedRatio sdk.Dec, totalStakingSupply math.Int) sdk.Dec {
return minter.NextInflationRate(params, bondedRatio, totalStakingSupply)
}

Expand Down
2 changes: 1 addition & 1 deletion x/mint/types/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ValidateMinter(minter Minter) error {
}

// NextInflationRate returns the new inflation rate for the next hour.
func (m Minter) NextInflationRate(params Params, bondedRatio sdk.Dec, totalStakingSupply sdk.Int) sdk.Dec {
func (m Minter) NextInflationRate(params Params, bondedRatio sdk.Dec, totalStakingSupply math.Int) sdk.Dec {
totalStakingSupplyDec := sdk.NewDecFromInt(totalStakingSupply)

// The target annual inflation rate is recalculated for each previsions cycle. The
Expand Down
65 changes: 33 additions & 32 deletions x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"sigs.k8s.io/yaml"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
Expand All @@ -28,7 +29,7 @@ func ParamKeyTable() paramtypes.KeyTable {
}

func NewParams(
mintDenom string, inflationRateChange, inflationMax, inflationMin, goalBonded sdk.Dec, blocksPerYear uint64, tokenPerYear sdk.Int,
mintDenom string, inflationRateChange, _, _, goalBonded sdk.Dec, blocksPerYear uint64, tokenPerYear math.Int,
) Params {
return Params{
MintDenom: mintDenom,
Expand Down Expand Up @@ -126,37 +127,37 @@ func validateInflationRateChange(i interface{}) error {
return nil
}

func validateInflationMax(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNegative() {
return fmt.Errorf("max inflation cannot be negative: %s", v)
}
if v.GT(sdk.OneDec()) {
return fmt.Errorf("max inflation too large: %s", v)
}

return nil
}

func validateInflationMin(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNegative() {
return fmt.Errorf("min inflation cannot be negative: %s", v)
}
if v.GT(sdk.OneDec()) {
return fmt.Errorf("min inflation too large: %s", v)
}

return nil
}
// func validateInflationMax(i interface{}) error {
// v, ok := i.(sdk.Dec)
// if !ok {
// return fmt.Errorf("invalid parameter type: %T", i)
// }

// if v.IsNegative() {
// return fmt.Errorf("max inflation cannot be negative: %s", v)
// }
// if v.GT(sdk.OneDec()) {
// return fmt.Errorf("max inflation too large: %s", v)
// }

// return nil
// }

// func validateInflationMin(i interface{}) error {
// v, ok := i.(sdk.Dec)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we remove this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Golint said it unused @vuong177

// if !ok {
// return fmt.Errorf("invalid parameter type: %T", i)
// }

// if v.IsNegative() {
// return fmt.Errorf("min inflation cannot be negative: %s", v)
// }
// if v.GT(sdk.OneDec()) {
// return fmt.Errorf("min inflation too large: %s", v)
// }

// return nil
// }

func validateGoalBonded(i interface{}) error {
v, ok := i.(sdk.Dec)
Expand Down
2 changes: 1 addition & 1 deletion x/transfermiddleware/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func GetCmdParaTokenInfo() *cobra.Command {
Use: "para-token-info",
Short: "Query the current transfer middleware para-token-info based on denom",
Long: "Query the current transfer middleware para-token-info based on denom",
Args: cobra.ExactValidArgs(1),
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Example: fmt.Sprintf("%s query transfermiddleware para-token-info atom", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand Down
2 changes: 1 addition & 1 deletion x/transfermiddleware/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
}

// ValidateGenesis performs genesis state validation for the mint module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var data types.GenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
Expand Down
17 changes: 8 additions & 9 deletions x/transfermiddleware/pfm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/cometbft/cometbft/crypto"
"github.com/cometbft/cometbft/crypto/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
customibctesting "github.com/notional-labs/banksy/v2/app/ibctesting"
Expand Down Expand Up @@ -52,8 +51,8 @@ func NewTransferPath(chainA, chainB *customibctesting.TestChain) *customibctesti
path := customibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig.PortID = customibctesting.TransferPort
path.EndpointB.ChannelConfig.PortID = customibctesting.TransferPort
path.EndpointA.ChannelConfig.Version = ibctransfertypes.Version
path.EndpointB.ChannelConfig.Version = ibctransfertypes.Version
path.EndpointA.ChannelConfig.Version = transfertypes.Version
path.EndpointB.ChannelConfig.Version = transfertypes.Version

return path
}
Expand Down Expand Up @@ -128,18 +127,18 @@ func (suite *TransferMiddlewareTestSuite) TestTransferWithPFM_ErrorAck() {
Next: "",
},
}
memo_marshalled, err := json.Marshal(&memo)
memoMarshalled, err := json.Marshal(&memo)
suite.Require().NoError(err)

msg := ibctransfertypes.NewMsgTransfer(
msg := transfertypes.NewMsgTransfer(
pathAtoB.EndpointA.ChannelConfig.PortID,
pathAtoB.EndpointA.ChannelID,
sdk.NewCoin(sdk.DefaultBondDenom, transferAmount),
suite.chainA.SenderAccount.GetAddress().String(),
testAcc.String(),
timeoutHeight,
0,
string(memo_marshalled),
string(memoMarshalled),
)
_, err = suite.chainA.SendMsgs(msg)
suite.Require().NoError(err)
Expand Down Expand Up @@ -271,20 +270,20 @@ func (suite *TransferMiddlewareTestSuite) TestTransferWithPFM() {
Next: "",
},
}
memo_marshalled, err := json.Marshal(&memo)
memoMarshalled, err := json.Marshal(&memo)
suite.Require().NoError(err)

intermediaryOriginalBalance := suite.chainB.AllBalances(suite.chainB.SenderAccount.GetAddress())

msg := ibctransfertypes.NewMsgTransfer(
msg := transfertypes.NewMsgTransfer(
pathAtoB.EndpointA.ChannelConfig.PortID,
pathAtoB.EndpointA.ChannelID,
sdk.NewCoin(sdk.DefaultBondDenom, transferAmount),
suite.chainA.SenderAccount.GetAddress().String(),
suite.chainB.SenderAccount.GetAddress().String(),
timeoutHeight,
0,
string(memo_marshalled),
string(memoMarshalled),
)
_, err = suite.chainA.SendMsgs(msg)
suite.Require().NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion x/transfermiddleware/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ func DefaultGenesisState() *GenesisState {

// ValidateGenesis validates the provided genesis state to ensure the
// expected invariants holds.
func ValidateGenesis(data GenesisState) error {
func ValidateGenesis(_ GenesisState) error {
return nil
}