stackitem

package
v0.106.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 17 Imported by: 53

Documentation

Index

Constants

View Source
const (
	// MaxBigIntegerSizeBits is the maximum size of a BigInt item in bits.
	MaxBigIntegerSizeBits = 32 * 8
	// MaxSize is the maximum item size allowed in the VM.
	MaxSize = math.MaxUint16 * 2
	// MaxComparableNumOfItems is the maximum number of items that can be compared for structs.
	MaxComparableNumOfItems = MaxDeserialized
	// MaxClonableNumOfItems is the maximum number of items that can be cloned in structs.
	MaxClonableNumOfItems = MaxDeserialized
	// MaxByteArrayComparableSize is the maximum allowed length of a ByteArray for Equals method.
	// It is set to be the maximum uint16 value + 1.
	MaxByteArrayComparableSize = math.MaxUint16 + 1
	// MaxKeySize is the maximum size of a map key.
	MaxKeySize = 64
)
View Source
const (
	// MaxIntegerPrec is the maximum precision allowed for big.Integer parsing.
	// It allows to properly parse integer numbers that our 256-bit VM is able to
	// handle.
	MaxIntegerPrec = 1<<8 + 1
	// CompatIntegerPrec is the maximum precision allowed for big.Integer parsing
	// by the C# node before the Basilisk hardfork. It doesn't allow to precisely
	// parse big numbers, see the https://github.com/neo-project/neo/issues/2879.
	CompatIntegerPrec = 53
)
View Source
const MaxAllowedInteger = 2<<53 - 1

MaxAllowedInteger is the maximum integer allowed to be encoded.

View Source
const MaxDeserialized = 2048

MaxDeserialized is the maximum number one deserialized item can contain (including itself).

View Source
const MaxJSONDepth = 10

MaxJSONDepth is the maximum allowed nesting level of an encoded/decoded JSON.

View Source
const MaxSerialized = MaxDeserialized

MaxSerialized is the maximum number one serialized item can contain (including itself).

Variables

View Source
var (
	// ErrInvalidConversion is returned upon an attempt to make an incorrect
	// conversion between item types.
	ErrInvalidConversion = errors.New("invalid conversion")

	// ErrTooBig is returned when an item exceeds some size constraints, like
	// the maximum allowed integer value of the number of elements in an array. It
	// can also be returned by serialization functions if the resulting
	// value exceeds MaxSize.
	ErrTooBig = errors.New("too big")
	// ErrReadOnly is returned on attempt to modify immutable stack item.
	ErrReadOnly = errors.New("item is read-only")
)
View Source
var ErrInvalidType = errors.New("invalid type")

ErrInvalidType is returned upon attempts to deserialize some unknown item type.

View Source
var ErrInvalidValue = errors.New("invalid value")

ErrInvalidValue is returned when an item value doesn't fit some constraints during serialization or deserialization.

View Source
var ErrRecursive = errors.New("recursive item")

ErrRecursive is returned upon an attempt to serialize some recursive stack item (like an array including an item with the reference to the same array).

View Source
var ErrTooDeep = errors.New("too deep")

ErrTooDeep is returned when JSON encoder/decoder goes beyond MaxJSONDepth in its processing.

View Source
var ErrUnserializable = errors.New("unserializable")

ErrUnserializable is returned upon an attempt to serialize some item that can't be serialized (like Interop item or Pointer).

Functions

func CheckIntegerSize added in v0.98.2

func CheckIntegerSize(value *big.Int) error

CheckIntegerSize checks that the value size doesn't exceed the VM limit for Interer.

func DeserializeConvertible added in v0.96.0

func DeserializeConvertible(data []byte, conv Convertible) error

DeserializeConvertible deserializes Convertible from a slice of bytes.

func EncodeBinary added in v0.95.4

func EncodeBinary(item Item, w *io.BinWriter)

EncodeBinary encodes the given Item into the given BinWriter. It's similar to io.Serializable's EncodeBinary but works with Item interface.

