Documentation ¶
Index ¶
- Variables
- type Candidate
- func (c *Candidate) Address() []byte
- func (c *Candidate) Clone() *Candidate
- func (c *Candidate) FromProtoMsg(msg *pb.Candidate) error
- func (c *Candidate) Name() []byte
- func (c *Candidate) OperatorAddress() []byte
- func (c *Candidate) RewardAddress() []byte
- func (c *Candidate) Score() *big.Int
- func (c *Candidate) SelfStakingTokens() *big.Int
- func (c *Candidate) SelfStakingWeight() uint64
- func (c *Candidate) ToProtoMsg() (*pb.Candidate, error)
- type CandidateFilterFunc
- type ElectionResult
- func (r *ElectionResult) Delegates() []*Candidate
- func (r *ElectionResult) Deserialize(data []byte) error
- func (r *ElectionResult) FromProtoMsg(rPb *pb.ElectionResult) (err error)
- func (r *ElectionResult) MintTime() time.Time
- func (r *ElectionResult) Serialize() ([]byte, error)
- func (r *ElectionResult) ToProtoMsg() (*pb.ElectionResult, error)
- func (r *ElectionResult) TotalVotedStakes() *big.Int
- func (r *ElectionResult) TotalVotes() *big.Int
- func (r *ElectionResult) VotesByDelegate(name []byte) []*Vote
- type ResultCalculator
- type Vote
- func (v *Vote) Amount() *big.Int
- func (v *Vote) Candidate() []byte
- func (v *Vote) Clone() *Vote
- func (v *Vote) Decay() bool
- func (v *Vote) Deserialize(data []byte) error
- func (v *Vote) Duration() time.Duration
- func (v *Vote) FromProtoMsg(vPb *pb.Vote) (err error)
- func (v *Vote) RemainingTime(now time.Time) time.Duration
- func (v *Vote) Serialize() ([]byte, error)
- func (v *Vote) SetWeightedAmount(w *big.Int) error
- func (v *Vote) StartTime() time.Time
- func (v *Vote) ToProtoMsg() (*pb.Vote, error)
- func (v *Vote) Voter() []byte
- func (v *Vote) WeightedAmount() *big.Int
- type VoteFilterFunc
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidProto = errors.New("Invalid election proto")
ErrInvalidProto indicates a format error of an election proto
Functions ¶
This section is empty.
Types ¶
type Candidate ¶
type Candidate struct {
// contains filtered or unexported fields
}
Candidate defines a delegate candidate
func NewCandidate ¶
func NewCandidate( name []byte, address []byte, operatorAddress []byte, rewardPubKey []byte, selfStakingWeight uint64, ) *Candidate
NewCandidate creates a new candidate with scores as 0s
func (*Candidate) FromProtoMsg ¶
FromProtoMsg fills the instance with a protobuf message
func (*Candidate) OperatorAddress ¶
OperatorAddress returns the address of the assigned operator on chain
func (*Candidate) RewardAddress ¶
RewardAddress returns the address of the assigned benefiter on chain
func (*Candidate) SelfStakingTokens ¶
SelfStakingTokens returns the total self votes (weighted)
func (*Candidate) SelfStakingWeight ¶
SelfStakingWeight returns the extra weight for self staking
type CandidateFilterFunc ¶
CandidateFilterFunc defines the function to filter candidate
type ElectionResult ¶
type ElectionResult struct {
// contains filtered or unexported fields
}
ElectionResult defines the collection of voting result on a height
func NewElectionResultForTest ¶
func NewElectionResultForTest( mintTime time.Time, ) *ElectionResult
NewElectionResultForTest creates an election result for test purpose only
func (*ElectionResult) Delegates ¶
func (r *ElectionResult) Delegates() []*Candidate
Delegates returns a list of sorted delegates
func (*ElectionResult) Deserialize ¶
func (r *ElectionResult) Deserialize(data []byte) error
Deserialize converts a byte array to election result
func (*ElectionResult) FromProtoMsg ¶
func (r *ElectionResult) FromProtoMsg(rPb *pb.ElectionResult) (err error)
FromProtoMsg extracts result details from protobuf message
func (*ElectionResult) MintTime ¶
func (r *ElectionResult) MintTime() time.Time
MintTime returns the mint time of the corresponding beacon chain block
func (*ElectionResult) Serialize ¶
func (r *ElectionResult) Serialize() ([]byte, error)
Serialize converts result to byte array
func (*ElectionResult) ToProtoMsg ¶
func (r *ElectionResult) ToProtoMsg() (*pb.ElectionResult, error)
ToProtoMsg converts the vote to protobuf
func (*ElectionResult) TotalVotedStakes ¶
func (r *ElectionResult) TotalVotedStakes() *big.Int
TotalVotedStakes returns the total amount of stakings which has been voted
func (*ElectionResult) TotalVotes ¶
func (r *ElectionResult) TotalVotes() *big.Int
TotalVotes returns the total votes in the result
func (*ElectionResult) VotesByDelegate ¶
func (r *ElectionResult) VotesByDelegate(name []byte) []*Vote
VotesByDelegate returns a list of votes for a given delegate
type ResultCalculator ¶
type ResultCalculator struct {
// contains filtered or unexported fields
}
ResultCalculator defines a calculator for a set of votes
func NewResultCalculator ¶
func NewResultCalculator( mintTime time.Time, voteFilter VoteFilterFunc, calcScore func(*Vote, time.Time) *big.Int, candidateFilter CandidateFilterFunc, ) *ResultCalculator
NewResultCalculator creates a result calculator
func (*ResultCalculator) AddCandidates ¶
func (calculator *ResultCalculator) AddCandidates(candidates []*Candidate) error
AddCandidates adds candidates to result
func (*ResultCalculator) AddVotes ¶
func (calculator *ResultCalculator) AddVotes(votes []*Vote) error
AddVotes adds votes to result
func (*ResultCalculator) Calculate ¶
func (calculator *ResultCalculator) Calculate() (*ElectionResult, error)
Calculate summaries the result with candidates and votes added
type Vote ¶
type Vote struct {
// contains filtered or unexported fields
}
Vote defines the structure of a vote
func NewVote ¶
func NewVote( startTime time.Time, duration time.Duration, amount *big.Int, weighted *big.Int, voter []byte, candidate []byte, decay bool, ) (*Vote, error)
NewVote creates a new vote
func (*Vote) Deserialize ¶
Deserialize deserializes a byte array to vote
func (*Vote) FromProtoMsg ¶
FromProtoMsg extracts vote details from protobuf message
func (*Vote) RemainingTime ¶
RemainingTime returns the remaining time to given time
func (*Vote) SetWeightedAmount ¶
SetWeightedAmount sets the weighted amount for the vote
func (*Vote) ToProtoMsg ¶
ToProtoMsg converts the vote to protobuf
func (*Vote) WeightedAmount ¶
WeightedAmount returns the weighted amount of vote
type VoteFilterFunc ¶
VoteFilterFunc defines the function to filter vote