election

package
v0.6.1-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2019 License: GPL-3.0 Imports: 16 Imported by: 11

Documentation

Index

Constants

View Source
const (
	ContractAddr = "0x0000000000000000000000000000000000000009"
	VoteLimit    = 30
	OneDay       = int64(24) * 3600
)
View Source
const (
	VOTERPREFIX     = byte(0)
	CANDIDATEPREFIX = byte(1)
	STAKEPREFIX     = byte(2)
	BOUNTYPREFIX    = byte(3)
	PREFIXLENGTH    = 4 // key的结构为,4位表前缀,20位address,8位的value在struct中的位置
)
View Source
const AbiJSON = `` /* 951-byte string literal not displayed */

Variables

View Source
var (
	ErrCandiNameLenInvalid    = errors.New("the length of candidate's name should between [3, 20]")
	ErrCandiUrlLenInvalid     = errors.New("the length of candidate's website url should between [3, 60]")
	ErrCandiNameInvalid       = errors.New("candidate's name should consist of digits and lowercase letters")
	ErrCandiInfoDup           = errors.New("candidate's name, website url or node url is duplicated with a registered candidate")
	ErrCandiAlreadyRegistered = errors.New("candidate is already registered")
)

Functions

func AddCandidatesBounty

func AddCandidatesBounty(stateDB inter.StateDB, bonus map[common.Address]*big.Int) error

func GetFirstNCandidates

func GetFirstNCandidates(stateDB inter.StateDB, witnessesNum int) ([]common.Address, []string)

GetFirstNCandidates get candidates with most votes as witness from specific stateDB

func GrantBounty

func GrantBounty(stateDB inter.StateDB, grantAmount *big.Int) (*big.Int, error)

GrantBounty grants VNT bounty. Returns an error, if RestTotalBounty is less than grantAmount.

func QueryRestVNTBounty

func QueryRestVNTBounty(stateDB inter.StateDB) *big.Int

QueryRestVNTBounty returns the value of RestTotalBounty.

Types

type Bounty

type Bounty struct {
	RestTotalBounty *big.Int // 剩余总激励,初始值10亿VNT
}

type Candidate

type Candidate struct {
	Owner           common.Address // 候选人地址
	VoteCount       *big.Int       // 收到的票数
	Active          bool           // 当前是否是候选人
	Url             []byte         // 节点的URL
	TotalBounty     *big.Int       // 总奖励金额
	ExtractedBounty *big.Int       // 已提取奖励金额
	LastExtractTime *big.Int       // 上次提权时间
	Website         []byte         // 节点网站地址
	Name            []byte         // 节点名字
}

Candidate information of witness candidates. Tips: Modify CandidateList.Swap when adding element of Candidate.

func (*Candidate) String

func (c *Candidate) String() string

type CandidateList

type CandidateList []Candidate

func GetAllCandidates

func GetAllCandidates(stateDB inter.StateDB, sorted bool) CandidateList

GetAllCandidates return the list of all candidate. Candidates will be sort by votes and address, if sorted is true.

func (CandidateList) Len

func (c CandidateList) Len() int

func (CandidateList) Less

func (c CandidateList) Less(i, j int) bool

Less for Sort interface, actually implement of c[i] more than c[j] Rule 1: 票数越多排名越靠前 Rule 2: 票数相等,地址越小越靠前

sort.Stable对于big.Int并不能真正的stable,所以排序还参考地址,并且排序不再使用stable

func (CandidateList) Sort

func (c CandidateList) Sort()

Sort

func (CandidateList) Swap

func (c CandidateList) Swap(i, j int)

type Election

type Election struct{}

func (*Election) RequiredGas

func (e *Election) RequiredGas(input []byte) uint64

func (*Election) Run

func (e *Election) Run(ctx inter.ChainContext, input []byte) ([]byte, error)

type Stake

type Stake struct {
	Owner      common.Address // 抵押人地址
	StakeCount *big.Int       // 抵押的数量
	TimeStamp  *big.Int       // 时间戳
}

func GetStake

func GetStake(stateDB inter.StateDB, addr common.Address) *Stake

GetStake returns a user's information

type Voter

type Voter struct {
	Owner          common.Address   // 投票人的地址
	IsProxy        bool             // 是否是代理人
	ProxyVoteCount *big.Int         // 收到的代理的票数
	Proxy          common.Address   // 代理人
	LastVoteCount  *big.Int         // 票数
	TimeStamp      *big.Int         // 时间戳
	VoteCandidates []common.Address // 投了哪些人
}

func GetVoter

func GetVoter(stateDB inter.StateDB, addr common.Address) *Voter

GetVoter returns a voter's information

Jump to

Keyboard shortcuts

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