scale

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// MoveBit for the highest six bit is has special means, in order to get origin num, must move right 2bit
	// also encode a number must move left 2bit
	MoveBit = 2

	// SingleMode the higher six bit is LE for value, which is 0 to 63
	SingleMode = 0b00
	MaxSingle  = 63
	// DoubleMode the higher six bit and next byte is LE for value, which is 64 to 1<<14 - 1
	DoubleMode = 0b01
	MaxDouble  = 1<<14 - 1
	// FourByteMode the higher six bit and next three bytes is LE for value, which is 1<<14 -1 to 1<<30-1
	FourByteMode = 0b10
	MaxFour      = 1<<30 - 1
	// BigIntMode the highest six bit represent the bytes num in the next, which less than 4.
	// then, the next bytes contain the LE for value. the highest one can not be 0, which is
	// 1<<30-1 to 1<<536-1
	BigIntMode = 0b11
)
View Source
const CustomParamsSection = "params"

CustomParamsSection custom section named `params` in wasm defined by us.

Variables

View Source
var (
	U8OutOfRange   = errors.New("out of range Compact<u8>")
	U16OutOfRange  = errors.New("out of range Compact<u16>")
	U32OutOfRange  = errors.New("out of range Compact<u32>")
	U64OutOfRange  = errors.New("out of range Compact<u64>")
	U128OutOfRange = errors.New("out of range Compact<u128>")
)
View Source
var BaseIntEncode littleEncode

Functions

func GetCompactValue

func GetCompactValue(val Compact) interface{}

Types

type Abi

type Abi struct {
	Contract Contract `json:"contract"`
	Methods  []Method `json:"methods"`
	Types    []Type   `json:"types"`
	// contains filtered or unexported fields
}

func JSON

func JSON(reader io.Reader) (Abi, error)

func (*Abi) DecodeInput

func (a *Abi) DecodeInput(methodName string, val []byte) (*InvokeBean, error)

func (*Abi) DecodeRet

func (a *Abi) DecodeRet(ret []byte, methodName string) (*InvokeBean, error)

func (*Abi) Encode

func (a *Abi) Encode(methodName string, params ...interface{}) ([]byte, error)

func (*Abi) EncodeCompact

func (a *Abi) EncodeCompact(methodName string, params ...Compact) ([]byte, error)

func (*Abi) GetMethod added in v1.4.0

func (a *Abi) GetMethod(name string) (*Method, error)

type Compact

type Compact interface {
	Encode() ([]byte, error)
	Decode(val []byte) (int, error)
	GetVal() interface{}
	GetType() TypeString
	CloneNew() Compact
}

