Skip to main content

Election Contract

Used for voting for Block Producers.Implement aelf Standards ACS1.

Contract Methods

Method NameRequest TypeResponse TypeDescription
InitialElectionContractElection.InitialElectionContractInputgoogle.protobuf.EmptyInitialize the election contract.
RegisterElectionVotingEventgoogle.protobuf.Emptygoogle.protobuf.EmptyRegister a new voting item through the vote contract.
TakeSnapshotElection.TakeElectionSnapshotInputgoogle.protobuf.EmptyTake a snapshot according to the term number and distribute profits.
AnnounceElectionaelf.Addressgoogle.protobuf.EmptyTo be a block producer, a user should first register to be a candidate and lock some tokens as a deposit. If the data center is not full, the user will be added automatically and get one weight for sharing a bonus in the future.
QuitElectiongoogle.protobuf.StringValuegoogle.protobuf.EmptyA candidate is able to quit the election provided they are not currently elected. If you quit successfully, the candidate will get their locked tokens back and will not receive any more bonus.
VoteElection.VoteMinerInputaelf.HashUsed for voting for a candidate to be elected. The tokens you vote with will be locked until the end time. According to the number of tokens you voted and their lock time, you can get a corresponding weight for sharing the bonus in the future. Returns the vote id.
ChangeVotingOptionElection.ChangeVotingOptionInputgoogle.protobuf.EmptyBefore the end time, you are able to change your vote target to other candidates.
Withdrawaelf.Hashgoogle.protobuf.EmptyAfter the lock time, your locked tokens will be unlocked, and you can withdraw them according to the vote id.
UpdateCandidateInformationElection.UpdateCandidateInformationInputgoogle.protobuf.EmptyUpdate candidate information by the consensus contract.
UpdateMultipleCandidateInformationElection.UpdateMultipleCandidateInformationInputgoogle.protobuf.EmptyBatch update candidate information by the consensus contract.
UpdateMinersCountElection.UpdateMinersCountInputgoogle.protobuf.EmptyUpdate the count of miners by the consensus contract.
SetProfitsReceiverElection.SetProfitsReceiverInputgoogle.protobuf.EmptySet the collect profits receiver address.
SetTreasurySchemeIdsElection.SetTreasurySchemeIdsInputgoogle.protobuf.EmptySet the treasury profit ids.
SetVoteWeightInterestElection.VoteWeightInterestListgoogle.protobuf.EmptySet the weight of vote interest.
SetVoteWeightProportionElection.VoteWeightProportiongoogle.protobuf.EmptySet the weight of lock time and votes in the calculation of voting weight.
ChangeVoteWeightInterestControllerAuthorityInfogoogle.protobuf.EmptyChange the controller for the weight of vote interest.
ReplaceCandidatePubkeyElection.ReplaceCandidatePubkeyInputgoogle.protobuf.EmptyCandidate admin can replace the candidate pubkey with a new pubkey.
SetCandidateAdminElection.SetCandidateAdminInputgoogle.protobuf.EmptySet the admin address of the candidate (mostly supply).
GetCandidatesgoogle.protobuf.EmptyElection.PubkeyListGet all candidates' public keys.
GetVotedCandidatesgoogle.protobuf.EmptyElection.PubkeyListGet all candidates whose number of votes is greater than 0.
GetCandidateInformationgoogle.protobuf.StringValueElection.CandidateInformationGet a candidate’s information.
GetVictoriesgoogle.protobuf.EmptyElection.PubkeyListGet the victories of the latest term.
GetTermSnapshotElection.GetTermSnapshotInputElection.TermSnapshotGet the snapshot of term according to the term number.
GetMinersCountgoogle.protobuf.Emptygoogle.protobuf.Int32ValueGet the count of miners.
GetElectionResultElection.GetElectionResultInputElection.ElectionResultGet the election result according to the term id.
GetElectorVotegoogle.protobuf.StringValueElection.ElectorVoteGet the voter information according to the voter public key.
GetElectorVoteWithRecordsgoogle.protobuf.StringValueElection.ElectorVoteGets the voter information including the active voting records (excluding withdrawn voting records).
GetElectorVoteWithAllRecordsgoogle.protobuf.StringValueElection.ElectorVoteGets the voter information including the active and withdrawn voting records.
GetCandidateVotegoogle.protobuf.StringValueElection.CandidateVoteGet voting information for the candidate according to the public key of the candidate.
GetCandidateVoteWithRecordsgoogle.protobuf.StringValueElection.CandidateVoteGet voting information for the candidate according to the public key of the candidate.
GetCandidateVoteWithAllRecordsgoogle.protobuf.StringValueElection.CandidateVoteGet voting information for the candidate according to the public key of the candidate (including the active and withdrawn voting records).
GetVotersCountgoogle.protobuf.Emptygoogle.protobuf.Int64ValueGet the total number of voters.
GetVotesAmountgoogle.protobuf.Emptygoogle.protobuf.Int64ValueGet the total number of vote tokens.
GetPageableCandidateInformationElection.PageInformationElection.GetPageableCandidateInformationOutputGet candidate information according to the index and length.
GetMinerElectionVotingItemIdgoogle.protobuf.Emptyaelf.HashGet the voting item id of miner election.
GetDataCenterRankingListgoogle.protobuf.EmptyElection.DataCenterRankingListGet the data center ranking list.
GetVoteWeightSettinggoogle.protobuf.EmptyElection.VoteWeightInterestListGet the weight of vote interest.
GetVoteWeightProportiongoogle.protobuf.EmptyElection.VoteWeightProportionGet the weight of lock time and votes in the calculation of voting weight.
GetCalculateVoteWeightElection.VoteInformationgoogle.protobuf.Int64ValueUsed to calculate the bonus weights that users can get by voting.
GetVoteWeightInterestControllergoogle.protobuf.EmptyAuthorityInfoQuery the controller for the weight of vote interest.
GetMinerReplacementInformationElection.GetMinerReplacementInformationInputElection.MinerReplacementInformationInspect the evil nodes included in the specified miners and return to the replacement node.
GetCandidateAdmingoogle.protobuf.StringValueaelf.AddressQuery candidate admin.
GetNewestPubkeygoogle.protobuf.StringValuegoogle.protobuf.StringValueQuery the newest pubkey of an old pubkey.
GetReplacedPubkeygoogle.protobuf.StringValuegoogle.protobuf.StringValueQuery the old pubkey.