func EncodeBinaryProtected added in v0.95.4

func EncodeBinaryProtected(item Item, w *io.BinWriter)

EncodeBinaryProtected encodes the given Item into the given BinWriter. It's similar to EncodeBinary but allows to encode interop items (only type, value is lost) and doesn't return any errors in the w. Instead, if an error (like recursive array) is encountered, it just writes the special InvalidT type of an element to the w.

func IsValidMapKey

func IsValidMapKey(key Item) error

IsValidMapKey checks whether it's possible to use the given Item as a Map key.

func Serialize added in v0.95.4

func Serialize(item Item) ([]byte, error)

Serialize encodes the given Item into a byte slice.

func SerializeConvertible added in v0.96.0

func SerializeConvertible(conv Convertible) ([]byte, error)

SerializeConvertible serializes Convertible into a slice of bytes.

func SerializeLimited added in v0.104.0

func SerializeLimited(item Item, limit int) ([]byte, error)

SerializeLimited encodes the given Item into a byte slice using custom limit to restrict the maximum serialized number of elements.

func ToJSON

func ToJSON(item Item) ([]byte, error)

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

func ToJSONWithTypes(item Item) ([]byte, error)

ToJSONWithTypes serializes any stackitem to JSON in a lossless way.

func ToString added in v0.91.0

func ToString(item Item) (string, error)

ToString converts an Item to a string if it is a valid UTF-8.

Types

type Array

type Array struct {
	// contains filtered or unexported fields
}

Array represents a new Array object.

func NewArray

func NewArray(items []Item) *Array

NewArray returns a new Array object.

func (*Array) Append

func (i *Array) Append(item Item)

Append adds an Item to the end of the Array value.

func (*Array) Clear

func (i *Array) Clear()

Clear removes all elements from the Array item value.

func (*Array) Convert

func (i *Array) Convert(typ Type) (Item, error)

Convert implements the Item interface.

func (*Array) DecRC added in v0.97.2

func (r *Array) DecRC() int

func (*Array) Dup

func (i *Array) Dup() Item

Dup implements the Item interface.

func (*Array) Equals

func (i *Array) Equals(s Item) bool

Equals implements the Item interface.

func (*Array) IncRC added in v0.97.2

func (r *Array) IncRC() int

func (*Array) IsReadOnly added in v0.99.0

func (r *Array) IsReadOnly() bool

IsReadOnly implements Immutable interface.

func (*Array) Len

func (i *Array) Len() int

Len returns length of Array value.

func (*Array) MarkAsReadOnly added in v0.99.0

func (r *Array) MarkAsReadOnly()

MarkAsReadOnly implements immutable interface.

func (*Array) MarshalJSON

func (i *Array) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Array) Remove

func (i *Array) Remove(pos int)

Remove removes the element at `pos` index from Array value. It will panics on bad index.

func (*Array) String

func (i *Array) String() string

func (*Array) TryBool added in v0.92.0

func (i *Array) TryBool() (bool, error)

TryBool implements the Item interface.

func (*Array) TryBytes

func (i *Array) TryBytes() ([]byte, error)

TryBytes implements the Item interface.

func (*Array) TryInteger

func (i *Array) TryInteger() (*big.Int, error)

TryInteger implements the Item interface.

func (*Array) Type

func (i *Array) Type() Type

Type implements the Item interface.

func (*Array) Value

func (i *Array) Value() any

Value implements the Item interface.

type BigInteger

type BigInteger big.Int

BigInteger represents a big integer on the stack.

func NewBigInteger

func NewBigInteger(value *big.Int) *BigInteger

NewBigInteger returns an new BigInteger object.

func (*BigInteger) Big added in v0.97.2

func (i *BigInteger) Big() *big.Int

Big casts i to the big.Int type.

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 the Item interface.

func (*BigInteger) Dup

func (i *BigInteger) Dup() Item

Dup implements the Item interface.

func (*BigInteger) Equals

func (i *BigInteger) Equals(s Item) bool