Compact base interface for encoding and decoding. We redefine the way to encode and decode all the types in abi file. For more details see [SCALE Codec](https://docs.substrate.io/v3/advanced/scale-codec/)

type CompactArray

type CompactArray struct {
	Val      []Compact
	Len      int
	NextList []TypeString
}

func (*CompactArray) CloneNew

func (c *CompactArray) CloneNew() Compact

func (*CompactArray) Decode

func (c *CompactArray) Decode(value []byte) (int, error)

func (*CompactArray) Encode

func (c *CompactArray) Encode() ([]byte, error)

func (*CompactArray) GetType

func (c *CompactArray) GetType() TypeString

func (*CompactArray) GetVal

func (c *CompactArray) GetVal() interface{}

type CompactBool

type CompactBool struct {
	Val bool
}

func (*CompactBool) CloneNew

func (c *CompactBool) CloneNew() Compact

func (*CompactBool) Decode

func (c *CompactBool) Decode(val []byte) (int, error)

func (*CompactBool) Encode

func (c *CompactBool) Encode() ([]byte, error)

func (*CompactBool) GetType

func (c *CompactBool) GetType() TypeString

func (*CompactBool) GetVal

func (c *CompactBool) GetVal() interface{}

type CompactEnum added in v1.4.0

type CompactEnum struct {
	Val Compact
	// contains filtered or unexported fields
}

func (*CompactEnum) CloneNew added in v1.4.0

func (c *CompactEnum) CloneNew() Compact

func (*CompactEnum) Decode added in v1.4.0

func (c *CompactEnum) Decode(value []byte) (int, error)

func (*CompactEnum) Encode added in v1.4.0

func (c *CompactEnum) Encode() ([]byte, error)

func (*CompactEnum) GetType added in v1.4.0

func (c *CompactEnum) GetType() TypeString

func (*CompactEnum) GetVal added in v1.4.0

func (c *CompactEnum) GetVal() interface{}

type CompactString

type CompactString struct {
	Val  string
	Type TypeString
}

func (*CompactString) CloneNew

func (c *CompactString) CloneNew() Compact

func (*CompactString) Decode

func (c *CompactString) Decode(value []byte) (int, error)

func (*CompactString) Encode

func (c *CompactString) Encode() ([]byte, error)

func (*CompactString) GetType

func (c *CompactString) GetType() TypeString

func (*CompactString) GetVal

func (c *CompactString) GetVal() interface{}

type CompactStruct

type CompactStruct struct {
	Val []Compact
}

func (*CompactStruct) CloneNew

func (c *CompactStruct) CloneNew() Compact

func (*CompactStruct) Decode

func (c *CompactStruct) Decode(value []byte) (int, error)

func (*CompactStruct) Encode

func (c *CompactStruct) Encode() ([]byte, error)

func (*CompactStruct) GetType

func (c *CompactStruct) GetType() TypeString

func (*CompactStruct) GetVal

func (c *CompactStruct) GetVal() interface{}

type CompactTuple added in v1.4.0

type CompactTuple struct {
	Val []Compact
}

func (*CompactTuple) CloneNew added in v1.4.0

func (c *CompactTuple) CloneNew() Compact

func (*CompactTuple) Decode added in v1.4.0

func (c *CompactTuple) Decode(value []byte) (int, error)

func (*CompactTuple) Encode added in v1.4.0

func (c *CompactTuple) Encode() ([]byte, error)

func (*CompactTuple) GetType added in v1.4.0

func (c *CompactTuple) GetType() TypeString

func (*CompactTuple) GetVal added in v1.4.0

func (c *CompactTuple) GetVal() interface{}

type CompactU128

type CompactU128 struct {
	Val *big.Int
}

func (*CompactU128) CloneNew

func (c *CompactU128) CloneNew() Compact

func (*CompactU128) Decode

func (c *CompactU128) Decode(val []byte) (int, error)

func (*CompactU128) Encode

func (c *CompactU128) Encode() ([]byte, error)

func (*CompactU128) GetType

func (c *CompactU128) GetType() TypeString

func (*CompactU128) GetVal

func (c *CompactU128) GetVal() interface{}

type CompactU16

type CompactU16 struct {
	Val uint16
}

CompactU16 two bytes uint in compact mode

func (*CompactU16) CloneNew

func (u *CompactU16) CloneNew() Compact

func (*CompactU16) Decode

func (u *CompactU16) Decode(val []byte) (int, error)

func (*CompactU16) Encode

func (u *CompactU16) Encode() ([]byte, error)

func (*CompactU16) GetType

func (u *CompactU16) GetType() TypeString

func (*CompactU16) GetVal

func (u *CompactU16) GetVal() interface{}

type CompactU32

type CompactU32 struct {
	Val uint32
}

CompactU32 four bytes uint

func (*CompactU32) CloneNew

func (u *CompactU32) CloneNew() Compact

func (*CompactU32) Decode

func (u *CompactU32) Decode(val []byte) (int, error)

func (*CompactU32) Encode

func (u *CompactU32) Encode() ([]byte, error)

func (*CompactU32) GetType

func (u *CompactU32) GetType() TypeString

func (*CompactU32) GetVal

func (u *CompactU32) GetVal() interface{}

type CompactU64

type CompactU64 struct {
	Val uint64
}

func (*CompactU64) CloneNew

func (c *CompactU64) CloneNew() Compact

func (*CompactU64) Decode

func (c *CompactU64) Decode(val []byte) (int, error)

func (*CompactU64) Encode

func (c *CompactU64) Encode() ([]byte, error)

func (*CompactU64) GetType

func (c *CompactU64) GetType() TypeString

func (*CompactU64) GetVal

func (c *CompactU64) GetVal() interface{}

type CompactU8

type CompactU8 struct {
	Val uint8
}

CompactU8 one byte uint in compact mode

func (*CompactU8) CloneNew

func (c *CompactU8) CloneNew() Compact

func (*CompactU8) Decode

func (c *CompactU8) Decode(val []byte) (int, error)

func (*CompactU8) Encode

func (c *CompactU8) Encode() ([]byte, error)

func (*CompactU8) GetType

func (c *CompactU8) GetType() TypeString

func (*CompactU8) GetVal

func (c *CompactU8) GetVal() interface{}

type CompactVec

type CompactVec struct {
	Val      []Compact
	NextList []TypeString
}

func (*CompactVec) Clear

func (c *CompactVec) Clear()

func (*CompactVec) CloneNew

func (c *CompactVec) CloneNew() Compact

func (*CompactVec) Decode

func (c *CompactVec) Decode(value []byte) (int, error)

func (*CompactVec) Encode

func (c *CompactVec) Encode() ([]byte, error)

func (*CompactVec) GetType

func (c *CompactVec) GetType() TypeString

func (*CompactVec) GetVal

func (c *CompactVec) GetVal() interface{}

type ConstructorSpec

type ConstructorSpec struct {
	Input []TypeInfo `json:"input"`
}

type Contract

type Contract struct {
	Name        string          `json:"name"`
	Constructor ConstructorSpec `json:"constructor"`
}

type FixI128

type FixI128 struct {
	Val *big.Int
}

func (*FixI128) CloneNew

func (f *FixI128) CloneNew() Compact

func (*FixI128) Decode

func (f *FixI128) Decode(val []byte) (int, error)

func (*FixI128) Encode

func (f *FixI128) Encode() ([]byte, error)

func (*FixI128) GetType

func (f *FixI128) GetType() TypeString

func (*FixI128) GetVal

func (f *FixI128) GetVal() interface{}

type FixI16

type FixI16 struct {
	Val int16
}

func (*FixI16) CloneNew

func (f *FixI16) CloneNew() Compact

func (*FixI16) Decode

func (f *FixI16) Decode(val []byte) (int, error)

func (*FixI16) Encode

func (f *FixI16) Encode() ([]byte, error)

func (*FixI16) GetType

func (f *FixI16) GetType() TypeString

func (*FixI16) GetVal

func (f *FixI16) GetVal() interface{}

type FixI32

type FixI32 struct {
	Val int32
}

func (*FixI32) CloneNew

func (f *FixI32) CloneNew() Compact

func (*FixI32) Decode

func (f *FixI32) Decode(val []byte) (int, error)

func (*FixI32) Encode

func (f *FixI32) Encode() ([]byte, error)

func (*FixI32) GetType

func (f *FixI32) GetType() TypeString

func (*FixI32) GetVal

func (f *FixI32) GetVal() interface{}

type FixI64

type FixI64 struct {
	Val int64
}

func (*FixI64) CloneNew

func (f *FixI64) CloneNew() Compact

func (*FixI64) Decode

func (f *FixI64) Decode(val []byte) (int, error)

func (*FixI64) Encode

func (f *FixI64) Encode() ([]byte, error)

func (*FixI64) GetType

func (f *FixI64) GetType() TypeString

func (*FixI64) GetVal

func (f *FixI64) GetVal() interface{}

type FixI8

type FixI8 struct {
	Val int8
}

func (*FixI8) CloneNew

func (f *FixI8) CloneNew() Compact

func (*FixI8) Decode

func (f *FixI8) Decode(val []byte) (int, error)

func (*FixI8) Encode

func (f *FixI8) Encode() ([]byte, error)

func (*FixI8) GetType

func (f *FixI8) GetType() TypeString

func (*FixI8) GetVal

func (f *FixI8) GetVal() interface{}

type FixU128

type FixU128 struct {
	Val *big.Int
}

func (*FixU128) CloneNew

func (f *FixU128) CloneNew() Compact

func (*FixU128) Decode

func (f *FixU128) Decode(val []byte) (int, error)

func (*FixU128) Encode

func (f *FixU128) Encode() ([]byte, error)

func (*FixU128) GetType

func (f *FixU128) GetType() TypeString

func (*FixU128) GetVal

func (f *FixU128) GetVal() interface{}

type FixU16

type FixU16 struct {
	Val uint16
}

func (*FixU16) CloneNew

func (f *FixU16) CloneNew() Compact

func (*FixU16) Decode

func (f *FixU16) Decode(val []byte) (int, error)

func (*FixU16) Encode

func (f *FixU16) Encode() ([]byte, error)

func (*FixU16) GetType

func (f *FixU16) GetType() TypeString

func (*FixU16) GetVal

func (f *FixU16) GetVal() interface{}

type FixU32

type FixU32 struct {
	Val uint32
}

func (*FixU32) CloneNew

func (f *FixU32) CloneNew() Compact

func (*FixU32) Decode

func (f *FixU32) Decode(val []byte) (int, error)

func (*FixU32) Encode

func (f *FixU32) Encode() ([]byte, error)

func (*FixU32) GetType

func (f *FixU32) GetType() TypeString

func (*FixU32) GetVal

func (f *FixU32) GetVal() interface{}

type FixU64

type FixU64 struct {
	Val uint64
}

func (*FixU64) CloneNew

func (f *FixU64) CloneNew() Compact

func (*FixU64) Decode

func (f *FixU64) Decode(val []byte) (int, error)

func (*FixU64) Encode

func (f *FixU64) Encode() ([]byte, error)

func (*FixU64) GetType

func (f *FixU64) GetType() TypeString

func (*FixU64) GetVal

func (f *FixU64) GetVal() interface{}

type FixU8

type FixU8 struct {
	Val uint8
}

func (*FixU8) CloneNew

func (f *FixU8) CloneNew() Compact

func (*FixU8) Decode

func (f *FixU8) Decode(val []byte) (int, error)

func (*FixU8) Encode

func (f *FixU8) Encode() ([]byte, error)

func (*FixU8) GetType

func (f *FixU8) GetType() TypeString

func (*FixU8) GetVal

func (f *FixU8) GetVal() interface{}

type InvokeBean

type InvokeBean struct {
	MethodName string    `json:"method_name"`
	Params     []Compact `json:"params"`
}

type Method

type Method struct {
	Name   string     `json:"name"`
	Input  []TypeInfo `json:"input"`
	Output []TypeInfo `json:"output"`
}

type PrimitiveType

type PrimitiveType int
const (
	None PrimitiveType = iota
	String
	Struct
	Uint8
	Int8
	CompactUInt8
	Uint16
	Int16
	CompactUint16
	Uint32
	Int32
	CompactUint32
	Uint64
	Int64
	CompactUint64
	BigInt
	BigUint
	CompactBigInt
	Bool
	Vec
	Primitive
	Array
	Tuple
	Enum
)

type Type

type Type struct {
	Id        uint32       `json:"id"`
	Type      string       `json:"type"`
	Fields    []TypeInfo   `json:"fields"`
	ArrayLen  int          `json:"array_len"`
	Primitive string       `json:"primitive"`
	Variants  [][]TypeInfo `json:"variants"`
}

type TypeInfo

type TypeInfo struct {
	TypeId uint32 `json:"type_id"`
}

type TypeString

type TypeString string
const (
	NoneName          TypeString = TypeString("None")
	StringName        TypeString = "String"
	StructName        TypeString = "struct"
	Uint8Name         TypeString = "u8"
	Int8Name          TypeString = "i8"
	CompactUInt8Name  TypeString = "Compact < u8 >"
	Uint16Name        TypeString = "u16"
	Int16Name         TypeString = "i16"
	CompactUint16Name TypeString = "Compact < u16 >"
	Uint32Name        TypeString = "u32"
	Int32Name         TypeString = "i32"
	CompactUint32Name TypeString = "Compact < u32 >"
	Uint64Name        TypeString = "u64"
	Int64Name         TypeString = "i64"
	CompactUint64Name TypeString = "Compact < u64 >"
	BigIntName        TypeString = "i128"
	BigUIntName       TypeString = "u128"
	CompactBigIntName TypeString = "Compact < u128 >"
	BoolName          TypeString = "bool"
	VecName           TypeString = "Vec"
	PrimitiveName     TypeString = "primitive"
	ArrayName         TypeString = "Array"
	TupleName         TypeString = "tuple"
	EnumName          TypeString = "enum"
)

func (TypeString) String

func (t TypeString) String() string

Jump to

Keyboard shortcuts

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