Merge pull request #64 from thanhson1085/master

update smart contract, hard-code first 3-masternodes
This commit is contained in:
Tuna 2018-06-28 00:42:16 +07:00 committed by GitHub
commit fbbdb05b51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 19 deletions

View file

@ -24,8 +24,12 @@ contract TomoValidator is IValidator {
mapping(address => ValidatorState) validatorsState;
mapping(address => address[]) voters;
address[] public candidates;
uint256 candidateCount = 0;
address[] public candidates = [
0xf99805B536609cC03AcBB2604dFaC11E9E54a448,
0x31b249fE6F267aa2396Eb2DC36E9c79351d97Ec5,
0xfC5571921c6d3672e13B58EA23DEA534f2b35fA0
];
uint256 candidateCount = 3;
uint256 public minCandidateCap;
uint256 public maxValidatorNumber;
uint256 public candidateWithdrawDelay; // blocks
@ -67,24 +71,24 @@ contract TomoValidator is IValidator {
_;
}
function TomoValidator (address[] _candidates, uint256[] _caps, uint256 _minCandidateCap, uint256 _maxValidatorNumber, uint256 _candidateWithdrawDelay
function TomoValidator (
uint256 _minCandidateCap,
uint256 _maxValidatorNumber,
uint256 _candidateWithdrawDelay
) public {
minCandidateCap = _minCandidateCap * 10 ** 18;
minCandidateCap = _minCandidateCap;
maxValidatorNumber = _maxValidatorNumber;
candidateWithdrawDelay = _candidateWithdrawDelay;
candidates = _candidates;
for (uint256 i = 0; i < _candidates.length; i++) {
validatorsState[_candidates[i]] = ValidatorState({
owner: msg.sender,
for (uint256 i = 0; i < candidates.length; i++) {
validatorsState[candidates[i]] = ValidatorState({
owner: 0x487d62d33467c4842c5e54Eb370837E4E88BBA0F,
nodeUrl: '',
isCandidate: true,
withdrawBlockNumber: 0,
cap: _caps[i]
cap: minCandidateCap
});
candidateCount = candidateCount + 1;
}
}
function propose(address _candidate, string _nodeUrl) external payable onlyValidCandidateCap onlyNotCandidate(_candidate) {

File diff suppressed because one or more lines are too long

View file

@ -27,8 +27,8 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address,
}, nil
}
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, candidates []common.Address, caps []*big.Int) (common.Address, *Validator, error) {
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, candidates, caps, big.NewInt(50000), big.NewInt(99), big.NewInt(100))
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *Validator, error) {
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100))
if err != nil {
return validatorAddr, nil, err
}

View file

@ -6,7 +6,6 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
)
@ -20,7 +19,7 @@ func TestValidator(t *testing.T) {
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
transactOpts := bind.NewKeyedTransactor(key)
_, validator, err := DeployValidator(transactOpts, contractBackend, []common.Address{addr}, []*big.Int{big.NewInt(0)})
_, validator, err := DeployValidator(transactOpts, contractBackend)
if err != nil {
t.Fatalf("can't deploy root registry: %v", err)
}