client

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitUnmarshalData

func InitUnmarshalData(info TokenInfo)

Types

type AccountBalance

type AccountBalance struct {
	Free     TokenBalance `json:"free"`
	Reserved TokenBalance `json:"reserved"`
	Frozen   TokenBalance `json:"frozen"`
}

func (*AccountBalance) GetTransferableBalance added in v0.0.16

func (ab *AccountBalance) GetTransferableBalance() *TokenBalance

type AccountIdentity

type AccountIdentity struct {
	Display string `json:"display,omitempty"`
}

type AccountInfo

type AccountInfo struct {
	Address  string          `json:"address"`
	Balance  AccountBalance  `json:"balance"`
	Identity AccountIdentity `json:"identity,omitempty"`
}

type CandidatePoolEntry

type CandidatePoolEntry struct {
	Owner  string
	Amount TokenAmount
}

type Client

type Client struct {
	RpcUrl      string      `json:"endpoint"`
	Chain       string      `json:"chain"`
	SpecVersion int         `json:"spec"`
	SnapBlock   SnapBlock   `json:"block"`
	SnapRound   SnapRound   `json:"round"`
	SnapStaking SnapStaking `json:"candidate_pool"`
	TokenInfo   TokenInfo   `json:"token"`
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config config.ChainConfig) (*Client, error)

func NewClientWithExternalCache

func NewClientWithExternalCache(cfg config.ChainConfig, cache *mcache.CacheDriver) (*Client, error)

func (*Client) FetchAccountInfo

func (c *Client) FetchAccountInfo(address string) (AccountInfo, error)

func (*Client) FetchCollatorBlocks

func (c *Client) FetchCollatorBlocks(address string, round uint32, blockHash types.Hash) (uint32, error)

func (*Client) FetchCollatorHistory

func (c *Client) FetchCollatorHistory(
	address string,
	historyRounds uint32,
) (map[uint32]CollatorHistory, error)

func (*Client) FetchCollatorInfo

func (c *Client) FetchCollatorInfo(
	address string,
	selected bool,
	rank uint32,
	cfg config.CollatorsPoolConfig,
) (CollatorInfo, error)

func (*Client) FetchCollatorPool

func (c *Client) FetchCollatorPool(poolConfig config.CollatorsPoolConfig) (CollatorPool, error)

func (*Client) FetchSelectedCandidates

func (c *Client) FetchSelectedCandidates(blockHash types.Hash) ([]string, error)

FetchSelectedCandidates returns a list of addresses currently selected

func (*Client) FetchSortedCandidatePool

func (c *Client) FetchSortedCandidatePool(blockHash types.Hash) ([]CandidatePoolEntry, error)

FetchSortedCandidatePool returns the full list of candidates with bonded amount

func (*Client) GetBlockNumber

func (c *Client) GetBlockNumber(hash types.Hash) (uint64, error)

func (*Client) GetCandidateBondLessDelay

func (c *Client) GetCandidateBondLessDelay() (uint32, error)

GetCandidateBondLessDelay will fetch current bond delay

func (*Client) GetConstantValue

func (c *Client) GetConstantValue(
	pallet string,
	method string,
	typeString string,
	targetValue any,
) error

GetConstantValue will fetch a constant value and Marshal it as JSON

func (*Client) GetRoundEndHash

func (c *Client) GetRoundEndHash(round uint32) (types.Hash, error)

func (*Client) GetRoundStartHash

func (c *Client) GetRoundStartHash(round uint32) (types.Hash, error)

func (*Client) GetStorage

func (c *Client) GetStorage(
	pallet string,
	method string,
	target interface{},
	args ...[]byte,
) (ok bool, err error)

func (*Client) GetStorageAt

func (c *Client) GetStorageAt(
	pallet string,
	method string,
	target interface{},
	blockHash types.Hash,
	args ...[]byte,
) (ok bool, err error)

func (*Client) GetStorageRaw

func (c *Client) GetStorageRaw(
	pallet string,
	method string,
	typeString string,
	targetValue any,
	args ...[]byte,
) error

GetStorageRaw will fetch storage at client snap block with minimum cache TTL (since we have no block reference)

func (*Client) GetStorageRawAt

func (c *Client) GetStorageRawAt(
	pallet string,
	method string,
	typeString string,
	blockHash types.Hash,
	targetValue any,
	args ...[]byte,
) error

GetStorageRawAt will fetch storage at given block with default cache TTL

func (*Client) GetStorageRawWithTtl

func (c *Client) GetStorageRawWithTtl(
	pallet string,
	method string,
	typeString string,
	cacheTtl time.Duration,
	targetValue any,
	args ...[]byte,
) error

