vm

package
v0.0.0-...-92cc422 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GasQuickStep   uint64 = 2
	GasFastestStep uint64 = 3
	GasFastStep    uint64 = 5
	GasMidStep     uint64 = 8
	GasSlowStep    uint64 = 10
	GasExtStep     uint64 = 20

	GasReturn       uint64 = 0
	GasStop         uint64 = 0
	GasContractByte uint64 = 200
)

天然气成本

Variables

View Source
var (
	ErrOutOfGas                 = errors.New("out of gas")
	ErrCodeStoreOutOfGas        = errors.New("contract creation code storage out of gas")
	ErrDepth                    = errors.New("max call depth exceeded")
	ErrTraceLimitReached        = errors.New("the number of logs reached the specified limit")
	ErrInsufficientBalance      = errors.New("insufficient balance for transfer")
	ErrContractAddressCollision = errors.New("contract address collision")
	ErrNoCompatibleInterpreter  = errors.New("no compatible interpreter")
)

列表执行错误

View Source
var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{
	common.BytesToAddress([]byte{1}): &ecrecover{},
	common.BytesToAddress([]byte{2}): &sha256hash{},
	common.BytesToAddress([]byte{3}): &ripemd160hash{},
	common.BytesToAddress([]byte{4}): &dataCopy{},
	common.BytesToAddress([]byte{5}): &bigModExp{},
	common.BytesToAddress([]byte{6}): &bn256Add{},
	common.BytesToAddress([]byte{7}): &bn256ScalarMul{},
	common.BytesToAddress([]byte{8}): &bn256Pairing{},
}

PrecompiledContractsByzantium包含预编译的ethereum的默认集 拜占庭协议中使用的合同。

View Source
var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{
	common.BytesToAddress([]byte{1}): &ecrecover{},
	common.BytesToAddress([]byte{2}): &sha256hash{},
	common.BytesToAddress([]byte{3}): &ripemd160hash{},
	common.BytesToAddress([]byte{4}): &dataCopy{},
}

预编译的ContractShomestead包含预编译的ethereum的默认集 边境地区使用的合同和宅基地释放。

Functions

func NoopCanTransfer

func NoopCanTransfer(db StateDB, from common.Address, balance *big.Int) bool

func NoopTransfer

func NoopTransfer(db StateDB, from, to common.Address, amount *big.Int)

func RunPrecompiledContract

func RunPrecompiledContract(p PrecompiledContract, input []byte, contract *Contract) (ret []byte, err error)

runPrecompiledContract运行并评估预编译合同的输出。

func WriteLogs

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

WriteLogs以可读的格式将VM日志写入给定的写入程序

func WriteTrace

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

WriteTrace将格式化的跟踪写入给定的写入程序

Types

type AccountRef

type AccountRef common.Address

accountRef执行contractRef。

在EVM初始化和 它的主要用途是获取地址。删除此对象 由于缓存的跳转目的地 从父合同(即调用者)中提取,其中 是ContractRef。

func (AccountRef) Address

func (ar AccountRef) Address() common.Address

地址将accountRef强制转换为地址

type CallContext

type CallContext interface {
	//调用另一个合同
	Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
	//采用他人的合同代码并在我们自己的上下文中执行
	CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
	//与callcode相同,但发送方和值从父作用域传播到子作用域
	DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
	//创建新合同
	Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
}

CallContext为EVM调用约定提供基本接口。EVM EVM 取决于为执行子调用和初始化新的EVM合同而实现的上下文。

type CanTransferFunc

type CanTransferFunc func(StateDB, common.Address, *big.Int) bool

cantransferfunc是传递保护函数的签名

type Config

type Config struct {
	//启用调试的调试解释器选项
	Debug bool
	//跟踪程序是操作代码记录器
	Tracer Tracer
	//无加密禁用的解释程序调用,调用代码,
	//委派呼叫并创建。
	NoRecursion bool
	//启用sha3/keccak preimages的录制
	EnablePreimageRecording bool
	//JumpTable包含EVM指令表。这个
	//可能未初始化,并将设置为默认值
	//表。
	JumpTable [256]operation
}