Equals implements the 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 the Item interface.

func (*BigInteger) TryBytes

func (i *BigInteger) TryBytes() ([]byte, error)

TryBytes implements the Item interface.

func (*BigInteger) TryInteger

func (i *BigInteger) TryInteger() (*big.Int, error)

TryInteger implements the Item interface.

func (*BigInteger) Type

func (i *BigInteger) Type() Type

Type implements the Item interface.

func (*BigInteger) Value

func (i *BigInteger) Value() any

Value implements the Item interface.

type Bool

type Bool bool

Bool represents a boolean Item.

func NewBool

func NewBool(val bool) Bool

NewBool returns an new Bool object.

func (Bool) Bytes

func (i Bool) Bytes() []byte

Bytes converts Bool to bytes.

func (Bool) Convert

func (i Bool) Convert(typ Type) (Item, error)

Convert implements the Item interface.

func (Bool) Dup

func (i Bool) Dup() Item

Dup implements the Item interface.

func (Bool) Equals

func (i Bool) Equals(s Item) bool

Equals implements the Item interface.

func (Bool) MarshalJSON

func (i Bool) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Bool) String

func (i Bool) String() string

func (Bool) TryBool added in v0.92.0

func (i Bool) TryBool() (bool, error)

TryBool implements the Item interface.

func (Bool) TryBytes

func (i Bool) TryBytes() ([]byte, error)

TryBytes implements the Item interface.

func (Bool) TryInteger

func (i Bool) TryInteger() (*big.Int, error)

TryInteger implements the Item interface.

func (Bool) Type

func (i Bool) Type() Type

Type implements the Item interface.

func (Bool) Value

func (i Bool) Value() any

Value implements the Item interface.

type Buffer

type Buffer []byte

Buffer represents represents a Buffer stack item.

func NewBuffer

func NewBuffer(b []byte) *Buffer

NewBuffer returns a new Buffer object.

func (*Buffer) Convert

func (i *Buffer) Convert(typ Type) (Item, error)

Convert implements the Item interface.

func (*Buffer) Dup

func (i *Buffer) Dup() Item

Dup implements the Item interface.

func (*Buffer) Equals

func (i *Buffer) Equals(s Item) bool

Equals implements the Item interface.

func (*Buffer) Len

func (i *Buffer) Len() int

Len returns the length of the Buffer value.

func (*Buffer) MarshalJSON

func (i *Buffer) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Buffer) String

func (i *Buffer) String() string

String implements the fmt.Stringer interface.

func (*Buffer) TryBool added in v0.92.0

func (i *Buffer) TryBool() (bool, error)

TryBool implements the Item interface.

func (*Buffer) TryBytes

func (i *Buffer) TryBytes() ([]byte, error)

TryBytes implements the Item interface.

func (*Buffer) TryInteger

func (i *Buffer) TryInteger() (*big.Int, error)

TryInteger implements the Item interface.

func (*Buffer) Type

func (i *Buffer) Type() Type

Type implements the Item interface.

func (*Buffer) Value

func (i *Buffer) Value() any

Value implements the Item interface.

type ByteArray

type ByteArray []byte

ByteArray represents a byte array on the stack.

func NewByteArray

func NewByteArray(b []byte) *ByteArray

NewByteArray returns an new ByteArray object.

func (*ByteArray) Convert

func (i *ByteArray) Convert(typ Type) (Item, error)

Convert implements the Item interface.

func (*ByteArray) Dup

func (i *ByteArray) Dup() Item

Dup implements the Item interface.

func (*ByteArray) Equals

func (i *ByteArray) Equals(s Item) bool

Equals implements the Item interface.

func (*ByteArray) MarshalJSON

func (i *ByteArray) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ByteArray) String

func (i *ByteArray) String() string

func (*ByteArray) TryBool added in v0.92.0

func (i *ByteArray) TryBool() (bool, error)

TryBool implements the Item interface.

func (ByteArray) TryBytes

