chore(all): modernized code with slices (#24125)
Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
This commit is contained in:
parent
731d9305ff
commit
5254d57c5b
@ -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 {
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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))
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user