config是解释器的配置选项

type Context

type Context struct {
	//CanTransfer返回帐户是否包含
	//足够的乙醚转移价值
	CanTransfer CanTransferFunc
	//将乙醚从一个帐户转移到另一个帐户
	Transfer TransferFunc
	//GetHash返回与n对应的哈希
	GetHash GetHashFunc

	// 消息信息
	Origin   common.Address //提供源站信息
	GasPrice *big.Int       //为Gasprice提供信息

	// 阻止信息
	Coinbase    common.Address //为CoinBase提供信息
	GasLimit    uint64         //提供气体限制信息
	BlockNumber *big.Int       //提供数字信息
	Time        *big.Int       //提供时间信息
	Difficulty  *big.Int       //为困难提供信息
}

上下文为EVM提供辅助信息。一旦提供 它不应该被修改。

type Contract

type Contract struct {
	//CallerAddress是调用方初始化此项的结果
	//合同。但是,当“调用方法”被委托时,这个值
	//需要初始化为调用方的调用方的调用方。
	CallerAddress common.Address

	Code     []byte
	CodeHash common.Hash
	CodeAddr *common.Address
	Input    []byte

	Gas uint64

	Args []byte

	DelegateCall bool
	// contains filtered or unexported fields
}

契约表示状态数据库中的以太坊契约。它包含 合同代码,调用参数。合同执行合同参考号

func NewContract

func NewContract(caller ContractRef, object ContractRef, value *big.Int, gas uint64) *Contract

NewContract返回执行EVM的新合同环境。

func (*Contract) Address

func (c *Contract) Address() common.Address

地址返回合同地址

func (*Contract) AsDelegate

func (c *Contract) AsDelegate() *Contract

asdelegate将协定设置为委托调用并返回当前 合同(用于链接呼叫)

func (*Contract) Caller

func (c *Contract) Caller() common.Address

调用者返回合同的调用者。

当协定是委托时,调用方将递归调用调用方 呼叫,包括呼叫者的呼叫。

func (*Contract) GetByte

func (c *Contract) GetByte(n uint64) byte

GetByte返回协定字节数组中的第n个字节

func (*Contract) GetOp

func (c *Contract) GetOp(n uint64) OpCode

getop返回契约字节数组中的第n个元素

func (*Contract) SetCallCode

func (c *Contract) SetCallCode(addr *common.Address, hash common.Hash, code []byte)

setcallcode设置合同的代码和支持数据的地址 对象

func (*Contract) SetCode

func (c *Contract) SetCode(hash common.Hash, code []byte)

setcode将代码设置为合同

func (*Contract) UseGas

func (c *Contract) UseGas(gas uint64) (ok bool)

use gas尝试使用气体并减去它,成功后返回true。

func (*Contract) Value

func (c *Contract) Value() *big.Int

value返回合同值(从调用方发送给它)

type ContractRef

type ContractRef interface {
	Address() common.Address
}

contractRef是对合同支持对象的引用

type EVM

type EVM struct {
	//上下文提供辅助区块链相关信息
	Context
	//statedb提供对底层状态的访问
	StateDB StateDB
	// contains filtered or unexported fields
}

EVM是以太坊虚拟机基础对象,它提供 在给定状态下运行合同所需的工具 提供的上下文。应该注意的是,任何错误 通过任何调用生成的应被视为 恢复状态并消耗所有气体操作,不检查 应执行特定错误。翻译使 确保生成的任何错误都被视为错误代码。

EVM不应该被重用,也不是线程安全的。

func NewEVM

func NewEVM(ctx Context, statedb StateDB, chainConfig *params.ChainConfig, vmConfig Config) *EVM

new evm返回新的evm。返回的EVM不是线程安全的,应该 只能使用一次。

func (*EVM) Call

func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error)

调用执行与给定输入为的addr关联的协定 参数。它还处理任何必要的价值转移,并采取 创建帐户和在 执行错误或值传输失败。

func (*EVM) CallCode

func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error)