func (i ByteArray) TryBytes() ([]byte, error)

TryBytes implements the Item interface.

func (ByteArray) TryInteger

func (i ByteArray) TryInteger() (*big.Int, error)

TryInteger implements the Item interface.

func (*ByteArray) Type

func (i *ByteArray) Type() Type

Type implements the Item interface.

func (*ByteArray) Value

func (i *ByteArray) Value() any

Value implements the Item interface.

type Convertible added in v0.96.0

type Convertible interface {
	ToStackItem() (Item, error)
	FromStackItem(Item) error
}

Convertible is something that can be converted to/from Item.

type Equatable added in v0.102.0

type Equatable interface {
	// Equals checks if two objects are equal.
	Equals(other Equatable) bool
}

Equatable describes a special value of Interop that can be compared with value of some other Interop that implements Equatable.

type Immutable added in v0.99.0

type Immutable interface {
	IsReadOnly() bool
	MarkAsReadOnly()
}

Immutable is an interface supported by compound types (Array, Map, Struct).

type Interop

type Interop struct {
	// contains filtered or unexported fields
}

Interop represents interop data on the stack.

func NewInterop

func NewInterop(value any) *Interop

NewInterop returns a new Interop object.

func (*Interop) Convert

func (i *Interop) Convert(typ Type) (Item, error)

Convert implements the Item interface.

func (*Interop) Dup

func (i *Interop) Dup() Item

Dup implements the Item interface.

func (*Interop) Equals

func (i *Interop) Equals(s Item) bool

Equals implements the Item interface.

func (*Interop) MarshalJSON

func (i *Interop) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Interop) String

func (i *Interop) String() string

String implements stringer interface.

func (*Interop) TryBool added in v0.92.0

func (i *Interop) TryBool() (bool, error)

TryBool implements the Item interface.

func (*Interop) TryBytes

func (i *Interop) TryBytes() ([]byte, error)

TryBytes implements the Item interface.

func (*Interop) TryInteger

func (i *Interop) TryInteger() (*big.Int, error)

TryInteger implements the Item interface.

func (*Interop) Type

func (i *Interop) Type() Type

Type implements the Item interface.

func (*Interop) Value

func (i *Interop) Value() any

Value implements the Item interface.

type Item

