Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 5 additions & 9 deletions api/logfilter/logfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logfilter

import (
"bytes"
"slices"

"github.com/iotexproject/go-pkgs/bloom"
"github.com/iotexproject/iotex-proto/golang/iotexapi"
Expand Down Expand Up @@ -57,11 +58,8 @@ func (l *LogFilter) MatchLogs(receipts []*action.Receipt) []*action.Log {
func (l *LogFilter) match(log *iotextypes.Log) bool {
addrMatch := len(l.pbFilter.Address) == 0
if !addrMatch {
for _, e := range l.pbFilter.Address {
if e == log.ContractAddress {
addrMatch = true
break
}
if slices.Contains(l.pbFilter.Address, log.ContractAddress) {
addrMatch = true
}
}
if !addrMatch {
Expand Down Expand Up @@ -105,10 +103,8 @@ func (l *LogFilter) ExistInBloomFilter(bf bloom.BloomFilter) bool {
continue
}

for _, v := range e.Topic {
if bf.Exist(v) {
return true
}
if slices.ContainsFunc(e.Topic, bf.Exist) {
return true
}
}
// {} or nil matches any address or topic list
Expand Down
9 changes: 2 additions & 7 deletions blockchain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package blockchain
import (
"crypto/ecdsa"
"os"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -263,11 +264,5 @@ func (cfg *Config) whitelistSignatureScheme(sk crypto.PrivateKey) bool {
if sigScheme == "" {
return false
}
for _, e := range cfg.SignatureScheme {
if sigScheme == e {
// signature scheme is whitelisted
return true
}
}
return false
return slices.Contains(cfg.SignatureScheme, sigScheme)
}
9 changes: 2 additions & 7 deletions consensus/scheme/rolldpos/roundcalculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package rolldpos

import (
"slices"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -118,13 +119,7 @@ func (c *roundCalculator) IsDelegate(addr string, height uint64) bool {
log.L().Warn("Failed to get delegates", zap.Error(err))
return false
}
for _, d := range delegates {
if addr == d {
return true
}
}

return false
return slices.Contains(delegates, addr)
}

// RoundInfo returns information of round by the given height and current time
Expand Down
9 changes: 2 additions & 7 deletions consensus/scheme/rolldpos/roundctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package rolldpos

import (
"slices"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -110,13 +111,7 @@ func (ctx *roundCtx) Proposers() []string {
}

func (ctx *roundCtx) IsDelegate(addr string) bool {
for _, d := range ctx.delegates {
if addr == d {
return true
}
}

return false
return slices.Contains(ctx.delegates, addr)
}

func (ctx *roundCtx) Block(blkHash []byte) *block.Block {
Expand Down
8 changes: 2 additions & 6 deletions ioctl/config/configsetget.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"regexp"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -226,12 +227,7 @@ func isValidEndpoint(endpoint string) bool {

// isValidExplorer checks if the explorer is a valid option
func isValidExplorer(arg string) bool {
for _, exp := range _validExpl {
if arg == exp {
return true
}
}
return false
return slices.Contains(_validExpl, arg)
}

// isSupportedLanguage checks if the language is a supported option and returns index when supported
Expand Down
8 changes: 2 additions & 6 deletions ioctl/newcmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -352,12 +353,7 @@ func isValidEndpoint(endpoint string) bool {

// isValidExplorer checks if the explorer is a valid option
func isValidExplorer(arg string) bool {
for _, exp := range _validExpl {
if arg == exp {
return true
}
}
return false
return slices.Contains(_validExpl, arg)
}

// writeConfig writes to config file
Expand Down
7 changes: 3 additions & 4 deletions ioctl/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"os/signal"
"path/filepath"
"slices"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -189,10 +190,8 @@ func JwtAuth() (jwt metadata.MD, err error) {
// CheckArgs used for check ioctl cmd arg(s)'s num
func CheckArgs(validNum ...int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
for _, n := range validNum {
if len(args) == n {
return nil
}
if slices.Contains(validNum, len(args)) {
return nil
}
nums := strings.Replace(strings.Trim(fmt.Sprint(validNum), "[]"), " ", " or ", -1)
return fmt.Errorf("accepts "+nums+" arg(s), received %d", len(args))
Expand Down