AElf.Standards.ACS1

Method NameRequest TypeResponse TypeDescription
SetMethodFeeacs1.MethodFeesgoogle.protobuf.EmptySet the method fees for the specified method. Note that this will override all fees of the method.
ChangeMethodFeeControllerAuthorityInfogoogle.protobuf.EmptyChange the method fee controller, the default is parliament and default organization.
GetMethodFeegoogle.protobuf.StringValueacs1.MethodFeesQuery method fee information by method name.
GetMethodFeeControllergoogle.protobuf.EmptyAuthorityInfoQuery the method fee controller.

Contract Types

AElf.Contracts.Election

Election.CandidateDetail

FieldTypeDescriptionLabel
candidate_informationCandidateInformationThe candidate information.
obtained_votes_amountint64The number of votes a candidate has obtained.

Election.CandidateInformation

FieldTypeDescriptionLabel
pubkeystringCandidate’s public key.
termsint64The number of terms that the candidate is elected.repeated
produced_blocksint64The number of blocks the candidate has produced.
missed_time_slotsint64The time slot for which the candidate failed to produce blocks.
continual_appointment_countint64The count of continual appointment.
announcement_transaction_idaelf.HashThe transaction id when the candidate announced.
is_current_candidateboolIndicate whether the candidate can be elected in the current term.

Election.CandidatePubkeyReplaced

FieldTypeDescriptionLabel
old_pubkeystring
new_pubkeystring

Election.CandidateVote

