chain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcPackedSize

func CalcPackedSize(i interface{}) (int, error)

func DecodeHash256

func DecodeHash256(hash string) ([]byte, error)

func GetBlockNumFromHex

func GetBlockNumFromHex(refBlock string) (uint32, error)

func GetRefBlockNum

func GetRefBlockNum(refBlock []byte) uint32

func GetRefBlockPrefix

func GetRefBlockPrefix(refBlock []byte) uint32

func IsNameValid

func IsNameValid(addr string) bool

func N2S

func N2S(value uint64) string

func PackArray

func PackArray(a []Serializer) []byte

func PackUint64

func PackUint64(n uint64) []byte

func PackVarInt32

func PackVarInt32(v int32) []byte

func PackVarUint32

func PackVarUint32(val uint32) []byte

func PackedVarInt32Length

func PackedVarInt32Length(v int32) int

func PackedVarUint32Length

func PackedVarUint32Length(val uint32) int

func S2N

func S2N(s string) uint64

func UnpackVarInt32

func UnpackVarInt32(buf []byte) (int32, int)

func UnpackVarUint32

func UnpackVarUint32(val []byte) (v uint32, n int)

Types

type Action

type Action struct {
	Account       Name               `json:"account"`
	Name          Name               `json:"name"`
	Authorization []*PermissionLevel `json:"authorization"`
	Data          Bytes              `json:"data"`
}

func NewAction

func NewAction(perm *PermissionLevel, account Name, name Name, args ...interface{}) *Action

func (*Action) AddPermission

func (a *Action) AddPermission(actor Name, permission Name)

func (*Action) Pack

func (a *Action) Pack() []byte

func (*Action) SetData

func (a *Action) SetData(data []byte)

func (*Action) Size

func (a *Action) Size() int

func (*Action) Unpack

func (a *Action) Unpack(b []byte) (int, error)

type BlockTimestampType

type BlockTimestampType struct {
	Slot uint32
}

func (*BlockTimestampType) Pack

func (t *BlockTimestampType) Pack() []byte

func (*BlockTimestampType) Size

func (t *BlockTimestampType) Size() int

func (*BlockTimestampType) Unpack

func (t *BlockTimestampType) Unpack(data []byte) (int, error)

type Bytes

type Bytes []byte

func (Bytes) MarshalJSON

func (t Bytes) MarshalJSON() ([]byte, error)

func (*Bytes) UnmarshalJSON

func (a *Bytes) UnmarshalJSON(b []byte) error

type Bytes32

type Bytes32 [32]byte

func NewBytes32

func NewBytes32(v []byte) *Bytes32

func NewBytes32FromHex

func NewBytes32FromHex(s string) (*Bytes32, error)

func (*Bytes32) HexString

func (t *Bytes32) HexString() string

type ChainApi

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

func NewChainApi

func NewChainApi(rpcUrl string) *ChainApi

func (*ChainApi) GetAccount

func (api *ChainApi) GetAccount(name string) (JsonObject, error)

func (*ChainApi) GetActions

func (api *ChainApi) GetActions(account string, pos int, offset int) (JsonObject, error)

func (*ChainApi) GetBlock

func (api *ChainApi) GetBlock(number uint32) (JsonObject, error)

func (*ChainApi) GetInfo

func (api *ChainApi) GetInfo() (*ChainInfo, error)

func (*ChainApi) GetRpc

func (api *ChainApi) GetRpc() *Rpc

func (*ChainApi) GetTableRows

func (api *ChainApi) GetTableRows(
	json bool,
	code string,
	scope string,
	table string,
	lowerbound string,
	upperbound string,
	limit int,
	keyType string,
	indexPosition int,
	reverse bool,
	showPayer bool,
) (JsonObject, error)

func (*ChainApi) PushAction

func (api *ChainApi) PushAction(action *Action) (JsonObject, error)

func (*ChainApi) PushActions

func (api *ChainApi) PushActions(actions []*Action) (JsonObject, error)

