Documentation ¶
Index ¶
- Constants
- func CheckMultisigPar(v *VM, curve elliptic.Curve, h []byte, pkeys [][]byte, sigs [][]byte) bool
- 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 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 NewMapIterator(m *stackitem.Map) *stackitem.Interop
- func ParseMultiSigContract(script []byte) (int, [][]byte, bool)
- func RuntimeDeserialize(vm *VM) error
- func RuntimeSerialize(vm *VM) error
- type Context
- func (c *Context) Bool() bool
- func (c *Context) Convert(_ stackitem.Type) (stackitem.Item, error)
- func (c *Context) Copy() *Context
- func (c *Context) CurrInstr() (int, opcode.Opcode)
- func (c *Context) Dup() stackitem.Item
- func (c *Context) Equals(s stackitem.Item) bool
- func (c *Context) GetCallFlags() smartcontract.CallFlag
- 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) TryBytes() ([]byte, error)
- func (c *Context) TryInteger() (*big.Int, error)
- func (c *Context) Type() stackitem.Type
- func (c *Context) Value() interface{}
- type Element
- func (e *Element) Array() []stackitem.Item
- func (e *Element) BigInt() *big.Int
- func (e *Element) Bool() bool
- func (e *Element) Bytes() []byte
- func (e *Element) Interop() *stackitem.Interop
- func (e *Element) Item() stackitem.Item
- func (e *Element) Next() *Element
- func (e *Element) Prev() *Element
- func (e *Element) String() string
- func (e *Element) Value() interface{}
- type Slot
- 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) PopSigElements() ([][]byte, error)
- 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) ReverseTop(n int) error
- func (s *Stack) Roll(n int) error
- func (s *Stack) Swap(n1, n2 int) error
- func (s *Stack) ToArray() []stackitem.Item
- func (s *Stack) Top() *Element
- type State
- type StateMessage
- type SyscallHandler
- type VM
- func (v *VM) AddBreakPoint(n int)
- func (v *VM) AddBreakPointRel(n int)
- func (v *VM) AddGas(gas int64) bool
- func (v *VM) AtBreakpoint() bool
- func (v *VM) Call(ctx *Context, offset int)
- func (v *VM) Context() *Context
- func (v *VM) Estack() *Stack
- func (v *VM) GasConsumed() int64
- func (v *VM) GetCallingScriptHash() util.Uint160
- func (v *VM) GetCurrentScriptHash() util.Uint160
- func (v *VM) GetEntryScriptHash() util.Uint160
- 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) Jump(ctx *Context, offset int)
- func (v *VM) Load(prog []byte)
- func (v *VM) LoadArgs(method []byte, args []stackitem.Item)
- func (v *VM) LoadFile(path string) error
- func (v *VM) LoadScript(b []byte)
- func (v *VM) LoadScriptWithFlags(b []byte, f smartcontract.CallFlag)
- func (v *VM) LoadScriptWithHash(b []byte, hash util.Uint160, f smartcontract.CallFlag)
- func (v *VM) PopResult() interface{}
- func (v *VM) PrintOps()
- func (v *VM) PushContextScriptHash(n int) error
- func (v *VM) Ready() bool
- func (v *VM) Run() error
- func (v *VM) SetPriceGetter(f func(*VM, opcode.Opcode, []byte) int64)
- func (v *VM) SetPublicKeys(keys map[string]*keys.PublicKey)
- func (v *VM) Stack(n string) string
- func (v *VM) State() State
- func (v *VM) Step() error
- func (v *VM) StepInto() error
- func (v *VM) StepOut() error
- func (v *VM) StepOver() error
Constants ¶
const ( // MaxInvocationStackSize is the maximum size of an invocation stack. MaxInvocationStackSize = 1024 // 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 CheckMultisigPar ¶ added in v0.90.0
CheckMultisigPar checks if sigs contains sufficient valid signatures.
func EnumeratorConcat ¶
EnumeratorConcat handles syscall System.Enumerator.Concat.
func EnumeratorCreate ¶
EnumeratorCreate handles syscall System.Enumerator.Create.
func EnumeratorNext ¶
EnumeratorNext handles syscall System.Enumerator.Next.
func EnumeratorValue ¶
EnumeratorValue handles syscall System.Enumerator.Value.
func GetInteropID ¶
GetInteropID converts instruction parameter to an interop ID.
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 System.Iterator.Concat.
func IteratorCreate ¶
IteratorCreate handles syscall System.Iterator.Create.
func IteratorKeys ¶
IteratorKeys handles syscall System.Iterator.Keys.
func IteratorValues ¶
IteratorValues handles syscall System.Iterator.Values.
func NewMapIterator ¶
NewMapIterator returns new interop item containing iterator over m.
func ParseMultiSigContract ¶
ParseMultiSigContract returns number of signatures and list of public keys from the verification script of the contract.
func RuntimeDeserialize ¶
RuntimeDeserialize handles System.Binary.Deserialize syscall.
func RuntimeSerialize ¶
RuntimeSerialize handles System.Binary.Serialize syscall.
Types ¶
type Context ¶
type Context struct { // CheckReturn specifies if amount of return values needs to be checked. CheckReturn bool // contains filtered or unexported fields }
Context represents the current execution context of the VM.
func (*Context) GetCallFlags ¶ added in v0.90.0
func (c *Context) GetCallFlags() smartcontract.CallFlag
GetCallFlags returns calling flags context was created with.
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) TryInteger ¶ added in v0.90.0
TryInteger implements stackitem.Item 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.Item.
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) 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 ¶
Interop attempts to get the underlying value of the element as an interop item.
type Slot ¶ added in v0.90.0
type Slot struct {
// contains filtered or unexported fields
}
Slot is a fixed-size slice of stack items.
func (*Slot) Clear ¶ added in v0.91.0
func (s *Slot) Clear()
Clear removes all slot variables from reference counter.
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) PopSigElements ¶ added in v0.90.0
PopSigElements pops keys or signatures from the stack as needed for CHECKMULTISIG.
func (*Stack) PushVal ¶
func (s *Stack) PushVal(v interface{})
PushVal pushes the given value on the stack. It will infer the underlying Item 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) ReverseTop ¶ added in v0.90.0
ReverseTop reverses top n items 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.
type State ¶
type State uint8
State of the VM.
const ( // NoneState represents NONE VM state. NoneState State = 0 // HaltState represents HALT VM state. HaltState State = 1 << iota // FaultState represents FAULT VM state. FaultState // BreakState represents BREAK VM state. BreakState )
Available States.
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 SyscallHandler ¶ added in v0.91.0
SyscallHandler is a type for syscall handler.
type VM ¶
type VM struct { GasLimit int64 // SyscallHandler handles SYSCALL opcode. SyscallHandler func(v *VM, id uint32) error // contains filtered or unexported fields }
VM represents the virtual machine.
func NewWithTrigger ¶ added in v0.90.0
NewWithTrigger returns a new VM for executions triggered by t.
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) AddGas ¶ added in v0.90.0
AddGas consumes specified amount of gas. It returns true iff gas limit wasn't exceeded.
func (*VM) AtBreakpoint ¶
AtBreakpoint returns whether VM is at breakpoint.
func (*VM) Call ¶ added in v0.91.0
Call calls method by offset. It is similar to Jump but also pushes new context to the invocation state
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) GetCallingScriptHash ¶ added in v0.90.0
GetCallingScriptHash implements ScriptHashGetter interface
func (*VM) GetCurrentScriptHash ¶ added in v0.90.0
GetCurrentScriptHash implements ScriptHashGetter interface
func (*VM) GetEntryScriptHash ¶ added in v0.90.0
GetEntryScriptHash implements ScriptHashGetter interface
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) LoadFile ¶
LoadFile loads a program in NEF format from the given path, ready to execute it.
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) LoadScriptWithFlags ¶ added in v0.90.0
func (v *VM) LoadScriptWithFlags(b []byte, f smartcontract.CallFlag)
LoadScriptWithFlags loads script and sets call flag to f.
func (*VM) LoadScriptWithHash ¶ added in v0.90.0
LoadScriptWithHash if similar to the LoadScriptWithFlags method, but it also loads given script hash directly into the Context to avoid its recalculations. It's up to user of this function to make sure the script and hash match each other.
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) PushContextScriptHash ¶ added in v0.90.0
PushContextScriptHash pushes to evaluation stack the script hash of the invocation stack element number n.
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) 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) 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.