callcode使用给定的输入执行与addr关联的协定 作为参数。它还处理任何必要的价值转移,并采取 创建帐户和在 执行错误或值传输失败。

callcode与call的区别在于它执行给定的地址' 以调用方为上下文的代码。

func (*EVM) Cancel

func (evm *EVM) Cancel()

取消取消任何正在运行的EVM操作。这可以同时调用,并且 多次打电话是安全的。

func (*EVM) ChainConfig

func (evm *EVM) ChainConfig() *params.ChainConfig

chainconfig返回环境的链配置

func (*EVM) Create

func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error)

创建使用代码作为部署代码创建新合同。

func (*EVM) Create2

func (evm *EVM) Create2(caller ContractRef, code []byte, gas uint64, endowment *big.Int, salt *big.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error)

Create2使用代码作为部署代码创建新合同。

create2与create的区别是create2使用sha3(0xff++msg.sender++salt++sha3(init_code))[12:] 而不是通常的发送者和nonce散列作为合同初始化的地址。

func (*EVM) DelegateCall

func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)

DelegateCall执行与给定输入的addr关联的协定 作为参数。如果发生执行错误,它将反转状态。

delegateCall与callcode的区别在于它执行给定的地址' 以调用者为上下文的代码,调用者被设置为调用者的调用者。

func (*EVM) Interpreter

func (evm *EVM) Interpreter() Interpreter

解释器返回当前解释器

func (*EVM) StaticCall

func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)

staticCall使用给定的输入执行与addr关联的协定 作为参数,同时不允许在调用期间对状态进行任何修改。 试图执行此类修改的操作码将导致异常 而不是执行修改。

type EVMInterpreter

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

evm interpreter表示evm解释器

func NewEVMInterpreter

func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter

NewEvminterPreter返回解释器的新实例。

func (*EVMInterpreter) CanRun

func (in *EVMInterpreter) CanRun(code []byte) bool

canrun告诉作为参数传递的契约是否可以 由当前解释器运行。

func (*EVMInterpreter) IsReadOnly

func (in *EVMInterpreter) IsReadOnly() bool

如果解释器处于只读模式,is read only将报告。

func (*EVMInterpreter) Run

func (in *EVMInterpreter) Run(contract *Contract, input []byte) (ret []byte, err error)

运行循环并使用给定的输入数据评估契约的代码并返回 返回字节切片,如果出现错误,则返回一个错误。

需要注意的是,解释程序返回的任何错误都应该 被认为是一种还原和消耗除 errExecutionReverted,这意味着还原并保留气体。

func (*EVMInterpreter) SetReadOnly

func (in *EVMInterpreter) SetReadOnly(ro bool)

setreadonly在解释器中设置(或取消设置)只读模式。

type GetHashFunc

type GetHashFunc func(uint64) common.Hash

gethashfunc返回区块链中的第n个区块哈希 并由blockhash evm op代码使用。

type Interpreter

type Interpreter interface {
	//运行循环并使用给定的输入数据评估契约的代码并返回
	//返回字节切片,如果出现错误,则返回一个错误。
	Run(contract *Contract, input []byte) ([]byte, error)
	//canrun告诉作为参数传递的契约是否可以
	//由当前解释器运行。这意味着
	//呼叫方可以执行以下操作:
	//
	//'Gangang'
	//对于u,解释器:=测距解释器
	//if explorer.canrun(contract.code)
	//解释器.run(contract.code,input)
	//}
	//}
	//` `
	CanRun([]byte) bool
	//如果解释器处于只读模式,is read only将报告。
	IsReadOnly() bool
	//setreadonly在解释器中设置(或取消设置)只读模式。
	SetReadOnly(bool)
}

解释器用于运行基于以太坊的合同,并将使用 已传递环境以查询外部源以获取状态信息。 解释器将根据传递的 配置。

type LogConfig

type LogConfig struct {
	DisableMemory  bool //禁用内存捕获
	DisableStack   bool //禁用堆栈捕获
	DisableStorage bool //禁用存储捕获
	Debug          bool //捕获结束时打印输出
	Limit          int  //最大输出长度,但零表示无限制
}