func (*ChainApi) PushTransaction

func (t *ChainApi) PushTransaction(tx *Transaction, signatures []string, comporess bool) (JsonObject, error)

type ChainInfo

type ChainInfo struct {
	ServerVersion             string `json:"server_version"`
	ChainID                   string `json:"chain_id"`
	HeadBlockNum              uint32 `json:"head_block_num"`
	LastIrreversibleBlockNum  uint32 `json:"last_irreversible_block_num"`
	LastIrreversibleBlockID   string `json:"last_irreversible_block_id"`
	HeadBlockID               string `json:"head_block_id"`
	HeadBlockTime             string `json:"head_block_time"`
	HeadBlockProducer         string `json:"head_block_producer"`
	VirtualBlockCPULimit      int64  `json:"virtual_block_cpu_limit"`
	VirtualBlockNetLimit      int64  `json:"virtual_block_net_limit"`
	BlockCPULimit             int64  `json:"block_cpu_limit"`
	BlockNetLimit             int64  `json:"block_net_limit"`
	ServerVersionString       string `json:"server_version_string"`
	ForkDBHeadBlockNum        int64  `json:"fork_db_head_block_num"`
	ForkDBHeadBlockID         string `json:"fork_db_head_block_id"`
	ServerFullVersionString   string `json:"server_full_version_string"`
	LastIrreversibleBlockTime string `json:"last_irreversible_block_time"`
}

func NewChainInfo

func NewChainInfo(info []byte) (*ChainInfo, error)

type Decoder

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

func NewDecoder

func NewDecoder(buf []byte) *Decoder

func (*Decoder) IsEnd

func (dec *Decoder) IsEnd() bool

func (*Decoder) Pos

func (dec *Decoder) Pos() int

func (*Decoder) Read

func (dec *Decoder) Read(b []byte) error

func (*Decoder) ReadBool

func (dec *Decoder) ReadBool() (bool, error)

func (*Decoder) ReadFloat32

func (dec *Decoder) ReadFloat32() (float32, error)

func (*Decoder) ReadFloat64

func (dec *Decoder) ReadFloat64() (float64, error)

func (*Decoder) ReadInt16

func (dec *Decoder) ReadInt16() (int16, error)

func (*Decoder) ReadInt32

func (dec *Decoder) ReadInt32() (int32, error)

func (*Decoder) ReadInt64

func (dec *Decoder) ReadInt64() (int64, error)

func (*Decoder) ReadInt8

func (dec *Decoder) ReadInt8() (int8, error)

func (*Decoder) ReadUint16

func (dec *Decoder) ReadUint16() (uint16, error)

func (*Decoder) ReadUint32

func (dec *Decoder) ReadUint32() (uint32, error)

func (*Decoder) ReadUint64

func (dec *Decoder) ReadUint64() (uint64, error)

func (*Decoder) ReadUint8

func (dec *Decoder) ReadUint8() (uint8, error)

func (*Decoder) Unpack

func (dec *Decoder) Unpack(i interface{}) (n int, err error)

func (*Decoder) UnpackAction

func (dec *Decoder) UnpackAction() (*Action, error)

func (*Decoder) UnpackBool

func (dec *Decoder) UnpackBool() (bool, error)

func (*Decoder) UnpackBytes

func (dec *Decoder) UnpackBytes() ([]byte, error)

func (*Decoder) UnpackFloat32

func (dec *Decoder) UnpackFloat32() (float32, error)

func (*Decoder) UnpackFloat64

func (dec *Decoder) UnpackFloat64() (float64, error)

func (*Decoder) UnpackI

func (dec *Decoder) UnpackI(unpacker Unpacker) error

func (*Decoder) UnpackInt16

func (dec *Decoder) UnpackInt16() (int16, error)

func (*Decoder) UnpackInt32

func (dec *Decoder) UnpackInt32() (int32, error)

func (*Decoder) UnpackInt64

