Documentation ¶
Index ¶
- Constants
- func EncodeBinaryStackItem(item Item, w *io.BinWriter)
- func IsValidMapKey(key Item) bool
- func SerializeItem(item Item) ([]byte, error)
- func ToJSON(item Item) ([]byte, error)
- type Array
- func (i *Array) Append(item Item)
- func (i *Array) Bool() bool
- func (i *Array) Clear()
- func (i *Array) Convert(typ Type) (Item, error)
- func (i *Array) Dup() Item
- func (i *Array) Equals(s Item) bool
- func (i *Array) Len() int
- func (i *Array) MarshalJSON() ([]byte, error)
- func (i *Array) Remove(pos int)
- func (i *Array) String() string
- func (i *Array) TryBytes() ([]byte, error)
- func (i *Array) TryInteger() (*big.Int, error)
- func (i *Array) Type() Type
- func (i *Array) Value() interface{}
- type BigInteger
- func (i *BigInteger) Bool() bool
- func (i *BigInteger) Bytes() []byte
- func (i *BigInteger) Convert(typ Type) (Item, error)
- func (i *BigInteger) Dup() Item
- func (i *BigInteger) Equals(s Item) bool
- func (i *BigInteger) MarshalJSON() ([]byte, error)
- func (i *BigInteger) String() string
- func (i *BigInteger) TryBytes() ([]byte, error)
- func (i *BigInteger) TryInteger() (*big.Int, error)
- func (i *BigInteger) Type() Type
- func (i *BigInteger) Value() interface{}
- type Bool
- func (i *Bool) Bool() bool
- func (i *Bool) Bytes() []byte
- func (i *Bool) Convert(typ Type) (Item, error)
- func (i *Bool) Dup() Item
- func (i *Bool) Equals(s Item) bool
- func (i *Bool) MarshalJSON() ([]byte, error)
- func (i *Bool) String() string
- func (i *Bool) TryBytes() ([]byte, error)
- func (i *Bool) TryInteger() (*big.Int, error)
- func (i *Bool) Type() Type
- func (i *Bool) Value() interface{}
- type Buffer
- func (i *Buffer) Bool() bool
- func (i *Buffer) Convert(typ Type) (Item, error)
- func (i *Buffer) Dup() Item
- func (i *Buffer) Equals(s Item) bool
- func (i *Buffer) Len() int
- func (i *Buffer) MarshalJSON() ([]byte, error)
- func (i *Buffer) String() string
- func (i *Buffer) TryBytes() ([]byte, error)
- func (i *Buffer) TryInteger() (*big.Int, error)
- func (i *Buffer) Type() Type
- func (i *Buffer) Value() interface{}
- type ByteArray
- func (i *ByteArray) Bool() bool
- func (i *ByteArray) Convert(typ Type) (Item, error)
- func (i *ByteArray) Dup() Item
- func (i *ByteArray) Equals(s Item) bool
- func (i *ByteArray) MarshalJSON() ([]byte, error)
- func (i *ByteArray) String() string
- func (i *ByteArray) TryBytes() ([]byte, error)
- func (i *ByteArray) TryInteger() (*big.Int, error)
- func (i *ByteArray) Type() Type
- func (i *ByteArray) Value() interface{}
- type Interop
- func (i *Interop) Bool() bool
- func (i *Interop) Convert(typ Type) (Item, error)
- func (i *Interop) Dup() Item
- func (i *Interop) Equals(s Item) bool
- func (i *Interop) MarshalJSON() ([]byte, error)
- func (i *Interop) String() string
- func (i *Interop) TryBytes() ([]byte, error)
- func (i *Interop) TryInteger() (*big.Int, error)
- func (i *Interop) Type() Type
- func (i *Interop) Value() interface{}
- type Item
- type Map
- func (i *Map) Add(key, value Item)
- func (i *Map) Bool() bool
- func (i *Map) Clear()
- func (i *Map) Convert(typ Type) (Item, error)
- func (i *Map) Drop(index int)
- func (i *Map) Dup() Item
- func (i *Map) Equals(s Item) bool
- func (i *Map) Has(key Item) bool
- func (i *Map) Index(key Item) int
- func (i *Map) Len() int
- func (i *Map) String() string
- func (i *Map) TryBytes() ([]byte, error)
- func (i *Map) TryInteger() (*big.Int, error)
- func (i *Map) Type() Type
- func (i *Map) Value() interface{}
- type MapElement
- type Null
- func (i Null) Bool() bool
- func (i Null) Convert(typ Type) (Item, error)
- func (i Null) Dup() Item
- func (i Null) Equals(s Item) bool
- func (i Null) String() string
- func (i Null) TryBytes() ([]byte, error)
- func (i Null) TryInteger() (*big.Int, error)
- func (i Null) Type() Type
- func (i Null) Value() interface{}
- type Pointer
- func (p *Pointer) Bool() bool
- func (p *Pointer) Convert(typ Type) (Item, error)
- func (p *Pointer) Dup() Item
- func (p *Pointer) Equals(s Item) bool
- func (p *Pointer) Position() int
- func (p *Pointer) ScriptHash() util.Uint160
- func (p *Pointer) String() string
- func (p *Pointer) TryBytes() ([]byte, error)
- func (p *Pointer) TryInteger() (*big.Int, error)
- func (p *Pointer) Type() Type
- func (p *Pointer) Value() interface{}
- type Struct
- func (i *Struct) Append(item Item)
- func (i *Struct) Bool() bool
- func (i *Struct) Clear()
- func (i *Struct) Clone() *Struct
- func (i *Struct) Convert(typ Type) (Item, error)
- func (i *Struct) Dup() Item
- func (i *Struct) Equals(s Item) bool
- func (i *Struct) Len() int
- func (i *Struct) Remove(pos int)
- func (i *Struct) String() string
- func (i *Struct) TryBytes() ([]byte, error)
- func (i *Struct) TryInteger() (*big.Int, error)
- func (i *Struct) Type() Type
- func (i *Struct) Value() interface{}
- type Type
Constants ¶
const MaxAllowedInteger = 2<<53 - 1
MaxAllowedInteger is the maximum integer allowed to be encoded.
const MaxArraySize = 1024
MaxArraySize is the maximum array size allowed in the VM.
const MaxBigIntegerSizeBits = 32 * 8
MaxBigIntegerSizeBits is the maximum size of BigInt item in bits.
const MaxSize = 1024 * 1024
MaxSize is the maximum item size allowed in the VM.
Variables ¶
This section is empty.
Functions ¶
func EncodeBinaryStackItem ¶
EncodeBinaryStackItem encodes given Item into the given BinWriter. It's similar to io.Serializable's EncodeBinary, but works with Item interface.
func IsValidMapKey ¶
IsValidMapKey checks whether it's possible to use given Item as a Map key.
func SerializeItem ¶
SerializeItem encodes given Item into the byte slice.
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array represents a new Array object.
func (*Array) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Array) Remove ¶
Remove removes element at `pos` index from Array value. It will panics on bad index.
func (*Array) TryInteger ¶
TryInteger implements Item interface.
type BigInteger ¶
type BigInteger struct {
// contains filtered or unexported fields
}
BigInteger represents a big integer on the stack.
func NewBigInteger ¶
func NewBigInteger(value *big.Int) *BigInteger
NewBigInteger returns an new BigInteger object.
func (*BigInteger) Bytes ¶
func (i *BigInteger) Bytes() []byte
Bytes converts i to a slice of bytes.
func (*BigInteger) Convert ¶
func (i *BigInteger) Convert(typ Type) (Item, error)
Convert implements Item interface.
func (*BigInteger) Equals ¶
func (i *BigInteger) Equals(s Item) bool
Equals implements Item interface.
func (*BigInteger) MarshalJSON ¶
func (i *BigInteger) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*BigInteger) String ¶
func (i *BigInteger) String() string
func (*BigInteger) TryBytes ¶
func (i *BigInteger) TryBytes() ([]byte, error)
TryBytes implements Item interface.
func (*BigInteger) TryInteger ¶
func (i *BigInteger) TryInteger() (*big.Int, error)
TryInteger implements Item interface.
func (*BigInteger) Value ¶
func (i *BigInteger) Value() interface{}
Value implements Item interface.
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool represents a boolean Item.
func (*Bool) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Bool) TryInteger ¶
TryInteger implements Item interface.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer represents represents Buffer stack item.
func (*Buffer) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Buffer) TryInteger ¶
TryInteger implements Item interface.
type ByteArray ¶
type ByteArray struct {
// contains filtered or unexported fields
}
ByteArray represents a byte array on the stack.
func NewByteArray ¶
NewByteArray returns an new ByteArray object.
func (*ByteArray) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*ByteArray) TryInteger ¶
TryInteger implements Item interface.
type Interop ¶
type Interop struct {
// contains filtered or unexported fields
}
Interop represents interop data on the stack.
func NewInterop ¶
func NewInterop(value interface{}) *Interop
NewInterop returns new Interop object.
func (*Interop) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Interop) TryInteger ¶
TryInteger implements Item interface.
type Item ¶
type Item interface { fmt.Stringer Value() interface{} // Dup duplicates current Item. Dup() Item // Bool converts Item to a boolean value. Bool() bool // TryBytes converts Item to a byte slice. TryBytes() ([]byte, error) // TryInteger converts Item to an integer. TryInteger() (*big.Int, error) // Equals checks if 2 StackItems are equal. Equals(s Item) bool // Type returns stack item type. Type() Type // Convert converts Item to another type. Convert(Type) (Item, error) }
Item represents the "real" value that is pushed on the stack.
func DecodeBinaryStackItem ¶
DecodeBinaryStackItem decodes previously serialized Item from the given reader. It's similar to the io.Serializable's DecodeBinary(), but implemented as a function because Item itself is an interface. Caveat: always check reader's error value before using the returned Item.
func DeserializeItem ¶
DeserializeItem decodes Item from the given byte slice.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map represents Map object. It's ordered, so we use slice representation which should be fine for maps with less than 32 or so elements. Given that our VM has quite low limit of overall stack items, it should be good enough, but it can be extended with a real map for fast random access in the future if need be.
func NewMapWithValue ¶
func NewMapWithValue(value []MapElement) *Map
NewMapWithValue returns new Map object filled with specified value.
func (*Map) TryInteger ¶
TryInteger implements Item interface.
type MapElement ¶
MapElement is a key-value pair of StackItems.
type Null ¶
type Null struct{}
Null represents null on the stack.
func (Null) Dup ¶
Dup implements Item interface. There is no need to perform a real copy here, as Null has no internal state.
func (Null) TryInteger ¶
TryInteger implements Item interface.
type Pointer ¶
type Pointer struct {
// contains filtered or unexported fields
}
Pointer represents VM-level instruction pointer.
func NewPointer ¶
NewPointer returns new pointer on the specified position.
func (*Pointer) ScriptHash ¶
ScriptHash returns pointer item hash
func (*Pointer) TryInteger ¶
TryInteger implements Item interface.
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct represents a struct on the stack.
func (*Struct) Clone ¶
Clone returns a Struct with all Struct fields copied by value. Array fields are still copied by reference.
func (*Struct) Remove ¶
Remove removes element at `pos` index from Struct value. It will panics on bad index.
func (*Struct) TryInteger ¶
TryInteger implements Item interface.
type Type ¶
type Type byte
Type represents type of the stack item.
const ( AnyT Type = 0x00 PointerT Type = 0x10 BooleanT Type = 0x20 IntegerT Type = 0x21 ByteArrayT Type = 0x28 BufferT Type = 0x30 ArrayT Type = 0x40 StructT Type = 0x41 MapT Type = 0x48 InteropT Type = 0x60 )
This block defines all known stack item types.