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)
}