vote

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ballots

type Ballots map[string]*Vote // BlockID -> Vote

Ballots ...

func NewBallots added in v1.0.1

func NewBallots(size ...int) *Ballots

NewBallots ...

type Results

type Results struct {
	OwnVote *Vote
	// contains filtered or unexported fields
}

Results holds the result of the vote

To vote for a specific period, you should prepare the results beforehand

results := NewResults(nil)
if results.RegisterBallots(list, onPeriodID) {
	results.ProcessVoter(p1, bk1)
	[...]
	results.ProcessVoter(pN, bkN)
	leaders, scores, err := results.GetPoll()
}

func NewResults

func NewResults(own *Vote) *Results

NewResults ...

func (*Results) AddPossibleVote

func (r *Results) AddPossibleVote(v *Vote) bool

AddPossibleVote adds a vote after the results were prepared, returning `true` if the vote was actually added to the pool of already existing possible votes NB: Use with caution

func (Results) Expressed

func (r Results) Expressed() int

Expressed returns the rate of espressed votes

func (Results) GetPeriodID

func (r Results) GetPeriodID() uint64

GetPeriodID ...

func (*Results) GetPoll

func (r *Results) GetPoll() (leaders Votes, scores ScoreMap, err error)

GetPoll ...

func (*Results) HasMajority

func (r *Results) HasMajority(vote *Vote) bool

HasMajority ...

func (*Results) ProcessVoter

func (r *Results) ProcessVoter(voter *peer.Peer, forBlockID model.Hash) bool

ProcessVoter casts a vote to the ballot

func (*Results) RegisterBallots

func (r *Results) RegisterBallots(list Ballots, forPeriodID uint64) bool

RegisterBallots adds non-existing ballots to the result bucket

type Score

type Score struct {
	ID    string
	Total int
	Rank  int
}

Score ...

type ScoreMap

type ScoreMap map[string]int // BlockID -> nb of votes

ScoreMap ...

func (ScoreMap) PrintAll

func (s ScoreMap) PrintAll(order sorting.SortOrder) (ranking string)

PrintAll ...

func (ScoreMap) Sort

func (s ScoreMap) Sort(order ...sorting.SortOrder) Scores

Sort ... You may add a sort order as argument (default: DESC)

type Scores

type Scores []Score

Scores ...

func (Scores) Len

func (t Scores) Len() int

func (Scores) Less

func (t Scores) Less(i, j int) bool

func (Scores) Reverse

func (ss Scores) Reverse()

Reverse ...

func (Scores) Swap

func (t Scores) Swap(i, j int)

type Vote

type Vote struct {
	OnBlock *block.Block
	sync.RWMutex
	// contains filtered or unexported fields
}

Vote ...

func (*Vote) Add

func (v *Vote) Add(voter *peer.Peer) bool

Add ...

func (*Vote) GetTotal

func (v *Vote) GetTotal() int

GetTotal ...

func (*Vote) GetVoters

func (v *Vote) GetVoters() []*peer.Peer

GetVoters ...

func (*Vote) IsVoter

func (v *Vote) IsVoter(voter *peer.Peer) bool

IsVoter ...

func (*Vote) Remove

func (v *Vote) Remove(voter *peer.Peer) (error, bool)

Remove returns an error if any and whether the passed voter did exist

type Votes

type Votes []*Vote

Votes ...

type Winner

type Winner struct {
	Block        *block.Block
	IsDifferent  bool
	WithMajority bool
	VoteClosed   bool
}

Winner ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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