github.com/ethereum/go-ethereum@v1.16.1/eth/tracers/native/noop.go (about) 1 // Copyright 2021 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package native 18 19 import ( 20 "encoding/json" 21 "math/big" 22 23 "github.com/ethereum/go-ethereum/common" 24 "github.com/ethereum/go-ethereum/core/tracing" 25 "github.com/ethereum/go-ethereum/core/types" 26 "github.com/ethereum/go-ethereum/eth/tracers" 27 "github.com/ethereum/go-ethereum/params" 28 ) 29 30 func init() { 31 tracers.DefaultDirectory.Register("noopTracer", newNoopTracer, false) 32 } 33 34 // noopTracer is a go implementation of the Tracer interface which 35 // performs no action. It's mostly useful for testing purposes. 36 type noopTracer struct{} 37 38 // newNoopTracer returns a new noop tracer. 39 func newNoopTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *params.ChainConfig) (*tracers.Tracer, error) { 40 t := &noopTracer{} 41 return &tracers.Tracer{ 42 Hooks: &tracing.Hooks{ 43 OnTxStart: t.OnTxStart, 44 OnTxEnd: t.OnTxEnd, 45 OnEnter: t.OnEnter, 46 OnExit: t.OnExit, 47 OnOpcode: t.OnOpcode, 48 OnFault: t.OnFault, 49 OnGasChange: t.OnGasChange, 50 OnBalanceChange: t.OnBalanceChange, 51 OnNonceChange: t.OnNonceChange, 52 OnCodeChange: t.OnCodeChange, 53 OnStorageChange: t.OnStorageChange, 54 OnLog: t.OnLog, 55 }, 56 GetResult: t.GetResult, 57 Stop: t.Stop, 58 }, nil 59 } 60 61 func (t *noopTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { 62 } 63 64 func (t *noopTracer) OnFault(pc uint64, op byte, gas, cost uint64, _ tracing.OpContext, depth int, err error) { 65 } 66 67 func (t *noopTracer) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {} 68 69 func (t *noopTracer) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) { 70 } 71 72 func (t *noopTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) { 73 } 74 75 func (*noopTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) { 76 } 77 78 func (*noopTracer) OnTxEnd(receipt *types.Receipt, err error) {} 79 80 func (*noopTracer) OnBalanceChange(a common.Address, prev, new *big.Int, reason tracing.BalanceChangeReason) { 81 } 82 83 func (*noopTracer) OnNonceChange(a common.Address, prev, new uint64) {} 84 85 func (*noopTracer) OnCodeChange(a common.Address, prevCodeHash common.Hash, prev []byte, codeHash common.Hash, code []byte) { 86 } 87 88 func (*noopTracer) OnStorageChange(a common.Address, k, prev, new common.Hash) {} 89 90 func (*noopTracer) OnLog(log *types.Log) {} 91 92 // GetResult returns an empty json object. 93 func (t *noopTracer) GetResult() (json.RawMessage, error) { 94 return json.RawMessage(`{}`), nil 95 } 96 97 // Stop terminates execution of the tracer at the first opportune moment. 98 func (t *noopTracer) Stop(err error) { 99 }