clvalue

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 2

README

Architecture

CLType and CLValue represent values with corresponding data types in Casper network that is used by smart contracts and deploys. This data communicate thought Network in the bytes' representation. Bytes serialization rules are described here.

The base functionality that provides by SDK is the working with bytes, string and json representation.

By the design all CLValues are represented in separate files, where is located the corresponded logic to work with a certain type. Only complex CLTypes are implemented as a separate types, other (simple types) is a values of a SimpleType data structure. The common logic to parse unknown types and values is stored in the parser files in corresponded packages.

Also, data from network is often represented as mix of json and byte representation. As example in args of the transfer of a deploy's succession result could be fiend next string: {"bytes":"01000000030000004142430a000000","cl_type":{"Map":{"key":"String","value":"I32"}}}. In this representation of data the bytes contains only encoded value and cl_type field represented as json object.

To convenient work with args implemented 'lazy load' behavior with delayed parsing by the direct client call, the ArgsParser struct responsible to do it.

Please check examples of usage in example_test.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBoolValueIsInvalid = errors.New("invalid bool value")
)
View Source
var ErrUnitByteNotEmpty = errors.New("byte source for unit type should be empty")
View Source
var (
	ErrUnsupportedCLType = errors.New("buffer constructor is not found")
)

Functions

func BigFromBuffer

func BigFromBuffer(buffer *bytes.Buffer) (*big.Int, error)

func BigToBytes

func BigToBytes(val *big.Int) []byte

func SizeToBytes

func SizeToBytes(val int) []byte

func ToBytesWithType

func ToBytesWithType(value CLValue) ([]byte, error)

func TrimByteSize

func TrimByteSize(buf *bytes.Buffer) (size uint32, err error)

Types

type Any

type Any []byte

func NewAnyFromBuffer

func NewAnyFromBuffer(buf *bytes.Buffer) Any

func (Any) Bytes

func (v Any) Bytes() []byte

func (Any) String

func (v Any) String() string

type Bool

type Bool bool

func NewBoolFromBuffer

func NewBoolFromBuffer(buffer *bytes.Buffer) (*Bool, error)

func NewBoolFromBytes

func NewBoolFromBytes(source []byte) (*Bool, error)

func (Bool) Bytes

func (v Bool) Bytes() []byte

func (Bool) String

func (v Bool) String() string

func (Bool) Value

func (v Bool) Value() bool

type ByteArray

type ByteArray []byte

func NewByteArrayFromBuffer

func NewByteArrayFromBuffer(buf *bytes.Buffer, clType *cltype.ByteArray) ByteArray

func NewByteArrayFromBytes

func NewByteArrayFromBytes(data []byte, clType *cltype.ByteArray) ByteArray

func (ByteArray) Bytes

func (b ByteArray) Bytes() []byte

func (ByteArray) String

func (b ByteArray) String() string

type CLValue

type CLValue struct {
	Type      cltype.CLType
	Bool      *Bool
	I32       *Int32
	I64       *Int64
	UI8       *UInt8
	UI32      *UInt32
	UI64      *UInt64
	UI128     *UInt128
	UI256     *UInt256
	UI512     *UInt512
	Unit      *Unit
	Uref      *key.URef
	Key       *key.Key
	Option    *Option
	List      *List
	ByteArray *ByteArray
	Result    *Result
	StringVal *String
	Map       *Map
	Tuple1    *Tuple1
	Tuple2    *Tuple2
	Tuple3    *Tuple3
	Any       *Any
	PublicKey *keypair.PublicKey
}

func FromBuffer

func FromBuffer(buffer *bytes.Buffer) (CLValue, error)

func FromBufferByType

func FromBufferByType(buf *bytes.Buffer, sourceType cltype.CLType) (result CLValue, err error)

func FromBytes

func FromBytes(source []byte) (CLValue, error)

func FromBytesByType

func FromBytesByType(source []byte, clType cltype.CLType) (CLValue, error)

