tip: 156
title: Vote instructions in TVM
author: taihao.fu@gmail.com
status: Draft
type: Standards Track
category : Core
created: 2020-06-03
To provide vote related operations in TVM.
Vote & withdrawReward operation in system contract are introduced, smart contract can vote for witness and get reward from the system.
Common user can vote for activated witness to get block reward. However, none privatekey accounts, like smart contracts, can't get benefit from this incentive mechanism. This TIP provide instructions to implement the incentive functionalities.
The following instructions are introduced:
The VOTE
takes 4 operands pop up from stack:
witnessOffset
: witness information offset.
witnessSize
: witness information size.
tronPowerOffset
: tron power information.
tronPowerSize
: tron power information array size.
TVM will get sr array from memory by using witnessOffset
and witnessSize
.
TVM will get tron power nubmer array from memory by using tronPowerOffset
and tronPowerSize
.
Execute vote function and push 0 to stack if fail, push 1 otherwize.
The WITHDRAWREWARD
takes 1 operand from stack.
accountAddress
: target account address.
Execute withdraw function and push 0 to stack if fail, push 1 otherwise.
The ISWITNESS
takes 1 operand from stack.
accountAddress
: target account address.
Push 0 if target address is not a witness, otherwise push 1.
SystemLog is contains system level operation result in transactioninfo for a specific transaction.
A system log structure can be defined as below:
message SystemLog {
enum operationType {
VOTE = 1;
WITHDRAWREWARD = 2;
}
bytes address = 1; // user address or contract address
repeated bytes params = 2;
// VOTE contains 2 parameters: VOTE(toAddress, TRONPowerValue);
// WITHDRAWREWARD contains 1 parameter: WITHDRAWREWARD(toAddress);
operationType type = 3;
}
Vote and withdraw infomation will be record in the SystemLog field in transactionInfo.
VOTE
tier.ExtTier
WITHDRAWREWARD
tier.ExtTier
REWARDBALANCE
tier.ExtTier
ISWITNESS
tier.ExtTier