logger

package
v2.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2024 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMarkdownLogger

func NewMarkdownLogger(cfg *Config, writer io.Writer) *mdLogger

NewMarkdownLogger creates a logger which outputs information in a format adapted for human readability, and is also a valid markdown table

func WriteLogs

func WriteLogs(writer io.Writer, logs []*types.Log)

WriteLogs writes vm logs in a readable format to the given writer

func WriteTrace

func WriteTrace(writer io.Writer, logs []StructLog)

WriteTrace writes a formatted trace to the given writer

Types

type Config

type Config struct {
	EnableMemory     bool // enable memory capture
	DisableStack     bool // disable stack capture
	DisableStorage   bool // disable storage capture
	EnableReturnData bool // enable return data capture
	Debug            bool // print output during capture end
	Limit            int  // maximum length of output, but zero means unlimited
}

Config are the configuration options for structured logger the EVM

type ExecutionResult

type ExecutionResult struct {
	Gas         uint64         `json:"gas"`
	Failed      bool           `json:"failed"`
	ReturnValue string         `json:"returnValue"`
	StructLogs  []StructLogRes `json:"structLogs"`
}

ExecutionResult groups all structured logs emitted by the EVM while replaying a transaction in debug mode as well as transaction execution status, the amount of gas used and the return value

type JSONLogger

type JSONLogger struct {
	// contains filtered or unexported fields
}

func NewJSONLogger

func NewJSONLogger(cfg *Config, writer io.Writer) *JSONLogger

NewJSONLogger creates a new EVM tracer that prints execution steps as JSON objects into the provided stream.

func (*JSONLogger) CaptureEnd

func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, err error)

CaptureEnd is triggered at end of execution.

func (*JSONLogger) CaptureEnter

func (l *JSONLogger) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)

func (*JSONLogger) CaptureExit

func (l *JSONLogger) CaptureExit(output []byte, gasUsed uint64, err error)

func (*JSONLogger) CaptureFault

func (l *JSONLogger) CaptureFault(pc uint64, op vm.OpCode, gas uint64, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error)

func (*JSONLogger) CaptureStart

func (l *JSONLogger) CaptureStart(env *vm.EVM, from, to common.Address, create bool, input []byte, gas uint64, value *big.Int)

func (*JSONLogger) CaptureState

func (l *JSONLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, rData []byte, depth int, err error)

CaptureState outputs state information on the logger.

type Storage

type Storage map[common.Hash]common.Hash

Storage represents a contract's storage.

func (Storage) Copy

func (s Storage) Copy() Storage

Copy duplicates the current storage.

type StructLog

type StructLog struct {
	Pc            uint64                      `json:"pc"`
	Op            vm.OpCode                   `json:"op"`
	Gas           uint64                      `json:"gas"`
	GasCost       uint64                      `json:"gasCost"`
	Memory        []byte                      `json:"memory,omitempty"`
	MemorySize    int                         `json:"memSize"`
	Stack         []uint256.Int               `json:"stack"`
	ReturnData    []byte                      `json:"returnData,omitempty"`
	Storage       map[common.Hash]common.Hash `json:"-"`
	Depth         int                         `json:"depth"`
	RefundCounter uint64                      `json:"refund"`
	Err           error                       `json:"-"`
}

StructLog is emitted to the EVM each cycle and lists information about the current internal state prior to the execution of the statement.

func (*StructLog) ErrorString

func (s *StructLog) ErrorString() string

ErrorString formats the log's error as a string.

func (StructLog) MarshalJSON

func (s StructLog) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*StructLog) OpName

func (s *StructLog) OpName() string

OpName formats the operand name in a human-readable format.

func (*StructLog) UnmarshalJSON

func (s *StructLog) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type StructLogRes

type StructLogRes struct {
	Pc            uint64             `json:"pc"`
	Op            string             `json:"op"`
	Gas           uint64             `json:"gas"`
	GasCost       uint64             `json:"gasCost"`
	Depth         int                `json:"depth"`
	Error         string             `json:"error,omitempty"`
	Stack         *[]string          `json:"stack,omitempty"`
	ReturnData    string             `json:"returnData,omitempty"`
	Memory        *[]string          `json:"memory,omitempty"`
	Storage       *map[string]string `json:"storage,omitempty"`
	RefundCounter uint64             `json:"refund,omitempty"`
}

StructLogRes stores a structured log emitted by the EVM while replaying a transaction in debug mode

type StructLogger

type StructLogger struct {
	// contains filtered or unexported fields
}

StructLogger is an EVM state logger and implements EVMLogger.

StructLogger can capture state based on the given Log configuration and also keeps a track record of modified storage which is used in reporting snapshots of the contract their storage.

func NewStructLogger

func NewStructLogger(cfg json.RawMessage) (*StructLogger, error)

NewStructLogger returns a new logger

func (*StructLogger) CaptureClauseEnd

func (l *StructLogger) CaptureClauseEnd(restGas uint64)

func (*StructLogger) CaptureClauseStart

func (l *StructLogger) CaptureClauseStart(gasLimit uint64)

func (*StructLogger) CaptureEnd

func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, err error)

CaptureEnd is called after the call finishes to finalize the tracing.

func (*StructLogger) CaptureEnter

func (l *StructLogger) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)

func (*StructLogger) CaptureExit

func (l *StructLogger) CaptureExit(output []byte, gasUsed uint64, err error)

func (*StructLogger) CaptureFault

func (l *StructLogger) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error)

CaptureFault implements the EVMLogger interface to trace an execution fault while running an opcode.

func (*StructLogger) CaptureStart

func (l *StructLogger) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int)

CaptureStart implements the EVMLogger interface to initialize the tracing operation.

func (*StructLogger) CaptureState

func (l *StructLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, rData []byte, depth int, err error)

CaptureState logs a new structured log message and pushes it out to the environment

CaptureState also tracks SLOAD/SSTORE ops to track storage change.

func (*StructLogger) Error

func (l *StructLogger) Error() error

Error returns the VM error captured by the trace.

func (*StructLogger) GetResult

func (l *StructLogger) GetResult() (json.RawMessage, error)

func (*StructLogger) Output

func (l *StructLogger) Output() []byte

Output returns the VM return value captured by the trace.

func (*StructLogger) Reset

func (l *StructLogger) Reset()

Reset clears the data held by the logger.

func (*StructLogger) SetContext

func (l *StructLogger) SetContext(ctx *tracers.Context)

func (*StructLogger) Stop

func (l *StructLogger) Stop(err error)

Stop terminates execution of the tracer at the first opportune moment.

func (*StructLogger) StructLogs

func (l *StructLogger) StructLogs() []StructLog

StructLogs returns the captured log entries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL