Documentation ¶
Index ¶
- Constants
- Variables
- func GetElectionABI() (abi.ABI, error)
- func GetFirstNCandidates(stateDB inter.StateDB, witnessesNum int) ([]common.Address, []string)
- func GrantReward(stateDB inter.StateDB, rewards map[common.Address]*big.Int) (err error)
- func PackInput(abiobj abi.ABI, name string, args ...interface{}) ([]byte, error)
- func QueryRestReward(stateDB inter.StateDB) *big.Int
- type AllLock
- type BindInfo
- type Candidate
- type CandidateList
- type Election
- type NodeInfo
- type Stake
- type Voter
Constants ¶
const ( ContractAddr = "0x0000000000000000000000000000000000000009" VoteLimit = 30 OneDay = int64(24) * 3600 )
const ( VOTERPREFIX = byte(0) CANDIDATEPREFIX = byte(1) STAKEPREFIX = byte(2) ALLLOCKPREFIX = byte(3) PREFIXLENGTH = 4 // key的结构为,4位表前缀,20位address,8位的value在struct中的位置 )
const ElectionAbiJSON = `` /* 1282-byte string literal not displayed */
Variables ¶
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
To show how to use election abi
func GetFirstNCandidates ¶
GetFirstNCandidates get candidates with most votes as witness from specific stateDB
func GrantReward ¶ added in v0.6.2
GrantReward 发放激励给该候选节点的受益人,返回错误。 发放激励的接口不区分是产块激励还是投票激励,超级节点必须是Active,否则无收益。 激励金额不足发放时为正常情况不返回error,返回nil。 返回错误时,数据状态恢复到原始情况,即所有激励都不发放。
Types ¶
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
GetCandidate returns a candidate's information. Return nil if not find.
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) Swap ¶
func (c CandidateList) Swap(i, j int)