refactor: use slices.Contains to simplify code#4545
refactor: use slices.Contains to simplify code#4545nuxtreact wants to merge 1 commit intozeta-chain:developfrom
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe pull request refactors six files to replace manual containment checks with the standard library Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@rpc/namespaces/ethereum/eth/filters/utils.go`:
- Around line 40-44: The loop over topics currently uses slices0.Contains(sub,
log.Topics[i]) which returns false for empty sub-slices and breaks the wildcard
semantics; change the conditional in the topics loop (the block that references
topics, sub, and log.Topics[i]) to treat an empty sub as a match (e.g., if
len(sub) == 0 then consider it matched) and only call slices0.Contains when sub
is non-empty, mirroring the bloomFilter logic that uses included := len(sub) ==
0; preserve the existing control flow that uses the Logs label when a non-match
occurs.
🧹 Nitpick comments (1)
rpc/namespaces/ethereum/eth/filters/utils.go (1)
5-5: Consolidate dualslicesimports to use only the standard library package.The file imports both
slices(standard library, aliased asslices0) andgolang.org/x/exp/slices, with inconsistent usage: line 41 uses the unaliased experimental import while line 42 uses the aliased stdlib import. Since the project targets Go 1.23.8—well above the Go 1.21 requirement when stdlibslicesbecame stable—the external dependency is redundant. Removegolang.org/x/exp/slicesand unify bothContains()calls to use the stdlibslicespackage.♻️ Consolidation
import ( "math/big" - slices0 "slices" + "slices" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" - "golang.org/x/exp/slices" )Update line 41 (
slices.Contains) and line 42 to use the unaliasedslices.Contains.
Signed-off-by: nuxtreact <nuxtreact@outlook.com>
Description
There is a new function added in the go1.21 standard library, which can make the code more concise and easy to read.
How Has This Been Tested?
Summary by CodeRabbit
Refactor
Bug Fixes