logconfig是结构化记录器evm的配置选项

type Memory

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

内存为以太坊虚拟机实现了一个简单的内存模型。

func NewMemory

func NewMemory() *Memory

new memory返回新的内存模型。

func (*Memory) Data

func (m *Memory) Data() []byte

数据返回备份切片

func (*Memory) Get

func (m *Memory) Get(offset, size int64) (cpy []byte)

get返回偏移量+作为新切片的大小

func (*Memory) GetPtr

func (m *Memory) GetPtr(offset, size int64) []byte

getptr返回偏移量+大小

func (*Memory) Len

func (m *Memory) Len() int

len返回背衬片的长度

func (*Memory) Print

func (m *Memory) Print()

打印转储内存的内容。

func (*Memory) Resize

func (m *Memory) Resize(size uint64)

调整大小将内存大小调整为

func (*Memory) Set

func (m *Memory) Set(offset, size uint64, value []byte)

将“设置偏移量+大小”设置为“值”

func (*Memory) Set32

func (m *Memory) Set32(offset uint64, val *big.Int)

set32将从偏移量开始的32个字节设置为val值,用零左填充到 32字节。

type NoopEVMCallContext

type NoopEVMCallContext struct{}

func (NoopEVMCallContext) Call

func (NoopEVMCallContext) Call(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)

func (NoopEVMCallContext) CallCode

func (NoopEVMCallContext) CallCode(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)

func (NoopEVMCallContext) Create

func (NoopEVMCallContext) Create(caller ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)

func (NoopEVMCallContext) DelegateCall

func (NoopEVMCallContext) DelegateCall(me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)

type NoopStateDB

type NoopStateDB struct{}

func (NoopStateDB) AddBalance

func (NoopStateDB) AddBalance(common.Address, *big.Int)

func (NoopStateDB) AddLog

func (NoopStateDB) AddLog(*types.Log)

func (NoopStateDB) AddPreimage

func (NoopStateDB) AddPreimage(common.Hash, []byte)

func (NoopStateDB) AddRefund

func (NoopStateDB) AddRefund(uint64)

func (NoopStateDB) CreateAccount

func (NoopStateDB) CreateAccount(common.Address)

func (NoopStateDB) Empty

func (NoopStateDB) Empty(common.Address) bool

func (NoopStateDB) Exist

func (NoopStateDB) Exist(common.Address) bool

func (NoopStateDB) ForEachStorage

func (NoopStateDB) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool)

func (NoopStateDB) GetBalance

func (NoopStateDB) GetBalance(common.Address) *big.Int

func (NoopStateDB) GetCode

func (NoopStateDB) GetCode(common.Address) []byte

func (NoopStateDB) GetCodeHash

func (NoopStateDB) GetCodeHash(common.Address) common.Hash

func (NoopStateDB) GetCodeSize

func (NoopStateDB) GetCodeSize(common.Address) int

func (NoopStateDB) GetNonce

func (NoopStateDB) GetNonce(common.Address) uint64

func (NoopStateDB) GetRefund

func (NoopStateDB) GetRefund() uint64

func (NoopStateDB) GetState

func (NoopStateDB) HasSuicided

func (NoopStateDB) HasSuicided(common.Address) bool

func (NoopStateDB) RevertToSnapshot

func (NoopStateDB) RevertToSnapshot(int)

func (NoopStateDB) SetCode

func (NoopStateDB) SetCode(common.Address, []byte)

func (NoopStateDB) SetNonce

func (NoopStateDB) SetNonce(common.Address, uint64)

func (NoopStateDB) SetState

func (NoopStateDB) Snapshot

func (NoopStateDB) Snapshot() int

func (NoopStateDB) SubBalance

func (NoopStateDB) SubBalance(common.Address, *big.Int)

func (NoopStateDB) Suicide

func (NoopStateDB) Suicide(common.Address) bool

type OpCode

type OpCode byte

操作码是EVM操作码

