From aa06d56b984658167f1bd891ad33ed9eabeed8e2 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Thu, 12 Jul 2018 08:15:29 +0000 Subject: [PATCH 01/18] log contract code for debug and genensis generator --- accounts/abi/bind/backends/simulated.go | 13 ++ contracts/blocksigner/blocksigner_test.go | 12 ++ contracts/randomize/randomize_test.go | 18 ++- .../validator/contract/TomoValidator.sol | 71 +++++--- contracts/validator/contract/validator.go | 152 +++++++++++++++--- contracts/validator/validator.go | 6 +- contracts/validator/validator_test.go | 18 ++- 7 files changed, 239 insertions(+), 51 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 2b5c5fc4a4..10e16d5ec9 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -157,6 +157,19 @@ func (b *SimulatedBackend) StorageAt(ctx context.Context, contract common.Addres return val[:], nil } +// ForEachStorageAt returns func to read all keys, values in the storage +func (b *SimulatedBackend) ForEachStorageAt(ctx context.Context, contract common.Address, blockNumber *big.Int, f func(key, val common.Hash) bool) error { + b.mu.Lock() + defer b.mu.Unlock() + + if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) != 0 { + return errBlockNumberUnsupported + } + statedb, _ := b.blockchain.State() + statedb.ForEachStorage(contract, f) + return nil +} + // TransactionReceipt returns the receipt of a transaction. func (b *SimulatedBackend) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { receipt, _, _, _ := core.GetReceipt(b.database, txHash) diff --git a/contracts/blocksigner/blocksigner_test.go b/contracts/blocksigner/blocksigner_test.go index 16c6128aba..6bbdadfe6f 100644 --- a/contracts/blocksigner/blocksigner_test.go +++ b/contracts/blocksigner/blocksigner_test.go @@ -1,8 +1,10 @@ package blocksigner import ( + "context" "math/big" "testing" + "time" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" @@ -25,6 +27,16 @@ func TestBlockSigner(t *testing.T) { } contractBackend.Commit() + d := time.Now().Add(1000 * time.Millisecond) + ctx, _ := context.WithDeadline(context.Background(), d) + code, _ := contractBackend.CodeAt(ctx, blockSignerAddress, nil) + t.Log("contract code", common.ToHex(code)) + f := func(key, val common.Hash) bool { + t.Log(key.Hex(), val.Hex()) + return true + } + contractBackend.ForEachStorageAt(ctx, blockSignerAddress, nil, f) + signers, err := blockSigner.GetSigners(big.NewInt(0)) if err != nil { t.Fatalf("can't get candidates: %v", err) diff --git a/contracts/randomize/randomize_test.go b/contracts/randomize/randomize_test.go index 76ca30fb96..275e081721 100644 --- a/contracts/randomize/randomize_test.go +++ b/contracts/randomize/randomize_test.go @@ -1,11 +1,14 @@ package randomize import ( + "context" "math/big" "testing" + "time" "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,16 +23,27 @@ func TestRandomize(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) transactOpts := bind.NewKeyedTransactor(key) - _, randomize, err := DeployRandomize(transactOpts, contractBackend) + randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend) + t.Log("contract address", randomizeAddress.String()) if err != nil { t.Fatalf("can't deploy root registry: %v", err) } contractBackend.Commit() + d := time.Now().Add(1000 * time.Millisecond) + ctx, _ := context.WithDeadline(context.Background(), d) + code, _ := contractBackend.CodeAt(ctx, randomizeAddress, nil) + t.Log("contract code", common.ToHex(code)) + f := func(key, val common.Hash) bool { + t.Log(key.Hex(), val.Hex()) + return true + } + contractBackend.ForEachStorageAt(ctx, randomizeAddress, nil, f) + s, err := randomize.SetSecret(byte0) if err != nil { t.Fatalf("can't get secret: %v", err) } - t.Log("secret", s) + t.Log("tx data", s) contractBackend.Commit() } diff --git a/contracts/validator/contract/TomoValidator.sol b/contracts/validator/contract/TomoValidator.sol index 84b3450bc0..20b79c2853 100644 --- a/contracts/validator/contract/TomoValidator.sol +++ b/contracts/validator/contract/TomoValidator.sol @@ -11,7 +11,7 @@ contract TomoValidator is IValidator { event Propose(address _owner, address _candidate, uint256 _cap); event Resign(address _owner, address _candidate); event SetNodeUrl(address _owner, address _candidate, string _nodeUrl); - event Withdraw(address _owner, address _candidate, uint256 _cap); + event Withdraw(address _owner, uint256 _blockNumber, uint256 _cap); struct ValidatorState { address owner; @@ -22,6 +22,13 @@ contract TomoValidator is IValidator { mapping(address => uint256) voters; } + struct WithdrawState { + mapping(uint256 => uint256) caps; + uint256[] blockNumbers; + } + + mapping(address => WithdrawState) withdrawsState; + mapping(address => ValidatorState) validatorsState; mapping(address => address[]) voters; address[] public candidates = [ @@ -29,10 +36,13 @@ contract TomoValidator is IValidator { 0x31b249fE6F267aa2396Eb2DC36E9c79351d97Ec5, 0xfC5571921c6d3672e13B58EA23DEA534f2b35fA0 ]; - uint256 candidateCount = 3; + + address public firstOwner = 0x487d62d33467c4842c5e54Eb370837E4E88BBA0F; + uint256 public candidateCount = 3; uint256 public minCandidateCap; uint256 public maxValidatorNumber; - uint256 public candidateWithdrawDelay; // blocks + uint256 public candidateWithdrawDelay; + uint256 public voterWithdrawDelay; modifier onlyValidCandidateCap { // anyone can deposit X TOMO to become a candidate @@ -50,12 +60,6 @@ contract TomoValidator is IValidator { _; } - modifier onlyAlreadyResigned(address _candidate) { - require(validatorsState[_candidate].withdrawBlockNumber > 0); - require(block.number >= validatorsState[_candidate].withdrawBlockNumber); - _; - } - modifier onlyValidCandidate (address _candidate) { require(validatorsState[_candidate].isCandidate); _; @@ -71,23 +75,35 @@ contract TomoValidator is IValidator { _; } + modifier onlyValidWithdraw (uint256 _blockNumber, uint _index) { + require(_blockNumber > 0); + require(block.number >= _blockNumber); + require(withdrawsState[msg.sender].caps[_blockNumber] > 0); + require(withdrawsState[msg.sender].blockNumbers[_index] == _blockNumber); + _; + } + function TomoValidator ( uint256 _minCandidateCap, uint256 _maxValidatorNumber, - uint256 _candidateWithdrawDelay + uint256 _candidateWithdrawDelay, + uint256 _voterWithdrawDelay ) public { minCandidateCap = _minCandidateCap; maxValidatorNumber = _maxValidatorNumber; candidateWithdrawDelay = _candidateWithdrawDelay; + voterWithdrawDelay = _voterWithdrawDelay; for (uint256 i = 0; i < candidates.length; i++) { validatorsState[candidates[i]] = ValidatorState({ - owner: 0x487d62d33467c4842c5e54Eb370837E4E88BBA0F, + owner: firstOwner, nodeUrl: '', isCandidate: true, withdrawBlockNumber: 0, cap: minCandidateCap }); + voters[candidates[i]].push(firstOwner); + validatorsState[candidates[i]].voters[firstOwner] = minCandidateCap; } } @@ -102,6 +118,7 @@ contract TomoValidator is IValidator { }); validatorsState[_candidate].voters[msg.sender] = msg.value; candidateCount = candidateCount + 1; + voters[_candidate].push(_candidate); emit Propose(msg.sender, _candidate, msg.value); } @@ -146,11 +163,19 @@ contract TomoValidator is IValidator { return validatorsState[_candidate].isCandidate; } + function getWithdrawBlockNumbers() public view returns(uint256[]) { + return withdrawsState[msg.sender].blockNumbers; + } + function unvote(address _candidate, uint256 _cap) public onlyValidVote(_candidate, _cap) { validatorsState[_candidate].cap = validatorsState[_candidate].cap.sub(_cap); validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].sub(_cap); - // refunding to user after unvoting - msg.sender.transfer(_cap); + + // refund after delay X blocks + uint256 withdrawBlockNumber = voterWithdrawDelay.add(block.number); + withdrawsState[msg.sender].caps[withdrawBlockNumber] = withdrawsState[msg.sender].caps[withdrawBlockNumber].add(_cap); + withdrawsState[msg.sender].blockNumbers.push(withdrawBlockNumber); + emit Unvote(msg.sender, _candidate, _cap); } @@ -168,17 +193,21 @@ contract TomoValidator is IValidator { break; } } - // refunding after retiring X blocks - validatorsState[_candidate].withdrawBlockNumber = validatorsState[_candidate].withdrawBlockNumber.add(block.number).add(candidateWithdrawDelay); - emit Resign(msg.sender, _candidate); - } - - function withdraw(address _candidate) public onlyOwner(_candidate) onlyNotCandidate(_candidate) onlyAlreadyResigned(_candidate) { uint256 cap = validatorsState[_candidate].voters[msg.sender]; validatorsState[_candidate].cap = validatorsState[_candidate].cap.sub(cap); validatorsState[_candidate].voters[msg.sender] = 0; - validatorsState[_candidate].withdrawBlockNumber = 0; + // refunding after retiring X blocks + uint256 withdrawBlockNumber = candidateWithdrawDelay.add(block.number); + withdrawsState[msg.sender].caps[withdrawBlockNumber] = withdrawsState[msg.sender].caps[withdrawBlockNumber].add(cap); + withdrawsState[msg.sender].blockNumbers.push(withdrawBlockNumber); + emit Resign(msg.sender, _candidate); + } + + function withdraw(uint256 _blockNumber, uint _index) public onlyValidWithdraw(_blockNumber, _index) { + uint256 cap = withdrawsState[msg.sender].caps[_blockNumber]; + delete withdrawsState[msg.sender].caps[_blockNumber]; + delete withdrawsState[msg.sender].blockNumbers[_index]; msg.sender.transfer(cap); - emit Withdraw(msg.sender, _candidate, cap); + emit Withdraw(msg.sender, _blockNumber, cap); } } diff --git a/contracts/validator/contract/validator.go b/contracts/validator/contract/validator.go index c3af56acd7..3f69d6c521 100644 --- a/contracts/validator/contract/validator.go +++ b/contracts/validator/contract/validator.go @@ -380,18 +380,18 @@ func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method } // TomoValidatorABI is the input ABI used to generate the binding from. -const TomoValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"unvote\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getCandidates\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateWithdrawBlockNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getVoters\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_voter\",\"type\":\"address\"}],\"name\":\"getVoterCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"candidates\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"withdraw\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"setNodeUrl\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"resign\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateOwner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"maxValidatorNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"candidateWithdrawDelay\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"isCandidate\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"minCandidateCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateNodeUrl\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_minCandidateCap\",\"type\":\"uint256\"},{\"name\":\"_maxValidatorNumber\",\"type\":\"uint256\"},{\"name\":\"_candidateWithdrawDelay\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_voter\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Vote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_voter\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Unvote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Propose\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"Resign\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"SetNodeUrl\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Withdraw\",\"type\":\"event\"}]" +const TomoValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"unvote\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getCandidates\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateWithdrawBlockNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getVoters\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getWithdrawBlockNumbers\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_voter\",\"type\":\"address\"}],\"name\":\"getVoterCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"candidates\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"name\":\"_index\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"firstOwner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"setNodeUrl\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"candidateCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"voterWithdrawDelay\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"resign\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateOwner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"maxValidatorNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"candidateWithdrawDelay\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"isCandidate\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"minCandidateCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateNodeUrl\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_minCandidateCap\",\"type\":\"uint256\"},{\"name\":\"_maxValidatorNumber\",\"type\":\"uint256\"},{\"name\":\"_candidateWithdrawDelay\",\"type\":\"uint256\"},{\"name\":\"_voterWithdrawDelay\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_voter\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Vote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_voter\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Unvote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Propose\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"Resign\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"SetNodeUrl\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Withdraw\",\"type\":\"event\"}]" // TomoValidatorBin is the compiled bytecode used for deploying new contracts. -const TomoValidatorBin = `0x60606040526060604051908101604090815273f99805b536609cc03acbb2604dfac11e9e54a44882527331b249fe6f267aa2396eb2dc36e9c79351d97ec5602083015273fc5571921c6d3672e13b58ea23dea534f2b35fa0908201526200006b906002906003620001cc565b506003805534156200007c57600080fd5b6040516060806200149a8339810160405280805191906020018051919060200180516004859055600584905560068190559150600090505b600254811015620001c25760a06040519081016040528073487d62d33467c4842c5e54eb370837e4e88bba0f600160a060020a0316815260200160206040519081016040528060008152508152602001600115158152602001600454815260200160008152506000806002848154811015156200012d57fe5b6000918252602080832090910154600160a060020a03168352820192909252604001902081518154600160a060020a031916600160a060020a03919091161781556020820151816001019080516200018a92916020019062000238565b50604082015160028201805460ff191691151591909117905560608201518160030155608082015160049091015550600101620000b4565b5050505062000300565b82805482825590600052602060002090810192821562000226579160200282015b82811115620002265782518254600160a060020a031916600160a060020a039190911617825560209290920191600190910190620001ed565b5062000234929150620002b9565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200027b57805160ff1916838001178555620002ab565b82800160010185558215620002ab579182015b82811115620002ab5782518255916020019190600101906200028e565b5062000234929150620002e3565b620002e091905b8082111562000234578054600160a060020a0319168155600101620002c0565b90565b620002e091905b80821115620002345760008155600101620002ea565b61118a80620003106000396000f3006060604052600436106100fb5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302aa9be2811461010057806306a49fce14610124578063282652941461018a5780632d15cc04146101bb578063302b6872146101da5780633477ee2e146101ff57806351cff8d91461023157806358e7525f146102505780636dd7d8ea1461026f578063a3ec796514610283578063ae6e43f5146102e2578063b642facd14610301578063d09f1ab414610320578063d161c76714610333578063d51b9e9314610346578063d55b7dff14610379578063d6f0948c1461038c578063da67b599146103ac575b600080fd5b341561010b57600080fd5b610122600160a060020a0360043516602435610442565b005b341561012f57600080fd5b61013761059a565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561017657808201518382015260200161015e565b505050509050019250505060405180910390f35b341561019557600080fd5b6101a9600160a060020a0360043516610603565b60405190815260200160405180910390f35b34156101c657600080fd5b610137600160a060020a0360043516610621565b34156101e557600080fd5b6101a9600160a060020a03600435811690602435166106ae565b341561020a57600080fd5b6102156004356106db565b604051600160a060020a03909116815260200160405180910390f35b341561023c57600080fd5b610122600160a060020a0360043516610703565b341561025b57600080fd5b6101a9600160a060020a03600435166108b4565b610122600160a060020a03600435166108d2565b341561028e57600080fd5b61012260048035600160a060020a03169060446024803590810190830135806020601f82018190048102016040519081016040528181529291906020840183838082843750949650610a7c95505050505050565b34156102ed57600080fd5b610122600160a060020a0360043516610b8c565b341561030c57600080fd5b610215600160a060020a0360043516610d4e565b341561032b57600080fd5b6101a9610d6c565b341561033e57600080fd5b6101a9610d72565b341561035157600080fd5b610365600160a060020a0360043516610d78565b604051901515815260200160405180910390f35b341561038457600080fd5b6101a9610d99565b61012260048035600160a060020a03169060248035908101910135610d9f565b34156103b757600080fd5b6103cb600160a060020a0360043516610f9e565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156104075780820151838201526020016103ef565b50505050905090810190601f1680156104345780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600160a060020a03808316600090815260208181526040808320339094168352600590930190522054829082908190101561047c57600080fd5b600160a060020a0384166000908152602081905260409020600301546104a8908463ffffffff61106316565b600160a060020a03808616600090815260208181526040808320600381019590955533909316825260059093019092529020546104eb908463ffffffff61106316565b600160a060020a0380861660009081526020818152604080832033909416808452600590940190915290819020929092559084156108fc0290859051600060405180830381858888f19350505050151561054457600080fd5b7faa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2338585604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b6105a261108b565b60028054806020026020016040519081016040528092919081815260200182805480156105f857602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116105da575b505050505090505b90565b600160a060020a031660009081526020819052604090206004015490565b61062961108b565b6001600083600160a060020a0316600160a060020a031681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156106a257602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610684575b50505050509050919050565b600160a060020a039182166000908152602081815260408083209390941682526005909201909152205490565b60028054829081106106e957fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a038181166000908152602081905260408120549091839133821691161461073057600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff161561075b57600080fd5b600160a060020a0384166000908152602081905260408120600401548591901161078457600080fd5b600160a060020a0381166000908152602081905260409020600401544310156107ac57600080fd5b600160a060020a03808616600081815260208181526040808320339095168352600585018252822054928252526003909101549094506107f2908563ffffffff61106316565b600160a060020a0380871660008181526020818152604080832060038101969096553390941680835260058601825284832083905592825281905260049093019290925585156108fc0290869051600060405180830381858888f19350505050151561085d57600080fd5b7f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb338686604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050505050565b600160a060020a031660009081526020819052604090206003015490565b600160a060020a038116600090815260208190526040902060020154819060ff1615156108fe57600080fd5b600160a060020a03821660009081526020819052604090206003015461092a903463ffffffff61107516565b600160a060020a038084166000908152602081815260408083206003810195909555339093168252600590930190925290205415156109c157600160a060020a038216600090815260016020819052604090912080549091810161098e838261109d565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790555b600160a060020a038083166000908152602081815260408083203390941683526005909301905220546109fa903463ffffffff61107516565b600160a060020a0380841660009081526020818152604080832033948516845260050190915290819020929092557f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc918490349051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050565b600160a060020a038281166000908152602081905260409020548391338116911614610aa757600080fd5b600160a060020a0383166000908152602081905260409020600101828051610ad39291602001906110c6565b507f63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4338484604051600160a060020a0380851682528316602082015260606040820181815290820183818151815260200191508051906020019080838360005b83811015610b4b578082015183820152602001610b33565b50505050905090810190601f168015610b785780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1505050565b600160a060020a0381811660009081526020819052604081205490918391338216911614610bb957600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff161515610be557600080fd5b600160a060020a0384166000908152602081905260408120600201805460ff191690556003805460001901905592505b600254831015610c975783600160a060020a0316600284815481101515610c3857fe5b600091825260209091200154600160a060020a03161415610c8c576002805484908110610c6157fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19169055610c97565b600190920191610c15565b600654600160a060020a038516600090815260208190526040902060040154610cd79190610ccb904363ffffffff61107516565b9063ffffffff61107516565b60008086600160a060020a0316600160a060020a03168152602001908152602001600020600401819055507f4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d33385604051600160a060020a039283168152911660208201526040908101905180910390a150505050565b600160a060020a039081166000908152602081905260409020541690565b60055481565b60065481565b600160a060020a031660009081526020819052604090206002015460ff1690565b60045481565b600454341015610dae57600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff1615610dd957600080fd5b6002805460018101610deb838261109d565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03861617905560a06040519081016040528033600160a060020a0316815260200184848080601f0160208091040260200160405190810160405281815292919060208401838380828437505050928452505060016020808401919091523460408085019190915260006060909401849052600160a060020a03891684529083905290912090508151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0391909116178155602082015181600101908051610ee19291602001906110c6565b50604082015160028201805460ff191691151591909117905560608201518160030155608082015160049091015550600160a060020a038085166000908152602081815260408083203394851684526005019091529081902034908190556003805460010190557f7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1929187919051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b610fa661108b565b60008083600160a060020a0316600160a060020a031681526020019081526020016000206001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106a25780601f10611036576101008083540402835291602001916106a2565b820191906000526020600020905b8154815290600101906020018083116110445750939695505050505050565b60008282111561106f57fe5b50900390565b60008282018381101561108457fe5b9392505050565b60206040519081016040526000815290565b8154818355818115116110c1576000838152602090206110c1918101908301611144565b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061110757805160ff1916838001178555611134565b82800160010185558215611134579182015b82811115611134578251825591602001919060010190611119565b50611140929150611144565b5090565b61060091905b80821115611140576000815560010161114a5600a165627a7a72305820643a4d877b1248c19e7e8749d7279654d953dd5ebfd06be341ab10da6ae4d4d70029` +const TomoValidatorBin = `0x60606040526060604051908101604090815273f99805b536609cc03acbb2604dfac11e9e54a44882527331b249fe6f267aa2396eb2dc36e9c79351d97ec5602083015273fc5571921c6d3672e13b58ea23dea534f2b35fa0908201526200006a9060039081620002bb565b5060048054600160a060020a03191673487d62d33467c4842c5e54eb370837e4e88bba0f17905560036005553415620000a257600080fd5b604051608080620017ec8339810160405280805191906020018051919060200180519190602001805160068690556007859055600884905560098190559150600090505b600354811015620002b05760a06040519081016040908152600454600160a060020a0316825260208083019151908101604052806000815250815260200160011515815260200160065481526020016000815250600160006003848154811015156200014e57fe5b6000918252602080832090910154600160a060020a03168352820192909252604001902081518154600160a060020a031916600160a060020a0391909116178155602082015181600101908051620001ab92916020019062000327565b50604082015160028201805460ff1916911515919091179055606082015181600301556080820151816004015590505060026000600383815481101515620001ef57fe5b6000918252602080832090910154600160a060020a031683528201929092526040019020805460018101620002258382620003a8565b5060009182526020822060045491018054600160a060020a031916600160a060020a03909216919091179055600654600380549192600192909190859081106200026b57fe5b6000918252602080832090910154600160a060020a039081168452838201949094526040928301822060045490941682526005909301909252902055600101620000e6565b50505050506200041b565b82805482825590600052602060002090810192821562000315579160200282015b82811115620003155782518254600160a060020a031916600160a060020a039190911617825560209290920191600190910190620002dc565b5062000323929150620003d4565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200036a57805160ff19168380011785556200039a565b828001600101855582156200039a579182015b828111156200039a5782518255916020019190600101906200037d565b5062000323929150620003fe565b815481835581811511620003cf57600083815260209020620003cf918101908301620003fe565b505050565b620003fb91905b8082111562000323578054600160a060020a0319168155600101620003db565b90565b620003fb91905b8082111562000323576000815560010162000405565b6113c1806200042b6000396000f3006060604052600436106101275763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302aa9be2811461012c57806306a49fce1461015057806328265294146101b65780632d15cc04146101e75780632f9c4bba14610206578063302b6872146102195780633477ee2e1461023e578063441a3e701461027057806358e7525f146102895780636bc28781146102a85780636dd7d8ea146102bb578063a3ec7965146102cf578063a9a981a31461032e578063a9ff959e14610341578063ae6e43f514610354578063b642facd14610373578063d09f1ab414610392578063d161c767146103a5578063d51b9e93146103b8578063d55b7dff146103eb578063d6f0948c146103fe578063da67b5991461041e575b600080fd5b341561013757600080fd5b61014e600160a060020a03600435166024356104b4565b005b341561015b57600080fd5b61016361067c565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156101a257808201518382015260200161018a565b505050509050019250505060405180910390f35b34156101c157600080fd5b6101d5600160a060020a03600435166106e5565b60405190815260200160405180910390f35b34156101f257600080fd5b610163600160a060020a0360043516610703565b341561021157600080fd5b610163610790565b341561022457600080fd5b6101d5600160a060020a0360043581169060243516610812565b341561024957600080fd5b610254600435610841565b604051600160a060020a03909116815260200160405180910390f35b341561027b57600080fd5b61014e600435602435610869565b341561029457600080fd5b6101d5600160a060020a03600435166109d0565b34156102b357600080fd5b6102546109ee565b61014e600160a060020a03600435166109fd565b34156102da57600080fd5b61014e60048035600160a060020a03169060446024803590810190830135806020601f82018190048102016040519081016040528181529291906020840183838082843750949650610baa95505050505050565b341561033957600080fd5b6101d5610cbb565b341561034c57600080fd5b6101d5610cc1565b341561035f57600080fd5b61014e600160a060020a0360043516610cc7565b341561037e57600080fd5b610254600160a060020a0360043516610f3a565b341561039d57600080fd5b6101d5610f58565b34156103b057600080fd5b6101d5610f5e565b34156103c357600080fd5b6103d7600160a060020a0360043516610f64565b604051901515815260200160405180910390f35b34156103f657600080fd5b6101d5610f85565b61014e60048035600160a060020a03169060248035908101910135610f8b565b341561042957600080fd5b61043d600160a060020a03600435166111d4565b60405160208082528190810183818151815260200191508051906020019080838360005b83811015610479578082015183820152602001610461565b50505050905090810190601f1680156104a65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600160a060020a038083166000908152600160209081526040808320339094168352600590930190529081205483908390819010156104f257600080fd5b600160a060020a03851660009081526001602052604090206003015461051e908563ffffffff61129a16565b600160a060020a03808716600090815260016020908152604080832060038101959095553390931682526005909301909252902054610563908563ffffffff61129a16565b600160a060020a0380871660009081526001602090815260408083203390941683526005909301905220556009546105a1904363ffffffff6112ac16565b600160a060020a0333166000908152602081815260408083208484529091529020549093506105d6908563ffffffff6112ac16565b600160a060020a033316600081815260208181526040808320888452808352908320949094559181529052600190810180549091810161061683826112c2565b5060009182526020909120018390557faa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2338686604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050505050565b6106846112eb565b60038054806020026020016040519081016040528092919081815260200182805480156106da57602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116106bc575b505050505090505b90565b600160a060020a031660009081526001602052604090206004015490565b61070b6112eb565b6002600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561078457602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610766575b50505050509050919050565b6107986112eb565b60008033600160a060020a0316600160a060020a031681526020019081526020016000206001018054806020026020016040519081016040528092919081815260200182805480156106da57602002820191906000526020600020905b8154815260200190600101908083116107f5575050505050905090565b600160a060020a0391821660009081526001602090815260408083209390941682526005909201909152205490565b600380548290811061084f57fe5b600091825260209091200154600160a060020a0316905081565b6000828282821161087957600080fd5b438290101561088757600080fd5b600160a060020a033316600090815260208181526040808320858452909152812054116108b357600080fd5b600160a060020a03331660009081526020819052604090206001018054839190839081106108dd57fe5b600091825260209091200154146108f357600080fd5b600160a060020a0333166000818152602081815260408083208984528083529083208054908490559383529190526001018054919450908590811061093457fe5b6000918252602082200155600160a060020a03331683156108fc0284604051600060405180830381858888f19350505050151561097057600080fd5b7ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b5683386856040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390a15050505050565b600160a060020a031660009081526001602052604090206003015490565b600454600160a060020a031681565b600160a060020a038116600090815260016020526040902060020154819060ff161515610a2957600080fd5b600160a060020a038216600090815260016020526040902060030154610a55903463ffffffff6112ac16565b600160a060020a038084166000908152600160209081526040808320600381019590955533909316825260059093019092529020541515610aeb57600160a060020a0382166000908152600260205260409020805460018101610ab883826112c2565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790555b600160a060020a038083166000908152600160209081526040808320339094168352600590930190522054610b26903463ffffffff6112ac16565b600160a060020a03808416600090815260016020908152604080832033948516845260050190915290819020929092557f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc918490349051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050565b600160a060020a038281166000908152600160205260409020548391338116911614610bd557600080fd5b600160a060020a038316600090815260016020819052604090912001828051610c029291602001906112fd565b507f63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4338484604051600160a060020a0380851682528316602082015260606040820181815290820183818151815260200191508051906020019080838360005b83811015610c7a578082015183820152602001610c62565b50505050905090810190601f168015610ca75780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1505050565b60055481565b60095481565b600160a060020a038181166000908152600160205260408120549091829182918591338216911614610cf857600080fd5b600160a060020a038516600090815260016020526040902060020154859060ff161515610d2457600080fd5b600160a060020a0386166000908152600160205260408120600201805460ff191690556005805460001901905594505b600354851015610dd65785600160a060020a0316600386815481101515610d7757fe5b600091825260209091200154600160a060020a03161415610dcb576003805486908110610da057fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19169055610dd6565b600190940193610d54565b600160a060020a038087166000818152600160208181526040808420339096168452600586018252832054939092529052600390910154909450610e20908563ffffffff61129a16565b600160a060020a03808816600090815260016020908152604080832060038101959095553390931682526005909301909252812055600854610e68904363ffffffff6112ac16565b600160a060020a033316600090815260208181526040808320848452909152902054909350610e9d908563ffffffff6112ac16565b600160a060020a0333166000818152602081815260408083208884528083529083209490945591815290526001908101805490918101610edd83826112c2565b5060009182526020909120018390557f4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d33387604051600160a060020a039283168152911660208201526040908101905180910390a1505050505050565b600160a060020a039081166000908152600160205260409020541690565b60075481565b60085481565b600160a060020a031660009081526001602052604090206002015460ff1690565b60065481565b600654341015610f9a57600080fd5b600160a060020a038316600090815260016020526040902060020154839060ff1615610fc557600080fd5b6003805460018101610fd783826112c2565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03861617905560a06040519081016040528033600160a060020a0316815260200184848080601f01602080910402602001604051908101604052818152929190602084018383808284375050509284525050600160208084018290523460408086019190915260006060909501859052600160a060020a038a16855291905290912090508151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03919091161781556020820151816001019080516110cb9291602001906112fd565b50604082015160028201805460ff191691151591909117905560608201518160030155608082015160049091015550600160a060020a038085166000818152600160208181526040808420339096168452600595860182528084203490558554830190955592825260029092529190912080549091810161114c83826112c2565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0386161790557f7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1338534604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b6111dc6112eb565b6001600083600160a060020a0316600160a060020a031681526020019081526020016000206001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156107845780601f1061126d57610100808354040283529160200191610784565b820191906000526020600020905b81548152906001019060200180831161127b5750939695505050505050565b6000828211156112a657fe5b50900390565b6000828201838110156112bb57fe5b9392505050565b8154818355818115116112e6576000838152602090206112e691810190830161137b565b505050565b60206040519081016040526000815290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061133e57805160ff191683800117855561136b565b8280016001018555821561136b579182015b8281111561136b578251825591602001919060010190611350565b5061137792915061137b565b5090565b6106e291905b8082111561137757600081556001016113815600a165627a7a72305820479a652c5721d1178b9d8443fe6dd8b949fe0bf883ba1dd1879aab405681fbf70029` // DeployTomoValidator deploys a new Ethereum contract, binding an instance of TomoValidator to it. -func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _minCandidateCap *big.Int, _maxValidatorNumber *big.Int, _candidateWithdrawDelay *big.Int) (common.Address, *types.Transaction, *TomoValidator, error) { +func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _minCandidateCap *big.Int, _maxValidatorNumber *big.Int, _candidateWithdrawDelay *big.Int, _voterWithdrawDelay *big.Int) (common.Address, *types.Transaction, *TomoValidator, error) { parsed, err := abi.JSON(strings.NewReader(TomoValidatorABI)) if err != nil { return common.Address{}, nil, nil, err } - address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TomoValidatorBin), backend, _minCandidateCap, _maxValidatorNumber, _candidateWithdrawDelay) + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TomoValidatorBin), backend, _minCandidateCap, _maxValidatorNumber, _candidateWithdrawDelay, _voterWithdrawDelay) if err != nil { return common.Address{}, nil, nil, err } @@ -540,6 +540,32 @@ func (_TomoValidator *TomoValidatorTransactorRaw) Transact(opts *bind.TransactOp return _TomoValidator.Contract.contract.Transact(opts, method, params...) } +// CandidateCount is a free data retrieval call binding the contract method 0xa9a981a3. +// +// Solidity: function candidateCount() constant returns(uint256) +func (_TomoValidator *TomoValidatorCaller) CandidateCount(opts *bind.CallOpts) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "candidateCount") + return *ret0, err +} + +// CandidateCount is a free data retrieval call binding the contract method 0xa9a981a3. +// +// Solidity: function candidateCount() constant returns(uint256) +func (_TomoValidator *TomoValidatorSession) CandidateCount() (*big.Int, error) { + return _TomoValidator.Contract.CandidateCount(&_TomoValidator.CallOpts) +} + +// CandidateCount is a free data retrieval call binding the contract method 0xa9a981a3. +// +// Solidity: function candidateCount() constant returns(uint256) +func (_TomoValidator *TomoValidatorCallerSession) CandidateCount() (*big.Int, error) { + return _TomoValidator.Contract.CandidateCount(&_TomoValidator.CallOpts) +} + // CandidateWithdrawDelay is a free data retrieval call binding the contract method 0xd161c767. // // Solidity: function candidateWithdrawDelay() constant returns(uint256) @@ -592,6 +618,32 @@ func (_TomoValidator *TomoValidatorCallerSession) Candidates(arg0 *big.Int) (com return _TomoValidator.Contract.Candidates(&_TomoValidator.CallOpts, arg0) } +// FirstOwner is a free data retrieval call binding the contract method 0x6bc28781. +// +// Solidity: function firstOwner() constant returns(address) +func (_TomoValidator *TomoValidatorCaller) FirstOwner(opts *bind.CallOpts) (common.Address, error) { + var ( + ret0 = new(common.Address) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "firstOwner") + return *ret0, err +} + +// FirstOwner is a free data retrieval call binding the contract method 0x6bc28781. +// +// Solidity: function firstOwner() constant returns(address) +func (_TomoValidator *TomoValidatorSession) FirstOwner() (common.Address, error) { + return _TomoValidator.Contract.FirstOwner(&_TomoValidator.CallOpts) +} + +// FirstOwner is a free data retrieval call binding the contract method 0x6bc28781. +// +// Solidity: function firstOwner() constant returns(address) +func (_TomoValidator *TomoValidatorCallerSession) FirstOwner() (common.Address, error) { + return _TomoValidator.Contract.FirstOwner(&_TomoValidator.CallOpts) +} + // GetCandidateCap is a free data retrieval call binding the contract method 0x58e7525f. // // Solidity: function getCandidateCap(_candidate address) constant returns(uint256) @@ -774,6 +826,32 @@ func (_TomoValidator *TomoValidatorCallerSession) GetVoters(_candidate common.Ad return _TomoValidator.Contract.GetVoters(&_TomoValidator.CallOpts, _candidate) } +// GetWithdrawBlockNumbers is a free data retrieval call binding the contract method 0x2f9c4bba. +// +// Solidity: function getWithdrawBlockNumbers() constant returns(uint256[]) +func (_TomoValidator *TomoValidatorCaller) GetWithdrawBlockNumbers(opts *bind.CallOpts) ([]*big.Int, error) { + var ( + ret0 = new([]*big.Int) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "getWithdrawBlockNumbers") + return *ret0, err +} + +// GetWithdrawBlockNumbers is a free data retrieval call binding the contract method 0x2f9c4bba. +// +// Solidity: function getWithdrawBlockNumbers() constant returns(uint256[]) +func (_TomoValidator *TomoValidatorSession) GetWithdrawBlockNumbers() ([]*big.Int, error) { + return _TomoValidator.Contract.GetWithdrawBlockNumbers(&_TomoValidator.CallOpts) +} + +// GetWithdrawBlockNumbers is a free data retrieval call binding the contract method 0x2f9c4bba. +// +// Solidity: function getWithdrawBlockNumbers() constant returns(uint256[]) +func (_TomoValidator *TomoValidatorCallerSession) GetWithdrawBlockNumbers() ([]*big.Int, error) { + return _TomoValidator.Contract.GetWithdrawBlockNumbers(&_TomoValidator.CallOpts) +} + // IsCandidate is a free data retrieval call binding the contract method 0xd51b9e93. // // Solidity: function isCandidate(_candidate address) constant returns(bool) @@ -852,6 +930,32 @@ func (_TomoValidator *TomoValidatorCallerSession) MinCandidateCap() (*big.Int, e return _TomoValidator.Contract.MinCandidateCap(&_TomoValidator.CallOpts) } +// VoterWithdrawDelay is a free data retrieval call binding the contract method 0xa9ff959e. +// +// Solidity: function voterWithdrawDelay() constant returns(uint256) +func (_TomoValidator *TomoValidatorCaller) VoterWithdrawDelay(opts *bind.CallOpts) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "voterWithdrawDelay") + return *ret0, err +} + +// VoterWithdrawDelay is a free data retrieval call binding the contract method 0xa9ff959e. +// +// Solidity: function voterWithdrawDelay() constant returns(uint256) +func (_TomoValidator *TomoValidatorSession) VoterWithdrawDelay() (*big.Int, error) { + return _TomoValidator.Contract.VoterWithdrawDelay(&_TomoValidator.CallOpts) +} + +// VoterWithdrawDelay is a free data retrieval call binding the contract method 0xa9ff959e. +// +// Solidity: function voterWithdrawDelay() constant returns(uint256) +func (_TomoValidator *TomoValidatorCallerSession) VoterWithdrawDelay() (*big.Int, error) { + return _TomoValidator.Contract.VoterWithdrawDelay(&_TomoValidator.CallOpts) +} + // Propose is a paid mutator transaction binding the contract method 0xd6f0948c. // // Solidity: function propose(_candidate address, _nodeUrl string) returns() @@ -957,25 +1061,25 @@ func (_TomoValidator *TomoValidatorTransactorSession) Vote(_candidate common.Add return _TomoValidator.Contract.Vote(&_TomoValidator.TransactOpts, _candidate) } -// Withdraw is a paid mutator transaction binding the contract method 0x51cff8d9. +// Withdraw is a paid mutator transaction binding the contract method 0x441a3e70. // -// Solidity: function withdraw(_candidate address) returns() -func (_TomoValidator *TomoValidatorTransactor) Withdraw(opts *bind.TransactOpts, _candidate common.Address) (*types.Transaction, error) { - return _TomoValidator.contract.Transact(opts, "withdraw", _candidate) +// Solidity: function withdraw(_blockNumber uint256, _index uint256) returns() +func (_TomoValidator *TomoValidatorTransactor) Withdraw(opts *bind.TransactOpts, _blockNumber *big.Int, _index *big.Int) (*types.Transaction, error) { + return _TomoValidator.contract.Transact(opts, "withdraw", _blockNumber, _index) } -// Withdraw is a paid mutator transaction binding the contract method 0x51cff8d9. +// Withdraw is a paid mutator transaction binding the contract method 0x441a3e70. // -// Solidity: function withdraw(_candidate address) returns() -func (_TomoValidator *TomoValidatorSession) Withdraw(_candidate common.Address) (*types.Transaction, error) { - return _TomoValidator.Contract.Withdraw(&_TomoValidator.TransactOpts, _candidate) +// Solidity: function withdraw(_blockNumber uint256, _index uint256) returns() +func (_TomoValidator *TomoValidatorSession) Withdraw(_blockNumber *big.Int, _index *big.Int) (*types.Transaction, error) { + return _TomoValidator.Contract.Withdraw(&_TomoValidator.TransactOpts, _blockNumber, _index) } -// Withdraw is a paid mutator transaction binding the contract method 0x51cff8d9. +// Withdraw is a paid mutator transaction binding the contract method 0x441a3e70. // -// Solidity: function withdraw(_candidate address) returns() -func (_TomoValidator *TomoValidatorTransactorSession) Withdraw(_candidate common.Address) (*types.Transaction, error) { - return _TomoValidator.Contract.Withdraw(&_TomoValidator.TransactOpts, _candidate) +// Solidity: function withdraw(_blockNumber uint256, _index uint256) returns() +func (_TomoValidator *TomoValidatorTransactorSession) Withdraw(_blockNumber *big.Int, _index *big.Int) (*types.Transaction, error) { + return _TomoValidator.Contract.Withdraw(&_TomoValidator.TransactOpts, _blockNumber, _index) } // TomoValidatorProposeIterator is returned from FilterPropose and is used to iterate over the raw logs and unpacked data for Propose events raised by the TomoValidator contract. @@ -1666,15 +1770,15 @@ func (it *TomoValidatorWithdrawIterator) Close() error { // TomoValidatorWithdraw represents a Withdraw event raised by the TomoValidator contract. type TomoValidatorWithdraw struct { - Owner common.Address - Candidate common.Address - Cap *big.Int - Raw types.Log // Blockchain specific contextual infos + Owner common.Address + BlockNumber *big.Int + Cap *big.Int + Raw types.Log // Blockchain specific contextual infos } -// FilterWithdraw is a free log retrieval operation binding the contract event 0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb. +// FilterWithdraw is a free log retrieval operation binding the contract event 0xf279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b568. // -// Solidity: event Withdraw(_owner address, _candidate address, _cap uint256) +// Solidity: event Withdraw(_owner address, _blockNumber uint256, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) FilterWithdraw(opts *bind.FilterOpts) (*TomoValidatorWithdrawIterator, error) { logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Withdraw") @@ -1684,9 +1788,9 @@ func (_TomoValidator *TomoValidatorFilterer) FilterWithdraw(opts *bind.FilterOpt return &TomoValidatorWithdrawIterator{contract: _TomoValidator.contract, event: "Withdraw", logs: logs, sub: sub}, nil } -// WatchWithdraw is a free log subscription operation binding the contract event 0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb. +// WatchWithdraw is a free log subscription operation binding the contract event 0xf279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b568. // -// Solidity: event Withdraw(_owner address, _candidate address, _cap uint256) +// Solidity: event Withdraw(_owner address, _blockNumber uint256, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) WatchWithdraw(opts *bind.WatchOpts, sink chan<- *TomoValidatorWithdraw) (event.Subscription, error) { logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Withdraw") diff --git a/contracts/validator/validator.go b/contracts/validator/validator.go index f9e7891e07..f3bcc2ae77 100644 --- a/contracts/validator/validator.go +++ b/contracts/validator/validator.go @@ -1,6 +1,7 @@ package validator import ( + "fmt" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/contracts/validator/contract" @@ -28,7 +29,10 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address, } 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)) + minDeposit := new(big.Int) + minDeposit.SetString("50000000000000000000000", 10) + fmt.Println("--->", common.BigToHash(minDeposit).Hex()) + validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, minDeposit, big.NewInt(99), big.NewInt(100), big.NewInt(100)) if err != nil { return validatorAddr, nil, err } diff --git a/contracts/validator/validator_test.go b/contracts/validator/validator_test.go index 000fc165c6..9ccdbd5f34 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -1,17 +1,19 @@ package validator import ( + "context" "math/big" "testing" + "time" "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/contracts" "github.com/ethereum/go-ethereum/contracts/validator/contract" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/crypto" "math/rand" - "time" ) var ( @@ -31,12 +33,22 @@ func TestValidator(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) transactOpts := bind.NewKeyedTransactor(key) - _, validator, err := DeployValidator(transactOpts, contractBackend) + validatorAddress, validator, err := DeployValidator(transactOpts, contractBackend) if err != nil { t.Fatalf("can't deploy root registry: %v", err) } contractBackend.Commit() + d := time.Now().Add(1000 * time.Millisecond) + ctx, _ := context.WithDeadline(context.Background(), d) + code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil) + t.Log("contract code", common.ToHex(code)) + f := func(key, val common.Hash) bool { + t.Log(key.Hex(), val.Hex()) + return true + } + contractBackend.ForEachStorageAt(ctx, validatorAddress, nil, f) + candidates, err := validator.GetCandidates() if err != nil { t.Fatalf("can't get candidates: %v", err) @@ -61,7 +73,7 @@ func TestRewardBalance(t *testing.T) { accounts := []*bind.TransactOpts{acc1Opts, acc2Opts} transactOpts := bind.NewKeyedTransactor(acc1Key) - validatorAddr, _, baseValidator, err := contract.DeployTomoValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100)) + validatorAddr, _, baseValidator, err := contract.DeployTomoValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100), big.NewInt(100)) if err != nil { t.Fatalf("can't deploy root registry: %v", err) } From dd353d6bb581bfbb72e482675f8f239b2033b361 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Thu, 12 Jul 2018 10:06:00 +0000 Subject: [PATCH 02/18] add option genesis generator for POSV --- cmd/puppeth/wizard_genesis.go | 87 ++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index 89423e8b55..eb89a4ec71 100644 --- a/cmd/puppeth/wizard_genesis.go +++ b/cmd/puppeth/wizard_genesis.go @@ -21,7 +21,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "math/big" "math/rand" "time" @@ -29,6 +28,14 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" + + "context" + "math/big" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" + validatorContract "github.com/ethereum/go-ethereum/contracts/validator" + "github.com/ethereum/go-ethereum/crypto" ) // makeGenesis creates a new genesis struct based on some user input. @@ -52,6 +59,7 @@ func (w *wizard) makeGenesis() { fmt.Println("Which consensus engine to use? (default = clique)") fmt.Println(" 1. Ethash - proof-of-work") fmt.Println(" 2. Clique - proof-of-authority") + fmt.Println(" 3. Tomo - proof-of-stake-voting") choice := w.read() switch { @@ -107,6 +115,83 @@ func (w *wizard) makeGenesis() { fmt.Println("How many blocks per checkpoint? (default = 990)") genesis.Config.Clique.RewardCheckpoint = uint64(w.readDefaultInt(990)) + case choice == "3": + genesis.Difficulty = big.NewInt(1) + genesis.Config.Clique = ¶ms.CliqueConfig{ + Period: 15, + Epoch: 30000, + Reward: 0, + } + fmt.Println() + fmt.Println("How many seconds should blocks take? (default = 2)") + genesis.Config.Clique.Period = uint64(w.readDefaultInt(2)) + + fmt.Println() + fmt.Println("How many Ethers should be rewarded to masternode? (default = 10)") + genesis.Config.Clique.Reward = uint64(w.readDefaultInt(10)) + + fmt.Println() + fmt.Println("Who own the first masternodes? (mandatory)") + w.readAddress() + + // We also need the initial list of signers + fmt.Println() + fmt.Println("Which accounts are allowed to seal (signers)? (mandatory at least one)") + + var signers []common.Address + for { + if address := w.readAddress(); address != nil { + signers = append(signers, *address) + continue + } + if len(signers) > 0 { + break + } + } + // Sort the signers and embed into the extra-data section + for i := 0; i < len(signers); i++ { + for j := i + 1; j < len(signers); j++ { + if bytes.Compare(signers[i][:], signers[j][:]) > 0 { + signers[i], signers[j] = signers[j], signers[i] + } + } + } + genesis.ExtraData = make([]byte, 32+len(signers)*common.AddressLength+65) + for i, signer := range signers { + copy(genesis.ExtraData[32+i*common.AddressLength:], signer[:]) + } + + fmt.Println() + fmt.Println("How many blocks per checkpoint? (default = 990)") + genesis.Config.Clique.RewardCheckpoint = uint64(w.readDefaultInt(990)) + + // Smart Contract Code + key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + addr := crypto.PubkeyToAddress(key.PublicKey) + contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) + transactOpts := bind.NewKeyedTransactor(key) + + validatorAddress, _, err := validatorContract.DeployValidator(transactOpts, contractBackend) + if err != nil { + fmt.Println("can't deploy root registry: %v", err) + } + contractBackend.Commit() + + d := time.Now().Add(1000 * time.Millisecond) + ctx, _ := context.WithDeadline(context.Background(), d) + code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil) + storage := make(map[common.Hash]common.Hash) + f := func(key, val common.Hash) bool { + storage[key] = val + return true + } + contractBackend.ForEachStorageAt(ctx, validatorAddress, nil, f) + genesis.Alloc[common.StringToAddress("0x0000000000000000000000000000000000000089")] = core.GenesisAccount{ + Balance: big.NewInt(0), + Code: code, + Storage: storage, + } + default: log.Crit("Invalid consensus engine choice", "choice", choice) } From 66b1e8ad50c2273708cd527c1fc0073df8bfac5c Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Mon, 16 Jul 2018 06:44:51 +0000 Subject: [PATCH 03/18] fix unit test, safe cancel context --- cmd/puppeth/wizard_genesis.go | 5 +++-- contracts/blocksigner/blocksigner_test.go | 6 ++++-- contracts/randomize/randomize_test.go | 3 ++- contracts/validator/validator_test.go | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index eb89a4ec71..1b1f75096e 100644 --- a/cmd/puppeth/wizard_genesis.go +++ b/cmd/puppeth/wizard_genesis.go @@ -173,12 +173,13 @@ func (w *wizard) makeGenesis() { validatorAddress, _, err := validatorContract.DeployValidator(transactOpts, contractBackend) if err != nil { - fmt.Println("can't deploy root registry: %v", err) + fmt.Println("Can't deploy root registry") } contractBackend.Commit() d := time.Now().Add(1000 * time.Millisecond) - ctx, _ := context.WithDeadline(context.Background(), d) + ctx, cancel := context.WithDeadline(context.Background(), d) + defer cancel() code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil) storage := make(map[common.Hash]common.Hash) f := func(key, val common.Hash) bool { diff --git a/contracts/blocksigner/blocksigner_test.go b/contracts/blocksigner/blocksigner_test.go index 6bbdadfe6f..b2576203c0 100644 --- a/contracts/blocksigner/blocksigner_test.go +++ b/contracts/blocksigner/blocksigner_test.go @@ -8,6 +8,7 @@ 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" ) @@ -21,14 +22,15 @@ func TestBlockSigner(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) transactOpts := bind.NewKeyedTransactor(key) - _, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend) + blockSignerAddress, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend) if err != nil { t.Fatalf("can't deploy root registry: %v", err) } contractBackend.Commit() d := time.Now().Add(1000 * time.Millisecond) - ctx, _ := context.WithDeadline(context.Background(), d) + ctx, cancel := context.WithDeadline(context.Background(), d) + defer cancel() code, _ := contractBackend.CodeAt(ctx, blockSignerAddress, nil) t.Log("contract code", common.ToHex(code)) f := func(key, val common.Hash) bool { diff --git a/contracts/randomize/randomize_test.go b/contracts/randomize/randomize_test.go index 275e081721..909de5116c 100644 --- a/contracts/randomize/randomize_test.go +++ b/contracts/randomize/randomize_test.go @@ -31,7 +31,8 @@ func TestRandomize(t *testing.T) { contractBackend.Commit() d := time.Now().Add(1000 * time.Millisecond) - ctx, _ := context.WithDeadline(context.Background(), d) + ctx, cancel := context.WithDeadline(context.Background(), d) + defer cancel() code, _ := contractBackend.CodeAt(ctx, randomizeAddress, nil) t.Log("contract code", common.ToHex(code)) f := func(key, val common.Hash) bool { diff --git a/contracts/validator/validator_test.go b/contracts/validator/validator_test.go index 9ccdbd5f34..0842b06760 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -40,7 +40,8 @@ func TestValidator(t *testing.T) { contractBackend.Commit() d := time.Now().Add(1000 * time.Millisecond) - ctx, _ := context.WithDeadline(context.Background(), d) + ctx, cancel := context.WithDeadline(context.Background(), d) + defer cancel() code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil) t.Log("contract code", common.ToHex(code)) f := func(key, val common.Hash) bool { From cbb706e435d2f992e03aab8984d26943a5a4866e Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Mon, 16 Jul 2018 07:21:39 +0000 Subject: [PATCH 04/18] update new blocksigner smartcontract --- contracts/blocksigner/blocksigner.go | 3 +- contracts/blocksigner/blocksigner_test.go | 3 +- .../blocksigner/contract/BlockSigner.sol | 23 +++-- contracts/blocksigner/contract/blocksigner.go | 91 ++++++++++++------- 4 files changed, 78 insertions(+), 42 deletions(-) diff --git a/contracts/blocksigner/blocksigner.go b/contracts/blocksigner/blocksigner.go index f23cfbd669..29d69d0432 100644 --- a/contracts/blocksigner/blocksigner.go +++ b/contracts/blocksigner/blocksigner.go @@ -4,6 +4,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/contracts/blocksigner/contract" + "math/big" ) type BlockSigner struct { @@ -27,7 +28,7 @@ func NewBlockSigner(transactOpts *bind.TransactOpts, contractAddr common.Address } func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *BlockSigner, error) { - blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend) + blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, big.NewInt(990)) if err != nil { return blockSignerAddr, nil, err } diff --git a/contracts/blocksigner/blocksigner_test.go b/contracts/blocksigner/blocksigner_test.go index b2576203c0..d2e58b905f 100644 --- a/contracts/blocksigner/blocksigner_test.go +++ b/contracts/blocksigner/blocksigner_test.go @@ -39,7 +39,8 @@ func TestBlockSigner(t *testing.T) { } contractBackend.ForEachStorageAt(ctx, blockSignerAddress, nil, f) - signers, err := blockSigner.GetSigners(big.NewInt(0)) + byte0 := [32]byte{} + signers, err := blockSigner.GetSigners(byte0) if err != nil { t.Fatalf("can't get candidates: %v", err) } diff --git a/contracts/blocksigner/contract/BlockSigner.sol b/contracts/blocksigner/contract/BlockSigner.sol index 424427593d..3fc80b6cb1 100644 --- a/contracts/blocksigner/contract/BlockSigner.sol +++ b/contracts/blocksigner/contract/BlockSigner.sol @@ -5,20 +5,27 @@ import "./libs/SafeMath.sol"; contract BlockSigner { using SafeMath for uint256; - event Sign(address _signer, uint256 _blockNumber); + event Sign(address _signer, uint256 _blockNumber, bytes32 _blockHash); - mapping(uint256 => address[]) blockSigners; + mapping(bytes32 => address[]) blockSigners; + mapping(uint256 => bytes32[]) blocks; + uint256 public epochNumber; - function sign(uint256 _blockNumber) external { + function BlockSigner(uint256 _epochNumber) public { + epochNumber = _epochNumber; + } + + function sign(uint256 _blockNumber, bytes32 _blockHash) external { // consensus should validate all senders are validators, gas = 0 require(block.number >= _blockNumber); - require(block.number <= _blockNumber.add(990 * 2)); - blockSigners[_blockNumber].push(msg.sender); + require(block.number <= _blockNumber.add(epochNumber * 2)); + blocks[_blockNumber].push(_blockHash); + blockSigners[_blockHash].push(msg.sender); - emit Sign(msg.sender, _blockNumber); + emit Sign(msg.sender, _blockNumber, _blockHash); } - function getSigners(uint256 _blockNumber) public view returns(address[]) { - return blockSigners[_blockNumber]; + function getSigners(bytes32 _blockHash) public view returns(address[]) { + return blockSigners[_blockHash]; } } diff --git a/contracts/blocksigner/contract/blocksigner.go b/contracts/blocksigner/contract/blocksigner.go index 78fe74efd4..385c1f525c 100644 --- a/contracts/blocksigner/contract/blocksigner.go +++ b/contracts/blocksigner/contract/blocksigner.go @@ -16,18 +16,18 @@ import ( ) // BlockSignerABI is the input ABI used to generate the binding from. -const BlockSignerABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"}],\"name\":\"sign\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"}],\"name\":\"getSigners\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_signer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_blockNumber\",\"type\":\"uint256\"}],\"name\":\"Sign\",\"type\":\"event\"}]" +const BlockSignerABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"sign\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"getSigners\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"epochNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_epochNumber\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_signer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"Sign\",\"type\":\"event\"}]" // BlockSignerBin is the compiled bytecode used for deploying new contracts. -const BlockSignerBin = `0x6060604052341561000f57600080fd5b6102d88061001e6000396000f30060606040526004361061004b5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632fb1b25f8114610050578063dfceceae14610068575b600080fd5b341561005b57600080fd5b6100666004356100d1565b005b341561007357600080fd5b61007e6004356101b3565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100bd5780820151838201526020016100a5565b505050509050019250505060405180910390f35b43819010156100df57600080fd5b6100f1816107bc63ffffffff61023a16565b4311156100fd57600080fd5b600081815260208190526040902080546001810161011b8382610250565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19163373ffffffffffffffffffffffffffffffffffffffff8116919091179091557f9a10b6124411386407c4a174729b856d293832181c352e98b5cb316b96cd3059908260405173ffffffffffffffffffffffffffffffffffffffff909216825260208201526040908101905180910390a150565b6101bb610279565b60008083815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561022e57602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610203575b50505050509050919050565b60008282018381101561024957fe5b9392505050565b8154818355818115116102745760008381526020902061027491810190830161028b565b505050565b60206040519081016040526000815290565b6102a991905b808211156102a55760008155600101610291565b5090565b905600a165627a7a7230582072c605c43392422edd0a185ff1131c536a80cb5329c717d23fc954f2afb51b5e0029` +const BlockSignerBin = `0x6060604052341561000f57600080fd5b604051602080610386833981016040528080516002555050610350806100366000396000f3006060604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663e341eaa4811461005b578063e7ec6aef14610076578063f4145a83146100df575b600080fd5b341561006657600080fd5b610074600435602435610104565b005b341561008157600080fd5b61008c600435610227565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cb5780820151838201526020016100b3565b505050509050019250505060405180910390f35b34156100ea57600080fd5b6100f26102ac565b60405190815260200160405180910390f35b438290101561011257600080fd5b600280546101289184910263ffffffff6102b216565b43111561013457600080fd5b600082815260016020819052604090912080549091810161015583826102c8565b5060009182526020808320919091018390558282528190526040902080546001810161018183826102c8565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19163373ffffffffffffffffffffffffffffffffffffffff8116919091179091557f62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f5490838360405173ffffffffffffffffffffffffffffffffffffffff909316835260208301919091526040808301919091526060909101905180910390a15050565b61022f6102f1565b600082815260208181526040918290208054909290918281020190519081016040528092919081815260200182805480156102a057602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610275575b50505050509050919050565b60025481565b6000828201838110156102c157fe5b9392505050565b8154818355818115116102ec576000838152602090206102ec918101908301610303565b505050565b60206040519081016040526000815290565b61032191905b8082111561031d5760008155600101610309565b5090565b905600a165627a7a72305820a8ceddaea8e4ae00991e2ae81c8c88e160dd8770f255523282c24c2df4c30ec70029` // DeployBlockSigner deploys a new Ethereum contract, binding an instance of BlockSigner to it. -func DeployBlockSigner(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *BlockSigner, error) { +func DeployBlockSigner(auth *bind.TransactOpts, backend bind.ContractBackend, _epochNumber *big.Int) (common.Address, *types.Transaction, *BlockSigner, error) { parsed, err := abi.JSON(strings.NewReader(BlockSignerABI)) if err != nil { return common.Address{}, nil, nil, err } - address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(BlockSignerBin), backend) + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(BlockSignerBin), backend, _epochNumber) if err != nil { return common.Address{}, nil, nil, err } @@ -176,51 +176,77 @@ func (_BlockSigner *BlockSignerTransactorRaw) Transact(opts *bind.TransactOpts, return _BlockSigner.Contract.contract.Transact(opts, method, params...) } -// GetSigners is a free data retrieval call binding the contract method 0xdfceceae. +// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83. // -// Solidity: function getSigners(_blockNumber uint256) constant returns(address[]) -func (_BlockSigner *BlockSignerCaller) GetSigners(opts *bind.CallOpts, _blockNumber *big.Int) ([]common.Address, error) { +// Solidity: function epochNumber() constant returns(uint256) +func (_BlockSigner *BlockSignerCaller) EpochNumber(opts *bind.CallOpts) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _BlockSigner.contract.Call(opts, out, "epochNumber") + return *ret0, err +} + +// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83. +// +// Solidity: function epochNumber() constant returns(uint256) +func (_BlockSigner *BlockSignerSession) EpochNumber() (*big.Int, error) { + return _BlockSigner.Contract.EpochNumber(&_BlockSigner.CallOpts) +} + +// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83. +// +// Solidity: function epochNumber() constant returns(uint256) +func (_BlockSigner *BlockSignerCallerSession) EpochNumber() (*big.Int, error) { + return _BlockSigner.Contract.EpochNumber(&_BlockSigner.CallOpts) +} + +// GetSigners is a free data retrieval call binding the contract method 0xe7ec6aef. +// +// Solidity: function getSigners(_blockHash bytes32) constant returns(address[]) +func (_BlockSigner *BlockSignerCaller) GetSigners(opts *bind.CallOpts, _blockHash [32]byte) ([]common.Address, error) { var ( ret0 = new([]common.Address) ) out := ret0 - err := _BlockSigner.contract.Call(opts, out, "getSigners", _blockNumber) + err := _BlockSigner.contract.Call(opts, out, "getSigners", _blockHash) return *ret0, err } -// GetSigners is a free data retrieval call binding the contract method 0xdfceceae. +// GetSigners is a free data retrieval call binding the contract method 0xe7ec6aef. // -// Solidity: function getSigners(_blockNumber uint256) constant returns(address[]) -func (_BlockSigner *BlockSignerSession) GetSigners(_blockNumber *big.Int) ([]common.Address, error) { - return _BlockSigner.Contract.GetSigners(&_BlockSigner.CallOpts, _blockNumber) +// Solidity: function getSigners(_blockHash bytes32) constant returns(address[]) +func (_BlockSigner *BlockSignerSession) GetSigners(_blockHash [32]byte) ([]common.Address, error) { + return _BlockSigner.Contract.GetSigners(&_BlockSigner.CallOpts, _blockHash) } -// GetSigners is a free data retrieval call binding the contract method 0xdfceceae. +// GetSigners is a free data retrieval call binding the contract method 0xe7ec6aef. // -// Solidity: function getSigners(_blockNumber uint256) constant returns(address[]) -func (_BlockSigner *BlockSignerCallerSession) GetSigners(_blockNumber *big.Int) ([]common.Address, error) { - return _BlockSigner.Contract.GetSigners(&_BlockSigner.CallOpts, _blockNumber) +// Solidity: function getSigners(_blockHash bytes32) constant returns(address[]) +func (_BlockSigner *BlockSignerCallerSession) GetSigners(_blockHash [32]byte) ([]common.Address, error) { + return _BlockSigner.Contract.GetSigners(&_BlockSigner.CallOpts, _blockHash) } -// Sign is a paid mutator transaction binding the contract method 0x2fb1b25f. +// Sign is a paid mutator transaction binding the contract method 0xe341eaa4. // -// Solidity: function sign(_blockNumber uint256) returns() -func (_BlockSigner *BlockSignerTransactor) Sign(opts *bind.TransactOpts, _blockNumber *big.Int) (*types.Transaction, error) { - return _BlockSigner.contract.Transact(opts, "sign", _blockNumber) +// Solidity: function sign(_blockNumber uint256, _blockHash bytes32) returns() +func (_BlockSigner *BlockSignerTransactor) Sign(opts *bind.TransactOpts, _blockNumber *big.Int, _blockHash [32]byte) (*types.Transaction, error) { + return _BlockSigner.contract.Transact(opts, "sign", _blockNumber, _blockHash) } -// Sign is a paid mutator transaction binding the contract method 0x2fb1b25f. +// Sign is a paid mutator transaction binding the contract method 0xe341eaa4. // -// Solidity: function sign(_blockNumber uint256) returns() -func (_BlockSigner *BlockSignerSession) Sign(_blockNumber *big.Int) (*types.Transaction, error) { - return _BlockSigner.Contract.Sign(&_BlockSigner.TransactOpts, _blockNumber) +// Solidity: function sign(_blockNumber uint256, _blockHash bytes32) returns() +func (_BlockSigner *BlockSignerSession) Sign(_blockNumber *big.Int, _blockHash [32]byte) (*types.Transaction, error) { + return _BlockSigner.Contract.Sign(&_BlockSigner.TransactOpts, _blockNumber, _blockHash) } -// Sign is a paid mutator transaction binding the contract method 0x2fb1b25f. +// Sign is a paid mutator transaction binding the contract method 0xe341eaa4. // -// Solidity: function sign(_blockNumber uint256) returns() -func (_BlockSigner *BlockSignerTransactorSession) Sign(_blockNumber *big.Int) (*types.Transaction, error) { - return _BlockSigner.Contract.Sign(&_BlockSigner.TransactOpts, _blockNumber) +// Solidity: function sign(_blockNumber uint256, _blockHash bytes32) returns() +func (_BlockSigner *BlockSignerTransactorSession) Sign(_blockNumber *big.Int, _blockHash [32]byte) (*types.Transaction, error) { + return _BlockSigner.Contract.Sign(&_BlockSigner.TransactOpts, _blockNumber, _blockHash) } // BlockSignerSignIterator is returned from FilterSign and is used to iterate over the raw logs and unpacked data for Sign events raised by the BlockSigner contract. @@ -294,12 +320,13 @@ func (it *BlockSignerSignIterator) Close() error { type BlockSignerSign struct { Signer common.Address BlockNumber *big.Int + BlockHash [32]byte Raw types.Log // Blockchain specific contextual infos } -// FilterSign is a free log retrieval operation binding the contract event 0x9a10b6124411386407c4a174729b856d293832181c352e98b5cb316b96cd3059. +// FilterSign is a free log retrieval operation binding the contract event 0x62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f54. // -// Solidity: event Sign(_signer address, _blockNumber uint256) +// Solidity: event Sign(_signer address, _blockNumber uint256, _blockHash bytes32) func (_BlockSigner *BlockSignerFilterer) FilterSign(opts *bind.FilterOpts) (*BlockSignerSignIterator, error) { logs, sub, err := _BlockSigner.contract.FilterLogs(opts, "Sign") @@ -309,9 +336,9 @@ func (_BlockSigner *BlockSignerFilterer) FilterSign(opts *bind.FilterOpts) (*Blo return &BlockSignerSignIterator{contract: _BlockSigner.contract, event: "Sign", logs: logs, sub: sub}, nil } -// WatchSign is a free log subscription operation binding the contract event 0x9a10b6124411386407c4a174729b856d293832181c352e98b5cb316b96cd3059. +// WatchSign is a free log subscription operation binding the contract event 0x62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f54. // -// Solidity: event Sign(_signer address, _blockNumber uint256) +// Solidity: event Sign(_signer address, _blockNumber uint256, _blockHash bytes32) func (_BlockSigner *BlockSignerFilterer) WatchSign(opts *bind.WatchOpts, sink chan<- *BlockSignerSign) (event.Subscription, error) { logs, sub, err := _BlockSigner.contract.WatchLogs(opts, "Sign") From 4cc12d3ed621242cffc0d2efb0da2357c4cef45f Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Mon, 16 Jul 2018 08:03:44 +0000 Subject: [PATCH 05/18] update new Tomo Validator --- .../validator/contract/TomoValidator.sol | 33 +-- contracts/validator/contract/validator.go | 263 +----------------- contracts/validator/validator.go | 6 +- contracts/validator/validator_test.go | 12 +- 4 files changed, 26 insertions(+), 288 deletions(-) diff --git a/contracts/validator/contract/TomoValidator.sol b/contracts/validator/contract/TomoValidator.sol index 20b79c2853..a518565843 100644 --- a/contracts/validator/contract/TomoValidator.sol +++ b/contracts/validator/contract/TomoValidator.sol @@ -1,9 +1,8 @@ pragma solidity ^0.4.21; -import "./interfaces/IValidator.sol"; import "./libs/SafeMath.sol"; -contract TomoValidator is IValidator { +contract TomoValidator { using SafeMath for uint256; event Vote(address _voter, address _candidate, uint256 _cap); @@ -18,7 +17,6 @@ contract TomoValidator is IValidator { string nodeUrl; bool isCandidate; uint256 cap; - uint256 withdrawBlockNumber; mapping(address => uint256) voters; } @@ -31,13 +29,8 @@ contract TomoValidator is IValidator { mapping(address => ValidatorState) validatorsState; mapping(address => address[]) voters; - address[] public candidates = [ - 0xf99805B536609cC03AcBB2604dFaC11E9E54a448, - 0x31b249fE6F267aa2396Eb2DC36E9c79351d97Ec5, - 0xfC5571921c6d3672e13B58EA23DEA534f2b35fA0 - ]; + address[] public candidates; - address public firstOwner = 0x487d62d33467c4842c5e54Eb370837E4E88BBA0F; uint256 public candidateCount = 3; uint256 public minCandidateCap; uint256 public maxValidatorNumber; @@ -84,6 +77,9 @@ contract TomoValidator is IValidator { } function TomoValidator ( + address[] _candidates, + uint256[] _caps, + address _firstOwner, uint256 _minCandidateCap, uint256 _maxValidatorNumber, uint256 _candidateWithdrawDelay, @@ -94,16 +90,16 @@ contract TomoValidator is IValidator { candidateWithdrawDelay = _candidateWithdrawDelay; voterWithdrawDelay = _voterWithdrawDelay; - for (uint256 i = 0; i < candidates.length; i++) { - validatorsState[candidates[i]] = ValidatorState({ - owner: firstOwner, + for (uint256 i = 0; i < _candidates.length; i++) { + candidates.push(_candidates[i]); + validatorsState[_candidates[i]] = ValidatorState({ + owner: _firstOwner, nodeUrl: '', isCandidate: true, - withdrawBlockNumber: 0, - cap: minCandidateCap + cap: _caps[i] }); - voters[candidates[i]].push(firstOwner); - validatorsState[candidates[i]].voters[firstOwner] = minCandidateCap; + voters[_candidates[i]].push(_firstOwner); + validatorsState[candidates[i]].voters[_firstOwner] = minCandidateCap; } } @@ -113,7 +109,6 @@ contract TomoValidator is IValidator { owner: msg.sender, nodeUrl: _nodeUrl, isCandidate: true, - withdrawBlockNumber: 0, cap: msg.value }); validatorsState[_candidate].voters[msg.sender] = msg.value; @@ -147,10 +142,6 @@ contract TomoValidator is IValidator { 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) { return validatorsState[_candidate].voters[_voter]; } diff --git a/contracts/validator/contract/validator.go b/contracts/validator/contract/validator.go index 3f69d6c521..67be0eaeb4 100644 --- a/contracts/validator/contract/validator.go +++ b/contracts/validator/contract/validator.go @@ -15,209 +15,6 @@ import ( "github.com/ethereum/go-ethereum/event" ) -// IValidatorABI is the input ABI used to generate the binding from. -const IValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"string\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"}]" - -// IValidatorBin is the compiled bytecode used for deploying new contracts. -const IValidatorBin = `0x` - -// DeployIValidator deploys a new Ethereum contract, binding an instance of IValidator to it. -func DeployIValidator(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *IValidator, error) { - parsed, err := abi.JSON(strings.NewReader(IValidatorABI)) - if err != nil { - return common.Address{}, nil, nil, err - } - address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(IValidatorBin), backend) - if err != nil { - return common.Address{}, nil, nil, err - } - return address, tx, &IValidator{IValidatorCaller: IValidatorCaller{contract: contract}, IValidatorTransactor: IValidatorTransactor{contract: contract}, IValidatorFilterer: IValidatorFilterer{contract: contract}}, nil -} - -// IValidator is an auto generated Go binding around an Ethereum contract. -type IValidator struct { - IValidatorCaller // Read-only binding to the contract - IValidatorTransactor // Write-only binding to the contract - IValidatorFilterer // Log filterer for contract events -} - -// IValidatorCaller is an auto generated read-only Go binding around an Ethereum contract. -type IValidatorCaller struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// IValidatorTransactor is an auto generated write-only Go binding around an Ethereum contract. -type IValidatorTransactor struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// IValidatorFilterer is an auto generated log filtering Go binding around an Ethereum contract events. -type IValidatorFilterer struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// IValidatorSession is an auto generated Go binding around an Ethereum contract, -// with pre-set call and transact options. -type IValidatorSession struct { - Contract *IValidator // Generic contract binding to set the session for - CallOpts bind.CallOpts // Call options to use throughout this session - TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session -} - -// IValidatorCallerSession is an auto generated read-only Go binding around an Ethereum contract, -// with pre-set call options. -type IValidatorCallerSession struct { - Contract *IValidatorCaller // Generic contract caller binding to set the session for - CallOpts bind.CallOpts // Call options to use throughout this session -} - -// IValidatorTransactorSession is an auto generated write-only Go binding around an Ethereum contract, -// with pre-set transact options. -type IValidatorTransactorSession struct { - Contract *IValidatorTransactor // Generic contract transactor binding to set the session for - TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session -} - -// IValidatorRaw is an auto generated low-level Go binding around an Ethereum contract. -type IValidatorRaw struct { - Contract *IValidator // Generic contract binding to access the raw methods on -} - -// IValidatorCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. -type IValidatorCallerRaw struct { - Contract *IValidatorCaller // Generic read-only contract binding to access the raw methods on -} - -// IValidatorTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. -type IValidatorTransactorRaw struct { - Contract *IValidatorTransactor // Generic write-only contract binding to access the raw methods on -} - -// NewIValidator creates a new instance of IValidator, bound to a specific deployed contract. -func NewIValidator(address common.Address, backend bind.ContractBackend) (*IValidator, error) { - contract, err := bindIValidator(address, backend, backend, backend) - if err != nil { - return nil, err - } - return &IValidator{IValidatorCaller: IValidatorCaller{contract: contract}, IValidatorTransactor: IValidatorTransactor{contract: contract}, IValidatorFilterer: IValidatorFilterer{contract: contract}}, nil -} - -// NewIValidatorCaller creates a new read-only instance of IValidator, bound to a specific deployed contract. -func NewIValidatorCaller(address common.Address, caller bind.ContractCaller) (*IValidatorCaller, error) { - contract, err := bindIValidator(address, caller, nil, nil) - if err != nil { - return nil, err - } - return &IValidatorCaller{contract: contract}, nil -} - -// NewIValidatorTransactor creates a new write-only instance of IValidator, bound to a specific deployed contract. -func NewIValidatorTransactor(address common.Address, transactor bind.ContractTransactor) (*IValidatorTransactor, error) { - contract, err := bindIValidator(address, nil, transactor, nil) - if err != nil { - return nil, err - } - return &IValidatorTransactor{contract: contract}, nil -} - -// NewIValidatorFilterer creates a new log filterer instance of IValidator, bound to a specific deployed contract. -func NewIValidatorFilterer(address common.Address, filterer bind.ContractFilterer) (*IValidatorFilterer, error) { - contract, err := bindIValidator(address, nil, nil, filterer) - if err != nil { - return nil, err - } - return &IValidatorFilterer{contract: contract}, nil -} - -// bindIValidator binds a generic wrapper to an already deployed contract. -func bindIValidator(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { - parsed, err := abi.JSON(strings.NewReader(IValidatorABI)) - if err != nil { - return nil, err - } - return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil -} - -// Call invokes the (constant) contract method with params as input values and -// sets the output to result. The result type might be a single field for simple -// returns, a slice of interfaces for anonymous returns and a struct for named -// returns. -func (_IValidator *IValidatorRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { - return _IValidator.Contract.IValidatorCaller.contract.Call(opts, result, method, params...) -} - -// Transfer initiates a plain transaction to move funds to the contract, calling -// its default method if one is available. -func (_IValidator *IValidatorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { - return _IValidator.Contract.IValidatorTransactor.contract.Transfer(opts) -} - -// Transact invokes the (paid) contract method with params as input values. -func (_IValidator *IValidatorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { - return _IValidator.Contract.IValidatorTransactor.contract.Transact(opts, method, params...) -} - -// Call invokes the (constant) contract method with params as input values and -// sets the output to result. The result type might be a single field for simple -// returns, a slice of interfaces for anonymous returns and a struct for named -// returns. -func (_IValidator *IValidatorCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { - return _IValidator.Contract.contract.Call(opts, result, method, params...) -} - -// Transfer initiates a plain transaction to move funds to the contract, calling -// its default method if one is available. -func (_IValidator *IValidatorTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { - return _IValidator.Contract.contract.Transfer(opts) -} - -// Transact invokes the (paid) contract method with params as input values. -func (_IValidator *IValidatorTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { - return _IValidator.Contract.contract.Transact(opts, method, params...) -} - -// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. -// -// Solidity: function propose( address, string) returns() -func (_IValidator *IValidatorTransactor) Propose(opts *bind.TransactOpts, arg0 common.Address, arg1 string) (*types.Transaction, error) { - return _IValidator.contract.Transact(opts, "propose", arg0, arg1) -} - -// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. -// -// Solidity: function propose( address, string) returns() -func (_IValidator *IValidatorSession) Propose(arg0 common.Address, arg1 string) (*types.Transaction, error) { - return _IValidator.Contract.Propose(&_IValidator.TransactOpts, arg0, arg1) -} - -// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. -// -// Solidity: function propose( address, string) returns() -func (_IValidator *IValidatorTransactorSession) Propose(arg0 common.Address, arg1 string) (*types.Transaction, error) { - return _IValidator.Contract.Propose(&_IValidator.TransactOpts, arg0, arg1) -} - -// Vote is a paid mutator transaction binding the contract method 0x6dd7d8ea. -// -// Solidity: function vote( address) returns() -func (_IValidator *IValidatorTransactor) Vote(opts *bind.TransactOpts, arg0 common.Address) (*types.Transaction, error) { - return _IValidator.contract.Transact(opts, "vote", arg0) -} - -// Vote is a paid mutator transaction binding the contract method 0x6dd7d8ea. -// -// Solidity: function vote( address) returns() -func (_IValidator *IValidatorSession) Vote(arg0 common.Address) (*types.Transaction, error) { - return _IValidator.Contract.Vote(&_IValidator.TransactOpts, arg0) -} - -// Vote is a paid mutator transaction binding the contract method 0x6dd7d8ea. -// -// Solidity: function vote( address) returns() -func (_IValidator *IValidatorTransactorSession) Vote(arg0 common.Address) (*types.Transaction, error) { - return _IValidator.Contract.Vote(&_IValidator.TransactOpts, arg0) -} - // SafeMathABI is the input ABI used to generate the binding from. const SafeMathABI = "[]" @@ -380,18 +177,18 @@ func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method } // TomoValidatorABI is the input ABI used to generate the binding from. -const TomoValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"unvote\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getCandidates\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateWithdrawBlockNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getVoters\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getWithdrawBlockNumbers\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_voter\",\"type\":\"address\"}],\"name\":\"getVoterCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"candidates\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"name\":\"_index\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"firstOwner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"setNodeUrl\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"candidateCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"voterWithdrawDelay\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"resign\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateOwner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"maxValidatorNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"candidateWithdrawDelay\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"isCandidate\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"minCandidateCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateNodeUrl\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_minCandidateCap\",\"type\":\"uint256\"},{\"name\":\"_maxValidatorNumber\",\"type\":\"uint256\"},{\"name\":\"_candidateWithdrawDelay\",\"type\":\"uint256\"},{\"name\":\"_voterWithdrawDelay\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_voter\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Vote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_voter\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Unvote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Propose\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"Resign\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"SetNodeUrl\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Withdraw\",\"type\":\"event\"}]" +const TomoValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"unvote\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getCandidates\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getVoters\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getWithdrawBlockNumbers\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_voter\",\"type\":\"address\"}],\"name\":\"getVoterCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"candidates\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"name\":\"_index\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"setNodeUrl\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"candidateCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"voterWithdrawDelay\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"resign\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateOwner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"maxValidatorNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"candidateWithdrawDelay\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"isCandidate\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"minCandidateCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateNodeUrl\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_candidates\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"},{\"name\":\"_firstOwner\",\"type\":\"address\"},{\"name\":\"_minCandidateCap\",\"type\":\"uint256\"},{\"name\":\"_maxValidatorNumber\",\"type\":\"uint256\"},{\"name\":\"_candidateWithdrawDelay\",\"type\":\"uint256\"},{\"name\":\"_voterWithdrawDelay\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_voter\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Vote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_voter\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Unvote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Propose\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"Resign\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"SetNodeUrl\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Withdraw\",\"type\":\"event\"}]" // TomoValidatorBin is the compiled bytecode used for deploying new contracts. -const TomoValidatorBin = `0x60606040526060604051908101604090815273f99805b536609cc03acbb2604dfac11e9e54a44882527331b249fe6f267aa2396eb2dc36e9c79351d97ec5602083015273fc5571921c6d3672e13b58ea23dea534f2b35fa0908201526200006a9060039081620002bb565b5060048054600160a060020a03191673487d62d33467c4842c5e54eb370837e4e88bba0f17905560036005553415620000a257600080fd5b604051608080620017ec8339810160405280805191906020018051919060200180519190602001805160068690556007859055600884905560098190559150600090505b600354811015620002b05760a06040519081016040908152600454600160a060020a0316825260208083019151908101604052806000815250815260200160011515815260200160065481526020016000815250600160006003848154811015156200014e57fe5b6000918252602080832090910154600160a060020a03168352820192909252604001902081518154600160a060020a031916600160a060020a0391909116178155602082015181600101908051620001ab92916020019062000327565b50604082015160028201805460ff1916911515919091179055606082015181600301556080820151816004015590505060026000600383815481101515620001ef57fe5b6000918252602080832090910154600160a060020a031683528201929092526040019020805460018101620002258382620003a8565b5060009182526020822060045491018054600160a060020a031916600160a060020a03909216919091179055600654600380549192600192909190859081106200026b57fe5b6000918252602080832090910154600160a060020a039081168452838201949094526040928301822060045490941682526005909301909252902055600101620000e6565b50505050506200041b565b82805482825590600052602060002090810192821562000315579160200282015b82811115620003155782518254600160a060020a031916600160a060020a039190911617825560209290920191600190910190620002dc565b5062000323929150620003d4565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200036a57805160ff19168380011785556200039a565b828001600101855582156200039a579182015b828111156200039a5782518255916020019190600101906200037d565b5062000323929150620003fe565b815481835581811511620003cf57600083815260209020620003cf918101908301620003fe565b505050565b620003fb91905b8082111562000323578054600160a060020a0319168155600101620003db565b90565b620003fb91905b8082111562000323576000815560010162000405565b6113c1806200042b6000396000f3006060604052600436106101275763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302aa9be2811461012c57806306a49fce1461015057806328265294146101b65780632d15cc04146101e75780632f9c4bba14610206578063302b6872146102195780633477ee2e1461023e578063441a3e701461027057806358e7525f146102895780636bc28781146102a85780636dd7d8ea146102bb578063a3ec7965146102cf578063a9a981a31461032e578063a9ff959e14610341578063ae6e43f514610354578063b642facd14610373578063d09f1ab414610392578063d161c767146103a5578063d51b9e93146103b8578063d55b7dff146103eb578063d6f0948c146103fe578063da67b5991461041e575b600080fd5b341561013757600080fd5b61014e600160a060020a03600435166024356104b4565b005b341561015b57600080fd5b61016361067c565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156101a257808201518382015260200161018a565b505050509050019250505060405180910390f35b34156101c157600080fd5b6101d5600160a060020a03600435166106e5565b60405190815260200160405180910390f35b34156101f257600080fd5b610163600160a060020a0360043516610703565b341561021157600080fd5b610163610790565b341561022457600080fd5b6101d5600160a060020a0360043581169060243516610812565b341561024957600080fd5b610254600435610841565b604051600160a060020a03909116815260200160405180910390f35b341561027b57600080fd5b61014e600435602435610869565b341561029457600080fd5b6101d5600160a060020a03600435166109d0565b34156102b357600080fd5b6102546109ee565b61014e600160a060020a03600435166109fd565b34156102da57600080fd5b61014e60048035600160a060020a03169060446024803590810190830135806020601f82018190048102016040519081016040528181529291906020840183838082843750949650610baa95505050505050565b341561033957600080fd5b6101d5610cbb565b341561034c57600080fd5b6101d5610cc1565b341561035f57600080fd5b61014e600160a060020a0360043516610cc7565b341561037e57600080fd5b610254600160a060020a0360043516610f3a565b341561039d57600080fd5b6101d5610f58565b34156103b057600080fd5b6101d5610f5e565b34156103c357600080fd5b6103d7600160a060020a0360043516610f64565b604051901515815260200160405180910390f35b34156103f657600080fd5b6101d5610f85565b61014e60048035600160a060020a03169060248035908101910135610f8b565b341561042957600080fd5b61043d600160a060020a03600435166111d4565b60405160208082528190810183818151815260200191508051906020019080838360005b83811015610479578082015183820152602001610461565b50505050905090810190601f1680156104a65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600160a060020a038083166000908152600160209081526040808320339094168352600590930190529081205483908390819010156104f257600080fd5b600160a060020a03851660009081526001602052604090206003015461051e908563ffffffff61129a16565b600160a060020a03808716600090815260016020908152604080832060038101959095553390931682526005909301909252902054610563908563ffffffff61129a16565b600160a060020a0380871660009081526001602090815260408083203390941683526005909301905220556009546105a1904363ffffffff6112ac16565b600160a060020a0333166000908152602081815260408083208484529091529020549093506105d6908563ffffffff6112ac16565b600160a060020a033316600081815260208181526040808320888452808352908320949094559181529052600190810180549091810161061683826112c2565b5060009182526020909120018390557faa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2338686604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050505050565b6106846112eb565b60038054806020026020016040519081016040528092919081815260200182805480156106da57602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116106bc575b505050505090505b90565b600160a060020a031660009081526001602052604090206004015490565b61070b6112eb565b6002600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561078457602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610766575b50505050509050919050565b6107986112eb565b60008033600160a060020a0316600160a060020a031681526020019081526020016000206001018054806020026020016040519081016040528092919081815260200182805480156106da57602002820191906000526020600020905b8154815260200190600101908083116107f5575050505050905090565b600160a060020a0391821660009081526001602090815260408083209390941682526005909201909152205490565b600380548290811061084f57fe5b600091825260209091200154600160a060020a0316905081565b6000828282821161087957600080fd5b438290101561088757600080fd5b600160a060020a033316600090815260208181526040808320858452909152812054116108b357600080fd5b600160a060020a03331660009081526020819052604090206001018054839190839081106108dd57fe5b600091825260209091200154146108f357600080fd5b600160a060020a0333166000818152602081815260408083208984528083529083208054908490559383529190526001018054919450908590811061093457fe5b6000918252602082200155600160a060020a03331683156108fc0284604051600060405180830381858888f19350505050151561097057600080fd5b7ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b5683386856040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390a15050505050565b600160a060020a031660009081526001602052604090206003015490565b600454600160a060020a031681565b600160a060020a038116600090815260016020526040902060020154819060ff161515610a2957600080fd5b600160a060020a038216600090815260016020526040902060030154610a55903463ffffffff6112ac16565b600160a060020a038084166000908152600160209081526040808320600381019590955533909316825260059093019092529020541515610aeb57600160a060020a0382166000908152600260205260409020805460018101610ab883826112c2565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790555b600160a060020a038083166000908152600160209081526040808320339094168352600590930190522054610b26903463ffffffff6112ac16565b600160a060020a03808416600090815260016020908152604080832033948516845260050190915290819020929092557f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc918490349051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050565b600160a060020a038281166000908152600160205260409020548391338116911614610bd557600080fd5b600160a060020a038316600090815260016020819052604090912001828051610c029291602001906112fd565b507f63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4338484604051600160a060020a0380851682528316602082015260606040820181815290820183818151815260200191508051906020019080838360005b83811015610c7a578082015183820152602001610c62565b50505050905090810190601f168015610ca75780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1505050565b60055481565b60095481565b600160a060020a038181166000908152600160205260408120549091829182918591338216911614610cf857600080fd5b600160a060020a038516600090815260016020526040902060020154859060ff161515610d2457600080fd5b600160a060020a0386166000908152600160205260408120600201805460ff191690556005805460001901905594505b600354851015610dd65785600160a060020a0316600386815481101515610d7757fe5b600091825260209091200154600160a060020a03161415610dcb576003805486908110610da057fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19169055610dd6565b600190940193610d54565b600160a060020a038087166000818152600160208181526040808420339096168452600586018252832054939092529052600390910154909450610e20908563ffffffff61129a16565b600160a060020a03808816600090815260016020908152604080832060038101959095553390931682526005909301909252812055600854610e68904363ffffffff6112ac16565b600160a060020a033316600090815260208181526040808320848452909152902054909350610e9d908563ffffffff6112ac16565b600160a060020a0333166000818152602081815260408083208884528083529083209490945591815290526001908101805490918101610edd83826112c2565b5060009182526020909120018390557f4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d33387604051600160a060020a039283168152911660208201526040908101905180910390a1505050505050565b600160a060020a039081166000908152600160205260409020541690565b60075481565b60085481565b600160a060020a031660009081526001602052604090206002015460ff1690565b60065481565b600654341015610f9a57600080fd5b600160a060020a038316600090815260016020526040902060020154839060ff1615610fc557600080fd5b6003805460018101610fd783826112c2565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03861617905560a06040519081016040528033600160a060020a0316815260200184848080601f01602080910402602001604051908101604052818152929190602084018383808284375050509284525050600160208084018290523460408086019190915260006060909501859052600160a060020a038a16855291905290912090508151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03919091161781556020820151816001019080516110cb9291602001906112fd565b50604082015160028201805460ff191691151591909117905560608201518160030155608082015160049091015550600160a060020a038085166000818152600160208181526040808420339096168452600595860182528084203490558554830190955592825260029092529190912080549091810161114c83826112c2565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0386161790557f7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1338534604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b6111dc6112eb565b6001600083600160a060020a0316600160a060020a031681526020019081526020016000206001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156107845780601f1061126d57610100808354040283529160200191610784565b820191906000526020600020905b81548152906001019060200180831161127b5750939695505050505050565b6000828211156112a657fe5b50900390565b6000828201838110156112bb57fe5b9392505050565b8154818355818115116112e6576000838152602090206112e691810190830161137b565b505050565b60206040519081016040526000815290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061133e57805160ff191683800117855561136b565b8280016001018555821561136b579182015b8281111561136b578251825591602001919060010190611350565b5061137792915061137b565b5090565b6106e291905b8082111561137757600081556001016113815600a165627a7a72305820479a652c5721d1178b9d8443fe6dd8b949fe0bf883ba1dd1879aab405681fbf70029` +const TomoValidatorBin = `0x6060604052600360045534156200001557600080fd5b604051620016af380380620016af833981016040528080518201919060200180518201919060200180519190602001805191906020018051919060200180519190602001805160058690556006859055600784905560088190559150600090505b87518110156200028757600380546001810162000094838262000295565b916000526020600020900160008a8481518110620000ae57fe5b90602001906020020151909190916101000a815481600160a060020a030219169083600160a060020a031602179055505060806040519081016040528087600160a060020a03168152602001602060405190810160409081526000825290825260016020830152018883815181106200012357fe5b906020019060200201519052600160008a84815181106200014057fe5b90602001906020020151600160a060020a03168152602081019190915260400160002081518154600160a060020a031916600160a060020a03919091161781556020820151816001019080516200019c929160200190620002c1565b50604082015160028201805460ff191691151591909117905560608201516003909101555060026000898381518110620001d257fe5b90602001906020020151600160a060020a03168152602081019190915260400160002080546001810162000207838262000295565b50600091825260208220018054600160a060020a031916600160a060020a038916179055600554600380549192600192909190859081106200024557fe5b6000918252602080832090910154600160a060020a0390811684528382019490945260409283018220938b168252600490930190925290205560010162000076565b505050505050505062000366565b815481835581811511620002bc57600083815260209020620002bc91810190830162000346565b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200030457805160ff191683800117855562000334565b8280016001018555821562000334579182015b828111156200033457825182559160200191906001019062000317565b506200034292915062000346565b5090565b6200036391905b808211156200034257600081556001016200034d565b90565b61133980620003766000396000f3006060604052600436106101115763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302aa9be2811461011657806306a49fce1461013a5780632d15cc04146101a05780632f9c4bba146101bf578063302b6872146101d25780633477ee2e14610209578063441a3e701461023b57806358e7525f146102545780636dd7d8ea14610273578063a3ec796514610287578063a9a981a3146102e6578063a9ff959e146102f9578063ae6e43f51461030c578063b642facd1461032b578063d09f1ab41461034a578063d161c7671461035d578063d51b9e9314610370578063d55b7dff146103a3578063d6f0948c146103b6578063da67b599146103d6575b600080fd5b341561012157600080fd5b610138600160a060020a036004351660243561046c565b005b341561014557600080fd5b61014d610634565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561018c578082015183820152602001610174565b505050509050019250505060405180910390f35b34156101ab57600080fd5b61014d600160a060020a036004351661069d565b34156101ca57600080fd5b61014d61072a565b34156101dd57600080fd5b6101f7600160a060020a03600435811690602435166107ac565b60405190815260200160405180910390f35b341561021457600080fd5b61021f6004356107db565b604051600160a060020a03909116815260200160405180910390f35b341561024657600080fd5b610138600435602435610803565b341561025f57600080fd5b6101f7600160a060020a036004351661096a565b610138600160a060020a0360043516610988565b341561029257600080fd5b61013860048035600160a060020a03169060446024803590810190830135806020601f82018190048102016040519081016040528181529291906020840183838082843750949650610b3595505050505050565b34156102f157600080fd5b6101f7610c46565b341561030457600080fd5b6101f7610c4c565b341561031757600080fd5b610138600160a060020a0360043516610c52565b341561033657600080fd5b61021f600160a060020a0360043516610ec5565b341561035557600080fd5b6101f7610ee3565b341561036857600080fd5b6101f7610ee9565b341561037b57600080fd5b61038f600160a060020a0360043516610eef565b604051901515815260200160405180910390f35b34156103ae57600080fd5b6101f7610f10565b61013860048035600160a060020a03169060248035908101910135610f16565b34156103e157600080fd5b6103f5600160a060020a036004351661114c565b60405160208082528190810183818151815260200191508051906020019080838360005b83811015610431578082015183820152602001610419565b50505050905090810190601f16801561045e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600160a060020a038083166000908152600160209081526040808320339094168352600490930190529081205483908390819010156104aa57600080fd5b600160a060020a0385166000908152600160205260409020600301546104d6908563ffffffff61121216565b600160a060020a0380871660009081526001602090815260408083206003810195909555339093168252600490930190925290205461051b908563ffffffff61121216565b600160a060020a038087166000908152600160209081526040808320339094168352600490930190522055600854610559904363ffffffff61122416565b600160a060020a03331660009081526020818152604080832084845290915290205490935061058e908563ffffffff61122416565b600160a060020a03331660008181526020818152604080832088845280835290832094909455918152905260019081018054909181016105ce838261123a565b5060009182526020909120018390557faa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2338686604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050505050565b61063c611263565b600380548060200260200160405190810160405280929190818152602001828054801561069257602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610674575b505050505090505b90565b6106a5611263565b6002600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561071e57602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610700575b50505050509050919050565b610732611263565b60008033600160a060020a0316600160a060020a0316815260200190815260200160002060010180548060200260200160405190810160405280929190818152602001828054801561069257602002820191906000526020600020905b81548152602001906001019080831161078f575050505050905090565b600160a060020a0391821660009081526001602090815260408083209390941682526004909201909152205490565b60038054829081106107e957fe5b600091825260209091200154600160a060020a0316905081565b6000828282821161081357600080fd5b438290101561082157600080fd5b600160a060020a0333166000908152602081815260408083208584529091528120541161084d57600080fd5b600160a060020a033316600090815260208190526040902060010180548391908390811061087757fe5b6000918252602090912001541461088d57600080fd5b600160a060020a033316600081815260208181526040808320898452808352908320805490849055938352919052600101805491945090859081106108ce57fe5b6000918252602082200155600160a060020a03331683156108fc0284604051600060405180830381858888f19350505050151561090a57600080fd5b7ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b5683386856040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390a15050505050565b600160a060020a031660009081526001602052604090206003015490565b600160a060020a038116600090815260016020526040902060020154819060ff1615156109b457600080fd5b600160a060020a0382166000908152600160205260409020600301546109e0903463ffffffff61122416565b600160a060020a038084166000908152600160209081526040808320600381019590955533909316825260049093019092529020541515610a7657600160a060020a0382166000908152600260205260409020805460018101610a43838261123a565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790555b600160a060020a038083166000908152600160209081526040808320339094168352600490930190522054610ab1903463ffffffff61122416565b600160a060020a03808416600090815260016020908152604080832033948516845260040190915290819020929092557f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc918490349051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050565b600160a060020a038281166000908152600160205260409020548391338116911614610b6057600080fd5b600160a060020a038316600090815260016020819052604090912001828051610b8d929160200190611275565b507f63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4338484604051600160a060020a0380851682528316602082015260606040820181815290820183818151815260200191508051906020019080838360005b83811015610c05578082015183820152602001610bed565b50505050905090810190601f168015610c325780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1505050565b60045481565b60085481565b600160a060020a038181166000908152600160205260408120549091829182918591338216911614610c8357600080fd5b600160a060020a038516600090815260016020526040902060020154859060ff161515610caf57600080fd5b600160a060020a0386166000908152600160205260408120600201805460ff191690556004805460001901905594505b600354851015610d615785600160a060020a0316600386815481101515610d0257fe5b600091825260209091200154600160a060020a03161415610d56576003805486908110610d2b57fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19169055610d61565b600190940193610cdf565b600160a060020a038087166000818152600160208181526040808420339096168452600486018252832054939092529052600390910154909450610dab908563ffffffff61121216565b600160a060020a03808816600090815260016020908152604080832060038101959095553390931682526004909301909252812055600754610df3904363ffffffff61122416565b600160a060020a033316600090815260208181526040808320848452909152902054909350610e28908563ffffffff61122416565b600160a060020a0333166000818152602081815260408083208884528083529083209490945591815290526001908101805490918101610e68838261123a565b5060009182526020909120018390557f4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d33387604051600160a060020a039283168152911660208201526040908101905180910390a1505050505050565b600160a060020a039081166000908152600160205260409020541690565b60065481565b60075481565b600160a060020a031660009081526001602052604090206002015460ff1690565b60055481565b600554341015610f2557600080fd5b600160a060020a038316600090815260016020526040902060020154839060ff1615610f5057600080fd5b6003805460018101610f62838261123a565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03861617905560806040519081016040528033600160a060020a0316815260200184848080601f016020809104026020016040519081016040528181529291906020840183838082843750505092845250506001602080840182905234604094850152600160a060020a03891660009081529190529190912090508151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a039190911617815560208201518160010190805161104d929160200190611275565b50604082015160028201805460ff1916911515919091179055606082015160039091015550600160a060020a03808516600081815260016020818152604080842033909616845260049586018252808420349055855483019095559282526002909252919091208054909181016110c4838261123a565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0386161790557f7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1338534604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b611154611263565b6001600083600160a060020a0316600160a060020a031681526020019081526020016000206001018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561071e5780601f106111e55761010080835404028352916020019161071e565b820191906000526020600020905b8154815290600101906020018083116111f35750939695505050505050565b60008282111561121e57fe5b50900390565b60008282018381101561123357fe5b9392505050565b81548183558181151161125e5760008381526020902061125e9181019083016112f3565b505050565b60206040519081016040526000815290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106112b657805160ff19168380011785556112e3565b828001600101855582156112e3579182015b828111156112e35782518255916020019190600101906112c8565b506112ef9291506112f3565b5090565b61069a91905b808211156112ef57600081556001016112f95600a165627a7a72305820f127973d29fa5a4d12a54a58f7c375498148977e320761f9cefa40f5ea2afa680029` // DeployTomoValidator deploys a new Ethereum contract, binding an instance of TomoValidator to it. -func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _minCandidateCap *big.Int, _maxValidatorNumber *big.Int, _candidateWithdrawDelay *big.Int, _voterWithdrawDelay *big.Int) (common.Address, *types.Transaction, *TomoValidator, error) { +func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _candidates []common.Address, _caps []*big.Int, _firstOwner common.Address, _minCandidateCap *big.Int, _maxValidatorNumber *big.Int, _candidateWithdrawDelay *big.Int, _voterWithdrawDelay *big.Int) (common.Address, *types.Transaction, *TomoValidator, error) { parsed, err := abi.JSON(strings.NewReader(TomoValidatorABI)) if err != nil { return common.Address{}, nil, nil, err } - address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TomoValidatorBin), backend, _minCandidateCap, _maxValidatorNumber, _candidateWithdrawDelay, _voterWithdrawDelay) + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TomoValidatorBin), backend, _candidates, _caps, _firstOwner, _minCandidateCap, _maxValidatorNumber, _candidateWithdrawDelay, _voterWithdrawDelay) if err != nil { return common.Address{}, nil, nil, err } @@ -618,32 +415,6 @@ func (_TomoValidator *TomoValidatorCallerSession) Candidates(arg0 *big.Int) (com return _TomoValidator.Contract.Candidates(&_TomoValidator.CallOpts, arg0) } -// FirstOwner is a free data retrieval call binding the contract method 0x6bc28781. -// -// Solidity: function firstOwner() constant returns(address) -func (_TomoValidator *TomoValidatorCaller) FirstOwner(opts *bind.CallOpts) (common.Address, error) { - var ( - ret0 = new(common.Address) - ) - out := ret0 - err := _TomoValidator.contract.Call(opts, out, "firstOwner") - return *ret0, err -} - -// FirstOwner is a free data retrieval call binding the contract method 0x6bc28781. -// -// Solidity: function firstOwner() constant returns(address) -func (_TomoValidator *TomoValidatorSession) FirstOwner() (common.Address, error) { - return _TomoValidator.Contract.FirstOwner(&_TomoValidator.CallOpts) -} - -// FirstOwner is a free data retrieval call binding the contract method 0x6bc28781. -// -// Solidity: function firstOwner() constant returns(address) -func (_TomoValidator *TomoValidatorCallerSession) FirstOwner() (common.Address, error) { - return _TomoValidator.Contract.FirstOwner(&_TomoValidator.CallOpts) -} - // GetCandidateCap is a free data retrieval call binding the contract method 0x58e7525f. // // Solidity: function getCandidateCap(_candidate address) constant returns(uint256) @@ -722,32 +493,6 @@ func (_TomoValidator *TomoValidatorCallerSession) GetCandidateOwner(_candidate c return _TomoValidator.Contract.GetCandidateOwner(&_TomoValidator.CallOpts, _candidate) } -// GetCandidateWithdrawBlockNumber is a free data retrieval call binding the contract method 0x28265294. -// -// Solidity: function getCandidateWithdrawBlockNumber(_candidate address) constant returns(uint256) -func (_TomoValidator *TomoValidatorCaller) GetCandidateWithdrawBlockNumber(opts *bind.CallOpts, _candidate common.Address) (*big.Int, error) { - var ( - ret0 = new(*big.Int) - ) - out := ret0 - err := _TomoValidator.contract.Call(opts, out, "getCandidateWithdrawBlockNumber", _candidate) - return *ret0, err -} - -// GetCandidateWithdrawBlockNumber is a free data retrieval call binding the contract method 0x28265294. -// -// Solidity: function getCandidateWithdrawBlockNumber(_candidate address) constant returns(uint256) -func (_TomoValidator *TomoValidatorSession) GetCandidateWithdrawBlockNumber(_candidate common.Address) (*big.Int, error) { - return _TomoValidator.Contract.GetCandidateWithdrawBlockNumber(&_TomoValidator.CallOpts, _candidate) -} - -// GetCandidateWithdrawBlockNumber is a free data retrieval call binding the contract method 0x28265294. -// -// Solidity: function getCandidateWithdrawBlockNumber(_candidate address) constant returns(uint256) -func (_TomoValidator *TomoValidatorCallerSession) GetCandidateWithdrawBlockNumber(_candidate common.Address) (*big.Int, error) { - return _TomoValidator.Contract.GetCandidateWithdrawBlockNumber(&_TomoValidator.CallOpts, _candidate) -} - // GetCandidates is a free data retrieval call binding the contract method 0x06a49fce. // // Solidity: function getCandidates() constant returns(address[]) diff --git a/contracts/validator/validator.go b/contracts/validator/validator.go index f3bcc2ae77..6b1902f8a1 100644 --- a/contracts/validator/validator.go +++ b/contracts/validator/validator.go @@ -1,7 +1,6 @@ package validator import ( - "fmt" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/contracts/validator/contract" @@ -28,11 +27,10 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address, }, 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.SetString("50000000000000000000000", 10) - fmt.Println("--->", common.BigToHash(minDeposit).Hex()) - validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, minDeposit, big.NewInt(99), big.NewInt(100), big.NewInt(100)) + validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, big.NewInt(99), big.NewInt(100), big.NewInt(100)) if err != nil { return validatorAddr, nil, err } diff --git a/contracts/validator/validator_test.go b/contracts/validator/validator_test.go index 0842b06760..86366cbc15 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -9,11 +9,11 @@ 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/contracts" - "github.com/ethereum/go-ethereum/contracts/validator/contract" + // "github.com/ethereum/go-ethereum/contracts" + // "github.com/ethereum/go-ethereum/contracts/validator/contract" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/crypto" - "math/rand" + // "math/rand" ) var ( @@ -33,7 +33,9 @@ func TestValidator(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) 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 { t.Fatalf("can't deploy root registry: %v", err) } @@ -63,6 +65,7 @@ func TestValidator(t *testing.T) { contractBackend.Commit() } +/* func TestRewardBalance(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{ acc1Addr: {Balance: new(big.Int).SetUint64(10000000)}, @@ -143,3 +146,4 @@ func TestRewardBalance(t *testing.T) { } } +*/ From dc5576319ba007b505053ad1c1e195b24e26fd42 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Tue, 17 Jul 2018 08:00:43 +0000 Subject: [PATCH 06/18] update randomize - onlyone opening message --- .../randomize/contract/TomoRandomize.sol | 10 +++--- contracts/randomize/contract/randomize.go | 36 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/contracts/randomize/contract/TomoRandomize.sol b/contracts/randomize/contract/TomoRandomize.sol index f63e16457e..a82357d687 100644 --- a/contracts/randomize/contract/TomoRandomize.sol +++ b/contracts/randomize/contract/TomoRandomize.sol @@ -9,9 +9,9 @@ contract TomoRandomize { uint256 public blockTimeOpening; mapping (address=>bytes32[]) randomSecret; - mapping (address=>bytes32[]) randomOpening; + mapping (address=>bytes32) randomOpening; - function TomoRandomize (uint256 _epochNumber, uint256 _blockTimeSecret, uint256 _blockTimeOpening) public { + function TomoRandomize(uint256 _epochNumber, uint256 _blockTimeSecret, uint256 _blockTimeOpening) public { epochNumber = _epochNumber; blockTimeOpening = _blockTimeOpening; blockTimeSecret = _blockTimeSecret; @@ -28,9 +28,7 @@ contract TomoRandomize { randomSecret[msg.sender] = _secret; } - function setOpening(bytes32[] _opening) public { - require(_opening.length == epochNumber); - + function setOpening(bytes32 _opening) public { uint256 _blockNum = block.number; uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber)); @@ -49,7 +47,7 @@ contract TomoRandomize { return randomSecret[_validator]; } - function getOpening(address _validator) public view returns(bytes32[]) { + function getOpening(address _validator) public view returns(bytes32) { uint256 _blockNum = block.number; uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber)); diff --git a/contracts/randomize/contract/randomize.go b/contracts/randomize/contract/randomize.go index 622e64e7b5..fd62fef5c9 100644 --- a/contracts/randomize/contract/randomize.go +++ b/contracts/randomize/contract/randomize.go @@ -175,10 +175,10 @@ func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method } // TomoRandomizeABI is the input ABI used to generate the binding from. -const TomoRandomizeABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_opening\",\"type\":\"bytes32[]\"}],\"name\":\"setOpening\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"blockTimeSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_secret\",\"type\":\"bytes32[]\"}],\"name\":\"setSecret\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"blockTimeOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"epochNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_epochNumber\",\"type\":\"uint256\"},{\"name\":\"_blockTimeSecret\",\"type\":\"uint256\"},{\"name\":\"_blockTimeOpening\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" +const TomoRandomizeABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"blockTimeSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_secret\",\"type\":\"bytes32[]\"}],\"name\":\"setSecret\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"blockTimeOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_opening\",\"type\":\"bytes32\"}],\"name\":\"setOpening\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"epochNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_epochNumber\",\"type\":\"uint256\"},{\"name\":\"_blockTimeSecret\",\"type\":\"uint256\"},{\"name\":\"_blockTimeOpening\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" // TomoRandomizeBin is the compiled bytecode used for deploying new contracts. -const TomoRandomizeBin = `0x6060604052341561000f57600080fd5b6040516060806105d48339810160405280805191906020018051919060200180516000948555600255505060015561058790819061004d90396000f3006060604052600436106100825763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632141c7d98114610087578063257b03e9146100d8578063284180fc146100fd57806334d386001461016f57806337a52ecc146101be578063d442d6cc146101d1578063f4145a83146101f0575b600080fd5b341561009257600080fd5b6100d6600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061020395505050505050565b005b34156100e357600080fd5b6100eb61029b565b60405190815260200160405180910390f35b341561010857600080fd5b61011c600160a060020a03600435166102a1565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561015b578082015183820152602001610143565b505050509050019250505060405180910390f35b341561017a57600080fd5b6100d6600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061035795505050505050565b34156101c957600080fd5b6100eb6103c2565b34156101dc57600080fd5b61011c600160a060020a03600435166103c8565b34156101fb57600080fd5b6100eb61047c565b60008060005483511461021557600080fd5b60005443925061024c9061023f90610233858263ffffffff61048216565b9063ffffffff61049716565b839063ffffffff6104cd16565b90506001548111801561026157506002548111155b151561026c57600080fd5b600160a060020a03331660009081526004602052604090208380516102959291602001906104df565b50505050565b60015481565b6102a961052c565b600080544391906102c89061023f90610233858263ffffffff61048216565b60015490915081116102d957600080fd5b6003600085600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561034957602002820191906000526020600020905b81548152600190910190602001808311610334575b505050505092505050919050565b60008060005483511461036957600080fd5b6000544392506103879061023f90610233858263ffffffff61048216565b60015490915081111561039957600080fd5b600160a060020a03331660009081526003602052604090208380516102959291602001906104df565b60025481565b6103d061052c565b600080544391906103ef9061023f90610233858263ffffffff61048216565b600254909150811161040057600080fd5b6004600085600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561034957602002820191906000526020600020908154815260019091019060200180831161033457505050505092505050919050565b60005481565b6000818381151561048f57fe5b049392505050565b6000808315156104aa57600091506104c6565b508282028284828115156104ba57fe5b04146104c257fe5b8091505b5092915050565b6000828211156104d957fe5b50900390565b82805482825590600052602060002090810192821561051c579160200282015b8281111561051c57825182556020909201916001909101906104ff565b5061052892915061053e565b5090565b60206040519081016040526000815290565b61055891905b808211156105285760008155600101610544565b905600a165627a7a7230582031eb1183e55e5d47012ab3437f7e50e5d73edca48c1e66da1b1b45d7fa0d566b0029` +const TomoRandomizeBin = `0x6060604052341561000f57600080fd5b604051606080610519833981016040528080519190602001805191906020018051600094855560025550506001556104cc90819061004d90396000f3006060604052600436106100825763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663257b03e98114610087578063284180fc146100ac57806334d386001461011e57806337a52ecc1461016f578063d442d6cc14610182578063e11f5ba2146101a1578063f4145a83146101b7575b600080fd5b341561009257600080fd5b61009a6101ca565b60405190815260200160405180910390f35b34156100b757600080fd5b6100cb600160a060020a03600435166101d0565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561010a5780820151838201526020016100f2565b505050509050019250505060405180910390f35b341561012957600080fd5b61016d600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061029f95505050505050565b005b341561017a57600080fd5b61009a610310565b341561018d57600080fd5b61009a600160a060020a0360043516610316565b34156101ac57600080fd5b61016d600435610365565b34156101c257600080fd5b61009a6103c1565b60015481565b6101d8610424565b6000805443919061021090610203906101f7858263ffffffff6103c716565b9063ffffffff6103dc16565b839063ffffffff61041216565b600154909150811161022157600080fd5b6003600085600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561029157602002820191906000526020600020905b8154815260019091019060200180831161027c575b505050505092505050919050565b6000806000548351146102b157600080fd5b6000544392506102cf90610203906101f7858263ffffffff6103c716565b6001549091508111156102e157600080fd5b600160a060020a033316600090815260036020526040902083805161030a929160200190610436565b50505050565b60025481565b600080544390829061033690610203906101f7858263ffffffff6103c716565b600254909150811161034757600080fd5b505050600160a060020a031660009081526004602052604090205490565b6000805443919061038490610203906101f7858263ffffffff6103c716565b90506001548111801561039957506002548111155b15156103a457600080fd5b5050600160a060020a033316600090815260046020526040902055565b60005481565b600081838115156103d457fe5b049392505050565b6000808315156103ef576000915061040b565b508282028284828115156103ff57fe5b041461040757fe5b8091505b5092915050565b60008282111561041e57fe5b50900390565b60206040519081016040526000815290565b828054828255906000526020600020908101928215610473579160200282015b828111156104735782518255602090920191600190910190610456565b5061047f929150610483565b5090565b61049d91905b8082111561047f5760008155600101610489565b905600a165627a7a723058202fa3b5fc32ade1d70f848dad796c758037745b4346f871dc764b45d6d24dc0450029` // DeployTomoRandomize deploys a new Ethereum contract, binding an instance of TomoRandomize to it. func DeployTomoRandomize(auth *bind.TransactOpts, backend bind.ContractBackend, _epochNumber *big.Int, _blockTimeSecret *big.Int, _blockTimeOpening *big.Int) (common.Address, *types.Transaction, *TomoRandomize, error) { @@ -415,10 +415,10 @@ func (_TomoRandomize *TomoRandomizeCallerSession) EpochNumber() (*big.Int, error // GetOpening is a free data retrieval call binding the contract method 0xd442d6cc. // -// Solidity: function getOpening(_validator address) constant returns(bytes32[]) -func (_TomoRandomize *TomoRandomizeCaller) GetOpening(opts *bind.CallOpts, _validator common.Address) ([][32]byte, error) { +// Solidity: function getOpening(_validator address) constant returns(bytes32) +func (_TomoRandomize *TomoRandomizeCaller) GetOpening(opts *bind.CallOpts, _validator common.Address) ([32]byte, error) { var ( - ret0 = new([][32]byte) + ret0 = new([32]byte) ) out := ret0 err := _TomoRandomize.contract.Call(opts, out, "getOpening", _validator) @@ -427,15 +427,15 @@ func (_TomoRandomize *TomoRandomizeCaller) GetOpening(opts *bind.CallOpts, _vali // GetOpening is a free data retrieval call binding the contract method 0xd442d6cc. // -// Solidity: function getOpening(_validator address) constant returns(bytes32[]) -func (_TomoRandomize *TomoRandomizeSession) GetOpening(_validator common.Address) ([][32]byte, error) { +// Solidity: function getOpening(_validator address) constant returns(bytes32) +func (_TomoRandomize *TomoRandomizeSession) GetOpening(_validator common.Address) ([32]byte, error) { return _TomoRandomize.Contract.GetOpening(&_TomoRandomize.CallOpts, _validator) } // GetOpening is a free data retrieval call binding the contract method 0xd442d6cc. // -// Solidity: function getOpening(_validator address) constant returns(bytes32[]) -func (_TomoRandomize *TomoRandomizeCallerSession) GetOpening(_validator common.Address) ([][32]byte, error) { +// Solidity: function getOpening(_validator address) constant returns(bytes32) +func (_TomoRandomize *TomoRandomizeCallerSession) GetOpening(_validator common.Address) ([32]byte, error) { return _TomoRandomize.Contract.GetOpening(&_TomoRandomize.CallOpts, _validator) } @@ -465,24 +465,24 @@ func (_TomoRandomize *TomoRandomizeCallerSession) GetSecret(_validator common.Ad return _TomoRandomize.Contract.GetSecret(&_TomoRandomize.CallOpts, _validator) } -// SetOpening is a paid mutator transaction binding the contract method 0x2141c7d9. +// SetOpening is a paid mutator transaction binding the contract method 0xe11f5ba2. // -// Solidity: function setOpening(_opening bytes32[]) returns() -func (_TomoRandomize *TomoRandomizeTransactor) SetOpening(opts *bind.TransactOpts, _opening [][32]byte) (*types.Transaction, error) { +// Solidity: function setOpening(_opening bytes32) returns() +func (_TomoRandomize *TomoRandomizeTransactor) SetOpening(opts *bind.TransactOpts, _opening [32]byte) (*types.Transaction, error) { return _TomoRandomize.contract.Transact(opts, "setOpening", _opening) } -// SetOpening is a paid mutator transaction binding the contract method 0x2141c7d9. +// SetOpening is a paid mutator transaction binding the contract method 0xe11f5ba2. // -// Solidity: function setOpening(_opening bytes32[]) returns() -func (_TomoRandomize *TomoRandomizeSession) SetOpening(_opening [][32]byte) (*types.Transaction, error) { +// Solidity: function setOpening(_opening bytes32) returns() +func (_TomoRandomize *TomoRandomizeSession) SetOpening(_opening [32]byte) (*types.Transaction, error) { return _TomoRandomize.Contract.SetOpening(&_TomoRandomize.TransactOpts, _opening) } -// SetOpening is a paid mutator transaction binding the contract method 0x2141c7d9. +// SetOpening is a paid mutator transaction binding the contract method 0xe11f5ba2. // -// Solidity: function setOpening(_opening bytes32[]) returns() -func (_TomoRandomize *TomoRandomizeTransactorSession) SetOpening(_opening [][32]byte) (*types.Transaction, error) { +// Solidity: function setOpening(_opening bytes32) returns() +func (_TomoRandomize *TomoRandomizeTransactorSession) SetOpening(_opening [32]byte) (*types.Transaction, error) { return _TomoRandomize.Contract.SetOpening(&_TomoRandomize.TransactOpts, _opening) } From a7bd5d29decd04dd818a431726d8fe23dda24a29 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Tue, 17 Jul 2018 08:41:16 +0000 Subject: [PATCH 07/18] move blocknumber to blockhash --- contracts/utils.go | 5 ++++- contracts/validator/validator_test.go | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/contracts/utils.go b/contracts/utils.go index 6102f9504d..c0e98e36a1 100644 --- a/contracts/utils.go +++ b/contracts/utils.go @@ -75,7 +75,10 @@ func GetSignersFromContract(addrBlockSigner common.Address, client bind.Contract return nil, err } opts := new(bind.CallOpts) - addrs, err := blockSigner.GetSigners(opts, new(big.Int).SetUint64(blockNumber)) + // TODO: let move from blockNumber to blockHash + // addrs, err := blockSigner.GetSigners(opts, new(big.Int).SetUint64(blockNumber)) + log.Error("Should replace blockNumber to blockHash", blockNumber) + addrs, err := blockSigner.GetSigners(opts, [32]byte{}) if err != nil { log.Error("Fail get block signers", "error", err) return nil, err diff --git a/contracts/validator/validator_test.go b/contracts/validator/validator_test.go index 86366cbc15..043145417a 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -9,11 +9,11 @@ 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/contracts" - // "github.com/ethereum/go-ethereum/contracts/validator/contract" + "github.com/ethereum/go-ethereum/contracts" + "github.com/ethereum/go-ethereum/contracts/validator/contract" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/crypto" - // "math/rand" + "math/rand" ) var ( @@ -65,7 +65,6 @@ func TestValidator(t *testing.T) { contractBackend.Commit() } -/* func TestRewardBalance(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{ acc1Addr: {Balance: new(big.Int).SetUint64(10000000)}, @@ -77,7 +76,20 @@ func TestRewardBalance(t *testing.T) { accounts := []*bind.TransactOpts{acc1Opts, acc2Opts} transactOpts := bind.NewKeyedTransactor(acc1Key) - validatorAddr, _, baseValidator, err := contract.DeployTomoValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100), big.NewInt(100)) + // validatorAddr, _, baseValidator, err := contract.DeployTomoValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100), big.NewInt(100)) + validatorCap := new(big.Int) + validatorCap.SetString("50000000000000000000000", 10) + validatorAddr, _, baseValidator, err := contract.DeployTomoValidator( + transactOpts, + contractBackend, + []common.Address{addr}, + []*big.Int{validatorCap}, + addr, + big.NewInt(50000), + big.NewInt(99), + big.NewInt(100), + big.NewInt(100), + ) if err != nil { t.Fatalf("can't deploy root registry: %v", err) } @@ -146,4 +158,3 @@ func TestRewardBalance(t *testing.T) { } } -*/ From b75916339b42cb8b3e845d4db12de421d7693695 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Tue, 17 Jul 2018 09:16:01 +0000 Subject: [PATCH 08/18] add smart contract randomize blocksigner --- cmd/puppeth/wizard_genesis.go | 50 ++++++++++++++++++++++++---- contracts/blocksigner/blocksigner.go | 2 +- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index 1b1f75096e..9a735f650b 100644 --- a/cmd/puppeth/wizard_genesis.go +++ b/cmd/puppeth/wizard_genesis.go @@ -34,6 +34,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" + blockSignerContract "github.com/ethereum/go-ethereum/contracts/blocksigner" + randomizeContract "github.com/ethereum/go-ethereum/contracts/randomize" validatorContract "github.com/ethereum/go-ethereum/contracts/validator" "github.com/ethereum/go-ethereum/crypto" ) @@ -132,7 +134,7 @@ func (w *wizard) makeGenesis() { fmt.Println() fmt.Println("Who own the first masternodes? (mandatory)") - w.readAddress() + owner := *w.readAddress() // We also need the initial list of signers fmt.Println() @@ -156,8 +158,12 @@ func (w *wizard) makeGenesis() { } } } + validatorCap := new(big.Int) + validatorCap.SetString("50000000000000000000000", 10) + var validatorCaps []*big.Int genesis.ExtraData = make([]byte, 32+len(signers)*common.AddressLength+65) for i, signer := range signers { + validatorCaps = append(validatorCaps, validatorCap) copy(genesis.ExtraData[32+i*common.AddressLength:], signer[:]) } @@ -165,13 +171,13 @@ func (w *wizard) makeGenesis() { fmt.Println("How many blocks per checkpoint? (default = 990)") genesis.Config.Clique.RewardCheckpoint = uint64(w.readDefaultInt(990)) - // Smart Contract Code - key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") - addr := crypto.PubkeyToAddress(key.PublicKey) + // Validator Smart Contract Code + pKey, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + addr := crypto.PubkeyToAddress(pKey.PublicKey) contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) - transactOpts := bind.NewKeyedTransactor(key) + transactOpts := bind.NewKeyedTransactor(pKey) - validatorAddress, _, err := validatorContract.DeployValidator(transactOpts, contractBackend) + validatorAddress, _, err := validatorContract.DeployValidator(transactOpts, contractBackend, signers, validatorCaps, owner) if err != nil { fmt.Println("Can't deploy root registry") } @@ -187,12 +193,44 @@ func (w *wizard) makeGenesis() { return true } contractBackend.ForEachStorageAt(ctx, validatorAddress, nil, f) + genesis.Alloc[common.StringToAddress("0x0000000000000000000000000000000000000088")] = core.GenesisAccount{ + Balance: validatorCap.Mul(validatorCap, big.NewInt(int64(len(validatorCaps)))), + Code: code, + Storage: storage, + } + + // Block Signers Smart Contract + blockSignerAddress, _, err := blockSignerContract.DeployBlockSigner(transactOpts, contractBackend) + if err != nil { + fmt.Println("Can't deploy root registry") + } + contractBackend.Commit() + + code, _ = contractBackend.CodeAt(ctx, blockSignerAddress, nil) + storage = make(map[common.Hash]common.Hash) + contractBackend.ForEachStorageAt(ctx, blockSignerAddress, nil, f) genesis.Alloc[common.StringToAddress("0x0000000000000000000000000000000000000089")] = core.GenesisAccount{ Balance: big.NewInt(0), Code: code, Storage: storage, } + // Randomize Smart Contract Code + randomizeAddress, _, err := randomizeContract.DeployRandomize(transactOpts, contractBackend) + if err != nil { + fmt.Println("Can't deploy root registry") + } + contractBackend.Commit() + + code, _ = contractBackend.CodeAt(ctx, randomizeAddress, nil) + storage = make(map[common.Hash]common.Hash) + contractBackend.ForEachStorageAt(ctx, randomizeAddress, nil, f) + genesis.Alloc[common.StringToAddress("0x0000000000000000000000000000000000000090")] = core.GenesisAccount{ + Balance: big.NewInt(0), + Code: code, + Storage: storage, + } + default: log.Crit("Invalid consensus engine choice", "choice", choice) } diff --git a/contracts/blocksigner/blocksigner.go b/contracts/blocksigner/blocksigner.go index 29d69d0432..57846f6128 100644 --- a/contracts/blocksigner/blocksigner.go +++ b/contracts/blocksigner/blocksigner.go @@ -28,7 +28,7 @@ func NewBlockSigner(transactOpts *bind.TransactOpts, contractAddr common.Address } func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *BlockSigner, error) { - blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, big.NewInt(990)) + blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, big.NewInt(99)) if err != nil { return blockSignerAddr, nil, err } From 724d3f5043db988fa21306180db9a86374e17c7d Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Wed, 18 Jul 2018 07:49:39 +0000 Subject: [PATCH 09/18] fix issue with address of smc --- cmd/puppeth/wizard_genesis.go | 8 ++++---- common/types.go | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index 9a735f650b..00446017db 100644 --- a/cmd/puppeth/wizard_genesis.go +++ b/cmd/puppeth/wizard_genesis.go @@ -193,7 +193,7 @@ func (w *wizard) makeGenesis() { return true } contractBackend.ForEachStorageAt(ctx, validatorAddress, nil, f) - genesis.Alloc[common.StringToAddress("0x0000000000000000000000000000000000000088")] = core.GenesisAccount{ + genesis.Alloc[common.HexToAddress(common.MasternodeVotingSMC)] = core.GenesisAccount{ Balance: validatorCap.Mul(validatorCap, big.NewInt(int64(len(validatorCaps)))), Code: code, Storage: storage, @@ -209,7 +209,7 @@ func (w *wizard) makeGenesis() { code, _ = contractBackend.CodeAt(ctx, blockSignerAddress, nil) storage = make(map[common.Hash]common.Hash) contractBackend.ForEachStorageAt(ctx, blockSignerAddress, nil, f) - genesis.Alloc[common.StringToAddress("0x0000000000000000000000000000000000000089")] = core.GenesisAccount{ + genesis.Alloc[common.HexToAddress(common.BlockSigners)] = core.GenesisAccount{ Balance: big.NewInt(0), Code: code, Storage: storage, @@ -225,7 +225,7 @@ func (w *wizard) makeGenesis() { code, _ = contractBackend.CodeAt(ctx, randomizeAddress, nil) storage = make(map[common.Hash]common.Hash) contractBackend.ForEachStorageAt(ctx, randomizeAddress, nil, f) - genesis.Alloc[common.StringToAddress("0x0000000000000000000000000000000000000090")] = core.GenesisAccount{ + genesis.Alloc[common.HexToAddress(common.RandomizeSMC)] = core.GenesisAccount{ Balance: big.NewInt(0), Code: code, Storage: storage, @@ -248,7 +248,7 @@ func (w *wizard) makeGenesis() { break } // Add a batch of precompile balances to avoid them getting deleted - for i := int64(0); i < 256; i++ { + for i := int64(0); i < 2; i++ { genesis.Alloc[common.BigToAddress(big.NewInt(i))] = core.GenesisAccount{Balance: big.NewInt(1)} } // Query the user for some custom extras diff --git a/common/types.go b/common/types.go index 0e98608182..22d7613fae 100644 --- a/common/types.go +++ b/common/types.go @@ -32,6 +32,7 @@ const ( AddressLength = 20 BlockSigners = "0x0000000000000000000000000000000000000089" MasternodeVotingSMC = "0x0000000000000000000000000000000000000088" + RandomizeSMC = "0x0000000000000000000000000000000000000090" ) var ( From 92af755d524508bee891bad64c7db393c9b5d85e Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Wed, 18 Jul 2018 11:03:54 +0000 Subject: [PATCH 10/18] simplify randomize smart contract --- cmd/puppeth/wizard_genesis.go | 2 +- .../randomize/contract/TomoRandomize.sol | 33 +----- contracts/randomize/contract/randomize.go | 112 +++++------------- contracts/randomize/randomize.go | 4 +- contracts/randomize/randomize_test.go | 2 +- 5 files changed, 38 insertions(+), 115 deletions(-) diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index 00446017db..6502338fab 100644 --- a/cmd/puppeth/wizard_genesis.go +++ b/cmd/puppeth/wizard_genesis.go @@ -216,7 +216,7 @@ func (w *wizard) makeGenesis() { } // Randomize Smart Contract Code - randomizeAddress, _, err := randomizeContract.DeployRandomize(transactOpts, contractBackend) + randomizeAddress, _, err := randomizeContract.DeployRandomize(transactOpts, contractBackend, big.NewInt(99)) if err != nil { fmt.Println("Can't deploy root registry") } diff --git a/contracts/randomize/contract/TomoRandomize.sol b/contracts/randomize/contract/TomoRandomize.sol index a82357d687..dd1d05f625 100644 --- a/contracts/randomize/contract/TomoRandomize.sol +++ b/contracts/randomize/contract/TomoRandomize.sol @@ -4,55 +4,30 @@ import "./libs/SafeMath.sol"; contract TomoRandomize { using SafeMath for uint256; - uint256 public epochNumber; - uint256 public blockTimeSecret; - uint256 public blockTimeOpening; + uint256 public randomNumber; mapping (address=>bytes32[]) randomSecret; mapping (address=>bytes32) randomOpening; - function TomoRandomize(uint256 _epochNumber, uint256 _blockTimeSecret, uint256 _blockTimeOpening) public { - epochNumber = _epochNumber; - blockTimeOpening = _blockTimeOpening; - blockTimeSecret = _blockTimeSecret; + function TomoRandomize (uint256 _randomNumber) public { + randomNumber = _randomNumber; } function setSecret(bytes32[] _secret) public { - require(_secret.length == epochNumber); - - uint256 _blockNum = block.number; - uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber)); - - require(_epoch <= blockTimeSecret); + require(_secret.length == randomNumber); randomSecret[msg.sender] = _secret; } function setOpening(bytes32 _opening) public { - uint256 _blockNum = block.number; - uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber)); - - require(_epoch > blockTimeSecret && _epoch <= blockTimeOpening); - randomOpening[msg.sender] = _opening; - } function getSecret(address _validator) public view returns(bytes32[]) { - uint256 _blockNum = block.number; - uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber)); - - require(_epoch > blockTimeSecret); - return randomSecret[_validator]; } function getOpening(address _validator) public view returns(bytes32) { - uint256 _blockNum = block.number; - uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber)); - - require(_epoch > blockTimeOpening); - return randomOpening[_validator]; } } diff --git a/contracts/randomize/contract/randomize.go b/contracts/randomize/contract/randomize.go index fd62fef5c9..999306b5c6 100644 --- a/contracts/randomize/contract/randomize.go +++ b/contracts/randomize/contract/randomize.go @@ -175,18 +175,18 @@ func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method } // TomoRandomizeABI is the input ABI used to generate the binding from. -const TomoRandomizeABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"blockTimeSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_secret\",\"type\":\"bytes32[]\"}],\"name\":\"setSecret\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"blockTimeOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_opening\",\"type\":\"bytes32\"}],\"name\":\"setOpening\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"epochNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_epochNumber\",\"type\":\"uint256\"},{\"name\":\"_blockTimeSecret\",\"type\":\"uint256\"},{\"name\":\"_blockTimeOpening\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" +const TomoRandomizeABI = "[{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_secret\",\"type\":\"bytes32[]\"}],\"name\":\"setSecret\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"randomNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_opening\",\"type\":\"bytes32\"}],\"name\":\"setOpening\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_randomNumber\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" // TomoRandomizeBin is the compiled bytecode used for deploying new contracts. -const TomoRandomizeBin = `0x6060604052341561000f57600080fd5b604051606080610519833981016040528080519190602001805191906020018051600094855560025550506001556104cc90819061004d90396000f3006060604052600436106100825763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663257b03e98114610087578063284180fc146100ac57806334d386001461011e57806337a52ecc1461016f578063d442d6cc14610182578063e11f5ba2146101a1578063f4145a83146101b7575b600080fd5b341561009257600080fd5b61009a6101ca565b60405190815260200160405180910390f35b34156100b757600080fd5b6100cb600160a060020a03600435166101d0565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561010a5780820151838201526020016100f2565b505050509050019250505060405180910390f35b341561012957600080fd5b61016d600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061029f95505050505050565b005b341561017a57600080fd5b61009a610310565b341561018d57600080fd5b61009a600160a060020a0360043516610316565b34156101ac57600080fd5b61016d600435610365565b34156101c257600080fd5b61009a6103c1565b60015481565b6101d8610424565b6000805443919061021090610203906101f7858263ffffffff6103c716565b9063ffffffff6103dc16565b839063ffffffff61041216565b600154909150811161022157600080fd5b6003600085600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561029157602002820191906000526020600020905b8154815260019091019060200180831161027c575b505050505092505050919050565b6000806000548351146102b157600080fd5b6000544392506102cf90610203906101f7858263ffffffff6103c716565b6001549091508111156102e157600080fd5b600160a060020a033316600090815260036020526040902083805161030a929160200190610436565b50505050565b60025481565b600080544390829061033690610203906101f7858263ffffffff6103c716565b600254909150811161034757600080fd5b505050600160a060020a031660009081526004602052604090205490565b6000805443919061038490610203906101f7858263ffffffff6103c716565b90506001548111801561039957506002548111155b15156103a457600080fd5b5050600160a060020a033316600090815260046020526040902055565b60005481565b600081838115156103d457fe5b049392505050565b6000808315156103ef576000915061040b565b508282028284828115156103ff57fe5b041461040757fe5b8091505b5092915050565b60008282111561041e57fe5b50900390565b60206040519081016040526000815290565b828054828255906000526020600020908101928215610473579160200282015b828111156104735782518255602090920191600190910190610456565b5061047f929150610483565b5090565b61049d91905b8082111561047f5760008155600101610489565b905600a165627a7a723058202fa3b5fc32ade1d70f848dad796c758037745b4346f871dc764b45d6d24dc0450029` +const TomoRandomizeBin = `0x6060604052341561000f57600080fd5b604051602080610368833981016040528080516000555050610332806100366000396000f30060606040526004361061006c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663284180fc811461007157806334d38600146100e3578063ccbac9f514610134578063d442d6cc14610159578063e11f5ba214610178575b600080fd5b341561007c57600080fd5b610090600160a060020a036004351661018e565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cf5780820151838201526020016100b7565b505050509050019250505060405180910390f35b34156100ee57600080fd5b610132600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061021295505050505050565b005b341561013f57600080fd5b61014761024e565b60405190815260200160405180910390f35b341561016457600080fd5b610147600160a060020a0360043516610254565b341561018357600080fd5b61013260043561026f565b61019661028a565b6001600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561020657602002820191906000526020600020905b815481526001909101906020018083116101f1575b50505050509050919050565b60005481511461022157600080fd5b600160a060020a033316600090815260016020526040902081805161024a92916020019061029c565b5050565b60005481565b600160a060020a031660009081526002602052604090205490565b600160a060020a033316600090815260026020526040902055565b60206040519081016040526000815290565b8280548282559060005260206000209081019282156102d9579160200282015b828111156102d957825182556020909201916001909101906102bc565b506102e59291506102e9565b5090565b61030391905b808211156102e557600081556001016102ef565b905600a165627a7a7230582037ba8393f14ed0acf6abe37443bcf8598d148baa0a51b1f127f48eef0e2eeca80029` // DeployTomoRandomize deploys a new Ethereum contract, binding an instance of TomoRandomize to it. -func DeployTomoRandomize(auth *bind.TransactOpts, backend bind.ContractBackend, _epochNumber *big.Int, _blockTimeSecret *big.Int, _blockTimeOpening *big.Int) (common.Address, *types.Transaction, *TomoRandomize, error) { +func DeployTomoRandomize(auth *bind.TransactOpts, backend bind.ContractBackend, _randomNumber *big.Int) (common.Address, *types.Transaction, *TomoRandomize, error) { parsed, err := abi.JSON(strings.NewReader(TomoRandomizeABI)) if err != nil { return common.Address{}, nil, nil, err } - address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TomoRandomizeBin), backend, _epochNumber, _blockTimeSecret, _blockTimeOpening) + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TomoRandomizeBin), backend, _randomNumber) if err != nil { return common.Address{}, nil, nil, err } @@ -335,84 +335,6 @@ func (_TomoRandomize *TomoRandomizeTransactorRaw) Transact(opts *bind.TransactOp return _TomoRandomize.Contract.contract.Transact(opts, method, params...) } -// BlockTimeOpening is a free data retrieval call binding the contract method 0x37a52ecc. -// -// Solidity: function blockTimeOpening() constant returns(uint256) -func (_TomoRandomize *TomoRandomizeCaller) BlockTimeOpening(opts *bind.CallOpts) (*big.Int, error) { - var ( - ret0 = new(*big.Int) - ) - out := ret0 - err := _TomoRandomize.contract.Call(opts, out, "blockTimeOpening") - return *ret0, err -} - -// BlockTimeOpening is a free data retrieval call binding the contract method 0x37a52ecc. -// -// Solidity: function blockTimeOpening() constant returns(uint256) -func (_TomoRandomize *TomoRandomizeSession) BlockTimeOpening() (*big.Int, error) { - return _TomoRandomize.Contract.BlockTimeOpening(&_TomoRandomize.CallOpts) -} - -// BlockTimeOpening is a free data retrieval call binding the contract method 0x37a52ecc. -// -// Solidity: function blockTimeOpening() constant returns(uint256) -func (_TomoRandomize *TomoRandomizeCallerSession) BlockTimeOpening() (*big.Int, error) { - return _TomoRandomize.Contract.BlockTimeOpening(&_TomoRandomize.CallOpts) -} - -// BlockTimeSecret is a free data retrieval call binding the contract method 0x257b03e9. -// -// Solidity: function blockTimeSecret() constant returns(uint256) -func (_TomoRandomize *TomoRandomizeCaller) BlockTimeSecret(opts *bind.CallOpts) (*big.Int, error) { - var ( - ret0 = new(*big.Int) - ) - out := ret0 - err := _TomoRandomize.contract.Call(opts, out, "blockTimeSecret") - return *ret0, err -} - -// BlockTimeSecret is a free data retrieval call binding the contract method 0x257b03e9. -// -// Solidity: function blockTimeSecret() constant returns(uint256) -func (_TomoRandomize *TomoRandomizeSession) BlockTimeSecret() (*big.Int, error) { - return _TomoRandomize.Contract.BlockTimeSecret(&_TomoRandomize.CallOpts) -} - -// BlockTimeSecret is a free data retrieval call binding the contract method 0x257b03e9. -// -// Solidity: function blockTimeSecret() constant returns(uint256) -func (_TomoRandomize *TomoRandomizeCallerSession) BlockTimeSecret() (*big.Int, error) { - return _TomoRandomize.Contract.BlockTimeSecret(&_TomoRandomize.CallOpts) -} - -// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83. -// -// Solidity: function epochNumber() constant returns(uint256) -func (_TomoRandomize *TomoRandomizeCaller) EpochNumber(opts *bind.CallOpts) (*big.Int, error) { - var ( - ret0 = new(*big.Int) - ) - out := ret0 - err := _TomoRandomize.contract.Call(opts, out, "epochNumber") - return *ret0, err -} - -// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83. -// -// Solidity: function epochNumber() constant returns(uint256) -func (_TomoRandomize *TomoRandomizeSession) EpochNumber() (*big.Int, error) { - return _TomoRandomize.Contract.EpochNumber(&_TomoRandomize.CallOpts) -} - -// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83. -// -// Solidity: function epochNumber() constant returns(uint256) -func (_TomoRandomize *TomoRandomizeCallerSession) EpochNumber() (*big.Int, error) { - return _TomoRandomize.Contract.EpochNumber(&_TomoRandomize.CallOpts) -} - // GetOpening is a free data retrieval call binding the contract method 0xd442d6cc. // // Solidity: function getOpening(_validator address) constant returns(bytes32) @@ -465,6 +387,32 @@ func (_TomoRandomize *TomoRandomizeCallerSession) GetSecret(_validator common.Ad return _TomoRandomize.Contract.GetSecret(&_TomoRandomize.CallOpts, _validator) } +// RandomNumber is a free data retrieval call binding the contract method 0xccbac9f5. +// +// Solidity: function randomNumber() constant returns(uint256) +func (_TomoRandomize *TomoRandomizeCaller) RandomNumber(opts *bind.CallOpts) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _TomoRandomize.contract.Call(opts, out, "randomNumber") + return *ret0, err +} + +// RandomNumber is a free data retrieval call binding the contract method 0xccbac9f5. +// +// Solidity: function randomNumber() constant returns(uint256) +func (_TomoRandomize *TomoRandomizeSession) RandomNumber() (*big.Int, error) { + return _TomoRandomize.Contract.RandomNumber(&_TomoRandomize.CallOpts) +} + +// RandomNumber is a free data retrieval call binding the contract method 0xccbac9f5. +// +// Solidity: function randomNumber() constant returns(uint256) +func (_TomoRandomize *TomoRandomizeCallerSession) RandomNumber() (*big.Int, error) { + return _TomoRandomize.Contract.RandomNumber(&_TomoRandomize.CallOpts) +} + // SetOpening is a paid mutator transaction binding the contract method 0xe11f5ba2. // // Solidity: function setOpening(_opening bytes32) returns() diff --git a/contracts/randomize/randomize.go b/contracts/randomize/randomize.go index 07651f07e5..6b21c8a820 100644 --- a/contracts/randomize/randomize.go +++ b/contracts/randomize/randomize.go @@ -27,8 +27,8 @@ func NewRandomize(transactOpts *bind.TransactOpts, contractAddr common.Address, }, nil } -func DeployRandomize(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *Randomize, error) { - randomizeAddr, _, _, err := contract.DeployTomoRandomize(transactOpts, contractBackend, big.NewInt(2), big.NewInt(0), big.NewInt(1)) +func DeployRandomize(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, randomNumber *big.Int) (common.Address, *Randomize, error) { + randomizeAddr, _, _, err := contract.DeployTomoRandomize(transactOpts, contractBackend, randomNumber) if err != nil { return randomizeAddr, nil, err } diff --git a/contracts/randomize/randomize_test.go b/contracts/randomize/randomize_test.go index 909de5116c..0ce471e1cf 100644 --- a/contracts/randomize/randomize_test.go +++ b/contracts/randomize/randomize_test.go @@ -23,7 +23,7 @@ func TestRandomize(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) transactOpts := bind.NewKeyedTransactor(key) - randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend) + randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend, big.NewInt(2)) t.Log("contract address", randomizeAddress.String()) if err != nil { t.Fatalf("can't deploy root registry: %v", err) From f9f661779cf024156f6f1a2b02c8919484ce75fa Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Fri, 20 Jul 2018 04:01:58 +0000 Subject: [PATCH 11/18] remove require in randomize --- contracts/randomize/contract/TomoRandomize.sol | 2 -- contracts/randomize/contract/randomize.go | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/contracts/randomize/contract/TomoRandomize.sol b/contracts/randomize/contract/TomoRandomize.sol index dd1d05f625..9fc936fffd 100644 --- a/contracts/randomize/contract/TomoRandomize.sol +++ b/contracts/randomize/contract/TomoRandomize.sol @@ -14,8 +14,6 @@ contract TomoRandomize { } function setSecret(bytes32[] _secret) public { - require(_secret.length == randomNumber); - randomSecret[msg.sender] = _secret; } diff --git a/contracts/randomize/contract/randomize.go b/contracts/randomize/contract/randomize.go index 999306b5c6..b11d60be39 100644 --- a/contracts/randomize/contract/randomize.go +++ b/contracts/randomize/contract/randomize.go @@ -178,7 +178,7 @@ func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method const TomoRandomizeABI = "[{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_secret\",\"type\":\"bytes32[]\"}],\"name\":\"setSecret\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"randomNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_opening\",\"type\":\"bytes32\"}],\"name\":\"setOpening\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_randomNumber\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" // TomoRandomizeBin is the compiled bytecode used for deploying new contracts. -const TomoRandomizeBin = `0x6060604052341561000f57600080fd5b604051602080610368833981016040528080516000555050610332806100366000396000f30060606040526004361061006c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663284180fc811461007157806334d38600146100e3578063ccbac9f514610134578063d442d6cc14610159578063e11f5ba214610178575b600080fd5b341561007c57600080fd5b610090600160a060020a036004351661018e565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cf5780820151838201526020016100b7565b505050509050019250505060405180910390f35b34156100ee57600080fd5b610132600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061021295505050505050565b005b341561013f57600080fd5b61014761024e565b60405190815260200160405180910390f35b341561016457600080fd5b610147600160a060020a0360043516610254565b341561018357600080fd5b61013260043561026f565b61019661028a565b6001600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561020657602002820191906000526020600020905b815481526001909101906020018083116101f1575b50505050509050919050565b60005481511461022157600080fd5b600160a060020a033316600090815260016020526040902081805161024a92916020019061029c565b5050565b60005481565b600160a060020a031660009081526002602052604090205490565b600160a060020a033316600090815260026020526040902055565b60206040519081016040526000815290565b8280548282559060005260206000209081019282156102d9579160200282015b828111156102d957825182556020909201916001909101906102bc565b506102e59291506102e9565b5090565b61030391905b808211156102e557600081556001016102ef565b905600a165627a7a7230582037ba8393f14ed0acf6abe37443bcf8598d148baa0a51b1f127f48eef0e2eeca80029` +const TomoRandomizeBin = `0x6060604052341561000f57600080fd5b604051602080610359833981016040528080516000555050610323806100366000396000f30060606040526004361061006c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663284180fc811461007157806334d38600146100e3578063ccbac9f514610134578063d442d6cc14610159578063e11f5ba214610178575b600080fd5b341561007c57600080fd5b610090600160a060020a036004351661018e565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cf5780820151838201526020016100b7565b505050509050019250505060405180910390f35b34156100ee57600080fd5b610132600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061021295505050505050565b005b341561013f57600080fd5b61014761023f565b60405190815260200160405180910390f35b341561016457600080fd5b610147600160a060020a0360043516610245565b341561018357600080fd5b610132600435610260565b61019661027b565b6001600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561020657602002820191906000526020600020905b815481526001909101906020018083116101f1575b50505050509050919050565b600160a060020a033316600090815260016020526040902081805161023b92916020019061028d565b5050565b60005481565b600160a060020a031660009081526002602052604090205490565b600160a060020a033316600090815260026020526040902055565b60206040519081016040526000815290565b8280548282559060005260206000209081019282156102ca579160200282015b828111156102ca57825182556020909201916001909101906102ad565b506102d69291506102da565b5090565b6102f491905b808211156102d657600081556001016102e0565b905600a165627a7a7230582043a345787b9942e3361515ce1a0a4dbaab0ed6ce42c6ca0344119134351d9ffe0029` // DeployTomoRandomize deploys a new Ethereum contract, binding an instance of TomoRandomize to it. func DeployTomoRandomize(auth *bind.TransactOpts, backend bind.ContractBackend, _randomNumber *big.Int) (common.Address, *types.Transaction, *TomoRandomize, error) { From b13fd1f641890825707b6aab4cfd0317703f986a Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Fri, 20 Jul 2018 08:20:34 +0000 Subject: [PATCH 12/18] add sign in test --- contracts/blocksigner/blocksigner_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contracts/blocksigner/blocksigner_test.go b/contracts/blocksigner/blocksigner_test.go index d2e58b905f..e0c351495d 100644 --- a/contracts/blocksigner/blocksigner_test.go +++ b/contracts/blocksigner/blocksigner_test.go @@ -47,5 +47,11 @@ func TestBlockSigner(t *testing.T) { for _, it := range signers { t.Log("signer", it.String()) } + + s, err := blockSigner.Sign(big.NewInt(1), byte0) + if err != nil { + t.Fatalf("can't sign: %v", err) + } + t.Log("tx data", s) contractBackend.Commit() } From 908385b31d92e0db0dfe301bbf7631f9d6c686b4 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Fri, 27 Jul 2018 08:55:38 +0000 Subject: [PATCH 13/18] update block signer with epochNumber --- cmd/puppeth/wizard_genesis.go | 5 +++-- contracts/blocksigner/blocksigner.go | 4 ++-- contracts/blocksigner/blocksigner_test.go | 2 +- contracts/blocksigner/contract/BlockSigner.sol | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index edb4a3c1bb..5b2706f6d6 100644 --- a/cmd/puppeth/wizard_genesis.go +++ b/cmd/puppeth/wizard_genesis.go @@ -170,7 +170,8 @@ func (w *wizard) makeGenesis() { fmt.Println() fmt.Println("How many blocks per checkpoint? (default = 990)") - genesis.Config.Clique.RewardCheckpoint = uint64(w.readDefaultInt(990)) + epochNumber := w.readDefaultInt(990) + genesis.Config.Clique.RewardCheckpoint = uint64(epochNumber) // Validator Smart Contract Code pKey, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") @@ -201,7 +202,7 @@ func (w *wizard) makeGenesis() { } // Block Signers Smart Contract - blockSignerAddress, _, err := blockSignerContract.DeployBlockSigner(transactOpts, contractBackend) + blockSignerAddress, _, err := blockSignerContract.DeployBlockSigner(transactOpts, contractBackend, big.NewInt(int64(epochNumber))) if err != nil { fmt.Println("Can't deploy root registry") } diff --git a/contracts/blocksigner/blocksigner.go b/contracts/blocksigner/blocksigner.go index d7fe0970cb..6ad512dfba 100644 --- a/contracts/blocksigner/blocksigner.go +++ b/contracts/blocksigner/blocksigner.go @@ -42,8 +42,8 @@ func NewBlockSigner(transactOpts *bind.TransactOpts, contractAddr common.Address }, nil } -func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *BlockSigner, error) { - blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, big.NewInt(99)) +func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, epochNumber *big.Int) (common.Address, *BlockSigner, error) { + blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, epochNumber) if err != nil { return blockSignerAddr, nil, err } diff --git a/contracts/blocksigner/blocksigner_test.go b/contracts/blocksigner/blocksigner_test.go index 0759964ed4..c18d8b53ba 100644 --- a/contracts/blocksigner/blocksigner_test.go +++ b/contracts/blocksigner/blocksigner_test.go @@ -38,7 +38,7 @@ func TestBlockSigner(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) transactOpts := bind.NewKeyedTransactor(key) - blockSignerAddress, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend) + blockSignerAddress, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend, big.NewInt(99)) if err != nil { t.Fatalf("can't deploy root registry: %v", err) } diff --git a/contracts/blocksigner/contract/BlockSigner.sol b/contracts/blocksigner/contract/BlockSigner.sol index 82dcdb4c63..3fc80b6cb1 100644 --- a/contracts/blocksigner/contract/BlockSigner.sol +++ b/contracts/blocksigner/contract/BlockSigner.sol @@ -17,8 +17,8 @@ contract BlockSigner { function sign(uint256 _blockNumber, bytes32 _blockHash) external { // consensus should validate all senders are validators, gas = 0 - //require(block.number >= _blockNumber); - //require(block.number <= _blockNumber.add(epochNumber * 2)); + require(block.number >= _blockNumber); + require(block.number <= _blockNumber.add(epochNumber * 2)); blocks[_blockNumber].push(_blockHash); blockSigners[_blockHash].push(msg.sender); From 6bccdc725140346edd6d54047c84e6d6825808e3 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Mon, 30 Jul 2018 06:44:57 +0000 Subject: [PATCH 14/18] update require for blocksigners --- contracts/blocksigner/contract/blocksigner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/blocksigner/contract/blocksigner.go b/contracts/blocksigner/contract/blocksigner.go index 4e3a8509bc..385c1f525c 100644 --- a/contracts/blocksigner/contract/blocksigner.go +++ b/contracts/blocksigner/contract/blocksigner.go @@ -19,7 +19,7 @@ import ( const BlockSignerABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"sign\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"getSigners\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"epochNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_epochNumber\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_signer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"Sign\",\"type\":\"event\"}]" // BlockSignerBin is the compiled bytecode used for deploying new contracts. -const BlockSignerBin = `0x6060604052341561000f57600080fd5b60405160208061034083398101604052808051600255505061030a806100366000396000f3006060604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663e341eaa4811461005b578063e7ec6aef14610076578063f4145a83146100df575b600080fd5b341561006657600080fd5b610074600435602435610104565b005b341561008157600080fd5b61008c6004356101f7565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cb5780820151838201526020016100b3565b505050509050019250505060405180910390f35b34156100ea57600080fd5b6100f261027c565b60405190815260200160405180910390f35b60008281526001602081905260409091208054909181016101258382610282565b506000918252602080832091909101839055828252819052604090208054600181016101518382610282565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19163373ffffffffffffffffffffffffffffffffffffffff8116919091179091557f62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f5490838360405173ffffffffffffffffffffffffffffffffffffffff909316835260208301919091526040808301919091526060909101905180910390a15050565b6101ff6102ab565b6000828152602081815260409182902080549092909182810201905190810160405280929190818152602001828054801561027057602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610245575b50505050509050919050565b60025481565b8154818355818115116102a6576000838152602090206102a69181019083016102bd565b505050565b60206040519081016040526000815290565b6102db91905b808211156102d757600081556001016102c3565b5090565b905600a165627a7a72305820fd1c307716c14d8f8b179bb09b89555ec490e6b216e2c1018c7232361b947bc40029` +const BlockSignerBin = `0x6060604052341561000f57600080fd5b604051602080610386833981016040528080516002555050610350806100366000396000f3006060604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663e341eaa4811461005b578063e7ec6aef14610076578063f4145a83146100df575b600080fd5b341561006657600080fd5b610074600435602435610104565b005b341561008157600080fd5b61008c600435610227565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cb5780820151838201526020016100b3565b505050509050019250505060405180910390f35b34156100ea57600080fd5b6100f26102ac565b60405190815260200160405180910390f35b438290101561011257600080fd5b600280546101289184910263ffffffff6102b216565b43111561013457600080fd5b600082815260016020819052604090912080549091810161015583826102c8565b5060009182526020808320919091018390558282528190526040902080546001810161018183826102c8565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19163373ffffffffffffffffffffffffffffffffffffffff8116919091179091557f62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f5490838360405173ffffffffffffffffffffffffffffffffffffffff909316835260208301919091526040808301919091526060909101905180910390a15050565b61022f6102f1565b600082815260208181526040918290208054909290918281020190519081016040528092919081815260200182805480156102a057602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610275575b50505050509050919050565b60025481565b6000828201838110156102c157fe5b9392505050565b8154818355818115116102ec576000838152602090206102ec918101908301610303565b505050565b60206040519081016040526000815290565b61032191905b8082111561031d5760008155600101610309565b5090565b905600a165627a7a72305820a8ceddaea8e4ae00991e2ae81c8c88e160dd8770f255523282c24c2df4c30ec70029` // DeployBlockSigner deploys a new Ethereum contract, binding an instance of BlockSigner to it. func DeployBlockSigner(auth *bind.TransactOpts, backend bind.ContractBackend, _epochNumber *big.Int) (common.Address, *types.Transaction, *BlockSigner, error) { From df99d58a00d459c160597e10a602929041eec87f Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Tue, 7 Aug 2018 06:41:26 +0000 Subject: [PATCH 15/18] fix blocksigner deploy --- contracts/utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/utils_test.go b/contracts/utils_test.go index 9bfc9aa94b..78b068dcf6 100644 --- a/contracts/utils_test.go +++ b/contracts/utils_test.go @@ -50,7 +50,7 @@ func TestSendTxSign(t *testing.T) { ctx := context.Background() transactOpts := bind.NewKeyedTransactor(acc1Key) - blockSignerAddr, blockSigner, err := blocksigner.DeployBlockSigner(transactOpts, backend) + blockSignerAddr, blockSigner, err := blocksigner.DeployBlockSigner(transactOpts, backend, big.NewInt(99)) if err != nil { t.Fatalf("Can't get block signer: %v", err) } From aea989cb3a0bf125f99a07188326a9dbc7992f2c Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Tue, 7 Aug 2018 06:54:31 +0000 Subject: [PATCH 16/18] fix unittest block signer --- contracts/blocksigner/blocksigner_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/blocksigner/blocksigner_test.go b/contracts/blocksigner/blocksigner_test.go index c18d8b53ba..57bd5dd62d 100644 --- a/contracts/blocksigner/blocksigner_test.go +++ b/contracts/blocksigner/blocksigner_test.go @@ -58,7 +58,7 @@ func TestBlockSigner(t *testing.T) { byte0 := randomHash() // Test sign. - tx, err := blockSigner.Sign(big.NewInt(50), byte0) + tx, err := blockSigner.Sign(big.NewInt(2), byte0) if err != nil { t.Fatalf("can't sign: %v", err) } From bc2893404317a2ac82a1dff28c156057e18ff657 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Wed, 8 Aug 2018 04:30:46 +0000 Subject: [PATCH 17/18] fix test reward --- contracts/utils.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/contracts/utils.go b/contracts/utils.go index cd357519a4..b239e22e8d 100644 --- a/contracts/utils.go +++ b/contracts/utils.go @@ -216,12 +216,18 @@ func GetRewardBalancesRate(masterAddr common.Address, totalReward *big.Int, vali log.Error("Fail to get vote capacity", "error", err) return nil, err } + totalCap.Add(totalCap, voterCap) voterCaps[voteAddr] = voterCap } for addr, voteCap := range voterCaps { - balances[addr] = new(big.Int).Mul(totalVoterReward, voteCap) - balances[addr] = new(big.Int).Div(balances[addr], totalCap) + rcap := new(big.Int).Mul(totalVoterReward, voteCap) + rcap = new(big.Int).Div(rcap, totalCap) + if balances[addr] != nil { + balances[addr].Add(balances[addr], rcap) + } else { + balances[addr] = rcap + } } } From c517f4aaf0f73cbdc938b91843cbfaeebca84a6c Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Wed, 8 Aug 2018 05:01:22 +0000 Subject: [PATCH 18/18] accept range compare --- contracts/validator/validator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/validator/validator_test.go b/contracts/validator/validator_test.go index f20cb26d58..c00df0514b 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -152,7 +152,7 @@ func TestRewardBalance(t *testing.T) { afterReward = new(big.Int).Add(afterReward, value) } - if totalReward.Int64()+1 < afterReward.Int64() || totalReward.Int64()-1 > afterReward.Int64() { + if totalReward.Int64()+5 < afterReward.Int64() || totalReward.Int64()-5 > afterReward.Int64() { callOpts := new(bind.CallOpts) voters, err := baseValidator.GetVoters(callOpts, acc3Addr) if err != nil {