Merge pull request #148 from thanhson1085/master

add minvotercap
This commit is contained in:
Nguyen Sy Thanh Son 2018-08-18 17:26:30 +07:00 committed by GitHub
commit 9d60a50224
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 15 deletions

View file

@ -31,6 +31,7 @@ contract TomoValidator {
uint256 public candidateCount = 0; uint256 public candidateCount = 0;
uint256 public minCandidateCap; uint256 public minCandidateCap;
uint256 public minVoterCap;
uint256 public maxValidatorNumber; uint256 public maxValidatorNumber;
uint256 public candidateWithdrawDelay; uint256 public candidateWithdrawDelay;
uint256 public voterWithdrawDelay; uint256 public voterWithdrawDelay;
@ -41,6 +42,11 @@ contract TomoValidator {
_; _;
} }
modifier onlyValidVoterCap {
require(msg.value >= minVoterCap);
_;
}
modifier onlyOwner(address _candidate) { modifier onlyOwner(address _candidate) {
require(validatorsState[_candidate].owner == msg.sender); require(validatorsState[_candidate].owner == msg.sender);
_; _;
@ -82,11 +88,13 @@ contract TomoValidator {
uint256[] _caps, uint256[] _caps,
address _firstOwner, address _firstOwner,
uint256 _minCandidateCap, uint256 _minCandidateCap,
uint256 _minVoterCap,
uint256 _maxValidatorNumber, uint256 _maxValidatorNumber,
uint256 _candidateWithdrawDelay, uint256 _candidateWithdrawDelay,
uint256 _voterWithdrawDelay uint256 _voterWithdrawDelay
) public { ) public {
minCandidateCap = _minCandidateCap; minCandidateCap = _minCandidateCap;
minVoterCap = _minVoterCap;
maxValidatorNumber = _maxValidatorNumber; maxValidatorNumber = _maxValidatorNumber;
candidateWithdrawDelay = _candidateWithdrawDelay; candidateWithdrawDelay = _candidateWithdrawDelay;
voterWithdrawDelay = _voterWithdrawDelay; voterWithdrawDelay = _voterWithdrawDelay;
@ -118,7 +126,7 @@ contract TomoValidator {
emit Propose(msg.sender, _candidate, msg.value); 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); validatorsState[_candidate].cap = validatorsState[_candidate].cap.add(msg.value);
if (validatorsState[_candidate].voters[msg.sender] == 0) { if (validatorsState[_candidate].voters[msg.sender] == 0) {
voters[_candidate].push(msg.sender); 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) { 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 := new(big.Int)
minDeposit.SetString("50000000000000000000000", 10) minDeposit.SetString("50000000000000000000000", 10)
minVoterCap := new(big.Int)
minVoterCap.SetString("10000000000000000000", 10)
// Deposit 50K TOMO // Deposit 50K TOMO
// Min Voter Cap 10 TOMO
// 150 masternodes // 150 masternodes
// Candidate Delay Withdraw 30 days = 1296000 blocks // Candidate Delay Withdraw 30 days = 1296000 blocks
// Voter Delay Withdraw 2 days = 8640 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 { if err != nil {
return validatorAddr, nil, err return validatorAddr, nil, err
} }

View file

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