Add lint config and fix lint errors (#7)

* Add config file for linter

* Fix lint errors

* Fix gofumpt errors

* Fix pre-allocate slices lint error

* Remove unused lint rule

* Disable style check ID error

* Add gomodguard section in yml file

* Remove trailing white spaces

* Remove unnecessary comments

---------

Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
Isha Venikar
2024-07-16 09:25:39 +05:30
committed by nabarun
co-authored by prathamesh
parent 8c14d578f7
commit f23f691646
22 changed files with 199 additions and 53 deletions
+32 -10
View File
@@ -77,8 +77,12 @@ type Keeper struct {
// state management
Schema collections.Schema
Params collections.Item[auctiontypes.Params]
Auctions *collections.IndexedMap[string, auctiontypes.Auction, AuctionsIndexes] // map: auctionId -> Auction, index: owner -> Auctions
Bids *collections.IndexedMap[collections.Pair[string, string], auctiontypes.Bid, BidsIndexes] // map: (auctionId, bidder) -> Bid, index: bidder -> auctionId
Auctions *collections.IndexedMap[
string, auctiontypes.Auction, AuctionsIndexes,
] // map: auctionId -> Auction, index: owner -> Auctions
Bids *collections.IndexedMap[
collections.Pair[string, string], auctiontypes.Bid, BidsIndexes,
] // map: (auctionId, bidder) -> Bid, index: bidder -> auctionId
}
// NewKeeper creates a new Keeper instance
@@ -94,9 +98,16 @@ func NewKeeper(
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
Params: collections.NewItem(sb, auctiontypes.ParamsPrefix, "params", codec.CollValue[auctiontypes.Params](cdc)),
Auctions: collections.NewIndexedMap(sb, auctiontypes.AuctionsPrefix, "auctions", collections.StringKey, codec.CollValue[auctiontypes.Auction](cdc), newAuctionIndexes(sb)),
Bids: collections.NewIndexedMap(sb, auctiontypes.BidsPrefix, "bids", collections.PairKeyCodec(collections.StringKey, collections.StringKey), codec.CollValue[auctiontypes.Bid](cdc), newBidsIndexes(sb)),
usageKeepers: nil,
Auctions: collections.NewIndexedMap(
sb, auctiontypes.AuctionsPrefix, "auctions", collections.StringKey, codec.CollValue[auctiontypes.Auction](cdc), newAuctionIndexes(sb),
),
Bids: collections.NewIndexedMap(
sb, auctiontypes.BidsPrefix, "bids",
collections.PairKeyCodec(collections.StringKey, collections.StringKey),
codec.CollValue[auctiontypes.Bid](cdc),
newBidsIndexes(sb),
),
usageKeepers: nil,
}
schema, err := sb.Build()
@@ -191,10 +202,16 @@ func (k Keeper) GetBid(ctx sdk.Context, id string, bidder string) (auctiontypes.
func (k Keeper) GetBids(ctx sdk.Context, id string) ([]*auctiontypes.Bid, error) {
var bids []*auctiontypes.Bid
err := k.Bids.Walk(ctx, collections.NewPrefixedPairRange[string, string](id), func(key collections.Pair[string, string], value auctiontypes.Bid) (stop bool, err error) {
bids = append(bids, &value)
return false, nil
})
err := k.Bids.Walk(ctx,
collections.NewPrefixedPairRange[string, string](id),
func(
key collections.Pair[string, string],
value auctiontypes.Bid) (stop bool, err error,
) {
bids = append(bids, &value)
return false, nil
},
)
if err != nil {
return nil, err
}
@@ -716,7 +733,12 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
}
// Use auction burn module account instead of actually burning coins to better keep track of supply.
sdkErr = k.bankKeeper.SendCoinsFromModuleToModule(ctx, auctiontypes.ModuleName, auctiontypes.AuctionBurnModuleAccountName, sdk.NewCoins(amountToBurn))
sdkErr = k.bankKeeper.SendCoinsFromModuleToModule(
ctx,
auctiontypes.ModuleName,
auctiontypes.AuctionBurnModuleAccountName,
sdk.NewCoins(amountToBurn),
)
if sdkErr != nil {
k.Logger(ctx).Error(fmt.Sprintf("Auction error burning coins: %v", sdkErr))
panic(sdkErr)
+17 -4
View File
@@ -98,7 +98,10 @@ func (qs queryServer) GetBids(c context.Context, req *auctiontypes.QueryGetBidsR
}
// AuctionsByBidder queries auctions by bidder
func (qs queryServer) AuctionsByBidder(c context.Context, req *auctiontypes.QueryAuctionsByBidderRequest) (*auctiontypes.QueryAuctionsByBidderResponse, error) {
func (qs queryServer) AuctionsByBidder(
c context.Context,
req *auctiontypes.QueryAuctionsByBidderRequest,
) (*auctiontypes.QueryAuctionsByBidderResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.BidderAddress == "" {
@@ -110,11 +113,18 @@ func (qs queryServer) AuctionsByBidder(c context.Context, req *auctiontypes.Quer
return nil, err
}
return &auctiontypes.QueryAuctionsByBidderResponse{Auctions: &auctiontypes.Auctions{Auctions: auctions}}, nil
return &auctiontypes.QueryAuctionsByBidderResponse{
Auctions: &auctiontypes.Auctions{
Auctions: auctions,
},
}, nil
}
// AuctionsByOwner queries auctions by owner
func (qs queryServer) AuctionsByOwner(c context.Context, req *auctiontypes.QueryAuctionsByOwnerRequest) (*auctiontypes.QueryAuctionsByOwnerResponse, error) {
func (qs queryServer) AuctionsByOwner(
c context.Context,
req *auctiontypes.QueryAuctionsByOwnerRequest,
) (*auctiontypes.QueryAuctionsByOwnerResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.OwnerAddress == "" {
@@ -130,7 +140,10 @@ func (qs queryServer) AuctionsByOwner(c context.Context, req *auctiontypes.Query
}
// GetAuctionModuleBalance queries the auction module account balance
func (qs queryServer) GetAuctionModuleBalance(c context.Context, req *auctiontypes.QueryGetAuctionModuleBalanceRequest) (*auctiontypes.QueryGetAuctionModuleBalanceResponse, error) {
func (qs queryServer) GetAuctionModuleBalance(
c context.Context,
req *auctiontypes.QueryGetAuctionModuleBalanceRequest,
) (*auctiontypes.QueryGetAuctionModuleBalanceResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
balances := qs.k.GetAuctionModuleBalances(ctx)
+3 -5
View File
@@ -4,7 +4,6 @@ import (
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"golang.org/x/exp/maps"
"github.com/cosmos/cosmos-sdk/codec"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
@@ -64,15 +63,14 @@ func InvokeSetAuctionHooks(
keeper *keeper.Keeper,
auctionHooks map[string]auction.AuctionHooksWrapper,
) error {
// all arguments to invokers are optional
// All arguments to invokers are optional
if keeper == nil || config == nil {
return nil
}
var usageKeepers []auction.AuctionUsageKeeper
usageKeepers := make([]auction.AuctionUsageKeeper, 0, len(auctionHooks))
for _, modName := range maps.Keys(auctionHooks) {
hook := auctionHooks[modName]
for _, hook := range auctionHooks {
usageKeepers = append(usageKeepers, hook)
}
+4 -2
View File
@@ -71,8 +71,10 @@ func NewKeeper(
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
Params: collections.NewItem(sb, bondtypes.ParamsPrefix, "params", codec.CollValue[bondtypes.Params](cdc)),
Bonds: collections.NewIndexedMap(sb, bondtypes.BondsPrefix, "bonds", collections.StringKey, codec.CollValue[bondtypes.Bond](cdc), newBondIndexes(sb)),
usageKeepers: nil,
Bonds: collections.NewIndexedMap(
sb, bondtypes.BondsPrefix, "bonds", collections.StringKey, codec.CollValue[bondtypes.Bond](cdc), newBondIndexes(sb),
),
usageKeepers: nil,
}
schema, err := sb.Build()
+14 -4
View File
@@ -63,12 +63,17 @@ func (qs queryServer) GetBondById(c context.Context, req *bondtypes.QueryGetBond
}
// GetBondsByOwner implements bond.QueryServer.
func (qs queryServer) GetBondsByOwner(c context.Context, req *bondtypes.QueryGetBondsByOwnerRequest) (*bondtypes.QueryGetBondsByOwnerResponse, error) {
func (qs queryServer) GetBondsByOwner(
c context.Context,
req *bondtypes.QueryGetBondsByOwnerRequest,
) (*bondtypes.QueryGetBondsByOwnerResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
owner := req.GetOwner()
if len(owner) == 0 {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "owner required")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest,
"owner required",
)
}
bonds, err := qs.k.GetBondsByOwner(ctx, owner)
@@ -80,9 +85,14 @@ func (qs queryServer) GetBondsByOwner(c context.Context, req *bondtypes.QueryGet
}
// GetBondModuleBalance implements bond.QueryServer.
func (qs queryServer) GetBondModuleBalance(c context.Context, _ *bondtypes.QueryGetBondModuleBalanceRequest) (*bondtypes.QueryGetBondModuleBalanceResponse, error) {
func (qs queryServer) GetBondModuleBalance(
c context.Context,
_ *bondtypes.QueryGetBondModuleBalanceRequest,
) (*bondtypes.QueryGetBondModuleBalanceResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
balances := qs.k.GetBondModuleBalances(ctx)
return &bondtypes.QueryGetBondModuleBalanceResponse{Balance: balances}, nil
return &bondtypes.QueryGetBondModuleBalanceResponse{
Balance: balances,
}, nil
}
+3 -5
View File
@@ -4,7 +4,6 @@ import (
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"golang.org/x/exp/maps"
"github.com/cosmos/cosmos-sdk/codec"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
@@ -60,15 +59,14 @@ func InvokeSetBondHooks(
keeper *keeper.Keeper,
bondHooks map[string]bond.BondHooksWrapper,
) error {
// all arguments to invokers are optional
// All arguments to invokers are optional
if keeper == nil || config == nil {
return nil
}
var usageKeepers []bond.BondUsageKeeper
usageKeepers := make([]bond.BondUsageKeeper, 0, len(bondHooks))
for _, modName := range maps.Keys(bondHooks) {
hook := bondHooks[modName]
for _, hook := range bondHooks {
usageKeepers = append(usageKeepers, hook)
}
+1 -3
View File
@@ -6,9 +6,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
var (
_ sdk.Msg = &MsgCreateBond{}
)
var _ sdk.Msg = &MsgCreateBond{}
// NewMsgCreateBond is the constructor function for MsgCreateBond.
func NewMsgCreateBond(coins sdk.Coins, signer sdk.AccAddress) MsgCreateBond {
+1 -1
View File
@@ -8,7 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Default parameter values.
// DefaultMaxBondAmountTokens are the default parameter values.
var DefaultMaxBondAmountTokens = sdkmath.NewInt(100000000000)
func NewParams(maxBondAmount sdk.Coin) Params {
+13 -5
View File
@@ -44,7 +44,9 @@ func NewKeeper(cdc codec.BinaryCodec, addressCodec address.Codec, storeService s
addressCodec: addressCodec,
authority: authority,
Params: collections.NewItem(sb, onboardingTypes.ParamsPrefix, "params", codec.CollValue[onboardingTypes.Params](cdc)),
Participants: collections.NewMap(sb, onboardingTypes.ParticipantsPrefix, "participants", collections.StringKey, codec.CollValue[onboardingTypes.Participant](cdc)),
Participants: collections.NewMap(
sb, onboardingTypes.ParticipantsPrefix, "participants", collections.StringKey, codec.CollValue[onboardingTypes.Participant](cdc),
),
}
schema, err := sb.Build()
@@ -66,7 +68,11 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", onboardingTypes.ModuleName)
}
func (k Keeper) OnboardParticipant(ctx sdk.Context, msg *onboardingTypes.MsgOnboardParticipant, signerAddress sdk.AccAddress) (*onboardingTypes.MsgOnboardParticipantResponse, error) {
func (k Keeper) OnboardParticipant(
ctx sdk.Context,
msg *onboardingTypes.MsgOnboardParticipant,
signerAddress sdk.AccAddress,
) (*onboardingTypes.MsgOnboardParticipantResponse, error) {
params, err := k.Params.Get(ctx)
if err != nil {
return nil, err
@@ -82,6 +88,10 @@ func (k Keeper) OnboardParticipant(ctx sdk.Context, msg *onboardingTypes.MsgOnbo
}
ethereumAddress, err := utils.DecodeEthereumAddress(message, msg.EthSignature)
if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Failed to decode Ethereum address")
}
if ethereumAddress != msg.EthPayload.Address {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Recovered ethereum address does not match the address set in payload")
}
@@ -100,9 +110,7 @@ func (k Keeper) OnboardParticipant(ctx sdk.Context, msg *onboardingTypes.MsgOnbo
func (k Keeper) StoreParticipant(ctx sdk.Context, participant *onboardingTypes.Participant) error {
key := participant.CosmosAddress
k.Participants.Set(ctx, key, *participant)
return nil
return k.Participants.Set(ctx, key, *participant)
}
// ListParticipants - get all participants.
+4 -1
View File
@@ -20,7 +20,10 @@ func NewQueryServerImpl(k *Keeper) onboardingtypes.QueryServer {
}
// Participants implements Participants.QueryServer.
func (qs queryServer) Participants(c context.Context, _ *onboardingtypes.QueryParticipantsRequest) (*onboardingtypes.QueryParticipantsResponse, error) {
func (qs queryServer) Participants(
c context.Context,
_ *onboardingtypes.QueryParticipantsRequest,
) (*onboardingtypes.QueryParticipantsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
resp, err := qs.k.ListParticipants(ctx)
+1 -3
View File
@@ -6,9 +6,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
var (
_ sdk.Msg = &MsgOnboardParticipant{}
)
var _ sdk.Msg = &MsgOnboardParticipant{}
func (msg MsgOnboardParticipant) ValidateBasic() error {
if len(msg.Participant) == 0 {
-1
View File
@@ -61,7 +61,6 @@ func RecordBondInvariant(k *Keeper) sdk.Invariant {
return false, nil
})
if err != nil {
return sdk.FormatInvariant(
types.ModuleName,
+5 -1
View File
@@ -243,7 +243,11 @@ func (k Keeper) GetRecordsByBondId(ctx sdk.Context, bondId string) ([]registryty
}
// RecordsFromAttributes gets a list of records whose attributes match all provided values
func (k Keeper) RecordsFromAttributes(ctx sdk.Context, attributes []*registrytypes.QueryRecordsRequest_KeyValueInput, all bool) ([]registrytypes.Record, error) {
func (k Keeper) RecordsFromAttributes(
ctx sdk.Context,
attributes []*registrytypes.QueryRecordsRequest_KeyValueInput,
all bool,
) ([]registrytypes.Record, error) {
resultRecordIds := []string{}
for i, attr := range attributes {
suffix, err := QueryValueToJSON(attr.Value)
+4 -1
View File
@@ -320,7 +320,10 @@ func (ms msgServer) DissociateBond(c context.Context, msg *registrytypes.MsgDiss
return &registrytypes.MsgDissociateBondResponse{}, nil
}
func (ms msgServer) DissociateRecords(c context.Context, msg *registrytypes.MsgDissociateRecords) (*registrytypes.MsgDissociateRecordsResponse, error) {
func (ms msgServer) DissociateRecords(
c context.Context,
msg *registrytypes.MsgDissociateRecords,
) (*registrytypes.MsgDissociateRecordsResponse, error) {
if err := msg.ValidateBasic(); err != nil {
return nil, err
}
+4 -1
View File
@@ -75,7 +75,10 @@ func (qs queryServer) GetRecord(c context.Context, req *registrytypes.QueryGetRe
return &registrytypes.QueryGetRecordResponse{Record: record}, nil
}
func (qs queryServer) GetRecordsByBondId(c context.Context, req *registrytypes.QueryGetRecordsByBondIdRequest) (*registrytypes.QueryGetRecordsByBondIdResponse, error) {
func (qs queryServer) GetRecordsByBondId(
c context.Context,
req *registrytypes.QueryGetRecordsByBondIdRequest,
) (*registrytypes.QueryGetRecordsByBondIdResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
records, err := qs.k.GetRecordsByBondId(ctx, req.GetId())