type Item interface {
	fmt.Stringer
	Value() any
	// 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 DecodeBinary added in v0.95.4

func DecodeBinary(r *io.BinReader) Item

DecodeBinary decodes the 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 DecodeBinaryProtected added in v0.95.4

func DecodeBinaryProtected(r *io.BinReader) Item

DecodeBinaryProtected is similar to DecodeBinary but allows Interop and Invalid values to be present (making it symmetric to EncodeBinaryProtected).

func DeepCopy added in v0.91.0

func DeepCopy(item Item, asImmutable bool) Item

DeepCopy returns a 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 Deserialize added in v0.95.4

func Deserialize(data []byte) (Item, error)

Deserialize decodes the Item from the given byte slice.

func DeserializeLimited added in v0.101.1

func DeserializeLimited(data []byte, limit int) (Item, error)

DeserializeLimited returns Item deserialized from the given byte slice. limit restricts the maximum number of items deserialized item can contain (including itself). The default limit of MaxDeserialized is used if non-positive limit is specified.

func FromJSON

func FromJSON(data []byte, maxCount int, bestIntPrecision bool) (Item, error)

FromJSON decodes an 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

func FromJSONWithTypes(data []byte) (Item, error)

FromJSONWithTypes deserializes an item from typed-json representation.

func Make

func Make(v any) Item

Make tries to make an appropriate stack item from the provided value. It will panic if it's not possible.

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map represents a 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 needed.

func NewMap

func NewMap() *Map

NewMap returns a new Map object.

func NewMapWithValue

func NewMapWithValue(value []MapElement) *Map

NewMapWithValue returns a new Map object filled with the specified value.

func (*Map) Add

func (i *Map) Add(key, value Item)

Add adds a key-value pair to the map.

func (*Map) Clear

func (i *Map) Clear()

Clear removes all elements from the Map item value.

func (*Map) Convert

func (i *Map) Convert(typ Type) (Item, error)

Convert implements the Item interface.

func (*Map) DecRC added in v0.97.2

func (r *Map) DecRC() int

func (*Map) Drop

func (i *Map) Drop(index int)

Drop removes the given index from the map (no bounds check done here).

func (*Map) Dup

func (i *Map) Dup() Item

Dup implements the Item interface.

func (*Map) Equals

func (i *Map) Equals(s Item) bool

Equals implements the Item interface.

func (*Map) Has

func (i *Map) Has(key Item) bool

Has checks if the map has the specified key.

func (*Map) IncRC added in v0.97.2

func (r *Map) IncRC() int

func (*Map) Index

func (i *Map) Index(key Item) int

Index returns an index of the key in map.

func (*Map) IsReadOnly added in v0.99.0

func (r *Map) IsReadOnly() bool

IsReadOnly implements Immutable interface.

func (*Map) Len

func (i *Map) Len() int

Len returns the length of the Map value.

func (*Map) MarkAsReadOnly added in v0.99.0

func (r *Map) MarkAsReadOnly()

MarkAsReadOnly implements immutable interface.

func (*Map) String

func (i *Map) String() string

func (*Map) TryBool added in v0.92.0

func (i *Map) TryBool() (bool, error)

TryBool implements the Item interface.

func (*Map) TryBytes

func (i *Map) TryBytes() ([]byte, error)

TryBytes implements the Item interface.

func (*Map) TryInteger

func (i *Map) TryInteger() (*big.Int, error)

TryInteger implements the Item interface.

func (*Map) Type

func (i *Map) Type() Type

Type implements the Item interface.

func (*Map) Value

func (i *Map) Value() any

Value implements the Item interface.

type MapElement

type MapElement struct {
	Key   Item
	Value Item
}

MapElement is a key-value pair of StackItems.

type Null

type Null struct{}

Null represents null on the stack.

func (Null) Convert

func (i Null) Convert(typ Type) (Item, error)

Convert implements the Item interface.

func (Null) Dup

func (i Null) Dup() Item

Dup implements the Item interface. There is no need to perform a real copy here since Null has no internal state.

func (Null) Equals

func (i Null) Equals(s Item) bool

Equals implements the Item interface.

func (Null) String

func (i Null) String() string

String implements the Item interface.

func (Null) TryBool added in v0.92.0

func (i Null) TryBool() (bool, error)

TryBool implements the Item interface.

func (Null) TryBytes

func (i Null) TryBytes() ([]byte, error)

TryBytes implements the Item interface.

func (Null) TryInteger

func (i Null) TryInteger() (*big.Int, error)

TryInteger implements the Item interface.

func (Null) Type

func (i Null) Type() Type

Type implements the Item interface.

func (Null) Value

func (i Null) Value() any

Value implements the Item interface.

type Pointer

type Pointer struct {
	// contains filtered or unexported fields
}

Pointer represents a VM-level instruction pointer.

func NewPointer

func NewPointer(pos int, script []byte) *Pointer

NewPointer returns a new pointer on the specified position.

func NewPointerWithHash added in v0.92.0

func NewPointerWithHash(pos int, script []byte, h util.Uint160) *Pointer

NewPointerWithHash returns a 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 calculation. This hash is then being used for pointer comparisons.

func (*Pointer) Convert

func (p *Pointer) Convert(typ Type) (Item, error)

Convert implements the Item interface.

func (*Pointer) Dup

func (p *Pointer) Dup() Item

Dup implements the Item interface.

func (*Pointer) Equals

func (p *Pointer) Equals(s Item) bool

Equals implements the Item interface.

func (*Pointer) Position

func (p *Pointer) Position() int

Position returns the pointer item position.

func (*Pointer) ScriptHash

func (p *Pointer) ScriptHash() util.Uint160

ScriptHash returns the pointer item hash.

func (*Pointer) String

func (p *Pointer) String() string

String implements the Item interface.

func (*Pointer) TryBool added in v0.92.0

func (p *Pointer) TryBool() (bool, error)

TryBool implements the Item interface.

func (*Pointer) TryBytes

func (p *Pointer) TryBytes() ([]byte, error)

TryBytes implements the Item interface.

func (*Pointer) TryInteger

func (p *Pointer) TryInteger() (*big.Int, error)

TryInteger implements the Item interface.

func (*Pointer) Type

func (p *Pointer) Type() Type

Type implements the Item interface.

func (*Pointer) Value

func (p *Pointer) Value() any

Value implements the Item interface.

type SerializationContext added in v0.99.0

type SerializationContext struct {
	// contains filtered or unexported fields
}

SerializationContext is a serialization context.

func NewSerializationContext added in v0.99.0

func NewSerializationContext() *SerializationContext

NewSerializationContext returns reusable stack item serialization context.

func (*SerializationContext) Serialize added in v0.99.0

func (w *SerializationContext) Serialize(item Item, protected bool) ([]byte, error)

Serialize returns flat slice of bytes with the given item. The process can be protected from bad elements if appropriate flag is given (otherwise an error is returned on encountering any of them). The buffer returned is only valid until the call to Serialize. The number of serialized items is restricted with MaxSerialized.

type Struct

type Struct struct {
	// contains filtered or unexported fields
}

Struct represents a struct on the stack.

func NewStruct

func NewStruct(items []Item) *Struct

NewStruct returns a new Struct object.

func (*Struct) Append

func (i *Struct) Append(item Item)

Append adds an Item to the end of the Struct value.

func (*Struct) Clear

func (i *Struct) Clear()

Clear removes all elements from the Struct item value.

func (*Struct) Clone

func (i *Struct) Clone() (*Struct, error)

Clone returns a Struct with all Struct fields copied by the value. Array fields are still copied by reference.

func (*Struct) Convert

func (i *Struct) Convert(typ Type) (Item, error)

Convert implements the Item interface.

func (*Struct) DecRC added in v0.97.2

func (r *Struct) DecRC() int

func (*Struct) Dup

func (i *Struct) Dup() Item

Dup implements the Item interface.

func (*Struct) Equals

func (i *Struct) Equals(s Item) bool

Equals implements the Item interface.

func (*Struct) IncRC added in v0.97.2

func (r *Struct) IncRC() int

func (*Struct) IsReadOnly added in v0.99.0

func (r *Struct) IsReadOnly() bool

IsReadOnly implements Immutable interface.

func (*Struct) Len

func (i *Struct) Len() int

Len returns the length of the Struct value.

func (*Struct) MarkAsReadOnly added in v0.99.0

func (r *Struct) MarkAsReadOnly()

MarkAsReadOnly implements immutable interface.

func (*Struct) Remove

func (i *Struct) Remove(pos int)

Remove removes the element at `pos` index from the Struct value. It will panic if a bad index given.

func (*Struct) String

func (i *Struct) String() string

String implements the Item interface.

func (*Struct) TryBool added in v0.92.0

func (i *Struct) TryBool() (bool, error)

TryBool implements the Item interface.

func (*Struct) TryBytes

func (i *Struct) TryBytes() ([]byte, error)

TryBytes implements the Item interface.

func (*Struct) TryInteger

func (i *Struct) TryInteger() (*big.Int, error)

TryInteger implements the Item interface.

func (*Struct) Type

func (i *Struct) Type() Type

Type implements the Item interface.

func (*Struct) Value

func (i *Struct) Value() any

Value implements the Item interface.

type Type

type Type byte

Type represents a 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

func FromString(s string) (Type, error)

FromString returns stackitem type from the string.

func (Type) IsValid

func (t Type) IsValid() bool

IsValid checks if s is a well defined stack item type.

func (Type) String

func (t Type) String() string

String implements the fmt.Stringer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL