github.com/n1ghtfa1l/go-vnt@v0.6.4-alpha.6/core/vm/logger.go (about)

     1  // Copyright 2015 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 vm
    18  
    19  import (
    20  	"math/big"
    21  	"time"
    22  
    23  	"github.com/vntchain/go-vnt/common"
    24  	"github.com/vntchain/go-vnt/common/hexutil"
    25  	"github.com/vntchain/go-vnt/common/math"
    26  	"github.com/vntchain/go-vnt/core/vm/interface"
    27  )
    28  
    29  type Storage map[common.Hash]common.Hash
    30  
    31  func (s Storage) Copy() Storage {
    32  	cpy := make(Storage)
    33  	for key, value := range s {
    34  		cpy[key] = value
    35  	}
    36  
    37  	return cpy
    38  }
    39  
    40  // LogConfig are the configuration options for structured logger the VM
    41  type LogConfig struct {
    42  	DisableMemory  bool // disable memory capture
    43  	DisableStack   bool // disable stack capture
    44  	DisableStorage bool // disable storage capture
    45  	Debug          bool // print output during capture end
    46  	Limit          int  // maximum length of output, but zero means unlimited
    47  }
    48  
    49  //go:generate gencodec -type StructLog -field-override structLogMarshaling -out gen_structlog.go
    50  
    51  // StructLog is emitted to the VM each cycle and lists information about the current internal state
    52  // prior to the execution of the statement.
    53  type StructLog struct {
    54  	Pc         uint64                      `json:"pc"`
    55  	Op         OPCode                      `json:"op"`
    56  	Gas        uint64                      `json:"gas"`
    57  	GasCost    uint64                      `json:"gasCost"`
    58  	Memory     []byte                      `json:"memory"`
    59  	MemorySize int                         `json:"memSize"`
    60  	Stack      []*big.Int                  `json:"stack"`
    61  	Storage    map[common.Hash]common.Hash `json:"-"`
    62  	Depth      int                         `json:"depth"`
    63  	Err        error                       `json:"-"`
    64  }
    65  
    66  type DebugLog struct {
    67  	PrintMsg string `json:"printMsg"`
    68  }
    69  
    70  // overrides for gencodec
    71  type structLogMarshaling struct {
    72  	Stack       []*math.HexOrDecimal256
    73  	Gas         math.HexOrDecimal64
    74  	GasCost     math.HexOrDecimal64
    75  	Memory      hexutil.Bytes
    76  	OpName      string `json:"opName"` // adds call to OpName() in MarshalJSON
    77  	ErrorString string `json:"error"`  // adds call to ErrorString() in MarshalJSON
    78  }
    79  
    80  func (s *StructLog) OpName() string {
    81  	return s.Op.String()
    82  }
    83  
    84  func (s *StructLog) ErrorString() string {
    85  	if s.Err != nil {
    86  		return s.Err.Error()
    87  	}
    88  	return ""
    89  }
    90  
    91  // Tracer is used to collect execution traces from an VM transaction
    92  // execution. CaptureState is called for each step of the VM with the
    93  // current VM state.
    94  // Note that reference types are actual VM data structures; make copies
    95  // if you need to retain them beyond the current call.
    96  type Tracer interface {
    97  	CaptureStart(from common.Address, to common.Address, call bool, input []byte, gas uint64, value *big.Int) error
    98  	CaptureState(env VM, pc uint64, op OPCode, gas, cost uint64, contract inter.Contract, depth int, err error) error
    99  	CaptureLog(env VM, msg string) error
   100  	CaptureFault(env VM, pc uint64, op OPCode, gas, cost uint64, contract inter.Contract, depth int, err error) error
   101  	CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error
   102  }