Documentation
¶
Overview ¶
Package runopts provides configuration options for specops.Code.Run().
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultContractAddress ¶
DefaultContractAddress returns the default address used as [Contract.Address].
func DefaultFromAddress ¶
DefaultFromAddress returns the default address from which the contract is called.
Types ¶
type Captured ¶
type Captured[T any] struct { Val T // contains filtered or unexported fields }
A Captured value is an Option that stores part of the Configuration for later inspection. After Run() and similar functions return, the Val field will be populated.
A set of constructors is provided for commonly captured values.
Example ¶
const ( slot = 42 value = 314159 ) code := Code{ Fn(SSTORE, PUSH(slot), PUSH(value)), } // All runopts.Captured[T] values are passed to Run() to be populated, after // which, their Val fields can be used. db := runopts.CaptureStateDB() if _, err := code.Run(nil, db); err != nil { log.Fatal(err) } got := db.Val.GetState( runopts.DefaultContractAddress(), common.BigToHash(big.NewInt(slot)), ) fmt.Println(new(uint256.Int).SetBytes(got[:]))
Output: 314159
func Capture ¶
func Capture[T any](fn func(*Configuration) T) *Captured[T]
Capture returns a Captured value that is valid _after_ being passed as an option to Run(). [fn] must extract and return the value to capture.
func CaptureBytecode ¶
CaptureBytecode captures a copy of the compiled bytecode.
func CaptureConfig ¶
func CaptureConfig() *Captured[*Configuration]
CaptureConfig captures the entire Configuration.
func CaptureStateDB ¶
CaptureStateDB captures the vm.StateDB used for storage of accounts (i.e. balances, code, storage, etc).
type Configuration ¶
type Configuration struct { Contract *Contract From common.Address Value *uint256.Int NoErrorOnRevert bool // see Run() re errors // vm.NewEVM() BlockCtx vm.BlockContext TxCtx vm.TxContext StateDB vm.StateDB ChainConfig *params.ChainConfig VMConfig vm.Config }
A Configuration carries all values that can be modified to configure a call to specops.Code.Run(). It is intially set by Run() and then passed to all Options to be modified.
The vm.StateDB will be initialised to an empty but valid database that MAY be populated by an Option or even entirely replaced. The code for [Contract.Address] MUST NOT be prepopulated but storage and balance MAY be altered.
type Contract ¶
Contract defines how the compiled SpecOps bytecode will be "deployed" before being run. DefaultContractAddress returns the default address with which Contracts are constructed.
func NewContract ¶
NewContract returns a new Contract with the specified bytecode.
type Func ¶
type Func func(*Configuration) error
A Func converts a function into an Option by calling itself as Apply().
type Option ¶
type Option interface {
Apply(*Configuration) error
}
An Option modifies a Configuration.
func ContractAddress ¶
ContractAddress sets the address to which the compiled bytecode will be "deployed" before being run.
func From ¶
From sets the address calling the contract; i.e. the value pushed to the stack by the CALLER opcode.
func GenesisAlloc ¶
func GenesisAlloc(alloc types.GenesisAlloc) Option
GenesisAlloc preloads the state with code, storage values, and balances described in the alloc. This can be used for testing interaction with other contracts.
func NoErrorOnRevert ¶
func NoErrorOnRevert() Option
NoErrorOnRevert signals to Run() that it must return a nil error if the Code compiled and was successfully executed but the execution itself reverted. The error will still be available in the vm.ExecutionResult.
func Value ¶
Value sets the value sent when calling the contract; i.e. the value pushed to the stack by the CALLVALUE opcode.
func WithDebugger ¶
WithDebugger returns an Option that sets Configuration.VMConfig.Tracer to dbg.Tracer(), intercepting every opcode execution. See evmdebug for details.
func WithNewDebugger ¶
WithNewDebugger is a convenience function for constructing a new Debugger, passing it to WithDebugger(), and returning both the Debugger and the Option.