mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
update new Tomo Validator
This commit is contained in:
parent
cbb706e435
commit
4cc12d3ed6
4 changed files with 26 additions and 288 deletions
|
|
@ -1,9 +1,8 @@
|
||||||
pragma solidity ^0.4.21;
|
pragma solidity ^0.4.21;
|
||||||
|
|
||||||
import "./interfaces/IValidator.sol";
|
|
||||||
import "./libs/SafeMath.sol";
|
import "./libs/SafeMath.sol";
|
||||||
|
|
||||||
contract TomoValidator is IValidator {
|
contract TomoValidator {
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
|
||||||
event Vote(address _voter, address _candidate, uint256 _cap);
|
event Vote(address _voter, address _candidate, uint256 _cap);
|
||||||
|
|
@ -18,7 +17,6 @@ contract TomoValidator is IValidator {
|
||||||
string nodeUrl;
|
string nodeUrl;
|
||||||
bool isCandidate;
|
bool isCandidate;
|
||||||
uint256 cap;
|
uint256 cap;
|
||||||
uint256 withdrawBlockNumber;
|
|
||||||
mapping(address => uint256) voters;
|
mapping(address => uint256) voters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,13 +29,8 @@ contract TomoValidator is IValidator {
|
||||||
|
|
||||||
mapping(address => ValidatorState) validatorsState;
|
mapping(address => ValidatorState) validatorsState;
|
||||||
mapping(address => address[]) voters;
|
mapping(address => address[]) voters;
|
||||||
address[] public candidates = [
|
address[] public candidates;
|
||||||
0xf99805B536609cC03AcBB2604dFaC11E9E54a448,
|
|
||||||
0x31b249fE6F267aa2396Eb2DC36E9c79351d97Ec5,
|
|
||||||
0xfC5571921c6d3672e13B58EA23DEA534f2b35fA0
|
|
||||||
];
|
|
||||||
|
|
||||||
address public firstOwner = 0x487d62d33467c4842c5e54Eb370837E4E88BBA0F;
|
|
||||||
uint256 public candidateCount = 3;
|
uint256 public candidateCount = 3;
|
||||||
uint256 public minCandidateCap;
|
uint256 public minCandidateCap;
|
||||||
uint256 public maxValidatorNumber;
|
uint256 public maxValidatorNumber;
|
||||||
|
|
@ -84,6 +77,9 @@ contract TomoValidator is IValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
function TomoValidator (
|
function TomoValidator (
|
||||||
|
address[] _candidates,
|
||||||
|
uint256[] _caps,
|
||||||
|
address _firstOwner,
|
||||||
uint256 _minCandidateCap,
|
uint256 _minCandidateCap,
|
||||||
uint256 _maxValidatorNumber,
|
uint256 _maxValidatorNumber,
|
||||||
uint256 _candidateWithdrawDelay,
|
uint256 _candidateWithdrawDelay,
|
||||||
|
|
@ -94,16 +90,16 @@ contract TomoValidator is IValidator {
|
||||||
candidateWithdrawDelay = _candidateWithdrawDelay;
|
candidateWithdrawDelay = _candidateWithdrawDelay;
|
||||||
voterWithdrawDelay = _voterWithdrawDelay;
|
voterWithdrawDelay = _voterWithdrawDelay;
|
||||||
|
|
||||||
for (uint256 i = 0; i < candidates.length; i++) {
|
for (uint256 i = 0; i < _candidates.length; i++) {
|
||||||
validatorsState[candidates[i]] = ValidatorState({
|
candidates.push(_candidates[i]);
|
||||||
owner: firstOwner,
|
validatorsState[_candidates[i]] = ValidatorState({
|
||||||
|
owner: _firstOwner,
|
||||||
nodeUrl: '',
|
nodeUrl: '',
|
||||||
isCandidate: true,
|
isCandidate: true,
|
||||||
withdrawBlockNumber: 0,
|
cap: _caps[i]
|
||||||
cap: minCandidateCap
|
|
||||||
});
|
});
|
||||||
voters[candidates[i]].push(firstOwner);
|
voters[_candidates[i]].push(_firstOwner);
|
||||||
validatorsState[candidates[i]].voters[firstOwner] = minCandidateCap;
|
validatorsState[candidates[i]].voters[_firstOwner] = minCandidateCap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,7 +109,6 @@ contract TomoValidator is IValidator {
|
||||||
owner: msg.sender,
|
owner: msg.sender,
|
||||||
nodeUrl: _nodeUrl,
|
nodeUrl: _nodeUrl,
|
||||||
isCandidate: true,
|
isCandidate: true,
|
||||||
withdrawBlockNumber: 0,
|
|
||||||
cap: msg.value
|
cap: msg.value
|
||||||
});
|
});
|
||||||
validatorsState[_candidate].voters[msg.sender] = msg.value;
|
validatorsState[_candidate].voters[msg.sender] = msg.value;
|
||||||
|
|
@ -147,10 +142,6 @@ contract TomoValidator is IValidator {
|
||||||
return validatorsState[_candidate].owner;
|
return validatorsState[_candidate].owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCandidateWithdrawBlockNumber(address _candidate) public view returns(uint256) {
|
|
||||||
return validatorsState[_candidate].withdrawBlockNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getVoterCap(address _candidate, address _voter) public view returns(uint256) {
|
function getVoterCap(address _candidate, address _voter) public view returns(uint256) {
|
||||||
return validatorsState[_candidate].voters[_voter];
|
return validatorsState[_candidate].voters[_voter];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,7 +1,6 @@
|
||||||
package validator
|
package validator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/contracts/validator/contract"
|
"github.com/ethereum/go-ethereum/contracts/validator/contract"
|
||||||
|
|
@ -28,11 +27,10 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (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)
|
||||||
fmt.Println("--->", common.BigToHash(minDeposit).Hex())
|
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, big.NewInt(99), big.NewInt(100), big.NewInt(100))
|
||||||
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, minDeposit, big.NewInt(99), big.NewInt(100), big.NewInt(100))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return validatorAddr, nil, err
|
return validatorAddr, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,11 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/contracts"
|
// "github.com/ethereum/go-ethereum/contracts"
|
||||||
"github.com/ethereum/go-ethereum/contracts/validator/contract"
|
// "github.com/ethereum/go-ethereum/contracts/validator/contract"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"math/rand"
|
// "math/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -33,7 +33,9 @@ func TestValidator(t *testing.T) {
|
||||||
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
||||||
transactOpts := bind.NewKeyedTransactor(key)
|
transactOpts := bind.NewKeyedTransactor(key)
|
||||||
|
|
||||||
validatorAddress, validator, err := DeployValidator(transactOpts, contractBackend)
|
validatorCap := new(big.Int)
|
||||||
|
validatorCap.SetString("50000000000000000000000", 10)
|
||||||
|
validatorAddress, validator, err := DeployValidator(transactOpts, contractBackend, []common.Address{addr}, []*big.Int{validatorCap}, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't deploy root registry: %v", err)
|
t.Fatalf("can't deploy root registry: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -63,6 +65,7 @@ func TestValidator(t *testing.T) {
|
||||||
contractBackend.Commit()
|
contractBackend.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func TestRewardBalance(t *testing.T) {
|
func TestRewardBalance(t *testing.T) {
|
||||||
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{
|
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{
|
||||||
acc1Addr: {Balance: new(big.Int).SetUint64(10000000)},
|
acc1Addr: {Balance: new(big.Int).SetUint64(10000000)},
|
||||||
|
|
@ -143,3 +146,4 @@ func TestRewardBalance(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue