Documentation ¶
Index ¶
- Constants
- Variables
- func AddCandidatesBounty(stateDB inter.StateDB, bonus map[common.Address]*big.Int, allBonus *big.Int) error
- func GenFakeStartedTxs(nextNonce uint64, witness []common.Address) ([]*types.Transaction, error)
- func GetElectionABI() (abi.ABI, error)
- func GetFirstNCandidates(stateDB inter.StateDB, witnessesNum int) ([]common.Address, []string)
- func GrantBounty(stateDB inter.StateDB, grantAmount *big.Int) (*big.Int, error)
- func MainNetActive(stateDB inter.StateDB) bool
- func PackInput(abiobj abi.ABI, name string, args ...interface{}) ([]byte, error)
- func QueryRestVNTBounty(stateDB inter.StateDB) *big.Int
- func ResetActive()
- type Bounty
- type Candidate
- type CandidateList
- type Election
- type MainNetVotes
- type Stake
- type Voter
Constants ¶
const ( ContractAddr = "0x0000000000000000000000000000000000000009" VoteLimit = 30 OneDay = int64(24) * 3600 )
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中的位置 )
const ElectionAbiJSON = `` /* 951-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") 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 ¶
GenFakeStartedTxs generate 3 fake transaction to start the main net.
func GetElectionABI ¶ added in v0.6.2
func GetFirstNCandidates ¶
GetFirstNCandidates get candidates with most votes as witness from specific stateDB
func GrantBounty ¶
GrantBounty grants VNT bounty. Returns an error, if RestTotalBounty is less than grantAmount.
func MainNetActive ¶
MainNetActive returns whether the main net is started.
func QueryRestVNTBounty ¶
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 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.
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)
type MainNetVotes ¶
func GetMainNetVotes ¶
func GetMainNetVotes(stateDB inter.StateDB) *MainNetVotes
GetMainNetVotes return a pointer of main net vote information.