func NewAnyFromBytes

func NewAnyFromBytes(data []byte) *CLValue

func NewCLAny

func NewCLAny(data []byte) CLValue

func NewCLBool

func NewCLBool(val bool) CLValue

func NewCLByteArray

func NewCLByteArray(val []byte) CLValue

func NewCLInt32

func NewCLInt32(val int32) CLValue

func NewCLInt64

func NewCLInt64(val int64) *CLValue

func NewCLKey added in v0.9.6

func NewCLKey(data key.Key) CLValue

func NewCLList

func NewCLList(elementType cltype.CLType) CLValue

func NewCLMap

func NewCLMap(keyType cltype.CLType, valType cltype.CLType) CLValue

func NewCLOption

func NewCLOption(inner CLValue) CLValue

func NewCLPublicKey added in v0.9.6

func NewCLPublicKey(data keypair.PublicKey) CLValue

func NewCLResult

func NewCLResult(innerOk, innerErr cltype.CLType, value CLValue, isSuccess bool) CLValue

func NewCLString

func NewCLString(val string) *CLValue

func NewCLTuple1

func NewCLTuple1(val CLValue) CLValue

func NewCLTuple2

func NewCLTuple2(val1 CLValue, val2 CLValue) CLValue

func NewCLTuple3

func NewCLTuple3(val1 CLValue, val2 CLValue, val3 CLValue) CLValue

func NewCLUInt128

func NewCLUInt128(val *big.Int) *CLValue

func NewCLUInt256

func NewCLUInt256(val *big.Int) *CLValue

func NewCLUInt32

func NewCLUInt32(val uint32) *CLValue

func NewCLUInt512

func NewCLUInt512(val *big.Int) *CLValue

func NewCLUInt64

func NewCLUInt64(val uint64) *CLValue

func NewCLUint8

func NewCLUint8(val uint8) *CLValue

func NewCLUnit

func NewCLUnit() *CLValue

func NewCLUref added in v0.9.6

func NewCLUref(data key.URef) CLValue

func (CLValue) Bytes

func (c CLValue) Bytes() []byte

func (*CLValue) GetKey

func (c *CLValue) GetKey() (*key.Key, error)

func (CLValue) GetType

func (c CLValue) GetType() cltype.CLType

func (CLValue) GetValueByType

func (c CLValue) GetValueByType() IValue

func (CLValue) String

func (c CLValue) String() string

func (CLValue) ToBytesWithType

func (c CLValue) ToBytesWithType() ([]byte, error)

type IValue

type IValue interface {
	Bytes() []byte
	String() string
}

type Int32

type Int32 int32

func NewInt32FromBuffer

func NewInt32FromBuffer(buffer *bytes.Buffer) (*Int32, error)

func NewInt32FromBytes

func NewInt32FromBytes(source []byte) (*Int32, error)

func (*Int32) Bytes

func (v *Int32) Bytes() []byte

func (*Int32) String

func (v *Int32) String() string

func (*Int32) Value

func (v *Int32) Value() int32

type Int64

type Int64 int64

func NewInt64FromBuffer

func NewInt64FromBuffer(buf *bytes.Buffer) (*Int64, error)

func NewInt64FromBytes

func NewInt64FromBytes(source []byte) (*Int64, error)

func (*Int64) Bytes

func (v *Int64) Bytes() []byte

func (*Int64) String

func (v *Int64) String() string

func (*Int64) Value

func (v *Int64) Value() int64

type List

type List struct {
	Type     *cltype.List
	Elements []CLValue
}

func NewListFromBuffer

func NewListFromBuffer(buf *bytes.Buffer, clType *cltype.List) (*List, error)

func NewListFromBytes

func NewListFromBytes(source []byte, clType *cltype.List) (*List, error)

func (*List) Append

func (v *List) Append(value CLValue)

func (*List) Bytes

func (v *List) Bytes() []byte

func (*List) IsEmpty

