From f34e2a4a86f159fa6f1eb202c1270ee47e24832a Mon Sep 17 00:00:00 2001
From: Alex Gartner <alexg@zetachain.com>
Date: Fri, 27 Sep 2024 08:53:58 -0700
Subject: [PATCH] chore: move NewTracer to keeper (#126)

---
 x/evm/keeper/keeper.go |  2 +-
 x/evm/keeper/tracer.go | 50 ++++++++++++++++++++++++++++++++++++++++++
 x/evm/types/tracer.go  | 28 -----------------------
 3 files changed, 51 insertions(+), 29 deletions(-)
 create mode 100644 x/evm/keeper/tracer.go

diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go
index c2b41a33..c2414f1f 100644
--- a/x/evm/keeper/keeper.go
+++ b/x/evm/keeper/keeper.go
@@ -286,7 +286,7 @@ func (k *Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *et
 
 // Tracer return a default vm.Tracer based on current keeper state
 func (k Keeper) Tracer(ctx sdk.Context, msg core.Message, ethCfg *params.ChainConfig) vm.EVMLogger {
-	return types.NewTracer(k.tracer, msg, ethCfg, ctx.BlockHeight())
+	return NewTracer(k.tracer, msg, ethCfg, ctx.BlockHeight())
 }
 
 // GetAccountWithoutBalance load nonce and codehash without balance,
diff --git a/x/evm/keeper/tracer.go b/x/evm/keeper/tracer.go
new file mode 100644
index 00000000..35e77c8f
--- /dev/null
+++ b/x/evm/keeper/tracer.go
@@ -0,0 +1,50 @@
+// Copyright 2021 Evmos Foundation
+// This file is part of Evmos' Ethermint library.
+//
+// The Ethermint library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The Ethermint library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the Ethermint library. If not, see https://github.com/zeta-chain/ethermint/blob/main/LICENSE
+package keeper
+
+import (
+	"math/big"
+	"os"
+
+	"github.com/ethereum/go-ethereum/core"
+	"github.com/ethereum/go-ethereum/core/vm"
+	"github.com/ethereum/go-ethereum/eth/tracers/logger"
+	"github.com/ethereum/go-ethereum/params"
+	"github.com/zeta-chain/ethermint/x/evm/types"
+)
+
+// NewTracer creates a new Logger tracer to collect execution traces from an
+// EVM transaction.
+func NewTracer(tracer string, msg core.Message, cfg *params.ChainConfig, height int64) vm.EVMLogger {
+	// TODO: enable additional log configuration
+	logCfg := &logger.Config{
+		Debug: true,
+	}
+
+	switch tracer {
+	case types.TracerAccessList:
+		preCompiles := vm.DefaultActivePrecompiles(cfg.Rules(big.NewInt(height), cfg.MergeNetsplitBlock != nil))
+		return logger.NewAccessListTracer(msg.AccessList(), msg.From(), *msg.To(), preCompiles)
+	case types.TracerJSON:
+		return logger.NewJSONLogger(logCfg, os.Stderr)
+	case types.TracerMarkdown:
+		return logger.NewMarkdownLogger(logCfg, os.Stdout) // TODO: Stderr ?
+	case types.TracerStruct:
+		return logger.NewStructLogger(logCfg)
+	default:
+		return types.NewNoOpTracer()
+	}
+}
diff --git a/x/evm/types/tracer.go b/x/evm/types/tracer.go
index 41f8bf86..7461ea21 100644
--- a/x/evm/types/tracer.go
+++ b/x/evm/types/tracer.go
@@ -17,15 +17,10 @@ package types
 
 import (
 	"math/big"
-	"os"
 	"time"
 
-	"github.com/ethereum/go-ethereum/eth/tracers/logger"
-
 	"github.com/ethereum/go-ethereum/common"
-	"github.com/ethereum/go-ethereum/core"
 	"github.com/ethereum/go-ethereum/core/vm"
-	"github.com/ethereum/go-ethereum/params"
 )
 
 const (
@@ -35,29 +30,6 @@ const (
 	TracerMarkdown   = "markdown"
 )
 
-// NewTracer creates a new Logger tracer to collect execution traces from an
-// EVM transaction.
-func NewTracer(tracer string, msg core.Message, cfg *params.ChainConfig, height int64) vm.EVMLogger {
-	// TODO: enable additional log configuration
-	logCfg := &logger.Config{
-		Debug: true,
-	}
-
-	switch tracer {
-	case TracerAccessList:
-		preCompiles := vm.DefaultActivePrecompiles(cfg.Rules(big.NewInt(height), cfg.MergeNetsplitBlock != nil))
-		return logger.NewAccessListTracer(msg.AccessList(), msg.From(), *msg.To(), preCompiles)
-	case TracerJSON:
-		return logger.NewJSONLogger(logCfg, os.Stderr)
-	case TracerMarkdown:
-		return logger.NewMarkdownLogger(logCfg, os.Stdout) // TODO: Stderr ?
-	case TracerStruct:
-		return logger.NewStructLogger(logCfg)
-	default:
-		return NewNoOpTracer()
-	}
-}
-
 // TxTraceResult is the result of a single transaction trace during a block trace.
 type TxTraceResult struct {
 	Result interface{} `json:"result,omitempty"` // Trace results produced by the tracer