FieldTypeDescriptionLabel
obtained_active_voting_record_idsaelf.HashThe active voting record ids obtained.repeated
obtained_withdrawn_voting_record_idsaelf.HashThe active voting record ids that were withdrawn.repeated
obtained_active_voted_votes_amountint64The total number of active votes obtained.
all_obtained_voted_votes_amountint64The total number of votes obtained.
obtained_active_voting_recordsElectionVotingRecordThe active voting records.repeated
obtained_withdrawn_votes_recordsElectionVotingRecordThe voting records that were withdrawn.repeated
pubkeybytesPublic key for candidate.

Election.ChangeVotingOptionInput

FieldTypeDescriptionLabel
vote_idaelf.HashThe vote id to change.
candidate_pubkeystringThe new candidate public key.

Election.DataCenterRankingList

FieldTypeDescriptionLabel
data_centersDataCenterRankingList.DataCentersEntryThe top n * 5 candidates with vote amount, candidate public key -> vote amount.repeated

Election.DataCenterRankingList.DataCentersEntry

FieldTypeDescriptionLabel
keystring
valueint64

Election.ElectionResult

FieldTypeDescriptionLabel
term_numberint64The term number
resultsElectionResult.ResultsEntryThe election result, candidates’ public key -> number of votes.repeated
is_activeboolWhether an election is currently being held.

Election.ElectionResult.ResultsEntry

FieldTypeDescriptionLabel
keystring
valueint64

Election.ElectionVotingRecord

FieldTypeDescriptionLabel
voteraelf.AddressThe address of voter.
candidatestringThe public key of candidate.
amountint64Amount of voting.
term_numberint64The term number of voting.
vote_idaelf.HashThe vote id.
lock_timeint64Vote lock time.
unlock_timestampgoogle.protobuf.TimestampThe unlock timestamp.
withdraw_timestampgoogle.protobuf.TimestampThe withdraw timestamp.
vote_timestampgoogle.protobuf.TimestampThe vote timestamp.
is_withdrawnboolIndicates if the vote has been withdrawn.
weightint64Vote weight for sharing bonus.
is_change_targetboolWhether vote others.

Election.ElectorVote

FieldTypeDescriptionLabel
active_voting_record_idsaelf.HashThe active voting record ids.repeated
withdrawn_voting_record_idsaelf.HashThe voting record ids that were withdrawn.repeated
active_voted_votes_amountint64The total number of active votes.
all_voted_votes_amountint64The total number of votes (including the number of votes withdrawn).
active_voting_recordsElectionVotingRecordThe active voting records.repeated
withdrawn_votes_recordsElectionVotingRecordThe voting records that were withdrawn.repeated
pubkeybytesPublic key for voter.
addressaelf.AddressAddress for voter.

Election.EvilMinerDetected

FieldTypeDescriptionLabel
pubkeystringThe public key of evil miner.

Election.GetElectionResultInput

FieldTypeDescriptionLabel
term_numberint64The term number.

Election.GetMinerReplacementInformationInput

FieldTypeDescriptionLabel
current_miner_liststringThe current miner list to inspect.repeated

Election.GetPageableCandidateInformationOutput

FieldTypeDescriptionLabel
valueCandidateDetailThe details of the candidates.repeated

Election.GetTermSnapshotInput

FieldTypeDescriptionLabel
term_numberint64The term number.

Election.InitialElectionContractInput

FieldTypeDescriptionLabel
minimum_lock_timeint64Minimum number of seconds for locking.
maximum_lock_timeint64Maximum number of seconds for locking.
miner_liststringThe current miner list.repeated
time_each_termint64The number of seconds per term.
miner_increase_intervalint64The interval second that increases the number of miners.

Election.MinerReplacementInformation

FieldTypeDescriptionLabel
alternative_candidate_pubkeysstringThe alternative candidate public keys.repeated
evil_miner_pubkeysstringThe evil miner public keys.repeated

Election.PageInformation