func (v *List) IsEmpty() bool

func (*List) Len

func (v *List) Len() int

func (*List) String

func (v *List) String() string

type Map

type Map struct {
	Type *cltype.Map
	// contains filtered or unexported fields
}

func NewMapFromBuffer

func NewMapFromBuffer(buffer *bytes.Buffer, mapType *cltype.Map) (*Map, error)

func (*Map) Append

func (m *Map) Append(key CLValue, val CLValue) error

func (*Map) Bytes

func (m *Map) Bytes() []byte

func (*Map) Data added in v0.9.6

func (m *Map) Data() []Tuple2

func (*Map) Find

func (m *Map) Find(key string) (CLValue, bool)

func (*Map) FindAny

func (m *Map) FindAny(keys []string) (CLValue, bool)

func (*Map) Get

func (m *Map) Get(key string) CLValue

func (*Map) Len

func (m *Map) Len() int

func (*Map) Map

func (m *Map) Map() map[string]CLValue

func (*Map) String

func (m *Map) String() string

type Option

type Option struct {
	Type  *cltype.Option
	Inner *CLValue
}

func NewOptionFromBuffer

func NewOptionFromBuffer(buf *bytes.Buffer, clType *cltype.Option) (*Option, error)

func NewOptionFromBytes

func NewOptionFromBytes(source []byte, clType *cltype.Option) (*Option, error)

func (*Option) Bytes

func (v *Option) Bytes() []byte

func (*Option) IsEmpty

func (v *Option) IsEmpty() bool

func (*Option) String

func (v *Option) String() string

func (*Option) Value

func (v *Option) Value() *CLValue

type Result

type Result struct {
	Type      *cltype.Result
	IsSuccess bool
	Inner     CLValue
}

func NewResultFromBuffer

func NewResultFromBuffer(buf *bytes.Buffer, clType *cltype.Result) (*Result, error)

func NewResultFromBytes

func NewResultFromBytes(source []byte, clType *cltype.Result) (*Result, error)

func (*Result) Bytes

func (v *Result) Bytes() []byte

func (*Result) String

func (v *Result) String() string

func (*Result) Value

func (v *Result) Value() CLValue

type String

type String string

func NewStringFromBuffer

func NewStringFromBuffer(buffer *bytes.Buffer) (*String, error)

func NewStringFromBytes

func NewStringFromBytes(src []byte) (*String, error)

func (*String) Bytes

func (s *String) Bytes() []byte

func (*String) String

func (s *String) String() string

type Tuple1

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

func NewTuple1FromBuffer

func NewTuple1FromBuffer(buf *bytes.Buffer, tuple1Type *cltype.Tuple1) (*Tuple1, error)

func NewTuple1FromBytes

func NewTuple1FromBytes(source []byte, clType *cltype.Tuple1) (*Tuple1, error)

func (*Tuple1) Bytes

func (v *Tuple1) Bytes() []byte

func (*Tuple1) String

func (v *Tuple1) String() string

func (*Tuple1) Value

func (v *Tuple1) Value() CLValue

type Tuple2

type Tuple2 struct {
	Inner1 CLValue
	Inner2 CLValue
	// contains filtered or unexported fields
}

func NewTuple2FromBuffer

func NewTuple2FromBuffer(buf *bytes.Buffer, clType *cltype.Tuple2) (*Tuple2, error)

func NewTuple2FromBytes

func NewTuple2FromBytes(source []byte, clType *cltype.Tuple2) (*Tuple2, error)

func (*Tuple2) Bytes

func (v *Tuple2) Bytes() []byte

func (*Tuple2) String

func (v *Tuple2) String() string

func (*Tuple2) Value

func (v *Tuple2) Value() [2]CLValue

type Tuple3

type Tuple3 struct {
	Inner1 CLValue
	Inner2 CLValue
	Inner3 CLValue
	// contains filtered or unexported fields
}

func NewTuple3FromBuffer