func (dec *Decoder) UnpackInt64() (int64, error)

func (*Decoder) UnpackInt8

func (dec *Decoder) UnpackInt8() (int8, error)

func (*Decoder) UnpackLength

func (dec *Decoder) UnpackLength() (int, error)

func (*Decoder) UnpackName

func (dec *Decoder) UnpackName() (Name, error)

func (*Decoder) UnpackString

func (dec *Decoder) UnpackString() (string, error)

func (*Decoder) UnpackUint16

func (dec *Decoder) UnpackUint16() (uint16, error)

func (*Decoder) UnpackUint32

func (dec *Decoder) UnpackUint32() (uint32, error)

func (*Decoder) UnpackUint64

func (dec *Decoder) UnpackUint64() (uint64, error)

func (*Decoder) UnpackUint8

func (dec *Decoder) UnpackUint8() (uint8, error)

func (*Decoder) UnpackVarInt32

func (dec *Decoder) UnpackVarInt32() (int32, error)

func (*Decoder) UnpackVarUint32

func (dec *Decoder) UnpackVarUint32() (VarUint32, error)

type Encoder

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

func NewEncoder

func NewEncoder(initSize int) *Encoder

func (*Encoder) Bytes

func (enc *Encoder) Bytes() []byte

func (*Encoder) GetBytes

func (enc *Encoder) GetBytes() []byte

func (*Encoder) Pack

func (enc *Encoder) Pack(i interface{}) error

Pack supported types: Packer, interface string, bytes byte, uint16, int32, uint32, int64, uint64, float64 Name

func (*Encoder) PackBool

func (enc *Encoder) PackBool(b bool)

func (*Encoder) PackBytes

func (enc *Encoder) PackBytes(v []byte)

func (*Encoder) PackFloat32

func (enc *Encoder) PackFloat32(f float32)

func (*Encoder) PackFloat64

func (enc *Encoder) PackFloat64(f float64)

func (*Encoder) PackInt16

func (enc *Encoder) PackInt16(d int16)

func (*Encoder) PackInt32

func (enc *Encoder) PackInt32(d int32)

func (*Encoder) PackInt64

func (enc *Encoder) PackInt64(d int64)

func (*Encoder) PackInt8

func (enc *Encoder) PackInt8(d int8)

func (*Encoder) PackLength

func (enc *Encoder) PackLength(n int)

func (*Encoder) PackName

func (enc *Encoder) PackName(name Name)

func (*Encoder) PackString

func (enc *Encoder) PackString(s string)

func (*Encoder) PackUint16

func (enc *Encoder) PackUint16(d uint16)

func (*Encoder) PackUint32

func (enc *Encoder) PackUint32(d uint32)

func (*Encoder) PackUint64

func (enc *Encoder) PackUint64(d uint64)

func (*Encoder) PackUint8

func (enc *Encoder) PackUint8(d uint8)

func (*Encoder) PackVarInt32

func (enc *Encoder) PackVarInt32(n int32)

func (*Encoder) PackVarUint32

func (enc *Encoder) PackVarUint32(n uint32)

func (*Encoder) Reset

func (enc *Encoder) Reset()

func (*Encoder) Write

func (enc *Encoder) Write(b []byte)

func (*Encoder) WriteByte

func (enc *Encoder) WriteByte(b byte)

func (*Encoder) WriteBytes

func (enc *Encoder) WriteBytes(v []byte)

func (*Encoder) WriteInt

func (enc *Encoder) WriteInt(d int)

func (*Encoder) WriteInt16

func (enc *Encoder) WriteInt16(d int16)

func (*Encoder) WriteInt32

func (enc *Encoder) WriteInt32(d int32)

func (*Encoder) WriteInt64

func (enc *Encoder) WriteInt64(d int64)

func (*Encoder) WriteUint16

func (enc *Encoder) WriteUint16(d uint16)

func (*Encoder) WriteUint32

func (enc *Encoder) WriteUint32(d uint32)

