Documentation
¶
Index ¶
- Variables
- func NewVoteView(indexer staking.ContractStakingIndexer, cfg *VoteViewConfig, height uint64, ...) staking.ContractStakeView
- type Bucket
- type BucketReader
- type BucketStore
- type CalculateUnmutedVoteWeightAtFn
- type CalculateUnmutedVoteWeightFn
- type CalculateVoteWeightFunc
- type CandidateVotes
- type CandidateVotesManager
- type EventProcessorBuilder
- type Indexer
- func (s *Indexer) Bucket(id uint64, height uint64) (*VoteBucket, bool, error)
- func (s *Indexer) Buckets(height uint64) ([]*VoteBucket, error)
- func (s *Indexer) BucketsByCandidate(candidate address.Address, height uint64) ([]*VoteBucket, error)
- func (s *Indexer) BucketsByIndices(indices []uint64, height uint64) ([]*VoteBucket, error)
- func (s *Indexer) ContractAddress() address.Address
- func (s *Indexer) ContractStakingBuckets() (uint64, map[uint64]*Bucket, error)
- func (s *Indexer) CreateEventProcessor(ctx context.Context, handler staking.EventHandler) staking.EventProcessor
- func (s *Indexer) DeductBucket(addr address.Address, id uint64) (*contractstaking.Bucket, error)
- func (s *Indexer) Height() (uint64, error)
- func (s *Indexer) LoadStakeView(ctx context.Context, sr protocol.StateReader) (staking.ContractStakeView, error)
- func (s *Indexer) PutBlock(ctx context.Context, blk *block.Block) error
- func (s *Indexer) Start(ctx context.Context) error
- func (s *Indexer) StartHeight() uint64
- func (s *Indexer) Stop(ctx context.Context) error
- func (s *Indexer) TotalBucketCount(height uint64) (uint64, error)
- type IndexerOption
- type StakingIndexer
- type VoteBucket
- type VoteViewConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCandidateVotesIsDirty is returned when candidate votes are dirty ErrCandidateVotesIsDirty = errors.New("candidate votes is dirty") )
var ( // StakingContractABI is the abi of staking contract StakingContractABI abi.ABI )
Functions ¶
func NewVoteView ¶ added in v2.3.0
func NewVoteView( indexer staking.ContractStakingIndexer, cfg *VoteViewConfig, height uint64, cur CandidateVotes, processorBuilder EventProcessorBuilder, cvm CandidateVotesManager, fn CalculateUnmutedVoteWeightAtFn, ) staking.ContractStakeView
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) 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 ¶
ContractAddress returns the contract address
func (*Indexer) ContractStakingBuckets ¶ added in v2.3.0
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
DeductBucket deducts the bucket from the indexer
func (*Indexer) LoadStakeView ¶ added in v2.3.0
func (s *Indexer) LoadStakeView(ctx context.Context, sr protocol.StateReader) (staking.ContractStakeView, error)
LoadStakeView loads the contract stake view from state reader
func (*Indexer) StartHeight ¶
StartHeight returns the start height of the indexer
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
VoteViewConfig is the configuration for the vote view