From 138d0ae7cb777145136a39d28357c866ac361459 Mon Sep 17 00:00:00 2001 From: JukLee0ira Date: Fri, 25 Oct 2024 19:58:59 +0800 Subject: [PATCH] fix issues --- eth/tracers/native/contract.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/eth/tracers/native/contract.go b/eth/tracers/native/contract.go index 10f4f36379cf2..25483b137b6a8 100644 --- a/eth/tracers/native/contract.go +++ b/eth/tracers/native/contract.go @@ -33,7 +33,7 @@ func init() { } type contractTracer struct { - Addrs []string + Addrs map[string]string config contractTracerConfig interrupt uint32 // Atomic flag to signal execution interruption reason error // Textual reason for the interruption @@ -52,7 +52,7 @@ func NewContractTracer(cfg json.RawMessage) (tracers.Tracer, error) { } } t := &contractTracer{ - Addrs: make([]string, 0), + Addrs: make(map[string]string, 1), config: config, } // handle invalid opcode case @@ -67,7 +67,7 @@ func NewContractTracer(cfg json.RawMessage) (tracers.Tracer, error) { func (t *contractTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) { //When not searching for opcodes, record the contract address. if create && t.config.OpCode == "" { - t.Addrs = append(t.Addrs, addrToHex(to)) + t.Addrs[addrToHex(to)] = "" } } @@ -87,8 +87,7 @@ func (t *contractTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, targetOp := vm.StringToOp(t.config.OpCode) if op == targetOp { addr := scope.Contract.Address() - t.Addrs = append(t.Addrs, addrToHex(addr)) - t.Stop(nil) + t.Addrs[addrToHex(addr)] = "" } } @@ -102,7 +101,13 @@ func (t *contractTracer) CaptureExit(output []byte, gasUsed uint64, err error) { } func (t *contractTracer) GetResult() (json.RawMessage, error) { - res, err := json.Marshal(t.Addrs) + // return Address array without duplicate address + AddrArray := make([]string, 0, len(t.Addrs)) + for addr := range t.Addrs { + AddrArray = append(AddrArray, addr) + } + + res, err := json.Marshal(AddrArray) if err != nil { return nil, err }