emulator

package
v0.0.0-...-ac32242 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Emulator

type Emulator struct {
	ErrorCount uint
	// contains filtered or unexported fields
}

Emulator is a Solidity emulator.

func New

func New(source *sources.Source) *Emulator

New returns a new instance of Emulator.

func (*Emulator) AddFunctionDefinition

func (e *Emulator) AddFunctionDefinition(function *sources.Function)

AddFunctionDefinition adds a function definition.

func (*Emulator) AddStructDeclaration

func (e *Emulator) AddStructDeclaration(_struct *sources.Struct)

AddStructDeclaration adds a struct declaration.

func (*Emulator) Emit

func (e *Emulator) Emit(subject string, event *Event)

Emit emits an event.

func (*Emulator) Eval

func (e *Emulator) Eval(expr *sources.Expression) []*Value

Eval evaluates an expression, returning a new expression.

func (*Emulator) FindVariable

func (e *Emulator) FindVariable(name string) *Variable

FindVariable attempts to find and return a variable.

func (*Emulator) MustFindVariable

func (e *Emulator) MustFindVariable(name string) *Variable

MustFindVariable must return a variable, otherwise the emulator panics.

func (*Emulator) MustResolveIdentifier

func (e *Emulator) MustResolveIdentifier(name string) *Value

MustResolveIdentifier must return a value, otherwise the emulator panics.

func (*Emulator) MustSetVariable

func (e *Emulator) MustSetVariable(name string, value *Value)

MustSetVariable must find and set a variable, otherwise the emulator panics.

func (Emulator) OnEvent

func (e Emulator) OnEvent(subject string, handler func(*Event))

OnEvent adds a function that will be executed on an event.

func (*Emulator) Recover

func (e *Emulator) Recover(tokens sources.Tokens)

Recover acts as a recovery strategy when the emulator panics.

func (*Emulator) Reset

func (e *Emulator) Reset()

Reset resets the emulator's state.

func (*Emulator) ResetFunctions

func (e *Emulator) ResetFunctions()

ResetFunctions resets function definitions.

func (*Emulator) ResetStack

func (e *Emulator) ResetStack()

ResetMemory resets the stack.

func (*Emulator) ResetStorage

func (e *Emulator) ResetStorage()

ResetStorage resets the storage.

func (*Emulator) ResetStructs

func (e *Emulator) ResetStructs()

ResetStructs resets struct declarations.

func (*Emulator) ResolveIdentifier

func (e *Emulator) ResolveIdentifier(name string) *Value

ResolveIdentifier attempts to resolve an identifier's value.

func (*Emulator) Run

func (e *Emulator) Run()

Run runs the emulator.

func (*Emulator) SetVariable

func (e *Emulator) SetVariable(variable *Variable)

SetVariable sets a new variable.

type Event

type Event struct {
	Source                *sources.Source
	Stack                 *Stack
	Contract              *sources.Contract
	Function              *sources.Function
	CallerFunction        *sources.Function
	Expression            *sources.Expression
	Expressions           []*sources.Expression
	FunctionCallArguments *sources.FunctionCallArguments
}

Event is an event emitted by the emulator.

type Stack

type Stack []*StackFrame

func (*Stack) CurrentFrame

func (s *Stack) CurrentFrame() *StackFrame

func (*Stack) Pop

func (s *Stack) Pop() *StackFrame

func (*Stack) Push

func (s *Stack) Push(contract *sources.Contract, function *sources.Function) *StackFrame

type StackFrame

type StackFrame struct {
	Contract  *sources.Contract
	Function  *sources.Function
	Memory    []*Variable
	MemoryMap map[string]*Variable
}

type Value

type Value struct {
	Solved     bool
	Expression *sources.Expression
}

Value represents a value.

func NewValue

func NewValue() *Value

NewValue returns a new instance of Value.

func (Value) InferredTypeName

func (val Value) InferredTypeName() *sources.TypeName

InferredTypeName returns the inferred type name of a value.

func (*Value) String

func (val *Value) String() string

type Variable

type Variable struct {
	Identifier      string
	TypeName        *sources.TypeName
	StorageLocation string
	Value           *Value
}

Variable represents an emulated variable.

func NewVariable

func NewVariable(identifier string, typeName *sources.TypeName, storage string) *Variable

NewVariable returns a new instance of Variable.

func (*Variable) String

func (v *Variable) String() string

Jump to

Keyboard shortcuts

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