github.com/amazechain/amc@v0.1.3/internal/tracers/native/noop.go (about)

     1  // Copyright 2023 The AmazeChain Authors
     2  // This file is part of the AmazeChain library.
     3  //
     4  // The AmazeChain 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 AmazeChain 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 AmazeChain library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package native
    18  
    19  import (
    20  	"encoding/json"
    21  	"github.com/holiman/uint256"
    22  
    23  	common "github.com/amazechain/amc/common/types"
    24  	"github.com/amazechain/amc/internal/tracers"
    25  	"github.com/amazechain/amc/internal/vm"
    26  )
    27  
    28  func init() {
    29  	tracers.DefaultDirectory.Register("noopTracer", newNoopTracer, false)
    30  }
    31  
    32  // noopTracer is a go implementation of the Tracer interface which
    33  // performs no action. It's mostly useful for testing purposes.
    34  type noopTracer struct{}
    35  
    36  // newNoopTracer returns a new noop tracer.
    37  func newNoopTracer(ctx *tracers.Context, _ json.RawMessage) (tracers.Tracer, error) {
    38  	return &noopTracer{}, nil
    39  }
    40  
    41  // CaptureStart implements the EVMLogger interface to initialize the tracing operation.
    42  func (t *noopTracer) CaptureStart(env vm.VMInterface, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *uint256.Int) {
    43  }
    44  
    45  // CaptureEnd is called after the call finishes to finalize the tracing.
    46  func (t *noopTracer) CaptureEnd(output []byte, gasUsed uint64, err error) {
    47  }
    48  
    49  // CaptureState implements the EVMLogger interface to trace a single step of VM execution.
    50  func (t *noopTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) {
    51  }
    52  
    53  // CaptureFault implements the EVMLogger interface to trace an execution fault.
    54  func (t *noopTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, _ *vm.ScopeContext, depth int, err error) {
    55  }
    56  
    57  // CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
    58  func (t *noopTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *uint256.Int) {
    59  }
    60  
    61  // CaptureExit is called when EVM exits a scope, even if the scope didn't
    62  // execute any code.
    63  func (t *noopTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
    64  }
    65  
    66  func (*noopTracer) CaptureTxStart(gasLimit uint64) {}
    67  
    68  func (*noopTracer) CaptureTxEnd(restGas uint64) {}
    69  
    70  // GetResult returns an empty json object.
    71  func (t *noopTracer) GetResult() (json.RawMessage, error) {
    72  	return json.RawMessage(`{}`), nil
    73  }
    74  
    75  // Stop terminates execution of the tracer at the first opportune moment.
    76  func (t *noopTracer) Stop(err error) {
    77  }