const (
	STOP OpCode = iota
	ADD
	MUL
	SUB
	DIV
	SDIV
	MOD
	SMOD
	ADDMOD
	MULMOD
	EXP
	SIGNEXTEND
)

0x0范围-算术运算。

const (
	LT OpCode = iota + 0x10
	GT
	SLT
	SGT
	EQ
	ISZERO
	AND
	OR
	XOR
	NOT
	BYTE
	SHL
	SHR
	SAR

	SHA3 = 0x20
)

0x10范围-比较操作。

const (
	ADDRESS OpCode = 0x30 + iota
	BALANCE
	ORIGIN
	CALLER
	CALLVALUE
	CALLDATALOAD
	CALLDATASIZE
	CALLDATACOPY
	CODESIZE
	CODECOPY
	GASPRICE
	EXTCODESIZE
	EXTCODECOPY
	RETURNDATASIZE
	RETURNDATACOPY
	EXTCODEHASH
)

0x30范围-关闭状态。

const (
	BLOCKHASH OpCode = 0x40 + iota
	COINBASE
	TIMESTAMP
	NUMBER
	DIFFICULTY
	GASLIMIT
)

0x40范围-块操作。

const (
	POP OpCode = 0x50 + iota
	MLOAD
	MSTORE
	MSTORE8
	SLOAD
	SSTORE
	JUMP
	JUMPI
	PC
	MSIZE
	GAS
	JUMPDEST
)

0x50范围-“存储”和执行。

const (
	PUSH1 OpCode = 0x60 + iota
	PUSH2
	PUSH3
	PUSH4
	PUSH5
	PUSH6
	PUSH7
	PUSH8
	PUSH9
	PUSH10
	PUSH11
	PUSH12
	PUSH13
	PUSH14
	PUSH15
	PUSH16
	PUSH17
	PUSH18
	PUSH19
	PUSH20
	PUSH21
	PUSH22
	PUSH23
	PUSH24
	PUSH25
	PUSH26
	PUSH27
	PUSH28
	PUSH29
	PUSH30
	PUSH31
	PUSH32
	DUP1
	DUP2
	DUP3
	DUP4
	DUP5
	DUP6
	DUP7
	DUP8
	DUP9
	DUP10
	DUP11
	DUP12
	DUP13
	DUP14
	DUP15
	DUP16
	SWAP1
	SWAP2
	SWAP3
	SWAP4
	SWAP5
	SWAP6
	SWAP7
	SWAP8
	SWAP9
	SWAP10
	SWAP11
	SWAP12
	SWAP13
	SWAP14
	SWAP15
	SWAP16
)

0x60范围。

const (
	LOG0 OpCode = 0xa0 + iota
	LOG1
	LOG2
	LOG3
	LOG4
)

0XA0范围-记录操作。

const (
	PUSH OpCode = 0xb0 + iota
	DUP
	SWAP
)

用于解析的非官方操作码。

const (
	CREATE OpCode = 0xf0 + iota
	CALL
	CALLCODE
	RETURN
	DELEGATECALL
	CREATE2
	STATICCALL = 0xfa

	REVERT       = 0xfd
	SELFDESTRUCT = 0xff
)

0xF0范围-关闭。

func StringToOp

func StringToOp(str string) OpCode

stringtoop查找名称存储在“str”中的操作码。

func (OpCode) IsPush

func (op OpCode) IsPush() bool

is push指定操作码是否为推送操作码。

func (OpCode) IsStaticJump

func (op OpCode) IsStaticJump() bool

IsStaticJump指定操作码是否为跳转。

func (OpCode) String

func (op OpCode) String() string

type PrecompiledContract

type PrecompiledContract interface {
	RequiredGas(input []byte) uint64  //所需价格计算合同用气
	Run(input []byte) ([]byte, error) //运行运行预编译合同
}

预编译契约是本地Go契约的基本接口。实施 需要基于运行方法的输入大小确定的气体计数 合同。

type Stack

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

堆栈是用于基本堆栈操作的对象。弹出到堆栈的项是 需要更改和修改。堆栈不负责新添加 初始化的对象。

func (*Stack) Back

