runtime

package
v2.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: LGPL-3.0 Imports: 16 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// EmptyRuntimeBytecode is stored at every precompile address at fork activation.
	// This makes precompile addresses "exist" in Thor's state, which prevents
	// accidental contract deployment to those addresses (CREATE/CREATE2 will fail
	// with ErrContractAddressCollision since the code hash differs from emptyCodeHash).
	//
	// NOTE: This means EXTCODESIZE/EXTCODECOPY/EXTCODEHASH on any precompile address
	// returns 8 bytes of non-empty code on Thor, whereas on Ethereum precompile
	// addresses have no code (EXTCODESIZE returns 0). Contracts that detect
	// precompiles by checking extcodesize == 0 will behave differently on Thor.
	EmptyRuntimeBytecode = []byte{0x60, 0x60, 0x60, 0x40, 0x52, 0x60, 0x02, 0x56}
)

Functions

This section is empty.

Types

type Output

type Output struct {
	Data            []byte
	Events          tx.Events
	Transfers       tx.Transfers
	LeftOverGas     uint64
	RefundGas       uint64
	VMErr           error         // VMErr identify the execution result of the contract function, not evm function's err.
	ContractAddress *thor.Address // if create a new contract, or is nil.
}

Output output of clause execution.

type ResolvedTransaction

type ResolvedTransaction struct {
	Origin       thor.Address
	Delegator    *thor.Address
	IntrinsicGas uint64
	Clauses      []*tx.Clause
	// contains filtered or unexported fields
}

ResolvedTransaction resolve the transaction according to given state.

func ResolveTransaction

func ResolveTransaction(trx *tx.Transaction) (*ResolvedTransaction, error)

ResolveTransaction resolves the transaction and performs basic validation.

func (*ResolvedTransaction) BuyGas

func (r *ResolvedTransaction) BuyGas(state *state.State, blockTime uint64, baseFee *big.Int) (
	legacyTxBaseGasPrice *big.Int,
	effectiveGasPrice *big.Int,
	payer thor.Address,
	prepaid *big.Int,
	returnGas func(uint64) error,
	err error,
)

BuyGas consumes energy to buy gas, to prepare for execution.

func (*ResolvedTransaction) CommonTo

func (r *ResolvedTransaction) CommonTo() *thor.Address

CommonTo returns common 'To' field of clauses if any. Nil returned if no common 'To'.

func (*ResolvedTransaction) ToContext

func (r *ResolvedTransaction) ToContext(
	gasPrice *big.Int,
	gasPayer thor.Address,
	blockNumber uint32,
	getBlockID func(uint32) (thor.Bytes32, error),
) (*xenv.TransactionContext, error)

ToContext create a tx context object.

type Runtime

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

Runtime bases on EVM and VeChain Thor builtins.

func New

func New(
	chain *chain.Chain,
	state *state.State,
	ctx *xenv.BlockContext,
	forkConfig *thor.ForkConfig,
) *Runtime

New create a Runtime object.

func (*Runtime) Chain

func (rt *Runtime) Chain() *chain.Chain

func (*Runtime) Context

func (rt *Runtime) Context() *xenv.BlockContext

func (*Runtime) ExecuteTransaction

func (rt *Runtime) ExecuteTransaction(tx *tx.Transaction) (receipt *tx.Receipt, err error)

ExecuteTransaction executes a transaction. If some clause failed, receipt.Outputs will be nil and vmOutputs may shorter than clause count.

func (*Runtime) PrepareClause

func (rt *Runtime) PrepareClause(
	clause *tx.Clause,
	clauseIndex uint32,
	gas uint64,
	txCtx *xenv.TransactionContext,
) (exec func() (output *Output, interrupted bool, err error), interrupt func())

PrepareClause prepare to execute clause. It allows to interrupt execution.

func (*Runtime) PrepareTransaction

func (rt *Runtime) PrepareTransaction(trx *tx.Transaction) (*TransactionExecutor, error)

PrepareTransaction prepare to execute tx.

func (*Runtime) SetVMConfig

func (rt *Runtime) SetVMConfig(config vm.Config) *Runtime

SetVMConfig config VM. Returns this runtime.

func (*Runtime) State

func (rt *Runtime) State() *state.State

type TransactionExecutor

type TransactionExecutor struct {
	HasNextClause func() bool
	PrepareNext   func() (exec func() (interrupted bool, err error), interrupt func())
	Finalize      func() (*tx.Receipt, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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