service

package
v1.3.17 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PastElFieldElectionID = 0
	PastElFieldFrozenDict = 4
	PastElFieldTotalStake = 5
	PastElFieldBonuses    = 6
)

past_elections tuple layout from elector-code.fc: [election_id, unfreeze_at, stake_held, vset_hash, frozen_dict, total_stake, bonuses, complaints] https://github.com/ton-blockchain/ton/blob/master/crypto/smartcont/elector-code.fc

Variables

This section is empty.

Functions

func WithLoaders

func WithLoaders(ctx context.Context, client LiteClient) context.Context

WithLoaders creates a new context with dataloaders backed by the given client.

Types

type GetPoolDataConfigTlb

type GetPoolDataConfigTlb struct {
	ValidatorAddressBits256 tlb.Bits256
	ValidatorRewardShare    uint16
	MaxNominatorsCount      uint16
	MinValidatorStake       tlb.Coins
	MinNominatorStake       tlb.Coins
}

type GetPoolDataTlb

type GetPoolDataTlb struct {
	State           int8      // ds~load_uint(8), ;; state
	NominatorsCount uint16    // ds~load_uint(16), ;; nominators_count
	StakeAmountSent tlb.Coins // ds~load_coins(), ;; stake_amount_sent
	ValidatorAmount tlb.Coins // ds~load_coins(), ;; validator_amount

	Config GetPoolDataConfigTlb `tlb:"^"` // unpack_config(ds~load_ref().begin_parse()), ;; config

	Nominators               tlb.Maybe[tlb.Ref[tlb.Hashmap[tlb.Bits256, PackedNominatorData]]] // ds~load_dict(), ;; nominators
	WithdrawRequests         tlb.Maybe[tlb.Ref[tlb.Hashmap[tlb.Bits256, any]]]                 // ds~load_dict(), ;; withdraw_requests
	StakeAt                  uint32                                                            // ds~load_uint(32), ;; stake_at
	SavedValidatorSetHash    tlb.Bits256                                                       // ds~load_uint(256), ;; saved_validator_set_hash
	ValidatorSetChangesCount uint8                                                             // ds~load_uint(8), ;; validator_set_changes_count
	ValidatorSetChangeTime   uint32                                                            // ds~load_uint(32), ;; validator_set_change_time
	StakeHeldFor             uint32                                                            // ds~load_uint(32), ;; stake_held_for
	ConfigProposalVotings    tlb.Maybe[tlb.Ref[tlb.Hashmap[tlb.Bits256, any]]]                 // ds~load_dict() ;; config_proposal_votings
}

type LiteClient

LiteClient is the interface for blockchain operations. Implemented by RoundRobinClient and used by all service methods.

type PackedNominatorData

type PackedNominatorData struct {
	Amount               tlb.Coins
	PendingDepositAmount tlb.Coins
}

type RawPastElection

type RawPastElection struct {
	ElectAt    int64
	FrozenDict tlb.VmStackValue // cell: hashmap of frozen members
	TotalStake *big.Int         // nil if not available
	Bonuses    *big.Int         // nil if not available
}

RawPastElection holds a single parsed past_elections tuple from the elector contract.

type RetryExclude

type RetryExclude struct {
	Excluded map[int]bool // client IDs to exclude for this retry session
	LastUsed int          // set by client before each request
	// contains filtered or unexported fields
}

RetryExclude is a mutable struct passed via context. When a liteserver returns "state already gc'd", the retry loop adds that server to Excluded and retries with a different server. The client sets LastUsed before each request so the retry loop knows which server to exclude.

func WithRetryExclude

func WithRetryExclude(ctx context.Context) (context.Context, *RetryExclude)

WithRetryExclude returns a context with RetryExclude attached for use with retryWithExclude.

type RoundRobinClient

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