func NewTuple3FromBuffer(buf *bytes.Buffer, clType *cltype.Tuple3) (*Tuple3, error)

func NewTuple3FromBytes

func NewTuple3FromBytes(source []byte, clType *cltype.Tuple3) (*Tuple3, error)

func (*Tuple3) Bytes

func (v *Tuple3) Bytes() []byte

func (*Tuple3) String

func (v *Tuple3) String() string

func (*Tuple3) Value

func (v *Tuple3) Value() [3]CLValue

type UInt128

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

func NewUint128FromBuffer

func NewUint128FromBuffer(buffer *bytes.Buffer) (*UInt128, error)

func NewUint128FromBytes

func NewUint128FromBytes(source []byte) (*UInt128, error)

func (*UInt128) Bytes

func (v *UInt128) Bytes() []byte

func (*UInt128) String

func (v *UInt128) String() string

func (*UInt128) Value

func (v *UInt128) Value() *big.Int

type UInt256

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

func NewUint256FromBuffer

func NewUint256FromBuffer(buffer *bytes.Buffer) (*UInt256, error)

func NewUint256FromBytes

func NewUint256FromBytes(source []byte) (*UInt256, error)

func (*UInt256) Bytes

func (v *UInt256) Bytes() []byte

func (*UInt256) String

func (v *UInt256) String() string

func (*UInt256) Value

func (v *UInt256) Value() *big.Int

type UInt32

type UInt32 uint32

func NewUint32FromBuffer

func NewUint32FromBuffer(buffer *bytes.Buffer) (*UInt32, error)

func NewUint32FromBytes

func NewUint32FromBytes(source []byte) (*UInt32, error)

func (*UInt32) Bytes

func (v *UInt32) Bytes() []byte

func (*UInt32) String

func (v *UInt32) String() string

func (*UInt32) Value

func (v *UInt32) Value() uint32

type UInt512

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

func NewUint512FromBuffer

func NewUint512FromBuffer(buffer *bytes.Buffer) (*UInt512, error)

func NewUint512FromBytes

func NewUint512FromBytes(source []byte) (*UInt512, error)

func (*UInt512) Bytes

func (v *UInt512) Bytes() []byte

func (UInt512) MarshalJSON

func (v UInt512) MarshalJSON() ([]byte, error)

func (*UInt512) String

func (v *UInt512) String() string

func (*UInt512) UnmarshalJSON

func (v *UInt512) UnmarshalJSON(b []byte) error

func (*UInt512) Value

func (v *UInt512) Value() *big.Int

type UInt64

type UInt64 uint64

func NewUint64FromBuffer

func NewUint64FromBuffer(buffer *bytes.Buffer) (*UInt64, error)

func NewUint64FromBytes

func NewUint64FromBytes(source []byte) (*UInt64, error)

func (*UInt64) Bytes

func (v *UInt64) Bytes() []byte

func (*UInt64) String

func (v *UInt64) String() string

func (*UInt64) Value

func (v *UInt64) Value() uint64

type UInt8

type UInt8 uint8

func NewUInt8FromBuffer

func NewUInt8FromBuffer(buffer *bytes.Buffer) (*UInt8, error)

func NewUInt8FromBytes

func NewUInt8FromBytes(source []byte) (*UInt8, error)

func (*UInt8) Bytes

func (v *UInt8) Bytes() []byte

func (*UInt8) String

func (v *UInt8) String() string

func (*UInt8) Value

func (v *UInt8) Value() uint8

type Unit

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

func NewUnitFromBuffer

func NewUnitFromBuffer(buffer *bytes.Buffer) (*Unit, error)

func NewUnitFromBytes

func NewUnitFromBytes(source []byte) (*Unit, error)

func (*Unit) Bytes

func (v *Unit) Bytes() []byte

func (*Unit) String

func (v *Unit) String() string

func (*Unit) Value

func (v *Unit) Value() *types.Nil

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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