diff --git a/baseapp/streaming.go b/baseapp/streaming.go index c978d959aa..c548b2a1d2 100644 --- a/baseapp/streaming.go +++ b/baseapp/streaming.go @@ -2,6 +2,7 @@ package baseapp import ( "fmt" + "slices" "sort" "strings" @@ -80,12 +81,7 @@ func (app *BaseApp) registerABCIListenerPlugin( } func exposeAll(list []string) bool { - for _, ele := range list { - if ele == "*" { - return true - } - } - return false + return slices.Contains(list, "*") } func exposeStoreKeysSorted(keysStr []string, keys map[string]*storetypes.KVStoreKey) []storetypes.StoreKey { diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 0137a9259c..d810264163 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -1,6 +1,7 @@ package ante import ( + "slices" "time" errorsmod "cosmossdk.io/errors" @@ -168,10 +169,8 @@ func isIncompleteSignature(data signing.SignatureData) bool { if len(data.Signatures) == 0 { return true } - for _, s := range data.Signatures { - if isIncompleteSignature(s) { - return true - } + if slices.ContainsFunc(data.Signatures, isIncompleteSignature) { + return true } } diff --git a/x/auth/types/account.go b/x/auth/types/account.go index b111cf0c16..58b4cb99de 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "slices" "strings" "github.com/cometbft/cometbft/crypto" @@ -189,12 +190,7 @@ func NewModuleAccount(ba *BaseAccount, name string, permissions ...string) *Modu // HasPermission returns whether or not the module account has permission. func (ma ModuleAccount) HasPermission(permission string) bool { - for _, perm := range ma.Permissions { - if perm == permission { - return true - } - } - return false + return slices.Contains(ma.Permissions, permission) } // GetName returns the name of the holder's module diff --git a/x/auth/types/genesis.go b/x/auth/types/genesis.go index b3a66869da..06e0aae9e2 100644 --- a/x/auth/types/genesis.go +++ b/x/auth/types/genesis.go @@ -3,6 +3,7 @@ package types import ( "encoding/json" "fmt" + "slices" "sort" proto "github.com/cosmos/gogoproto/proto" @@ -95,9 +96,7 @@ func SanitizeGenesisAccounts(genAccs GenesisAccounts) GenesisAccounts { for num := range dupAccNum { dupAccNums = append(dupAccNums, num) } - sort.Slice(dupAccNums, func(i, j int) bool { - return dupAccNums[i] < dupAccNums[j] - }) + slices.Sort(dupAccNums) // Change the account number of the duplicated ones to the first unused value. globalNum := uint64(0) diff --git a/x/gov/migrations/v4/store.go b/x/gov/migrations/v4/store.go index 7a5857dd2a..0bb5bbf3c8 100644 --- a/x/gov/migrations/v4/store.go +++ b/x/gov/migrations/v4/store.go @@ -2,7 +2,7 @@ package v4 import ( "fmt" - "sort" + "slices" corestoretypes "cosmossdk.io/core/store" "cosmossdk.io/store/prefix" @@ -100,7 +100,7 @@ func AddProposerAddressToProposal(ctx sdk.Context, storeService corestoretypes.K } // sort the proposalIDs - sort.Slice(proposalIDs, func(i, j int) bool { return proposalIDs[i] < proposalIDs[j] }) + slices.Sort(proposalIDs) store := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx)) diff --git a/x/group/keeper/msg_server.go b/x/group/keeper/msg_server.go index 6689cf5739..58869a5b1b 100644 --- a/x/group/keeper/msg_server.go +++ b/x/group/keeper/msg_server.go @@ -6,6 +6,7 @@ import ( "encoding/binary" "encoding/json" "fmt" + "slices" "strings" errorsmod "cosmossdk.io/errors" @@ -1163,13 +1164,7 @@ func (k Keeper) validateMembers(members []group.MemberRequest) error { // isProposer checks that an address is a proposer of a given proposal. func isProposer(proposal group.Proposal, address string) bool { - for _, proposer := range proposal.Proposers { - if proposer == address { - return true - } - } - - return false + return slices.Contains(proposal.Proposers, address) } func validateMsgs(msgs []sdk.Msg) error { diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 19b7ba7a25..8ba7b9383b 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "slices" "strconv" "time" @@ -85,13 +86,7 @@ func (k msgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateVali cp := sdkCtx.ConsensusParams() if cp.Validator != nil { pkType := pk.Type() - hasKeyType := false - for _, keyType := range cp.Validator.PubKeyTypes { - if pkType == keyType { - hasKeyType = true - break - } - } + hasKeyType := slices.Contains(cp.Validator.PubKeyTypes, pkType) if !hasKeyType { return nil, errorsmod.Wrapf( types.ErrValidatorPubKeyTypeNotSupported, diff --git a/x/staking/migrations/v4/store.go b/x/staking/migrations/v4/store.go index a41069a09e..945c2b1f9f 100644 --- a/x/staking/migrations/v4/store.go +++ b/x/staking/migrations/v4/store.go @@ -1,7 +1,7 @@ package v4 import ( - "sort" + "slices" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" @@ -59,9 +59,7 @@ func migrateUBDEntries(ctx sdk.Context, store storetypes.KVStore, cdc codec.Bina for k := range entriesAtSameCreationHeight { creationHeights = append(creationHeights, k) } - - sort.Slice(creationHeights, func(i, j int) bool { return creationHeights[i] < creationHeights[j] }) - + slices.Sort(creationHeights) ubd.Entries = make([]types.UnbondingDelegationEntry, 0, len(creationHeights)) for _, h := range creationHeights {