Documentation ¶
Index ¶
- Constants
- func EncodeBinaryStackItem(item StackItem, w *io.BinWriter)
- func EnumeratorConcat(v *VM) error
- func EnumeratorCreate(v *VM) error
- func EnumeratorNext(v *VM) error
- func EnumeratorValue(v *VM) error
- func GetInteropID(parameter []byte) uint32
- func InteropNameToID(name []byte) uint32
- func IsMultiSigContract(script []byte) bool
- func IsSignatureContract(script []byte) bool
- func IsStandardContract(script []byte) bool
- func IteratorConcat(v *VM) error
- func IteratorCreate(v *VM) error
- func IteratorKey(v *VM) error
- func IteratorKeys(v *VM) error
- func IteratorValues(v *VM) error
- func RuntimeDeserialize(vm *VM) error
- func RuntimeSerialize(vm *VM) error
- func SerializeItem(item StackItem) ([]byte, error)
- type ArrayItem
- type BigIntegerItem
- type BoolItem
- type ByteArrayItem
- type Context
- func (c *Context) Copy() *Context
- func (c *Context) CurrInstr() (int, opcode.Opcode)
- func (c *Context) Dup() StackItem
- func (c *Context) IP() int
- func (c *Context) LenInstr() int
- func (c *Context) Next() (opcode.Opcode, []byte, error)
- func (c *Context) NextIP() int
- func (c *Context) Program() []byte
- func (c *Context) ScriptHash() util.Uint160
- func (c *Context) String() string
- func (c *Context) Value() interface{}
- type Element
- func (e *Element) Array() []StackItem
- func (e *Element) BigInt() *big.Int
- func (e *Element) Bool() bool
- func (e *Element) Bytes() []byte
- func (e *Element) Interop() *InteropItem
- func (e *Element) Item() StackItem
- func (e *Element) Next() *Element
- func (e *Element) Prev() *Element
- func (e *Element) TryBool() (bool, error)
- func (e *Element) Value() interface{}
- type InteropFunc
- type InteropFuncPrice
- type InteropGetterFunc
- type InteropItem
- type MapItem
- type Stack
- func (s *Stack) Back() *Element
- func (s *Stack) Clear()
- func (s *Stack) Dup(n int) *Element
- func (s *Stack) InsertAt(e *Element, n int) *Element
- func (s *Stack) Iter(f func(*Element))
- func (s *Stack) IterBack(f func(*Element))
- func (s *Stack) Len() int
- func (s *Stack) MarshalJSON() ([]byte, error)
- func (s *Stack) Peek(n int) *Element
- func (s *Stack) Pop() *Element
- func (s *Stack) Push(e *Element)
- func (s *Stack) PushVal(v interface{})
- func (s *Stack) Remove(e *Element) *Element
- func (s *Stack) RemoveAt(n int) *Element
- func (s *Stack) Roll(n int) error
- func (s *Stack) Swap(n1, n2 int) error
- func (s *Stack) Top() *Element
- type StackItem
- type State
- type StateMessage
- type StructItem
- type VM
- func (v *VM) AddBreakPoint(n int)
- func (v *VM) AddBreakPointRel(n int)
- func (v *VM) Astack() *Stack
- func (v *VM) AtBreakpoint() bool
- func (v *VM) Context() *Context
- func (v *VM) Estack() *Stack
- func (v *VM) GasConsumed() util.Fixed8
- func (v *VM) GetInteropByID(id uint32) *InteropFuncPrice
- func (v *VM) GetPublicKeys() map[string]*keys.PublicKey
- func (v *VM) HasFailed() bool
- func (v *VM) HasHalted() bool
- func (v *VM) HasStopped() bool
- func (v *VM) Istack() *Stack
- func (v *VM) Load(prog []byte)
- func (v *VM) LoadArgs(method []byte, args []StackItem)
- func (v *VM) LoadFile(path string) error
- func (v *VM) LoadScript(b []byte)
- func (v *VM) PopResult() interface{}
- func (v *VM) PrintOps()
- func (v *VM) Ready() bool
- func (v *VM) RegisterInteropGetter(f InteropGetterFunc)
- func (v *VM) Run() error
- func (v *VM) SetCheckedHash(h []byte)
- func (v *VM) SetGasLimit(max util.Fixed8)
- func (v *VM) SetPriceGetter(f func(*VM, opcode.Opcode, []byte) util.Fixed8)
- func (v *VM) SetPublicKeys(keys map[string]*keys.PublicKey)
- func (v *VM) SetScriptGetter(gs func(util.Uint160) []byte)
- func (v *VM) Stack(n string) string
- func (v *VM) State() string
- func (v *VM) Step() error
- func (v *VM) StepInto() error
- func (v *VM) StepOut() error
- func (v *VM) StepOver() error
Constants ¶
const ( // MaxArraySize is the maximum array size allowed in the VM. MaxArraySize = 1024 // MaxItemSize is the maximum item size allowed in the VM. MaxItemSize = 1024 * 1024 // MaxInvocationStackSize is the maximum size of an invocation stack. MaxInvocationStackSize = 1024 // MaxBigIntegerSizeBits is the maximum size of BigInt item in bits. MaxBigIntegerSizeBits = 32 * 8 // MaxStackSize is the maximum number of items allowed to be // on all stacks at once. MaxStackSize = 2 * 1024 )
Variables ¶
This section is empty.
Functions ¶
func EncodeBinaryStackItem ¶ added in v0.70.0
EncodeBinaryStackItem encodes given StackItem into the given BinWriter. It's similar to io.Serializable's EncodeBinary, but works with StackItem interface.
func EnumeratorConcat ¶ added in v0.71.0
EnumeratorConcat handles syscall Neo.Enumerator.Concat.
func EnumeratorCreate ¶ added in v0.71.0
EnumeratorCreate handles syscall Neo.Enumerator.Create.
func EnumeratorNext ¶ added in v0.71.0
EnumeratorNext handles syscall Neo.Enumerator.Next.
func EnumeratorValue ¶ added in v0.71.0
EnumeratorValue handles syscall Neo.Enumerator.Value.
func GetInteropID ¶ added in v0.72.0
GetInteropID converts instruction parameter to an interop ID.
func InteropNameToID ¶ added in v0.71.0
InteropNameToID returns an identificator of the method based on its name.
func IsMultiSigContract ¶ added in v0.51.0
IsMultiSigContract checks whether the passed script is a multi-signature contract.
func IsSignatureContract ¶ added in v0.51.0
IsSignatureContract checks whether the passed script is a signature check contract.
func IsStandardContract ¶ added in v0.51.0
IsStandardContract checks whether the passed script is a signature or multi-signature contract.
func IteratorConcat ¶ added in v0.71.0
IteratorConcat handles syscall Neo.Iterator.Concat.
func IteratorCreate ¶ added in v0.71.0
IteratorCreate handles syscall Neo.Iterator.Create.
func IteratorKey ¶ added in v0.71.0
IteratorKey handles syscall Neo.Iterator.Key.
func IteratorKeys ¶ added in v0.71.0
IteratorKeys handles syscall Neo.Iterator.Keys.
func IteratorValues ¶ added in v0.71.0
IteratorValues handles syscall Neo.Iterator.Values.
func RuntimeDeserialize ¶ added in v0.62.0
RuntimeDeserialize handles syscalls System.Runtime.Deserialize and Neo.Runtime.Deserialize.
func RuntimeSerialize ¶ added in v0.62.0
RuntimeSerialize handles syscalls System.Runtime.Serialize and Neo.Runtime.Serialize.
func SerializeItem ¶ added in v0.72.1
SerializeItem encodes given StackItem into the byte slice.
Types ¶
type ArrayItem ¶
type ArrayItem struct {
// contains filtered or unexported fields
}
ArrayItem represents a new ArrayItem object.
func NewArrayItem ¶
NewArrayItem returns a new ArrayItem object.
func (*ArrayItem) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
type BigIntegerItem ¶
type BigIntegerItem struct {
// contains filtered or unexported fields
}
BigIntegerItem represents a big integer on the stack.
func NewBigIntegerItem ¶
func NewBigIntegerItem(value int) *BigIntegerItem
NewBigIntegerItem returns an new BigIntegerItem object.
func (*BigIntegerItem) Bytes ¶ added in v0.62.0
func (i *BigIntegerItem) Bytes() []byte
Bytes converts i to a slice of bytes.
func (*BigIntegerItem) Dup ¶ added in v0.71.0
func (i *BigIntegerItem) Dup() StackItem
Dup implements StackItem interface.
func (*BigIntegerItem) MarshalJSON ¶
func (i *BigIntegerItem) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*BigIntegerItem) String ¶
func (i *BigIntegerItem) String() string
func (*BigIntegerItem) Value ¶
func (i *BigIntegerItem) Value() interface{}
Value implements StackItem interface.
type BoolItem ¶
type BoolItem struct {
// contains filtered or unexported fields
}
BoolItem represents a boolean StackItem.
func (*BoolItem) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
type ByteArrayItem ¶
type ByteArrayItem struct {
// contains filtered or unexported fields
}
ByteArrayItem represents a byte array on the stack.
func NewByteArrayItem ¶
func NewByteArrayItem(b []byte) *ByteArrayItem
NewByteArrayItem returns an new ByteArrayItem object.
func (*ByteArrayItem) Dup ¶ added in v0.71.0
func (i *ByteArrayItem) Dup() StackItem
Dup implements StackItem interface.
func (*ByteArrayItem) MarshalJSON ¶
func (i *ByteArrayItem) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*ByteArrayItem) String ¶
func (i *ByteArrayItem) String() string
func (*ByteArrayItem) Value ¶
func (i *ByteArrayItem) Value() interface{}
Value implements StackItem interface.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the current execution context of the VM.
func (*Context) IP ¶
IP returns the absolute instruction without taking 0 into account. If that program starts the ip = 0 but IP() will return 1, cause its the first instruction.
func (*Context) Next ¶
Next returns the next instruction to execute with its parameter if any. After its invocation the instruction pointer points to the instruction being returned.
func (*Context) ScriptHash ¶ added in v0.70.1
ScriptHash returns a hash of the script in the current context.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element represents an element in the double linked list (the stack), which will hold the underlying StackItem.
func NewElement ¶
func NewElement(v interface{}) *Element
NewElement returns a new Element object, with its underlying value inferred to the corresponding type.
func (*Element) Array ¶
Array attempts to get the underlying value of the element as an array of other items. Will panic if the item type is different which will be caught by the VM.
func (*Element) BigInt ¶
BigInt attempts to get the underlying value of the element as a big integer. Will panic if the assertion failed which will be caught by the VM.
func (*Element) Bool ¶
Bool attempts to get the underlying value of the element as a boolean. Will panic if the assertion failed which will be caught by the VM.
func (*Element) Bytes ¶
Bytes attempts to get the underlying value of the element as a byte array. Will panic if the assertion failed which will be caught by the VM.
func (*Element) Interop ¶ added in v0.71.0
func (e *Element) Interop() *InteropItem
Interop attempts to get the underlying value of the element as an interop item.
type InteropFuncPrice ¶ added in v0.51.0
type InteropFuncPrice struct { Func InteropFunc Price int }
InteropFuncPrice represents an interop function with a price.
type InteropGetterFunc ¶ added in v0.71.0
type InteropGetterFunc func(uint32) *InteropFuncPrice
InteropGetterFunc is a function that returns an interop function-price structure by the given interop ID.
type InteropItem ¶ added in v0.51.0
type InteropItem struct {
// contains filtered or unexported fields
}
InteropItem represents interop data on the stack.
func NewInteropItem ¶ added in v0.51.0
func NewInteropItem(value interface{}) *InteropItem
NewInteropItem returns new InteropItem object.
func NewMapIterator ¶ added in v0.71.0
func NewMapIterator(m map[interface{}]StackItem) *InteropItem
NewMapIterator returns new interop item containing iterator over m.
func (*InteropItem) Dup ¶ added in v0.71.0
func (i *InteropItem) Dup() StackItem
Dup implements StackItem interface.
func (*InteropItem) MarshalJSON ¶ added in v0.51.0
func (i *InteropItem) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*InteropItem) String ¶ added in v0.51.0
func (i *InteropItem) String() string
String implements stringer interface.
func (*InteropItem) Value ¶ added in v0.51.0
func (i *InteropItem) Value() interface{}
Value implements StackItem interface.
type MapItem ¶ added in v0.51.0
type MapItem struct {
// contains filtered or unexported fields
}
MapItem represents Map object.
func NewMapItem ¶ added in v0.51.0
func NewMapItem() *MapItem
NewMapItem returns new MapItem object.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack represents a Stack backed by a double linked list.
func (*Stack) Clear ¶
func (s *Stack) Clear()
Clear clears all elements on the stack and set its length to 0.
func (*Stack) Dup ¶
Dup duplicates and returns the element at position n. Dup is used for copying elements on to the top of its own stack.
s.Push(s.Peek(0)) // will result in unexpected behaviour. s.Push(s.Dup(0)) // is the correct approach.
func (*Stack) InsertAt ¶
InsertAt inserts the given item (n) deep on the stack. Be very careful using it and _always_ check both e and n before invocation as it will silently do wrong things otherwise.
func (*Stack) Iter ¶
Iter iterates over all the elements int the stack, starting from the top of the stack.
s.Iter(func(elem *Element) { // do something with the element. })
func (*Stack) IterBack ¶ added in v0.70.0
IterBack iterates over all the elements of the stack, starting from the bottom of the stack.
s.IterBack(func(elem *Element) { // do something with the element. })
func (*Stack) MarshalJSON ¶ added in v0.61.0
MarshalJSON implements JSON marshalling interface.
func (*Stack) Peek ¶
Peek returns the element (n) far in the stack beginning from the top of the stack.
n = 0 => will return the element on top of the stack.
func (*Stack) PushVal ¶
func (s *Stack) PushVal(v interface{})
PushVal pushes the given value on the stack. It will infer the underlying StackItem to its corresponding type.
func (*Stack) RemoveAt ¶
RemoveAt removes the element (n) deep on the stack beginning from the top of the stack.
func (*Stack) Roll ¶ added in v0.71.0
Roll brings an item with the given index to the top of the stack, moving all the other elements down accordingly. It does all of that without popping and pushing elements.
type StackItem ¶
type StackItem interface { fmt.Stringer Value() interface{} // Dup duplicates current StackItem. Dup() StackItem }
A StackItem represents the "real" value that is pushed on the stack.
func DecodeBinaryStackItem ¶ added in v0.70.0
DecodeBinaryStackItem decodes previously serialized StackItem from the given reader. It's similar to the io.Serializable's DecodeBinary(), but implemented as a function because StackItem itself is an interface. Caveat: always check reader's error value before using the returned StackItem.
func DeserializeItem ¶ added in v0.72.1
DeserializeItem decodes StackItem from the given byte slice.
type State ¶
type State uint8
State of the VM.
func StateFromString ¶
StateFromString converts string into the VM State.
func (State) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*State) UnmarshalJSON ¶
UnmarshalJSON implements the json.Marshaler interface.
type StateMessage ¶ added in v0.60.0
type StateMessage string
StateMessage is a vm state message which could be used as additional info for example by cli.
type StructItem ¶
type StructItem struct {
// contains filtered or unexported fields
}
StructItem represents a struct on the stack.
func NewStructItem ¶
func NewStructItem(items []StackItem) *StructItem
NewStructItem returns an new StructItem object.
func (*StructItem) Clone ¶ added in v0.51.0
func (i *StructItem) Clone() *StructItem
Clone returns a Struct with all Struct fields copied by value. Array fields are still copied by reference.
func (*StructItem) Dup ¶ added in v0.71.0
func (i *StructItem) Dup() StackItem
Dup implements StackItem interface.
func (*StructItem) String ¶
func (i *StructItem) String() string
func (*StructItem) Value ¶
func (i *StructItem) Value() interface{}
Value implements StackItem interface.
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM represents the virtual machine.
func (*VM) AddBreakPoint ¶
AddBreakPoint adds a breakpoint to the current context.
func (*VM) AddBreakPointRel ¶
AddBreakPointRel adds a breakpoint relative to the current instruction pointer.
func (*VM) AtBreakpoint ¶ added in v0.60.0
AtBreakpoint returns whether VM is at breakpoint.
func (*VM) Context ¶
Context returns the current executed context. Nil if there is no context, which implies no program is loaded.
func (*VM) GasConsumed ¶ added in v0.72.0
GasConsumed returns the amount of GAS consumed during execution.
func (*VM) GetInteropByID ¶ added in v0.72.0
func (v *VM) GetInteropByID(id uint32) *InteropFuncPrice
GetInteropByID returns interop function together with price. Registered callbacks are checked in LIFO order.
func (*VM) GetPublicKeys ¶ added in v0.70.1
GetPublicKeys returns internal key cache (note that it doesn't copy it).
func (*VM) HasFailed ¶ added in v0.51.0
HasFailed returns whether VM is in the failed state now. Usually used to check status after Run.
func (*VM) HasStopped ¶ added in v0.51.0
HasStopped returns whether VM is in Halt or Failed state.
func (*VM) LoadScript ¶
LoadScript loads a script from the internal script table. It will immediately push a new context created from this script to the invocation stack and starts executing it.
func (*VM) PopResult ¶
func (v *VM) PopResult() interface{}
PopResult is used to pop the first item of the evaluation stack. This allows us to test compiler and vm in a bi-directional way.
func (*VM) PrintOps ¶
func (v *VM) PrintOps()
PrintOps prints the opcodes of the current loaded program to stdout.
func (*VM) Ready ¶
Ready returns true if the VM ready to execute the loaded program. Will return false if no program is loaded.
func (*VM) RegisterInteropGetter ¶ added in v0.71.0
func (v *VM) RegisterInteropGetter(f InteropGetterFunc)
RegisterInteropGetter registers the given InteropGetterFunc into VM. There can be many interop getters and they're probed in LIFO order wrt their registration time.
func (*VM) SetCheckedHash ¶ added in v0.51.0
SetCheckedHash sets checked hash for CHECKSIG and CHECKMULTISIG instructions.
func (*VM) SetGasLimit ¶ added in v0.72.0
SetGasLimit sets maximum amount of gas which v can spent. If max <= 0, no limit is imposed.
func (*VM) SetPriceGetter ¶ added in v0.72.0
SetPriceGetter registers the given PriceGetterFunc in v. f accepts vm's Context, current instruction and instruction parameter.
func (*VM) SetPublicKeys ¶ added in v0.70.1
SetPublicKeys sets internal key cache to the specified value (note that it doesn't copy them).
func (*VM) SetScriptGetter ¶ added in v0.51.0
SetScriptGetter sets the script getter for CALL instructions.
func (*VM) StepInto ¶ added in v0.51.0
StepInto behaves the same as “step over” in case if the line does not contain a function. Otherwise the debugger will enter the called function and continue line-by-line debugging there.