github.1485827954.workers.dev/ethereum/go-ethereum@v1.14.3/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 ) 28 29 func init() { 30 tracers.DefaultDirectory.Register("noopTracer", newNoopTracer, false) 31 } 32 33 // noopTracer is a go implementation of the Tracer interface which 34 // performs no action. It's mostly useful for testing purposes. 35 type noopTracer struct{} 36 37 // newNoopTracer returns a new noop tracer. 38 func newNoopTracer(ctx *tracers.Context, _ json.RawMessage) (*tracers.Tracer, error) { 39 t := &noopTracer{} 40 return &tracers.Tracer{ 41 Hooks: &tracing.Hooks{ 42 OnTxStart: t.OnTxStart, 43 OnTxEnd: t.OnTxEnd, 44 OnEnter: t.OnEnter, 45 OnExit: t.OnExit, 46 OnOpcode: t.OnOpcode, 47 OnFault: t.OnFault, 48 OnGasChange: t.OnGasChange, 49 OnBalanceChange: t.OnBalanceChange, 50 OnNonceChange: t.OnNonceChange, 51 OnCodeChange: t.OnCodeChange, 52 OnStorageChange: t.OnStorageChange, 53 OnLog: t.OnLog, 54 }, 55 GetResult: t.GetResult, 56 Stop: t.Stop, 57 }, nil 58 } 59 60 func (t *noopTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { 61 } 62 63 func (t *noopTracer) OnFault(pc uint64, op byte, gas, cost uint64, _ tracing.OpContext, depth int, err error) { 64 } 65 66 func (t *noopTracer) OnGasChange(old, new uint64, reason tracing.GasChangeReason) {} 67 68 func (t *noopTracer) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) { 69 } 70 71 func (t *noopTracer) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) { 72 } 73 74 func (*noopTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from common.Address) { 75 } 76 77 func (*noopTracer) OnTxEnd(receipt *types.Receipt, err error) {} 78 79 func (*noopTracer) OnBalanceChange(a common.Address, prev, new *big.Int, reason tracing.BalanceChangeReason) { 80 } 81 82 func (*noopTracer) OnNonceChange(a common.Address, prev, new uint64) {} 83 84 func (*noopTracer) OnCodeChange(a common.Address, prevCodeHash common.Hash, prev []byte, codeHash common.Hash, code []byte) { 85 } 86 87 func (*noopTracer) OnStorageChange(a common.Address, k, prev, new common.Hash) {} 88 89 func (*noopTracer) OnLog(log *types.Log) {} 90 91 // GetResult returns an empty json object. 92 func (t *noopTracer) GetResult() (json.RawMessage, error) { 93 return json.RawMessage(`{}`), nil 94 } 95 96 // Stop terminates execution of the tracer at the first opportune moment. 97 func (t *noopTracer) Stop(err error) { 98 }