add min for voter

This commit is contained in:
Nguyen Sy Thanh Son 2018-08-18 10:00:23 +00:00
parent eb29771a1e
commit 5aa0f8b3aa
6 changed files with 54 additions and 14 deletions

View file

@ -31,6 +31,7 @@ contract TomoValidator {
uint256 public candidateCount = 0;
uint256 public minCandidateCap;
uint256 public minVoterCap;
uint256 public maxValidatorNumber;
uint256 public candidateWithdrawDelay;
uint256 public voterWithdrawDelay;
@ -41,6 +42,11 @@ contract TomoValidator {
_;
}
modifier onlyValidVoterCap {
require(msg.value >= minVoterCap);
_;
}
modifier onlyOwner(address _candidate) {
require(validatorsState[_candidate].owner == msg.sender);
_;
@ -82,11 +88,13 @@ contract TomoValidator {
uint256[] _caps,
address _firstOwner,
uint256 _minCandidateCap,
uint256 _minVoterCap,
uint256 _maxValidatorNumber,
uint256 _candidateWithdrawDelay,
uint256 _voterWithdrawDelay
) public {
minCandidateCap = _minCandidateCap;
minVoterCap = _minVoterCap;
maxValidatorNumber = _maxValidatorNumber;
candidateWithdrawDelay = _candidateWithdrawDelay;
voterWithdrawDelay = _voterWithdrawDelay;
@ -118,7 +126,7 @@ contract TomoValidator {
emit Propose(msg.sender, _candidate, msg.value);
}
function vote(address _candidate) external payable onlyValidCandidate(_candidate) {
function vote(address _candidate) external payable onlyValidVoterCap onlyValidCandidate(_candidate) {
validatorsState[_candidate].cap = validatorsState[_candidate].cap.add(msg.value);
if (validatorsState[_candidate].voters[msg.sender] == 0) {
voters[_candidate].push(msg.sender);

File diff suppressed because one or more lines are too long

View file

@ -45,11 +45,14 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address,
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, validatorAddress []common.Address, caps []*big.Int, ownerAddress common.Address) (common.Address, *Validator, error) {
minDeposit := new(big.Int)
minDeposit.SetString("50000000000000000000000", 10)
minVoterCap := new(big.Int)
minVoterCap.SetString("10000000000000000000", 10)
// Deposit 50K TOMO
// Min Voter Cap 10 TOMO
// 150 masternodes
// Candidate Delay Withdraw 30 days = 1296000 blocks
// Voter Delay Withdraw 2 days = 8640 blocks
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, big.NewInt(150), big.NewInt(1296000), big.NewInt(8640))
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, minVoterCap, big.NewInt(150), big.NewInt(1296000), big.NewInt(8640))
if err != nil {
return validatorAddr, nil, err
}

View file

@ -101,6 +101,7 @@ func TestRewardBalance(t *testing.T) {
[]*big.Int{validatorCap},
addr,
big.NewInt(50000),
big.NewInt(1),
big.NewInt(99),
big.NewInt(100),
big.NewInt(100),

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long