election

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 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)
	REWARDPREFIX    = byte(3)
	PREFIXLENGTH    = 4 // key的结构为,4位表前缀,20位address,8位的value在struct中的位置
)
View Source
const ElectionAbiJSON = `` /* 1282-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")
	ErrCandiAlreadyReg     = errors.New("candidate is already registered")
	ErrCandiNotReg         = errors.New("candidate is not registered")
	ErrCandiAlreadyBind    = errors.New("candidate is already bind")
	ErrCandiNotBind        = errors.New("candidate is not bind")
	ErrBindInfoMismatch    = errors.New("bind address not match candidates saved")
	ErrLockAmountMismatch  = errors.New("bind amount is not equal 10,000,000 VNT")
)

Functions

func GetElectionABI added in v0.6.2

func GetElectionABI() (abi.ABI, error)

To show how to use election abi

func GetFirstNCandidates

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

GetFirstNCandidates get candidates with most votes as witness from specific stateDB

func GrantReward added in v0.6.2

func GrantReward(stateDB inter.StateDB, rewards map[common.Address]*big.Int) (err error)

GrantReward 发放激励给该候选节点的受益人,返回错误。 发放激励的接口不区分是产块激励还是投票激励,超级节点必须是Active,否则无收益。 激励金额不足发放时为正常情况不返回error,返回nil。 返回错误时,数据状态恢复到原始情况,即所有激励都不发放。

func PackInput added in v0.6.2

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

func QueryRestReward added in v0.6.2

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

QueryRestReward returns the value of left reward for candidates.

Types

type BindInfo added in v0.6.2

type BindInfo struct {
	Candidate   common.Address // 绑定的候选账号
	Beneficiary common.Address // 收益的账号
}

type Candidate

type Candidate struct {
	Owner       common.Address // 候选人地址
	Binder      common.Address // 锁仓人/绑定人
	Beneficiary common.Address // 收益受益人
	VoteCount   *big.Int       // 收到的票数
	Registered  bool           // 当前是否注册为候选人
	Bind        bool           // 是否被绑定
	Url         []byte         // 节点的URL
	Website     []byte         // 节点网站地址
	Name        []byte         // 节点名字
}

Candidate information of witness candidates. Tips: Modify CandidateList.Swap() and Candidate.String() when adding or removing element of Candidate.

func GetCandidate added in v0.6.2

func GetCandidate(stateDB inter.StateDB, addr common.Address) *Candidate

GetCandidate returns a candidate's information. Return nil if not find.

func (*Candidate) Active

func (c *Candidate) Active() bool

Active 判断候选人是否已激活

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, value *big.Int) ([]byte, error)

type NodeInfo added in v0.6.2

type NodeInfo struct {
	NodeUrl     []byte
	Website     []byte
	NodeName    []byte
	Binder      common.Address // 绑定人
	Beneficiary common.Address // 受益人
}

type Reward added in v0.6.2

type Reward struct {
	Rest *big.Int // 剩余总激励
}

type Stake

type Stake struct {
	Owner      common.Address // 抵押人地址
	StakeCount *big.Int       // 抵押的数量,单位VNT,向下取整
	Vnt        *big.Int       // 抵押的实际代币数,单位Wei
	TimeStamp  *big.Int       // 时间戳
}

func GetStake

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

GetStake returns a user's information. Return nil if not find.

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. Return nil if not find.

Jump to

Keyboard shortcuts

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