func (st *Stack) Back(n int) *big.Int

返回堆栈中的第n项

func (*Stack) Data

func (st *Stack) Data() []*big.Int

data返回基础的big.int数组。

func (*Stack) Print

func (st *Stack) Print()

打印转储堆栈的内容

type StateDB

type StateDB interface {
	CreateAccount(common.Address)

	SubBalance(common.Address, *big.Int)
	AddBalance(common.Address, *big.Int)
	GetBalance(common.Address) *big.Int

	GetNonce(common.Address) uint64
	SetNonce(common.Address, uint64)

	GetCodeHash(common.Address) common.Hash
	GetCode(common.Address) []byte
	SetCode(common.Address, []byte)
	GetCodeSize(common.Address) int

	AddRefund(uint64)
	GetRefund() uint64

	GetState(common.Address, common.Hash) common.Hash
	SetState(common.Address, common.Hash, common.Hash)

	Suicide(common.Address) bool
	HasSuicided(common.Address) bool

	//exist报告给定帐户是否处于状态。
	//值得注意的是,对于自杀账户来说,这也应该是正确的。
	Exist(common.Address) bool
	//empty返回给定帐户是否为空。空的
	//根据EIP161定义(balance=nonce=code=0)。
	Empty(common.Address) bool

	RevertToSnapshot(int)
	Snapshot() int

	AddLog(*types.Log)
	AddPreimage(common.Hash, []byte)

	ForEachStorage(common.Address, func(common.Hash, common.Hash) bool)
}

StateDB是用于完整状态查询的EVM数据库。

type Storage

type Storage map[common.Hash]common.Hash

存储表示合同的存储。

func (Storage) Copy

func (s Storage) Copy() Storage

复制复制复制当前存储。

type StructLog

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

structlog在每个周期发送给evm,并列出有关当前内部状态的信息 在语句执行之前。

func (*StructLog) ErrorString

func (s *StructLog) ErrorString() string

ErrorString将日志的错误格式化为字符串。

func (StructLog) MarshalJSON

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

func (*StructLog) OpName

func (s *StructLog) OpName() string

opname将操作数名称格式化为可读格式。

func (*StructLog) UnmarshalJSON

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

type StructLogger

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

structlogger是一个EVM状态记录器并实现跟踪程序。

结构记录器可以根据给定的日志配置捕获状态,并且还可以保留 修改后的存储的跟踪记录,用于报告 把他们的仓库收起来。

func NewStructLogger

func NewStructLogger(cfg *LogConfig) *StructLogger

newstructlogger返回新的记录器

func (*StructLogger) CaptureEnd

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

在调用完成后调用CaptureEnd以完成跟踪。

func (*StructLogger) CaptureFault

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

CaptureFault实现跟踪程序接口来跟踪执行错误 运行操作码时。

func (*StructLogger) CaptureStart

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

CaptureStart实现跟踪程序接口以初始化跟踪操作。

func (*StructLogger) CaptureState

func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error

CaptureState记录新的结构化日志消息并将其推送到环境中

CaptureState还跟踪sstore操作以跟踪脏值。

func (*StructLogger) Error

func (l *StructLogger) Error() error

错误返回跟踪捕获的VM错误。

func (*StructLogger) Output

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

输出返回跟踪捕获的VM返回值。

func (*StructLogger) StructLogs

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

structlogs返回捕获的日志条目。

type Tracer

type Tracer interface {
	CaptureStart(from common.Address, to common.Address, call bool, input []byte, gas uint64, value *big.Int) error
	CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error
	CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error
	CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error
}

跟踪程序用于从EVM事务收集执行跟踪 执行。对带有 当前VM状态。 请注意,引用类型是实际的VM数据结构;复制 如果您需要在当前呼叫之外保留它们。

type TransferFunc

type TransferFunc func(StateDB, common.Address, common.Address, *big.Int)

transferFunc是传递函数的签名

Directories

Path Synopsis
包运行时提供执行EVM代码的基本执行模型。
包运行时提供执行EVM代码的基本执行模型。

Jump to

Keyboard shortcuts

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