From 5afd0c42c4824f140802c3fa6f35a4cef956acb3 Mon Sep 17 00:00:00 2001 From: Aaron Chen Date: Fri, 5 Apr 2024 16:03:53 +0800 Subject: [PATCH] eth/tracers: use slices.Contains --- eth/tracers/js/goja.go | 9 ++------- eth/tracers/native/call_flat.go | 8 ++------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/eth/tracers/js/goja.go b/eth/tracers/js/goja.go index 82666155ec76..5290d4f70995 100644 --- a/eth/tracers/js/goja.go +++ b/eth/tracers/js/goja.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "math/big" + "slices" "github.com/dop251/goja" "github.com/ethereum/go-ethereum/core/tracing" @@ -529,13 +530,7 @@ func (t *jsTracer) setBuiltinFunctions() { vm.Interrupt(err) return false } - addr := common.BytesToAddress(a) - for _, p := range t.activePrecompiles { - if p == addr { - return true - } - } - return false + return slices.Contains(t.activePrecompiles, common.BytesToAddress(a)) }) vm.Set("slice", func(slice goja.Value, start, end int64) goja.Value { b, err := t.fromBuf(vm, slice, false) diff --git a/eth/tracers/native/call_flat.go b/eth/tracers/native/call_flat.go index 37be64310c47..f8d38ddd2d5b 100644 --- a/eth/tracers/native/call_flat.go +++ b/eth/tracers/native/call_flat.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "math/big" + "slices" "strings" "github.com/ethereum/go-ethereum/common" @@ -228,12 +229,7 @@ func (t *flatCallTracer) Stop(err error) { // isPrecompiled returns whether the addr is a precompile. func (t *flatCallTracer) isPrecompiled(addr common.Address) bool { - for _, p := range t.activePrecompiles { - if p == addr { - return true - } - } - return false + return slices.Contains(t.activePrecompiles, addr) } func flatFromNested(input *callFrame, traceAddress []int, convertErrs bool, ctx *tracers.Context) (output []flatCallFrame, err error) {