Documentation ¶
Index ¶
- Variables
- func CalcWeightedVotes(v *Bucket, now time.Time) *big.Int
- type Bucket
- func (bucket *Bucket) Amount() *big.Int
- func (bucket *Bucket) Candidate() []byte
- func (bucket *Bucket) Clone() *Bucket
- func (bucket *Bucket) Decay() bool
- func (bucket *Bucket) Deserialize(data []byte) error
- func (bucket *Bucket) Duration() time.Duration
- func (bucket *Bucket) Equal(b *Bucket) bool
- func (bucket *Bucket) FromProtoMsg(vPb *pb.Bucket) (err error)
- func (bucket *Bucket) Hash() (hash.Hash256, error)
- func (bucket *Bucket) RemainingTime(now time.Time) time.Duration
- func (bucket *Bucket) Serialize() ([]byte, error)
- func (bucket *Bucket) StartTime() time.Time
- func (bucket *Bucket) ToProtoMsg() (*pb.Bucket, error)
- func (bucket *Bucket) Voter() []byte
- type BucketFilterFunc
- type Candidate
- func (c *Candidate) Clone() *Candidate
- func (c *Candidate) Equal(candidate *Candidate) bool
- func (c *Candidate) FromProtoMsg(msg *pb.Candidate) error
- func (c *Candidate) Score() *big.Int
- func (c *Candidate) SelfStakingTokens() *big.Int
- func (c *Candidate) SetScore(score *big.Int)
- func (c *Candidate) SetSelfStakingTokens(selfStakingTokens *big.Int)
- func (c *Candidate) ToProtoMsg() (*pb.Candidate, error)
- type CandidateFilterFunc
- type ElectionResult
- func (r *ElectionResult) DelegateByName(name []byte) *Candidate
- func (r *ElectionResult) Delegates() []*Candidate
- func (r *ElectionResult) Deserialize(data []byte) error
- func (r *ElectionResult) Equal(result *ElectionResult) bool
- func (r *ElectionResult) FromProtoMsg(rPb *pb.ElectionResult) (err error)
- func (r *ElectionResult) MintTime() time.Time
- func (r *ElectionResult) Serialize() ([]byte, error)
- func (r *ElectionResult) String() string
- func (r *ElectionResult) ToProtoMsg() (*pb.ElectionResult, error)
- func (r *ElectionResult) TotalVotedStakes() *big.Int
- func (r *ElectionResult) TotalVotes() *big.Int
- func (r *ElectionResult) Votes() []*Vote
- func (r *ElectionResult) VotesByDelegate(name []byte) []*Vote
- type Poll
- type Registration
- func (reg *Registration) Address() []byte
- func (reg *Registration) Clone() *Registration
- func (reg *Registration) Deserialize(data []byte) error
- func (reg *Registration) Equal(r *Registration) bool
- func (reg *Registration) FromProtoMsg(msg *pb.Registration) error
- func (reg *Registration) Hash() (hash.Hash256, error)
- func (reg *Registration) Name() []byte
- func (reg *Registration) OperatorAddress() []byte
- func (reg *Registration) RewardAddress() []byte
- func (reg *Registration) SelfStakingWeight() uint64
- func (reg *Registration) Serialize() ([]byte, error)
- func (reg *Registration) ToProtoMsg() (*pb.Registration, error)
- type ResultCalculator
- type Vote
- func (v *Vote) Clone() *Vote
- func (v *Vote) Deserialize(data []byte) error
- func (v *Vote) Equal(vote *Vote) bool
- func (v *Vote) FromProtoMsg(vPb *pb.Vote) (err error)
- func (v *Vote) Serialize() ([]byte, error)
- func (v *Vote) SetWeightedAmount(w *big.Int) error
- func (v *Vote) ToProtoMsg() (*pb.Vote, error)
- func (v *Vote) WeightedAmount() *big.Int
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidProto = errors.New("Invalid election proto")
ErrInvalidProto indicates a format error of an election proto
Functions ¶
Types ¶
type Bucket ¶ added in v0.2.0
type Bucket struct {
// contains filtered or unexported fields
}
Bucket defines a bucket stored in staking contract
func NewBucket ¶ added in v0.2.0
func NewBucket( startTime time.Time, duration time.Duration, amount *big.Int, voter []byte, candidate []byte, decay bool, ) (*Bucket, error)
NewBucket creates a new bucket
func (*Bucket) Deserialize ¶ added in v0.2.0
Deserialize deserializes a byte array to bucket
func (*Bucket) FromProtoMsg ¶ added in v0.2.0
FromProtoMsg extracts bucket details from protobuf message (voteCore)
func (*Bucket) RemainingTime ¶ added in v0.2.0
RemainingTime returns the remaining time to given time
func (*Bucket) ToProtoMsg ¶ added in v0.2.0
ToProtoMsg converts the bucket to protobuf
type BucketFilterFunc ¶ added in v0.2.0
BucketFilterFunc defines the function to filter vote
type Candidate ¶
type Candidate struct { Registration // contains filtered or unexported fields }
Candidate defines a delegate candidate
func NewCandidate ¶
NewCandidate creates a new candidate with scores as 0s
func (*Candidate) FromProtoMsg ¶
FromProtoMsg fills the instance with a protobuf message
func (*Candidate) SelfStakingTokens ¶
SelfStakingTokens returns the total self votes (weighted)
func (*Candidate) SetSelfStakingTokens ¶ added in v0.1.5
SetSelfStakingTokens set selfStakingTokens value in Candidate
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) DelegateByName ¶ added in v0.1.8
func (r *ElectionResult) DelegateByName(name []byte) *Candidate
DelegateByName returns the candidate details
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) Equal ¶ added in v0.2.0
func (r *ElectionResult) Equal(result *ElectionResult) bool
Equal compares two results and returns true if they are identical
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 gravity chain block
func (*ElectionResult) Serialize ¶
func (r *ElectionResult) Serialize() ([]byte, error)
Serialize converts result to byte array
func (*ElectionResult) String ¶ added in v0.1.4
func (r *ElectionResult) String() string
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) Votes ¶ added in v0.1.18
func (r *ElectionResult) Votes() []*Vote
Votes returns all votes
func (*ElectionResult) VotesByDelegate ¶
func (r *ElectionResult) VotesByDelegate(name []byte) []*Vote
VotesByDelegate returns a list of votes for a given delegate
type Poll ¶ added in v0.2.0
type Poll struct {
// contains filtered or unexported fields
}
Poll defines the struct stores election result in db
func (*Poll) Deserialize ¶ added in v0.2.0
Deserialize converts a byte array to election result
func (*Poll) FromProtoMsg ¶ added in v0.2.0
FromProtoMsg extracts result details from protobuf message
func (*Poll) Registrations ¶ added in v0.2.0
Registrations returns a list of Registrations
type Registration ¶ added in v0.2.0
type Registration struct {
// contains filtered or unexported fields
}
Registration defines a registration in contract
func NewRegistration ¶ added in v0.2.0
func NewRegistration( name []byte, address []byte, operatorAddress []byte, rewardPubKey []byte, selfStakingWeight uint64, ) *Registration
NewRegistration creates a new registration
func (*Registration) Address ¶ added in v0.2.0
func (reg *Registration) Address() []byte
Address returns the address of this candidate on gravity chain
func (*Registration) Clone ¶ added in v0.2.0
func (reg *Registration) Clone() *Registration
Clone clones the registration
func (*Registration) Deserialize ¶ added in v0.2.0
func (reg *Registration) Deserialize(data []byte) error
Deserialize deserializes a byte array to candidate
func (*Registration) Equal ¶ added in v0.2.0
func (reg *Registration) Equal(r *Registration) bool
Equal returns true if two candidates are identical
func (*Registration) FromProtoMsg ¶ added in v0.2.0
func (reg *Registration) FromProtoMsg(msg *pb.Registration) error
FromProtoMsg fills the instance with a protobuf message (CandidateCore)
func (*Registration) Hash ¶ added in v0.2.0
func (reg *Registration) Hash() (hash.Hash256, error)
Hash returns the hash of serialized data
func (*Registration) Name ¶ added in v0.2.0
func (reg *Registration) Name() []byte
Name returns the name of this candidate
func (*Registration) OperatorAddress ¶ added in v0.2.0
func (reg *Registration) OperatorAddress() []byte
OperatorAddress returns the address of the assigned operator on chain
func (*Registration) RewardAddress ¶ added in v0.2.0
func (reg *Registration) RewardAddress() []byte
RewardAddress returns the address of the assigned benefiter on chain
func (*Registration) SelfStakingWeight ¶ added in v0.2.0
func (reg *Registration) SelfStakingWeight() uint64
SelfStakingWeight returns the extra weight for self staking
func (*Registration) Serialize ¶ added in v0.2.0
func (reg *Registration) Serialize() ([]byte, error)
Serialize serializes the candidate to bytes
func (*Registration) ToProtoMsg ¶ added in v0.2.0
func (reg *Registration) ToProtoMsg() (*pb.Registration, error)
ToProtoMsg converts the instance to a protobuf message (CandidateCore)
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, skipManified bool, bucketFilter BucketFilterFunc, calcScore func(*Bucket, time.Time) *big.Int, candidateFilter CandidateFilterFunc, ) *ResultCalculator
NewResultCalculator creates a result calculator
func (*ResultCalculator) AddBuckets ¶ added in v0.2.0
func (calculator *ResultCalculator) AddBuckets(buckets []*Bucket) error
AddBuckets adds bucket to result
func (*ResultCalculator) AddRegistrations ¶ added in v0.2.0
func (calculator *ResultCalculator) AddRegistrations(candidates []*Registration) error
AddRegistrations adds candidates 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 { Bucket // contains filtered or unexported fields }
Vote defines the structure of a vote
func (*Vote) Deserialize ¶
Deserialize deserializes a byte array to vote
func (*Vote) FromProtoMsg ¶
FromProtoMsg extracts vote details from protobuf message
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