GetStorageRawWithTtl will fetch storage at client snap block caching with given TTL and ignoring block

type CollatorHistory

type CollatorHistory struct {
	Rank    uint32       `json:"rank"`
	Blocks  uint32       `json:"blocks"`
	Counted TokenBalance `json:"counted"`
}

type CollatorInfo

type CollatorInfo struct {
	Address     string                     `json:"address"`
	Selected    bool                       `json:"selected"`
	Rank        uint32                     `json:"rank"`
	Blocks      uint32                     `json:"blocks"`
	Counted     TokenBalance               `json:"counted"`
	MinBond     TokenBalance               `json:"min_bond"`
	Balance     AccountBalance             `json:"balance"`
	Display     string                     `json:"display"`
	History     map[uint32]CollatorHistory `json:"history,omitempty"`
	Delegations []DelegatorState           `json:"-"`
	Revokes     map[uint32]RevokeRound     `json:"revokes,omitempty"`
}

func (*CollatorInfo) AverageBlocks

func (ci *CollatorInfo) AverageBlocks() float32

func (*CollatorInfo) DisplayName

func (ci *CollatorInfo) DisplayName() string

func (*CollatorInfo) RevokeAt

func (ci *CollatorInfo) RevokeAt(round uint32) *RevokeRound

type CollatorPool

type CollatorPool struct {
	SelectedSize uint32         `json:"selected_size"`
	RoundNumber  uint32         `json:"round_number"`
	Collators    []CollatorInfo `json:"collators"`
}

func (*CollatorPool) CollatorInfoByAddress

func (cp *CollatorPool) CollatorInfoByAddress(address string) (CollatorInfo, bool)

type DelegatorState

type DelegatorState struct {
	Address      string       `json:"address"`
	Amount       TokenBalance `json:"amount"`
	RevokeAmount TokenBalance `json:"revoke_amount,omitempty"`
	RevokeReason string       `json:"revoke_reason,omitempty"`
	RevokeRound  uint32       `json:"revoke_round,omitempty"`
}

type RevokeRound

type RevokeRound struct {
	Rank    uint32       `json:"rank"`
	Counted TokenBalance `json:"counted"`
	Amount  TokenBalance `json:"amount"`
}

type ScaleEnum

type ScaleEnum map[string][]byte

func (*ScaleEnum) Value

func (s *ScaleEnum) Value() string

type Snap

type Snap struct {
	Block   SnapBlock
	Round   SnapRound
	Staking SnapStaking
}

type SnapBlock

type SnapBlock struct {
	Number       uint64     `json:"current"`
	Hash         types.Hash `json:"hash"`
	TsMillis     uint64     `json:"ts"`
	DurationSecs float64    `json:"duration"`
}

type SnapRound

type SnapRound struct {
	Number      uint32 `json:"number"`
	Length      uint32 `json:"length"`
	Start       uint32 `json:"start"`
	RevokeDelay uint32 `json:"revoke_delay"`
}

type SnapStaking

type SnapStaking struct {
	Selected uint32 `json:"selected"`
	Total    uint32 `json:"total"`
}

type TokenAmount

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

func (*TokenAmount) AsBalance

func (b *TokenAmount) AsBalance(info *TokenInfo) TokenBalance

func (*TokenAmount) AsBigInt

func (b *TokenAmount) AsBigInt() *big.Int

func (*TokenAmount) Cmp

func (b *TokenAmount) Cmp(y *TokenAmount) int

func (*TokenAmount) MarshalJSON

func (b *TokenAmount) MarshalJSON() ([]byte, error)

func (*TokenAmount) UnmarshalJSON

func (b *TokenAmount) UnmarshalJSON(p []byte) error

type TokenBalance

type TokenBalance struct {
	Balance *TokenAmount `json:"balance"`
	// contains filtered or unexported fields
}

func TokenBalanceU128

func TokenBalanceU128(c *Client, u128 types.U128) TokenBalance

func (*TokenBalance) Float64

func (tb *TokenBalance) Float64() float64

func (TokenBalance) MarshalJSON

func (tb TokenBalance) MarshalJSON() ([]byte, error)

func (*TokenBalance) UnmarshalJSON

func (tb *TokenBalance) UnmarshalJSON(p []byte) error

type TokenInfo

type TokenInfo struct {
	TokenDecimals uint32 `json:"decimals"`
	TokenSymbol   string `json:"symbol"`
}
var (
	GlobalTokenInfo TokenInfo
)

Jump to

Keyboard shortcuts

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