types

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 14, 2019 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) Address

func (c *Candidate) Address() []byte

Address returns the address of this candidate on gravity chain

func (*Candidate) Clone

func (c *Candidate) Clone() *Candidate

Clone clones the candidate

func (*Candidate) FromProtoMsg

func (c *Candidate) FromProtoMsg(msg *pb.Candidate) error

FromProtoMsg fills the instance with a protobuf message

func (*Candidate) Name

func (c *Candidate) Name() []byte

Name returns the name of this candidate

func (*Candidate) OperatorAddress

func (c *Candidate) OperatorAddress() []byte

OperatorAddress returns the address of the assigned operator on chain

func (*Candidate) RewardAddress

func (c *Candidate) RewardAddress() []byte

RewardAddress returns the address of the assigned benefiter on chain

func (*Candidate) Score

func (c *Candidate) Score() *big.Int

Score returns the total votes (weighted) of this candidate

func (*Candidate) SelfStakingTokens

func (c *Candidate) SelfStakingTokens() *big.Int

SelfStakingTokens returns the total self votes (weighted)

func (*Candidate) SelfStakingWeight

func (c *Candidate) SelfStakingWeight() uint64

SelfStakingWeight returns the extra weight for self staking

func (*Candidate) SetScore added in v0.1.5

func (c *Candidate) SetScore(score *big.Int)

SetScore set score value in Candidate

func (*Candidate) SetSelfStakingTokens added in v0.1.5

func (c *Candidate) SetSelfStakingTokens(selfStakingTokens *big.Int)

SetSelfStakingTokens set selfStakingTokens value in Candidate

func (*Candidate) ToProtoMsg

func (c *Candidate) ToProtoMsg() (*pb.Candidate, error)

ToProtoMsg converts the instance to a protobuf message

type CandidateFilterFunc

type CandidateFilterFunc func(*Candidate) bool

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) 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) 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,
	skipManified bool,
	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) Amount

func (v *Vote) Amount() *big.Int

Amount returns the amount of vote

func (*Vote) Candidate

func (v *Vote) Candidate() []byte

Candidate returns the candidate

func (*Vote) Clone

func (v *Vote) Clone() *Vote

Clone clones the vote

func (*Vote) Decay

func (v *Vote) Decay() bool

Decay returns whether this is a decay vote

func (*Vote) Deserialize

func (v *Vote) Deserialize(data []byte) error

Deserialize deserializes a byte array to vote

func (*Vote) Duration

func (v *Vote) Duration() time.Duration

Duration returns the duration this vote for

func (*Vote) FromProtoMsg

func (v *Vote) FromProtoMsg(vPb *pb.Vote) (err error)

FromProtoMsg extracts vote details from protobuf message

func (*Vote) RemainingTime

func (v *Vote) RemainingTime(now time.Time) time.Duration

RemainingTime returns the remaining time to given time

func (*Vote) Serialize

func (v *Vote) Serialize() ([]byte, error)

Serialize serializes the vote to bytes

func (*Vote) SetWeightedAmount

func (v *Vote) SetWeightedAmount(w *big.Int) error

SetWeightedAmount sets the weighted amount for the vote

func (*Vote) StartTime

func (v *Vote) StartTime() time.Time

StartTime returns the start time

func (*Vote) ToProtoMsg

func (v *Vote) ToProtoMsg() (*pb.Vote, error)

ToProtoMsg converts the vote to protobuf

func (*Vote) Voter

func (v *Vote) Voter() []byte

Voter returns the voter address in bytes

func (*Vote) WeightedAmount

func (v *Vote) WeightedAmount() *big.Int

WeightedAmount returns the weighted amount of vote

type VoteFilterFunc

type VoteFilterFunc func(*Vote) bool

VoteFilterFunc defines the function to filter vote

Jump to

Keyboard shortcuts

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