Documentation
¶
Index ¶
- Constants
- func EncodeBinaryStackItem(item Item, w *io.BinWriter)
- func EncodeBinaryStackItemAppExec(item Item, w *io.BinWriter)
- func IsValidMapKey(key Item) error
- func SerializeItem(item Item) ([]byte, error)
- func ToJSON(item Item) ([]byte, error)
- func ToJSONWithTypes(item Item) ([]byte, error)
- func ToString(item Item) (string, error)
- type Array
- func (i *Array) Append(item Item)
- 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) TryBool() (bool, error)
- 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) 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) TryBool() (bool, error)
- 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) 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) TryBool() (bool, error)
- 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) 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) TryBool() (bool, error)
- 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) 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) TryBool() (bool, error)
- 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) 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) TryBool() (bool, error)
- 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
- func DecodeBinaryStackItem(r *io.BinReader) Item
- func DecodeBinaryStackItemAppExec(r *io.BinReader) Item
- func DeepCopy(item Item) Item
- func DeserializeItem(data []byte) (Item, error)
- func FromJSON(data []byte) (Item, error)
- func FromJSONWithTypes(data []byte) (Item, error)
- func Make(v interface{}) Item
- type Map
- func (i *Map) Add(key, value Item)
- 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) TryBool() (bool, error)
- 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) 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) TryBool() (bool, error)
- 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) 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) TryBool() (bool, error)
- 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) 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) TryBool() (bool, error)
- 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 ( // MaxBigIntegerSizeBits is the maximum size of BigInt item in bits. MaxBigIntegerSizeBits = 32 * 8 // MaxArraySize is the maximum array size allowed in the VM. MaxArraySize = 1024 // MaxSize is the maximum item size allowed in the VM. MaxSize = 1024 * 1024 // MaxByteArrayComparableSize is the maximum allowed length of ByteArray for Equals method. // It is set to be the maximum uint16 value. MaxByteArrayComparableSize = math.MaxUint16 // MaxKeySize is the maximum size of map key. MaxKeySize = 64 )
const MaxAllowedInteger = 2<<53 - 1
MaxAllowedInteger is the maximum integer allowed to be encoded.
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 EncodeBinaryStackItemAppExec ¶ added in v0.92.0
EncodeBinaryStackItemAppExec encodes given Item into the given BinWriter. It's similar to EncodeBinaryStackItem but allows to encode interop (only type, value is lost).
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.
func ToJSON ¶
ToJSON encodes Item to JSON. It behaves as following:
ByteArray -> base64 string BigInteger -> number Bool -> bool Null -> null Array, Struct -> array Map -> map with keys as UTF-8 bytes
func ToJSONWithTypes ¶ added in v0.91.0
ToJSONWithTypes serializes any stackitem to JSON in a lossless way.
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) TryBool ¶ added in v0.92.0
func (i *BigInteger) TryBool() (bool, error)
TryBool implements Item interface.
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 // TryBool converts Item to a boolean value. TryBool() (bool, error) // TryBytes converts Item to a byte slice. If the underlying type is a // byte slice, it's returned as is without copying. 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 DecodeBinaryStackItemAppExec ¶ added in v0.92.0
DecodeBinaryStackItemAppExec is similar to DecodeBinaryStackItem but allows Interop values to be present.
func DeepCopy ¶ added in v0.91.0
DeepCopy returns new deep copy of the provided item. Values of Interop items are not deeply copied. It does preserve duplicates only for non-primitive types.
func DeserializeItem ¶
DeserializeItem decodes Item from the given byte slice.
func FromJSON ¶
FromJSON decodes Item from JSON. It behaves as following:
string -> ByteArray from base64 number -> BigInteger bool -> Bool null -> Null array -> Array map -> Map, keys are UTF-8
func FromJSONWithTypes ¶ added in v0.91.0
FromJSONWithTypes deserializes an item from typed-json representation.
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 NewPointerWithHash ¶ added in v0.92.0
NewPointerWithHash returns new pointer on the specified position of the specified script. It differs from NewPointer in that the script hash is being passed explicitly to save on hash calculcation. This hash is then being used for pointer comparisons.
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 InvalidT Type = 0xFF )
This block defines all known stack item types.
func FromString ¶ added in v0.91.0
FromString returns stackitem type from string.