stakingindex

package
v2.2.0-rc1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

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

	// ErrBucketNotExist is the error when bucket does not exist
	ErrBucketNotExist = errors.New("bucket does not exist")
)

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Candidate    address.Address
	Owner        address.Address
	StakedAmount *big.Int

	// Timestamped indicates whether the bucket time is in block height or timestamp
	Timestamped bool

	// these fields value are determined by the timestamped field
	StakedDuration uint64 // in seconds if timestamped, in block number if not
	CreatedAt      uint64 // in unix timestamp if timestamped, in block height if not
	UnlockedAt     uint64 // in unix timestamp if timestamped, in block height if not
	UnstakedAt     uint64 // in unix timestamp if timestamped, in block height if not

	// Muted indicates whether the bucket is vote weight muted
	Muted bool
}

func (*Bucket) Clone

func (b *Bucket) Clone() *Bucket

func (*Bucket) Deserialize

func (bi *Bucket) Deserialize(b []byte) error

Deserialize deserializes the bucket info

func (*Bucket) Serialize

func (bi *Bucket) Serialize() []byte

type Indexer

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

Indexer is the staking indexer

func NewIndexer

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

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() string

ContractAddress returns the contract address

func (*Indexer) Height

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

Height returns the tip block height

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 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() string
	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
}

StakingIndexer defines the interface of staking indexer

type VoteBucket

type VoteBucket = staking.VoteBucket

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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