FieldTypeDescriptionLabel
startint32The start index.
lengthint32The number of records.

Election.PubkeyList

FieldTypeDescriptionLabel
valuebytesCandidates’ public keysrepeated

Election.ReplaceCandidatePubkeyInput

FieldTypeDescriptionLabel
old_pubkeystring
new_pubkeystring

Election.SetCandidateAdminInput

FieldTypeDescriptionLabel
pubkeystring
adminaelf.Address

Election.SetProfitsReceiverInput

FieldTypeDescriptionLabel
candidate_pubkeystringThe candidate's public key.
profits_receiver_addressaelf.AddressThe address of profits receiver.
previous_receiver_addressaelf.AddressThe previous address of profits receiver.

Election.SetTreasurySchemeIdsInput

FieldTypeDescriptionLabel
treasury_hashaelf.HashThe scheme id of treasury reward.
welfare_hashaelf.HashThe scheme id of welfare reward.
subsidy_hashaelf.HashThe scheme id of subsidy reward.
votes_reward_hashaelf.HashThe scheme id of votes reward.
re_election_reward_hashaelf.HashThe scheme id of re-election reward.

Election.TakeElectionSnapshotInput

FieldTypeDescriptionLabel
term_numberint64The term number to take snapshot.
mined_blocksint64The number of mined blocks of this term.
round_numberint64The end round number of this term.

Election.TermSnapshot

FieldTypeDescriptionLabel
end_round_numberint64The end round number of this term.
mined_blocksint64The number of blocks mined in this term.
election_resultTermSnapshot.ElectionResultEntry (key: string, value: int64)The election result, candidates’ public key -> number of votes.repeated

Election.TermSnapshot.ElectionResultEntry

FieldTypeDescriptionLabel
keystring
valueint64

Election.UpdateCandidateInformationInput

FieldTypeDescriptionLabel
pubkeystringThe candidate public key.
recently_produced_blocksint64The number of blocks recently produced.
recently_missed_time_slotsint64The number of time slots recently missed.
is_evil_nodeboolIs it an evil node. If true, will remove the candidate.

Election.UpdateMinersCountInput

FieldTypeDescriptionLabel
miners_countint32The count of miner.

Election.UpdateMultipleCandidateInformationInput

FieldTypeDescriptionLabel
valueUpdateCandidateInformationInput (see below)The candidate information to update.repeated

UpdateCandidateInformationInput

FieldTypeDescriptionLabel
pubkeystringThe candidate public key.
recently_produced_blocksint64The number of blocks recently produced.
recently_missed_time_slotsint64The number of time slots recently missed.
is_evil_nodeboolIs it an evil node. If true, will remove the candidate.

Election.UpdateTermNumberInput

FieldTypeDescriptionLabel
term_numberint64The term number.

Election.VoteInformation

FieldTypeDescriptionLabel
amountint64Amount of voting.
lock_timeint64Vote lock time.

Election.VoteMinerInput

FieldTypeDescriptionLabel
candidate_pubkeystringThe candidate public key.
amountint64The amount token to vote.
end_timestampgoogle.protobuf.TimestampThe end timestamp of this vote.
tokenaelf.HashUsed to generate vote id.

Election.VoteWeightInterest

FieldTypeDescriptionLabel
dayint32Number of days locked.
interestint32Locked interest.
capitalint32

Election.VoteWeightInterestList

FieldTypeDescriptionLabel
vote_weight_interest_infosVoteWeightInterest (see above)The weight of vote interest.repeated

Election.VoteWeightProportion

FieldTypeDescriptionLabel
time_proportionint32The weight of lock time.
amount_proportionint32The weight of the votes cast.

AElf.Standards.ACS1

acs1.MethodFee

FieldTypeDescriptionLabel
symbolstringThe token symbol of the method fee.
basic_feeint64The amount of fees to be charged.

acs1.MethodFees

FieldTypeDescriptionLabel
method_namestringThe name of the method to be charged.
feesMethodFee (see above)List of fees to be charged.repeated
is_size_fee_freeboolOptional based on the implementation of SetMethodFee method.

