Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JukLee0ira committed Oct 25, 2024
1 parent cd73ea7 commit 138d0ae
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions eth/tracers/native/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)] = ""
}
}

Expand All @@ -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)] = ""
}
}

Expand All @@ -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
}
Expand Down

0 comments on commit 138d0ae

Please sign in to comment.