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 ParseMultiSigContract(script []byte) ([][]byte, bool)
- func RuntimeDeserialize(vm *VM) error
- func RuntimeSerialize(vm *VM) error
- func SerializeItem(item StackItem) ([]byte, error)
- type ArrayItem
- func (i *ArrayItem) Dup() StackItem
- func (i *ArrayItem) Equals(s StackItem) bool
- func (i *ArrayItem) MarshalJSON() ([]byte, error)
- func (i *ArrayItem) String() string
- func (i *ArrayItem) ToContractParameter(seen map[StackItem]bool) smartcontract.Parameter
- func (i *ArrayItem) TryBytes() ([]byte, error)
- func (i *ArrayItem) Value() interface{}
- type BigIntegerItem
- func (i *BigIntegerItem) Bytes() []byte
- func (i *BigIntegerItem) Dup() StackItem
- func (i *BigIntegerItem) Equals(s StackItem) bool
- func (i *BigIntegerItem) MarshalJSON() ([]byte, error)
- func (i *BigIntegerItem) String() string
- func (i *BigIntegerItem) ToContractParameter(map[StackItem]bool) smartcontract.Parameter
- func (i *BigIntegerItem) TryBytes() ([]byte, error)
- func (i *BigIntegerItem) Value() interface{}
- type BoolItem
- func (i *BoolItem) Bytes() []byte
- func (i *BoolItem) Dup() StackItem
- func (i *BoolItem) Equals(s StackItem) bool
- func (i *BoolItem) MarshalJSON() ([]byte, error)
- func (i *BoolItem) String() string
- func (i *BoolItem) ToContractParameter(map[StackItem]bool) smartcontract.Parameter
- func (i *BoolItem) TryBytes() ([]byte, error)
- func (i *BoolItem) Value() interface{}
- type ByteArrayItem
- func (i *ByteArrayItem) Dup() StackItem
- func (i *ByteArrayItem) Equals(s StackItem) bool
- func (i *ByteArrayItem) MarshalJSON() ([]byte, error)
- func (i *ByteArrayItem) String() string
- func (i *ByteArrayItem) ToContractParameter(map[StackItem]bool) smartcontract.Parameter
- func (i *ByteArrayItem) TryBytes() ([]byte, error)
- func (i *ByteArrayItem) Value() interface{}
- type Context
- func (c *Context) Copy() *Context
- func (c *Context) CurrInstr() (int, opcode.Opcode)
- func (c *Context) Dup() StackItem
- func (c *Context) Equals(s StackItem) bool
- 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) ToContractParameter(map[StackItem]bool) smartcontract.Parameter
- func (c *Context) TryBytes() ([]byte, error)
- 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
- func (i *InteropItem) Dup() StackItem
- func (i *InteropItem) Equals(s StackItem) bool
- func (i *InteropItem) MarshalJSON() ([]byte, error)
- func (i *InteropItem) String() string
- func (i *InteropItem) ToContractParameter(map[StackItem]bool) smartcontract.Parameter
- func (i *InteropItem) TryBytes() ([]byte, error)
- func (i *InteropItem) Value() interface{}
- type MapItem
- func (i *MapItem) Add(key, value StackItem)
- func (i *MapItem) Dup() StackItem
- func (i *MapItem) Equals(s StackItem) bool
- func (i *MapItem) Has(key StackItem) (ok bool)
- func (i *MapItem) String() string
- func (i *MapItem) ToContractParameter(seen map[StackItem]bool) smartcontract.Parameter
- func (i *MapItem) TryBytes() ([]byte, error)
- func (i *MapItem) Value() interface{}
- 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) ToContractParameters() []smartcontract.Parameter
- func (s *Stack) Top() *Element
- type StackItem
- type State
- type StateMessage
- type StructItem
- func (i *StructItem) Clone() *StructItem
- func (i *StructItem) Dup() StackItem
- func (i *StructItem) Equals(s StackItem) bool
- func (i *StructItem) String() string
- func (i *StructItem) ToContractParameter(seen map[StackItem]bool) smartcontract.Parameter
- func (i *StructItem) TryBytes() ([]byte, error)
- func (i *StructItem) Value() interface{}
- 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, bool))
- 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 ¶
EncodeBinaryStackItem encodes given StackItem into the given BinWriter. It's similar to io.Serializable's EncodeBinary, but works with StackItem interface.
func EnumeratorConcat ¶
EnumeratorConcat handles syscall Neo.Enumerator.Concat.
func EnumeratorCreate ¶
EnumeratorCreate handles syscall Neo.Enumerator.Create.
func EnumeratorNext ¶
EnumeratorNext handles syscall Neo.Enumerator.Next.
func EnumeratorValue ¶
EnumeratorValue handles syscall Neo.Enumerator.Value.
func GetInteropID ¶
GetInteropID converts instruction parameter to an interop ID.
func InteropNameToID ¶
InteropNameToID returns an identificator of the method based on its name.
func IsMultiSigContract ¶
IsMultiSigContract checks whether the passed script is a multi-signature contract.
func IsSignatureContract ¶
IsSignatureContract checks whether the passed script is a signature check contract.
func IsStandardContract ¶
IsStandardContract checks whether the passed script is a signature or multi-signature contract.
func IteratorConcat ¶
IteratorConcat handles syscall Neo.Iterator.Concat.
func IteratorCreate ¶
IteratorCreate handles syscall Neo.Iterator.Create.
func IteratorValues ¶
IteratorValues handles syscall Neo.Iterator.Values.
func ParseMultiSigContract ¶
ParseMultiSigContract returns list of public keys from the verification script of the contract.
func RuntimeDeserialize ¶
RuntimeDeserialize handles syscalls System.Runtime.Deserialize and Neo.Runtime.Deserialize.
func RuntimeSerialize ¶
RuntimeSerialize handles syscalls System.Runtime.Serialize and Neo.Runtime.Serialize.
func SerializeItem ¶
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.
func (*ArrayItem) ToContractParameter ¶
func (i *ArrayItem) ToContractParameter(seen map[StackItem]bool) smartcontract.Parameter
ToContractParameter implements StackItem 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 ¶
func (i *BigIntegerItem) Bytes() []byte
Bytes converts i to a slice of bytes.
func (*BigIntegerItem) Dup ¶
func (i *BigIntegerItem) Dup() StackItem
Dup implements StackItem interface.
func (*BigIntegerItem) Equals ¶
func (i *BigIntegerItem) Equals(s StackItem) bool
Equals 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) ToContractParameter ¶
func (i *BigIntegerItem) ToContractParameter(map[StackItem]bool) smartcontract.Parameter
ToContractParameter implements StackItem interface.
func (*BigIntegerItem) TryBytes ¶
func (i *BigIntegerItem) TryBytes() ([]byte, error)
TryBytes implements StackItem interface.
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.
func (*BoolItem) ToContractParameter ¶
func (i *BoolItem) ToContractParameter(map[StackItem]bool) smartcontract.Parameter
ToContractParameter implements StackItem 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 ¶
func (i *ByteArrayItem) Dup() StackItem
Dup implements StackItem interface.
func (*ByteArrayItem) Equals ¶
func (i *ByteArrayItem) Equals(s StackItem) bool
Equals 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) ToContractParameter ¶
func (i *ByteArrayItem) ToContractParameter(map[StackItem]bool) smartcontract.Parameter
ToContractParameter implements StackItem interface.
func (*ByteArrayItem) TryBytes ¶
func (i *ByteArrayItem) TryBytes() ([]byte, error)
TryBytes implements StackItem interface.
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 ¶
ScriptHash returns a hash of the script in the current context.
func (*Context) ToContractParameter ¶
func (c *Context) ToContractParameter(map[StackItem]bool) smartcontract.Parameter
ToContractParameter implements StackItem interface.
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 ¶
func (e *Element) Interop() *InteropItem
Interop attempts to get the underlying value of the element as an interop item.
type InteropFuncPrice ¶
type InteropFuncPrice struct { Func InteropFunc Price int }
InteropFuncPrice represents an interop function with a price.
type InteropGetterFunc ¶
type InteropGetterFunc func(uint32) *InteropFuncPrice
InteropGetterFunc is a function that returns an interop function-price structure by the given interop ID.
type InteropItem ¶
type InteropItem struct {
// contains filtered or unexported fields
}
InteropItem represents interop data on the stack.
func NewInteropItem ¶
func NewInteropItem(value interface{}) *InteropItem
NewInteropItem returns new InteropItem object.
func NewMapIterator ¶
func NewMapIterator(m map[interface{}]StackItem) *InteropItem
NewMapIterator returns new interop item containing iterator over m.
func (*InteropItem) Equals ¶
func (i *InteropItem) Equals(s StackItem) bool
Equals implements StackItem interface.
func (*InteropItem) MarshalJSON ¶
func (i *InteropItem) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*InteropItem) String ¶
func (i *InteropItem) String() string
String implements stringer interface.
func (*InteropItem) ToContractParameter ¶
func (i *InteropItem) ToContractParameter(map[StackItem]bool) smartcontract.Parameter
ToContractParameter implements StackItem interface.
func (*InteropItem) TryBytes ¶
func (i *InteropItem) TryBytes() ([]byte, error)
TryBytes implements StackItem interface.
func (*InteropItem) Value ¶
func (i *InteropItem) Value() interface{}
Value implements StackItem interface.
type MapItem ¶
type MapItem struct {
// contains filtered or unexported fields
}
MapItem represents Map object.
func (*MapItem) ToContractParameter ¶
func (i *MapItem) ToContractParameter(seen map[StackItem]bool) smartcontract.Parameter
ToContractParameter implements StackItem interface.
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 ¶
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 ¶
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 ¶
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.
func (*Stack) ToContractParameters ¶
func (s *Stack) ToContractParameters() []smartcontract.Parameter
ToContractParameters converts Stack to slice of smartcontract.Parameter.
type StackItem ¶
type StackItem interface { fmt.Stringer Value() interface{} // Dup duplicates current StackItem. Dup() StackItem // TryBytes converts StackItem to a byte slice. TryBytes() ([]byte, error) // Equals checks if 2 StackItems are equal. Equals(s StackItem) bool // ToContractParameter converts StackItem to smartcontract.Parameter ToContractParameter(map[StackItem]bool) smartcontract.Parameter }
A StackItem represents the "real" value that is pushed on the stack.
func DecodeBinaryStackItem ¶
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 ¶
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 ¶
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 ¶
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) Equals ¶
func (i *StructItem) Equals(s StackItem) bool
Equals implements StackItem interface.
func (*StructItem) String ¶
func (i *StructItem) String() string
func (*StructItem) ToContractParameter ¶
func (i *StructItem) ToContractParameter(seen map[StackItem]bool) smartcontract.Parameter
ToContractParameter implements StackItem interface.
func (*StructItem) TryBytes ¶
func (i *StructItem) TryBytes() ([]byte, error)
TryBytes implements StackItem interface.
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 ¶
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 ¶
GasConsumed returns the amount of GAS consumed during execution.
func (*VM) GetInteropByID ¶
func (v *VM) GetInteropByID(id uint32) *InteropFuncPrice
GetInteropByID returns interop function together with price. Registered callbacks are checked in LIFO order.
func (*VM) GetPublicKeys ¶
GetPublicKeys returns internal key cache (note that it doesn't copy it).
func (*VM) HasFailed ¶
HasFailed returns whether VM is in the failed state now. Usually used to check status after Run.
func (*VM) HasStopped ¶
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 ¶
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 ¶
SetCheckedHash sets checked hash for CHECKSIG and CHECKMULTISIG instructions.
func (*VM) SetGasLimit ¶
SetGasLimit sets maximum amount of gas which v can spent. If max <= 0, no limit is imposed.
func (*VM) SetPriceGetter ¶
SetPriceGetter registers the given PriceGetterFunc in v. f accepts vm's Context, current instruction and instruction parameter.
func (*VM) SetPublicKeys ¶
SetPublicKeys sets internal key cache to the specified value (note that it doesn't copy them).
func (*VM) SetScriptGetter ¶
SetScriptGetter sets the script getter for CALL instructions.
func (*VM) StepInto ¶
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.