func (*Encoder) WriteUint64

func (enc *Encoder) WriteUint64(d uint64)

func (*Encoder) WriteUint8

func (enc *Encoder) WriteUint8(d uint8)

type Float128

type Float128 [16]byte

func (*Float128) Pack

func (n *Float128) Pack() []byte

func (*Float128) Size

func (t *Float128) Size() int

func (*Float128) Unpack

func (n *Float128) Unpack(data []byte) (int, error)

type GetAccountArgs

type GetAccountArgs struct {
	AccountName string `json:"account_name"`
}

type GetActionsArgs

type GetActionsArgs struct {
	AccountName string `json:"account_name"`
	Pos         int    `json:"pos"`
	Offset      int    `json:"offset"`
}

type GetRequiredKeysArgs

type GetRequiredKeysArgs struct {
	Transaction   *Transaction `json:"transaction"`
	AvailableKeys []string     `json:"available_keys"`
}

type GetRequiredKeysResult

type GetRequiredKeysResult struct {
	RequiredKeys []string `json:"required_keys"`
}

required_keys

type GetTableRowsArgs

type GetTableRowsArgs struct {
	Json          bool   `json:"json"`
	Code          string `json:"code"`
	Scope         string `json:"scope"`
	Table         string `json:"table"`
	LowerBound    string `json:"lower_bound"`
	UpperBound    string `json:"upper_bound"`
	Limit         int    `json:"limit"`
	KeyType       string `json:"key_type"`
	IndexPosition int    `json:"index_position"`
	Reverse       bool   `json:"reverse"`
	ShowPayer     bool   `json:"show_payer"`
}

type Int128

type Int128 [16]byte

func (*Int128) Pack

func (n *Int128) Pack() []byte

func (*Int128) Size

func (t *Int128) Size() int

func (*Int128) Unpack

func (n *Int128) Unpack(data []byte) (int, error)

type JsonObject

type JsonObject map[string]interface{}

func NewJsonObjectFromBytes

func NewJsonObjectFromBytes(data []byte) (JsonObject, error)

func NewJsonObjectFromInterface

func NewJsonObjectFromInterface(obj interface{}) (JsonObject, bool)

func (JsonObject) Get

func (b JsonObject) Get(keys ...interface{}) (interface{}, error)

return string, []JsonObject, or map[string]interface{}

func (JsonObject) GetArray

func (b JsonObject) GetArray(keys ...interface{}) ([]interface{}, error)

func (JsonObject) GetInt64

func (b JsonObject) GetInt64(keys ...interface{}) (int64, error)

func (JsonObject) GetJsonObject

func (b JsonObject) GetJsonObject(keys ...interface{}) (JsonObject, error)

func (JsonObject) GetString

func (b JsonObject) GetString(keys ...interface{}) (string, error)

func (JsonObject) GetTime

func (b JsonObject) GetTime(keys ...interface{}) (*time.Time, error)

func (JsonObject) GetUint64

func (b JsonObject) GetUint64(keys ...interface{}) (uint64, error)

func (JsonObject) ToString

func (b JsonObject) ToString() string

type Name

type Name struct {
	N uint64
}

func NewName

func NewName(s string) Name

func (*Name) MarshalJSON

func (a *Name) MarshalJSON() ([]byte, error)

func (*Name) Pack

func (a *Name) Pack() []byte

func (*Name) Size

func (t *Name) Size() int

func (*Name) String

func (a *Name) String() string

func (*Name) UnmarshalJSON

func (a *Name) UnmarshalJSON(b []byte) error

func (*Name) Unpack

func (a *Name) Unpack(data []byte) (int, error)

type PackedSize

type PackedSize interface {
	Size() int
}

type PackedTransaction

type PackedTransaction struct {
	Signatures    []string `json:"signatures"`
	Compression   string   `json:"compression"`
	PackedContext Bytes    `json:"packed_context_free_data"`
	PackedTx      Bytes    `json:"packed_trx"`
}

