Skip to content

Commit c87ce10

Browse files
committed
refactor: use slices.Contains to simplify code
Signed-off-by: nuxtreact <nuxtreact@outlook.com>
1 parent 9c796d6 commit c87ce10

6 files changed

Lines changed: 21 additions & 40 deletions

File tree

app/ante/vesting.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package ante
22

33
import (
4+
"slices"
5+
46
errorsmod "cosmossdk.io/errors"
57
sdk "github.com/cosmos/cosmos-sdk/types"
68
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -35,14 +37,12 @@ func (vad VestingAccountDecorator) AnteHandle(
3537
for _, msg := range tx.GetMsgs() {
3638
typeURL := sdk.MsgTypeURL(msg)
3739

38-
for _, disabledTypeURL := range vad.disabledMsgTypeURLs {
39-
if typeURL == disabledTypeURL {
40-
return ctx, errorsmod.Wrapf(
41-
sdkerrors.ErrUnauthorized,
42-
"MsgTypeURL %s not supported",
43-
typeURL,
44-
)
45-
}
40+
if slices.Contains(vad.disabledMsgTypeURLs, typeURL) {
41+
return ctx, errorsmod.Wrapf(
42+
sdkerrors.ErrUnauthorized,
43+
"MsgTypeURL %s not supported",
44+
typeURL,
45+
)
4646
}
4747
}
4848

cmd/zetaclientd/utils.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"os"
6+
"slices"
67
"strconv"
78

89
"github.com/pkg/errors"
@@ -22,10 +23,8 @@ func isObserverNode(ctx context.Context, zc *zetacore.Client) (bool, error) {
2223

2324
operatorAddress := zc.GetKeys().GetOperatorAddress().String()
2425

25-
for _, observer := range observers {
26-
if observer == operatorAddress {
27-
return true, nil
28-
}
26+
if slices.Contains(observers, operatorAddress) {
27+
return true, nil
2928
}
3029

3130
return false, nil

cmd/zetae2e/local/monitor_priority_txs.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package local
33
import (
44
"context"
55
"errors"
6+
"slices"
67
"strings"
78
"time"
89

@@ -102,13 +103,7 @@ func isMsgTypeURLSystemTx(attr types.EventAttribute) bool {
102103
"\"/zetachain.zetacore.observer.MsgVoteBlame\"",
103104
}
104105

105-
for _, url := range systemTxsMsgTypeUrls {
106-
if url == attr.Value {
107-
return true
108-
}
109-
}
110-
111-
return false
106+
return slices.Contains(systemTxsMsgTypeUrls, attr.Value)
112107
}
113108

114109
func isActionNonSystemTx(attr types.EventAttribute) bool {

rpc/namespaces/ethereum/eth/filters/utils.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package filters
22

33
import (
44
"math/big"
5+
slices0 "slices"
56

67
"github.com/ethereum/go-ethereum/common"
78
ethtypes "github.com/ethereum/go-ethereum/core/types"
@@ -37,13 +38,7 @@ Logs:
3738
continue
3839
}
3940
for i, sub := range topics {
40-
match := len(sub) == 0 // empty rule set == wildcard
41-
for _, topic := range sub {
42-
if log.Topics[i] == topic {
43-
match = true
44-
break
45-
}
46-
}
41+
match := slices0.Contains(sub, log.Topics[i])
4742
if !match {
4843
continue Logs
4944
}

x/crosschain/keeper/cctx.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package keeper
22

33
import (
4+
"slices"
5+
46
"cosmossdk.io/store/prefix"
57
storetypes "cosmossdk.io/store/types"
68
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -47,14 +49,7 @@ func (k Keeper) updateInboundHashToCCTX(
4749
) {
4850
in, _ := k.GetInboundHashToCctx(ctx, cctx.InboundParams.ObservedHash)
4951
in.InboundHash = cctx.InboundParams.ObservedHash
50-
found := false
51-
for _, cctxIndex := range in.CctxIndex {
52-
if cctxIndex == cctx.Index {
53-
found = true
54-
break
55-
}
56-
}
57-
if !found {
52+
if !slices.Contains(in.CctxIndex, cctx.Index) {
5853
in.CctxIndex = append(in.CctxIndex, cctx.Index)
5954
}
6055
k.SetInboundHashToCctx(ctx, in)

x/observer/keeper/observer_set.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package keeper
22

33
import (
4+
"slices"
5+
46
"cosmossdk.io/errors"
57
"cosmossdk.io/store/prefix"
68
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -29,12 +31,7 @@ func (k Keeper) IsAddressPartOfObserverSet(ctx sdk.Context, address string) bool
2931
if !found {
3032
return false
3133
}
32-
for _, addr := range observerSet.ObserverList {
33-
if addr == address {
34-
return true
35-
}
36-
}
37-
return false
34+
return slices.Contains(observerSet.ObserverList, address)
3835
}
3936

4037
// AddObserverToSet adds an observer to the observer set.It makes sure the updated observer set is valid.

0 commit comments

Comments
 (0)