election

package
v0.6.2-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: GPL-3.0 Imports: 17 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)
	MAINNETVOTESPREFIX = byte(4)
	PREFIXLENGTH       = 4 // key的结构为,4位表前缀,20位address,8位的value在struct中的位置
)
View Source
const ElectionAbiJSON = `` /* 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, allBonus *big.Int) error

AddCandidatesBounty sends votes bounty to candidates.

func GenFakeStartedTxs

func GenFakeStartedTxs(nextNonce uint64, witness []common.Address) ([]*types.Transaction, error)

GenFakeStartedTxs generate 3 fake transaction to start the main net.

func GetElectionABI added in v0.6.2

func GetElectionABI() (abi.ABI, 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 MainNetActive

func MainNetActive(stateDB inter.StateDB) bool

MainNetActive returns whether the main net is started.

func PackInput added in v0.6.2

func PackInput(abiobj abi.ABI, name string, args ...interface{}) ([]byte, error)

func QueryRestVNTBounty

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

QueryRestVNTBounty returns the value of RestTotalBounty.

func ResetActive

func ResetActive()

ResetActive is reset the main net state in memory. Only used for tests.

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 MainNetVotes

type MainNetVotes struct {
	VoteStake *big.Int // 进行了投票的抵押代币数量,单位VNT
	Active    bool     // 主网是否已启动
}

func GetMainNetVotes

func GetMainNetVotes(stateDB inter.StateDB) *MainNetVotes

GetMainNetVotes return a pointer of main net vote information.

type Stake

type Stake struct {
	Owner      common.Address // 抵押人地址
	StakeCount *big.Int       // 抵押的数量,单位VNT
	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   // 代理人
	LastStakeCount *big.Int         // 投票时抵押的金额
	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