func NewPackedTransaction

func NewPackedTransaction(tx *Transaction, signatures []string, compress bool) *PackedTransaction

func (*PackedTransaction) AddSignatures

func (t *PackedTransaction) AddSignatures(signatures []string)

type Packer

type Packer interface {
	Pack() []byte
}

type PermissionLevel

type PermissionLevel struct {
	Actor      Name `json:"actor"`
	Permission Name `json:"permission"`
}

func (*PermissionLevel) Pack

func (t *PermissionLevel) Pack() []byte

func (*PermissionLevel) Size

func (t *PermissionLevel) Size() int

func (*PermissionLevel) Unpack

func (t *PermissionLevel) Unpack(data []byte) (int, error)

type Rpc

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

func NewRpc

func NewRpc(url string) *Rpc

func (*Rpc) Call

func (r *Rpc) Call(api string, endpoint string, params interface{}) ([]byte, error)

func (*Rpc) GetAccount

func (r *Rpc) GetAccount(args *GetAccountArgs) (JsonObject, error)

func (*Rpc) GetActions

func (t *Rpc) GetActions(args *GetActionsArgs) (JsonObject, error)

func (*Rpc) GetInfo

func (r *Rpc) GetInfo() (*ChainInfo, error)

func (*Rpc) GetRequiredKeys

func (r *Rpc) GetRequiredKeys(args *GetRequiredKeysArgs) (*GetRequiredKeysResult, error)

func (*Rpc) GetTableRows

func (t *Rpc) GetTableRows(args *GetTableRowsArgs) (JsonObject, error)

func (*Rpc) PushTransaction

func (t *Rpc) PushTransaction(tx *Transaction, signatures []string, compress bool) (JsonObject, error)

type RpcError

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

func NewRpcError

func NewRpcError(err string) *RpcError

func (*RpcError) Error

func (r *RpcError) Error() string

type Serializer

type Serializer interface {
	Pack() []byte
	Unpack([]byte) (int, uint64)
}

type TimePoint

type TimePoint struct {
	Elapsed uint64
}

func (*TimePoint) Pack

func (t *TimePoint) Pack() []byte

func (*TimePoint) Size

func (t *TimePoint) Size() int

func (*TimePoint) Unpack

func (t *TimePoint) Unpack(data []byte) (int, error)

type TimePointSec

type TimePointSec struct {
	UTCSeconds uint32
}

func (TimePointSec) MarshalJSON

func (t TimePointSec) MarshalJSON() ([]byte, error)

func (*TimePointSec) Pack

func (t *TimePointSec) Pack() []byte

func (*TimePointSec) Size

func (t *TimePointSec) Size() int

func (*TimePointSec) UnmarshalJSON

func (a *TimePointSec) UnmarshalJSON(b []byte) error

func (*TimePointSec) Unpack

func (t *TimePointSec) Unpack(data []byte) (int, error)

type Transaction

type Transaction struct {
	// time_point_sec  expiration;
	// uint16_t        ref_block_num;
	// uint32_t        ref_block_prefix;
	// unsigned_int    max_net_usage_words = 0UL; /// number of 8 byte words this transaction can serialize into after compressions
	// uint8_t         max_cpu_usage_ms = 0UL; /// number of CPU usage units to bill transaction for
	// unsigned_int    delay_sec = 0UL; /// number of seconds to delay transaction, default: 0
	Expiration     TimePointSec `json:"expiration"`
	RefBlockNum    uint16       `json:"ref_block_num"`
	RefBlockPrefix uint32       `json:"ref_block_prefix"`
	//[VLQ or Base-128 encoding](https://en.wikipedia.org/wiki/Variable-length_quantity)
	//unsigned_int vaint (eosio.cdt/libraries/eosiolib/core/eosio/varint.hpp)
	MaxNetUsageWords   VarUint32               `json:"max_net_usage_words"`
	MaxCpuUsageMs      uint8                   `json:"max_cpu_usage_ms"`
	DelaySec           VarUint32               `json:"delay_sec"`
	ContextFreeActions []*Action               `json:"context_free_actions"`
	Actions            []*Action               `json:"actions"`
	Extention          []*TransactionExtension `json:"transaction_extensions"`
}