RoundRobinClient wraps multiple liteapi clients (one per liteserver) and distributes requests across them via round-robin. Unlike the default liteapi pool which routes all traffic through a single "best" connection, this ensures all available connections are utilized.

func NewClient

func NewClient(liteServers []config.LiteServer) (*RoundRobinClient, error)

NewClient creates a round-robin client over liteapi that distributes requests across all available liteserver connections. Unlike the default liteapi pool which routes all traffic through a single "best" connection, this ensures all connections are utilized.

func NewRoundRobinClient

func NewRoundRobinClient(liteServers []config.LiteServer) (*RoundRobinClient, error)

NewRoundRobinClient creates a client that uses one liteapi connection per liteserver and round-robins requests across them.

func (*RoundRobinClient) GetAccountState

func (r *RoundRobinClient) GetAccountState(ctx context.Context, accountID ton.AccountID) (tlb.ShardAccount, error)

func (*RoundRobinClient) GetBlock

func (r *RoundRobinClient) GetBlock(ctx context.Context, blockID ton.BlockIDExt) (tlb.Block, error)

func (*RoundRobinClient) GetConfigParams

func (r *RoundRobinClient) GetConfigParams(ctx context.Context, mode liteapi.ConfigMode, paramList []uint32) (tlb.ConfigParams, error)

func (*RoundRobinClient) GetMasterchainInfo

func (*RoundRobinClient) LookupBlock

func (r *RoundRobinClient) LookupBlock(ctx context.Context, blockID ton.BlockID, mode uint32, lt *uint64, utime *uint32) (ton.BlockIDExt, tlb.BlockInfo, error)

func (*RoundRobinClient) RunSmcMethod

func (r *RoundRobinClient) RunSmcMethod(ctx context.Context, accountID ton.AccountID, method string, params tlb.VmStack) (uint32, tlb.VmStack, error)

func (*RoundRobinClient) RunSmcMethodByID

func (r *RoundRobinClient) RunSmcMethodByID(ctx context.Context, accountID ton.AccountID, methodID int, params tlb.VmStack) (uint32, tlb.VmStack, error)

func (*RoundRobinClient) WithBlock

func (r *RoundRobinClient) WithBlock(block ton.BlockIDExt) LiteClient

WithBlock returns a client pinned to the given block for block-specific queries.

type Service

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

Service holds the blockchain client and provides validator statistics methods.

func New

func New(client LiteClient, liteServers []config.LiteServer) *Service

New creates a new Service with the given blockchain client.

func (*Service) FetchPerBlockRewards

func (s *Service) FetchPerBlockRewards(ctx context.Context, seqno *uint32, unixtime *uint32, shallow bool) (*model.Output, error)

FetchPerBlockRewards fetches validator statistics for the given seqno (or latest if nil).

func (*Service) FetchRoundRewards

func (s *Service) FetchRoundRewards(ctx context.Context, query model.RoundRewardsQuery, shallow bool) (*model.RoundRewardsOutput, error)

FetchRoundRewards computes per-validator and per-nominator reward distribution for a finished validation round using the elector's bonuses value.

func (*Service) FetchValidationRounds

func (s *Service) FetchValidationRounds(ctx context.Context, query model.RoundsQuery) (*model.ValidationRoundsOutput, error)

FetchValidationRounds returns metadata for past and current validation rounds. It resolves the anchor round sequentially, then estimates middle blocks for remaining rounds and fetches them all in parallel.

type Stats

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

func NewStats

func NewStats(options ...liteapi.Option) *Stats

func (*Stats) GetAPY

func (s *Stats) GetAPY(poolAPYMul float64) float64

func (*Stats) GetRewardsStats

func (s *Stats) GetRewardsStats() (*oas.RewardsStats, error)

func (*Stats) GetStakingPoolHistory

func (s *Stats) GetStakingPoolHistory(poolAPYMul float64, limit int) (*oas.GetStakingPoolHistoryOK, error)

Jump to

Keyboard shortcuts

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