mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
commit
9d60a50224
6 changed files with 55 additions and 15 deletions
|
|
@ -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
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
Loading…
Reference in a new issue