AElf.Types

aelf.Address

FieldTypeDescriptionLabel
valuebytes

aelf.BinaryMerkleTree

FieldTypeDescriptionLabel
nodesHash (see below)The leaf nodes.repeated
rootHash (see below)The root node hash.
leaf_countint32The count of leaf node.

aelf.Hash

FieldTypeDescriptionLabel
valuebytes

aelf.LogEvent

FieldTypeDescriptionLabel
addressAddress (see above)The contract address.
namestringThe name of the log event.
indexedbytes (see below)The indexed data, used to calculate bloom.repeated
non_indexedbytesThe non indexed data.

aelf.MerklePath

FieldTypeDescriptionLabel
merkle_path_nodesMerklePathNode (see below)The merkle path nodes.repeated

aelf.MerklePathNode

FieldTypeDescriptionLabel
hashHash
is_left_childbool

aelf.SInt32Value

FieldTypeDescriptionLabel
valuesint32

aelf.SInt64Value

FieldTypeDescriptionLabel
valuesint64

aelf.ScopedStatePath

FieldTypeDescriptionLabel
addressAddress The scope address, which will be the contract address.
pathStatePath The path of contract state.

aelf.SmartContractRegistration

FieldTypeDescriptionLabel
categorysint32 The category of contract code(0: C#).
codebytes The byte array of the contract code.
code_hashHash The hash of the contract code.
is_system_contractbool Whether it is a system contract.
versionint32 The version of the current contract.

aelf.StatePath

FieldTypeDescriptionLabel
partsstring The partial path of the state path.repeated

aelf.Transaction

FieldTypeDescriptionLabel
fromAddress The address of the sender of the transaction.
toAddress The address of the contract when calling a contract.
ref_block_numberint64 The height of the referenced block hash.
ref_block_prefixbytes The first four bytes of the referenced block hash.
method_namestring The name of a method in the smart contract at the To address.
paramsbytes The parameters to pass to the smart contract method.
signaturebytes When signing a transaction it’s actually a subset of the fields: from/to and the target method as well as the parameter that were given. It also contains the reference block number and prefix.

aelf.TransactionExecutingStateSet

FieldTypeDescriptionLabel
writesTransactionExecutingStateSet.WritesEntry The changed states.repeated
readsTransactionExecutingStateSet.ReadsEntryThe read states.repeated
deletesTransactionExecutingStateSet.DeletesEntry The deleted states.repeated

aelf.TransactionExecutingStateSet.DeletesEntry

FieldTypeDescriptionLabel
keystring
valuebool

aelf.TransactionExecutingStateSet.ReadsEntry

FieldTypeDescriptionLabel
keystring
valuebool

aelf.TransactionExecutingStateSet.WritesEntry

FieldTypeDescriptionLabel
keystring
valuebytes

aelf.TransactionResult

FieldTypeDescriptionLabel
transaction_idHash The transaction id.
statusTransactionResultStatus The transaction result status.
logsLogEvent The log events.repeated
bloombytes Bloom filter for transaction logs.
return_valuebytes The return value of the transaction execution.
block_numberint64 The height of the block hat packages the transaction.
block_hashHash The hash of the block hat packages the transaction.
errorstring Failed execution error message.

aelf.TransactionResultStatus

NameNumberDescription
NOT_EXISTED0The execution result of the transaction does not exist.
PENDING1The transaction is in the transaction pool waiting to be packaged.
FAILED2Transaction execution failed.
MINED3The transaction was successfully executed and successfully packaged into a block.
CONFLICT4When executed in parallel, there are conflicts with other transactions.
PENDING_VALIDATION5The transaction is waiting for validation.
NODE_VALIDATION_FAILED6Transaction validation failed.

AuthorityInfo

FieldTypeDescriptionLabel
contract_addressaelf.Address The contract address of the controller.
owner_addressaelf.Address The address of the owner of the contract.