stakingindex

package
v2.3.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCandidateVotesIsDirty is returned when candidate votes are dirty
	ErrCandidateVotesIsDirty = errors.New("candidate votes is dirty")
)
View Source
var (

	// StakingContractABI is the abi of staking contract
	StakingContractABI abi.ABI
)

Functions

func NewVoteView added in v2.3.0

NewVoteView creates a new vote view

Types

type Bucket

type Bucket = contractstaking.Bucket

type BucketReader added in v2.3.0

type BucketReader = staking.BucketReader

type BucketStore added in v2.3.0

type BucketStore staking.EventHandler

BucketStore is the interface to manage buckets in the event handler

func NewVoteViewEventHandler added in v2.3.0

func NewVoteViewEventHandler(store BucketStore, view CandidateVotes, fn CalculateUnmutedVoteWeightFn) (BucketStore, error)

NewVoteViewEventHandler creates a new vote view event handler wrapper

type CalculateUnmutedVoteWeightAtFn added in v2.3.0

type CalculateUnmutedVoteWeightAtFn func(*contractstaking.Bucket, uint64) *big.Int

type CalculateUnmutedVoteWeightFn added in v2.3.0

type CalculateUnmutedVoteWeightFn func(*contractstaking.Bucket) *big.Int

type CalculateVoteWeightFunc added in v2.3.0

type CalculateVoteWeightFunc func(v *VoteBucket) *big.Int

type CandidateVotes added in v2.3.0

type CandidateVotes interface {
	Clone() CandidateVotes
	Votes(fCtx protocol.FeatureCtx, cand string) *big.Int
	Add(cand string, amount *big.Int, votes *big.Int)
	Commit() CandidateVotes
	Base() CandidateVotes
	IsDirty() bool
	Serialize() ([]byte, error)
	Deserialize(data []byte) error
}

CandidateVotes is the interface to manage candidate votes

func AggregateCandidateVotes added in v2.3.0

func AggregateCandidateVotes(bkts map[uint64]*Bucket, calculateUnmutedVoteWeight CalculateUnmutedVoteWeightFn) CandidateVotes

AggregateCandidateVotes aggregates the votes for each candidate from the given buckets

type CandidateVotesManager added in v2.3.0

type CandidateVotesManager interface {
	Load(ctx context.Context, sr protocol.StateReader) (CandidateVotes, error)
	Store(ctx context.Context, sm protocol.StateManager, candVotes CandidateVotes) error
}

CandidateVotesManager defines the interface to manage candidate votes

func NewCandidateVotesManager added in v2.3.0

func NewCandidateVotesManager(contractAddr address.Address) CandidateVotesManager

NewCandidateVotesManager creates a new instance of CandidateVotesManager

type EventProcessorBuilder added in v2.3.0

type EventProcessorBuilder interface {
	Build(context.Context, staking.EventHandler) staking.EventProcessor
}

EventProcessorBuilder is the interface to build event processor

type Indexer

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

Indexer is the staking indexer

func NewIndexer

func NewIndexer(kvstore db.KVStore, contractAddr address.Address, startHeight uint64, blocksToDurationFn blocksDurationAtFn, opts ...IndexerOption) (*Indexer, error)

NewIndexer creates a new staking indexer

func (*Indexer) Bucket

func (s *Indexer) Bucket(id uint64, height uint64) (*VoteBucket, bool, error)

Bucket returns the bucket

func (*Indexer) Buckets

func (s *Indexer) Buckets(height uint64) ([]*VoteBucket, error)

Buckets returns the buckets

func (*Indexer) BucketsByCandidate

func (s *Indexer) BucketsByCandidate(candidate address.Address, height uint64) ([]*VoteBucket, error)

BucketsByCandidate returns the buckets by candidate

func (*Indexer) BucketsByIndices

func (s *Indexer) BucketsByIndices(indices []uint64, height uint64) ([]*VoteBucket, error)

BucketsByIndices returns the buckets by indices

func (*Indexer) ContractAddress

func (s *Indexer) ContractAddress() address.Address

ContractAddress returns the contract address

func (*Indexer) ContractStakingBuckets added in v2.3.0

func (s *Indexer) ContractStakingBuckets() (uint64, map[uint64]*Bucket, error)

ContractStakingBuckets returns all the contract staking buckets

func (*Indexer) CreateEventProcessor added in v2.3.0

func (s *Indexer) CreateEventProcessor(ctx context.Context, handler staking.EventHandler) staking.EventProcessor

CreateEventProcessor creates a new event processor

func (*Indexer) DeductBucket added in v2.3.0

func (s *Indexer) DeductBucket(addr address.Address, id uint64) (*contractstaking.Bucket, error)

DeductBucket deducts the bucket from the indexer

func (*Indexer) Height

func (s *Indexer) Height() (uint64, error)

Height returns the tip block height

func (*Indexer) LoadStakeView added in v2.3.0

LoadStakeView loads the contract stake view from state reader

func (*Indexer) PutBlock

func (s *Indexer) PutBlock(ctx context.Context, blk *block.Block) error

PutBlock puts a block into indexer

func (*Indexer) Start

func (s *Indexer) Start(ctx context.Context) error

Start starts the indexer

func (*Indexer) StartHeight

func (s *Indexer) StartHeight() uint64

StartHeight returns the start height of the indexer

func (*Indexer) Stop

func (s *Indexer) Stop(ctx context.Context) error

Stop stops the indexer

func (*Indexer) TotalBucketCount

func (s *Indexer) TotalBucketCount(height uint64) (uint64, error)

TotalBucketCount returns the total bucket count including active and burnt buckets

type IndexerOption added in v2.2.0

type IndexerOption func(*Indexer)

IndexerOption is the option to create an indexer

func EnableTimestamped added in v2.2.0

func EnableTimestamped() IndexerOption

EnableTimestamped enables timestamped

func WithCalculateUnmutedVoteWeightFn added in v2.3.0

func WithCalculateUnmutedVoteWeightFn(f CalculateVoteWeightFunc) IndexerOption

WithCalculateUnmutedVoteWeightFn sets the function to calculate unmuted vote weight

func WithMuteHeight added in v2.2.0

func WithMuteHeight(height uint64) IndexerOption

WithMuteHeight sets the mute height

type StakingIndexer

type StakingIndexer interface {
	lifecycle.StartStopper
	Height() (uint64, error)
	StartHeight() uint64
	ContractAddress() address.Address
	Buckets(height uint64) ([]*VoteBucket, error)
	Bucket(id uint64, height uint64) (*VoteBucket, bool, error)
	BucketsByIndices(indices []uint64, height uint64) ([]*VoteBucket, error)
	BucketsByCandidate(candidate address.Address, height uint64) ([]*VoteBucket, error)
	TotalBucketCount(height uint64) (uint64, error)
	PutBlock(ctx context.Context, blk *block.Block) error
	LoadStakeView(context.Context, protocol.StateReader) (staking.ContractStakeView, error)
	CreateEventProcessor(context.Context, staking.EventHandler) staking.EventProcessor
	ContractStakingBuckets() (uint64, map[uint64]*Bucket, error)
	staking.BucketReader
}

StakingIndexer defines the interface of staking indexer

type VoteBucket

type VoteBucket = staking.VoteBucket

type VoteViewConfig added in v2.3.0

type VoteViewConfig struct {
	ContractAddr address.Address
}

VoteViewConfig is the configuration for the vote view

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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