func NewTransaction

func NewTransaction(expiration uint32) *Transaction

func (*Transaction) AddAction

func (t *Transaction) AddAction(a *Action)

func (*Transaction) Id

func (t *Transaction) Id(chainId *Bytes32) *Bytes32

func (*Transaction) Marshal

func (t *Transaction) Marshal() string

func (*Transaction) Pack

func (t *Transaction) Pack() []byte

func (*Transaction) SetReferenceBlock

func (t *Transaction) SetReferenceBlock(refBlock string) error

func (*Transaction) Sign

func (t *Transaction) Sign(privKey *secp256k1.PrivateKey, chainId *Bytes32) (*secp256k1.Signature, error)

func (*Transaction) SignWithPublicKey

func (t *Transaction) SignWithPublicKey(pubKey string, chainId *Bytes32) (*secp256k1.Signature, error)

func (*Transaction) Unpack

func (t *Transaction) Unpack(data []byte) (int, error)

type TransactionExtension

type TransactionExtension struct {
	Type uint16
	Data []byte
}

func (*TransactionExtension) Pack

func (t *TransactionExtension) Pack() []byte

func (*TransactionExtension) Size

func (a *TransactionExtension) Size() int

func (*TransactionExtension) Unpack

func (t *TransactionExtension) Unpack(data []byte) (int, error)

type Uint128

type Uint128 [16]byte

func (*Uint128) Pack

func (n *Uint128) Pack() []byte

func (*Uint128) SetUint64

func (n *Uint128) SetUint64(v uint64)

func (*Uint128) Size

func (t *Uint128) Size() int

func (*Uint128) Uint64

func (n *Uint128) Uint64() uint64

func (*Uint128) Unpack

func (n *Uint128) Unpack(data []byte) (int, error)

type Uint256

type Uint256 [32]uint8

func (*Uint256) Pack

func (n *Uint256) Pack() []byte

func (*Uint256) SetUint64

func (n *Uint256) SetUint64(v uint64)

func (*Uint256) Size

func (t *Uint256) Size() int

func (*Uint256) Uint64

func (n *Uint256) Uint64() uint64

func (*Uint256) Unpack

func (n *Uint256) Unpack(data []byte) (int, error)

type Unpacker

type Unpacker interface {
	Unpack(data []byte) (int, error)
}

type VarInt32

type VarInt32 int32

func (*VarInt32) Pack

func (t *VarInt32) Pack() []byte

func (*VarInt32) Size

func (t *VarInt32) Size() int

func (*VarInt32) Unpack

func (t *VarInt32) Unpack(data []byte) (int, error)

type VarUint32

type VarUint32 uint32

func (*VarUint32) MarshalJSON

func (t *VarUint32) MarshalJSON() ([]byte, error)

func (*VarUint32) Pack

func (t *VarUint32) Pack() []byte

func (*VarUint32) Size

func (t *VarUint32) Size() int

func (*VarUint32) Unpack

func (t *VarUint32) Unpack(data []byte) (int, error)

type Wallet

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

func GetWallet

func GetWallet() *Wallet

func (*Wallet) GetPrivateKey

func (w *Wallet) GetPrivateKey(pubKey string) (*secp256k1.PrivateKey, error)

func (*Wallet) GetPublicKeys

func (w *Wallet) GetPublicKeys() []string

GetPublicKeys

func (*Wallet) Import

func (w *Wallet) Import(name string, strPriv string) error

func (*Wallet) Sign

func (w *Wallet) Sign(digest *Bytes32, pubKey string) (*secp256k1.Signature, error)

Jump to

Keyboard shortcuts

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