diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index e88c797cb4..ac7b1f175d 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,16 @@ 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" + 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" ) // makeGenesis creates a new genesis struct based on some user input. @@ -52,6 +61,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 { @@ -112,6 +122,125 @@ func (w *wizard) makeGenesis() { fmt.Println("How many blocks before checkpoint need to prepare new set of masternodes? (default = 50)") genesis.Config.Clique.Gap = uint64(w.readDefaultInt(50)) + 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)") + owner := *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] + } + } + } + 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[:]) + } + + fmt.Println() + fmt.Println("How many blocks per epoch? (default = 990)") + epochNumber := w.readDefaultInt(990) + genesis.Config.Clique.RewardCheckpoint = uint64(epochNumber) + + fmt.Println() + fmt.Println("How many blocks before checkpoint need to prepare new set of masternodes? (default = 50)") + genesis.Config.Clique.Gap = uint64(w.readDefaultInt(50)) + + // 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(pKey) + + validatorAddress, _, err := validatorContract.DeployValidator(transactOpts, contractBackend, signers, validatorCaps, owner) + if err != nil { + fmt.Println("Can't deploy root registry") + } + contractBackend.Commit() + + d := time.Now().Add(1000 * time.Millisecond) + 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 { + storage[key] = val + return true + } + contractBackend.ForEachStorageAt(ctx, validatorAddress, nil, f) + genesis.Alloc[common.HexToAddress(common.MasternodeVotingSMC)] = 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, big.NewInt(int64(epochNumber))) + 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.HexToAddress(common.BlockSigners)] = core.GenesisAccount{ + Balance: big.NewInt(0), + Code: code, + Storage: storage, + } + + // Randomize Smart Contract Code + randomizeAddress, _, err := randomizeContract.DeployRandomize(transactOpts, contractBackend, big.NewInt(99)) + 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.HexToAddress(common.RandomizeSMC)] = core.GenesisAccount{ + Balance: big.NewInt(0), + Code: code, + Storage: storage, + } + default: log.Crit("Invalid consensus engine choice", "choice", choice) } @@ -129,7 +258,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 ( 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 f068c6bbee..57bd5dd62d 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.go b/contracts/blocksigner/contract/blocksigner.go index 6dfcdc9a6a..34bc1061b2 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 = `0x608060405234801561001057600080fd5b506040516020806102c58339810160405251600255610291806100346000396000f3006080604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663e341eaa4811461005b578063e7ec6aef14610078578063f4145a83146100e0575b600080fd5b34801561006757600080fd5b50610076600435602435610107565b005b34801561008457600080fd5b506100906004356101d2565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156100cc5781810151838201526020016100b4565b505050509050019250505060405180910390f35b3480156100ec57600080fd5b506100f5610249565b60408051918252519081900360200190f35b4382111561011457600080fd5b6002805461012a9184910263ffffffff61024f16565b43111561013657600080fd5b6000828152600160208181526040808420805480850182559085528285200185905584845283825280842080549384018155845292819020909101805473ffffffffffffffffffffffffffffffffffffffff191633908117909155825190815290810184905280820183905290517f62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f549181900360600190a15050565b6000818152602081815260409182902080548351818402810184019094528084526060939283018282801561023d57602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610212575b50505050509050919050565b60025481565b60008282018381101561025e57fe5b93925050505600a165627a7a72305820b035faa3fa77d5019e1705483157467de16d51fe08a7194c30e2586e42ca7ccb0029` +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) { diff --git a/contracts/randomize/contract/TomoRandomize.sol b/contracts/randomize/contract/TomoRandomize.sol index f63e16457e..9fc936fffd 100644 --- a/contracts/randomize/contract/TomoRandomize.sol +++ b/contracts/randomize/contract/TomoRandomize.sol @@ -4,57 +4,28 @@ 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; + 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); - randomSecret[msg.sender] = _secret; } - function setOpening(bytes32[] _opening) public { - require(_opening.length == epochNumber); - - uint256 _blockNum = block.number; - uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber)); - - require(_epoch > blockTimeSecret && _epoch <= blockTimeOpening); - + function setOpening(bytes32 _opening) public { 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); - + function getOpening(address _validator) public view returns(bytes32) { return randomOpening[_validator]; } } diff --git a/contracts/randomize/contract/randomize.go b/contracts/randomize/contract/randomize.go index 622e64e7b5..b11d60be39 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\":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\":\"_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 = `0x6060604052341561000f57600080fd5b6040516060806105d48339810160405280805191906020018051919060200180516000948555600255505060015561058790819061004d90396000f3006060604052600436106100825763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632141c7d98114610087578063257b03e9146100d8578063284180fc146100fd57806334d386001461016f57806337a52ecc146101be578063d442d6cc146101d1578063f4145a83146101f0575b600080fd5b341561009257600080fd5b6100d6600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061020395505050505050565b005b34156100e357600080fd5b6100eb61029b565b60405190815260200160405180910390f35b341561010857600080fd5b61011c600160a060020a03600435166102a1565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561015b578082015183820152602001610143565b505050509050019250505060405180910390f35b341561017a57600080fd5b6100d6600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061035795505050505050565b34156101c957600080fd5b6100eb6103c2565b34156101dc57600080fd5b61011c600160a060020a03600435166103c8565b34156101fb57600080fd5b6100eb61047c565b60008060005483511461021557600080fd5b60005443925061024c9061023f90610233858263ffffffff61048216565b9063ffffffff61049716565b839063ffffffff6104cd16565b90506001548111801561026157506002548111155b151561026c57600080fd5b600160a060020a03331660009081526004602052604090208380516102959291602001906104df565b50505050565b60015481565b6102a961052c565b600080544391906102c89061023f90610233858263ffffffff61048216565b60015490915081116102d957600080fd5b6003600085600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561034957602002820191906000526020600020905b81548152600190910190602001808311610334575b505050505092505050919050565b60008060005483511461036957600080fd5b6000544392506103879061023f90610233858263ffffffff61048216565b60015490915081111561039957600080fd5b600160a060020a03331660009081526003602052604090208380516102959291602001906104df565b60025481565b6103d061052c565b600080544391906103ef9061023f90610233858263ffffffff61048216565b600254909150811161040057600080fd5b6004600085600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561034957602002820191906000526020600020908154815260019091019060200180831161033457505050505092505050919050565b60005481565b6000818381151561048f57fe5b049392505050565b6000808315156104aa57600091506104c6565b508282028284828115156104ba57fe5b04146104c257fe5b8091505b5092915050565b6000828211156104d957fe5b50900390565b82805482825590600052602060002090810192821561051c579160200282015b8281111561051c57825182556020909201916001909101906104ff565b5061052892915061053e565b5090565b60206040519081016040526000815290565b61055891905b808211156105285760008155600101610544565b905600a165627a7a7230582031eb1183e55e5d47012ab3437f7e50e5d73edca48c1e66da1b1b45d7fa0d566b0029` +const TomoRandomizeBin = `0x6060604052341561000f57600080fd5b604051602080610359833981016040528080516000555050610323806100366000396000f30060606040526004361061006c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663284180fc811461007157806334d38600146100e3578063ccbac9f514610134578063d442d6cc14610159578063e11f5ba214610178575b600080fd5b341561007c57600080fd5b610090600160a060020a036004351661018e565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cf5780820151838201526020016100b7565b505050509050019250505060405180910390f35b34156100ee57600080fd5b610132600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061021295505050505050565b005b341561013f57600080fd5b61014761023f565b60405190815260200160405180910390f35b341561016457600080fd5b610147600160a060020a0360043516610245565b341561018357600080fd5b610132600435610260565b61019661027b565b6001600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561020657602002820191906000526020600020905b815481526001909101906020018083116101f1575b50505050509050919050565b600160a060020a033316600090815260016020526040902081805161023b92916020019061028d565b5050565b60005481565b600160a060020a031660009081526002602052604090205490565b600160a060020a033316600090815260026020526040902055565b60206040519081016040526000815290565b8280548282559060005260206000209081019282156102ca579160200282015b828111156102ca57825182556020909201916001909101906102ad565b506102d69291506102da565b5090565b6102f491905b808211156102d657600081556001016102e0565b905600a165627a7a7230582043a345787b9942e3361515ce1a0a4dbaab0ed6ce42c6ca0344119134351d9ffe0029` // 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,90 +335,12 @@ 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[]) -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 +349,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 +387,50 @@ 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. +// RandomNumber is a free data retrieval call binding the contract method 0xccbac9f5. // -// Solidity: function setOpening(_opening bytes32[]) returns() -func (_TomoRandomize *TomoRandomizeTransactor) SetOpening(opts *bind.TransactOpts, _opening [][32]byte) (*types.Transaction, error) { +// 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() +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) } diff --git a/contracts/randomize/randomize.go b/contracts/randomize/randomize.go index 15cdc05bbe..f2a0e344b8 100644 --- a/contracts/randomize/randomize.go +++ b/contracts/randomize/randomize.go @@ -42,8 +42,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 17c0993ea8..ef4868e84f 100644 --- a/contracts/randomize/randomize_test.go +++ b/contracts/randomize/randomize_test.go @@ -16,11 +16,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" ) @@ -35,16 +38,28 @@ 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, big.NewInt(2)) + 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, 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 { + 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/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 + } } } diff --git a/contracts/utils_test.go b/contracts/utils_test.go index c8fdd2845f..44ce479b35 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) } diff --git a/contracts/validator/contract/TomoValidator.sol b/contracts/validator/contract/TomoValidator.sol index 84b3450bc0..03e205694e 100644 --- a/contracts/validator/contract/TomoValidator.sol +++ b/contracts/validator/contract/TomoValidator.sol @@ -1,38 +1,41 @@ 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); event Unvote(address _voter, address _candidate, uint256 _cap); 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 SetNodeId(address _owner, address _candidate, string _nodeId); + event Withdraw(address _owner, uint256 _blockNumber, uint256 _cap); struct ValidatorState { address owner; - string nodeUrl; + string nodeId; bool isCandidate; uint256 cap; - uint256 withdrawBlockNumber; 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 = [ - 0xf99805B536609cC03AcBB2604dFaC11E9E54a448, - 0x31b249fE6F267aa2396Eb2DC36E9c79351d97Ec5, - 0xfC5571921c6d3672e13B58EA23DEA534f2b35fA0 - ]; - uint256 candidateCount = 3; + address[] public candidates; + + 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 +53,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,37 +68,52 @@ 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 ( + address[] _candidates, + uint256[] _caps, + address _firstOwner, 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, - nodeUrl: '', + for (uint256 i = 0; i < _candidates.length; i++) { + candidates.push(_candidates[i]); + validatorsState[_candidates[i]] = ValidatorState({ + owner: _firstOwner, + nodeId: '', isCandidate: true, - withdrawBlockNumber: 0, - cap: minCandidateCap + cap: _caps[i] }); + voters[_candidates[i]].push(_firstOwner); + validatorsState[candidates[i]].voters[_firstOwner] = minCandidateCap; } } - function propose(address _candidate, string _nodeUrl) external payable onlyValidCandidateCap onlyNotCandidate(_candidate) { + function propose(address _candidate, string _nodeId) external payable onlyValidCandidateCap onlyNotCandidate(_candidate) { candidates.push(_candidate); validatorsState[_candidate] = ValidatorState({ owner: msg.sender, - nodeUrl: _nodeUrl, + nodeId: _nodeId, isCandidate: true, - withdrawBlockNumber: 0, cap: msg.value }); validatorsState[_candidate].voters[msg.sender] = msg.value; candidateCount = candidateCount + 1; + voters[_candidate].push(_candidate); emit Propose(msg.sender, _candidate, msg.value); } @@ -122,18 +134,14 @@ contract TomoValidator is IValidator { return validatorsState[_candidate].cap; } - function getCandidateNodeUrl(address _candidate) public view returns(string) { - return validatorsState[_candidate].nodeUrl; + function getCandidateNodeId(address _candidate) public view returns(string) { + return validatorsState[_candidate].nodeId; } function getCandidateOwner(address _candidate) public view returns(address) { 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]; } @@ -146,17 +154,25 @@ 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); } - function setNodeUrl(address _candidate, string _nodeUrl) public onlyOwner(_candidate) { - validatorsState[_candidate].nodeUrl = _nodeUrl; - emit SetNodeUrl(msg.sender, _candidate, _nodeUrl); + function setNodeId(address _candidate, string _nodeId) public onlyOwner(_candidate) { + validatorsState[_candidate].nodeId = _nodeId; + emit SetNodeId(msg.sender, _candidate, _nodeId); } function resign(address _candidate) public onlyOwner(_candidate) onlyCandidate(_candidate) { @@ -168,17 +184,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..f17c62da35 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\":\"_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\":\"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\":\"_nodeId\",\"type\":\"string\"}],\"name\":\"setNodeId\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateNodeId\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"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\":\"_nodeId\",\"type\":\"string\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"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\":\"_nodeId\",\"type\":\"string\"}],\"name\":\"SetNodeId\",\"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 = `0x6060604052600360045534156200001557600080fd5b604051620016af380380620016af833981016040528080518201919060200180518201919060200180519190602001805191906020018051919060200180519190602001805160058690556006859055600784905560088190559150600090505b87518110156200028757600380546001810162000094838262000295565b916000526020600020900160008a8481518110620000ae57fe5b90602001906020020151909190916101000a815481600160a060020a030219169083600160a060020a031602179055505060806040519081016040528087600160a060020a03168152602001602060405190810160409081526000825290825260016020830152018883815181106200012357fe5b906020019060200201519052600160008a84815181106200014057fe5b90602001906020020151600160a060020a03168152602081019190915260400160002081518154600160a060020a031916600160a060020a03919091161781556020820151816001019080516200019c929160200190620002c1565b50604082015160028201805460ff191691151591909117905560608201516003909101555060026000898381518110620001d257fe5b90602001906020020151600160a060020a03168152602081019190915260400160002080546001810162000207838262000295565b50600091825260208220018054600160a060020a031916600160a060020a038916179055600554600380549192600192909190859081106200024557fe5b6000918252602080832090910154600160a060020a0390811684528382019490945260409283018220938b168252600490930190925290205560010162000076565b505050505050505062000366565b815481835581811511620002bc57600083815260209020620002bc91810190830162000346565b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200030457805160ff191683800117855562000334565b8280016001018555821562000334579182015b828111156200033457825182559160200191906001019062000317565b506200034292915062000346565b5090565b6200036391905b808211156200034257600081556001016200034d565b90565b61133980620003766000396000f3006060604052600436106101115763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302aa9be2811461011657806306a49fce1461013a5780632d15cc04146101a05780632f9c4bba146101bf578063302b6872146101d25780633477ee2e14610209578063441a3e701461023b57806358e7525f146102545780636a000d74146102735780636dd7d8ea146102d25780637d40257f146102e6578063a9a981a31461037c578063a9ff959e1461038f578063ae6e43f5146103a2578063b642facd146103c1578063d09f1ab4146103e0578063d161c767146103f3578063d51b9e9314610406578063d55b7dff14610439578063d6f0948c1461044c575b600080fd5b341561012157600080fd5b610138600160a060020a036004351660243561046c565b005b341561014557600080fd5b61014d610634565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561018c578082015183820152602001610174565b505050509050019250505060405180910390f35b34156101ab57600080fd5b61014d600160a060020a036004351661069d565b34156101ca57600080fd5b61014d61072a565b34156101dd57600080fd5b6101f7600160a060020a03600435811690602435166107ac565b60405190815260200160405180910390f35b341561021457600080fd5b61021f6004356107db565b604051600160a060020a03909116815260200160405180910390f35b341561024657600080fd5b610138600435602435610803565b341561025f57600080fd5b6101f7600160a060020a036004351661096a565b341561027e57600080fd5b61013860048035600160a060020a03169060446024803590810190830135806020601f8201819004810201604051908101604052818152929190602084018383808284375094965061098895505050505050565b610138600160a060020a0360043516610a99565b34156102f157600080fd5b610305600160a060020a0360043516610c46565b60405160208082528190810183818151815260200191508051906020019080838360005b83811015610341578082015183820152602001610329565b50505050905090810190601f16801561036e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561038757600080fd5b6101f7610d0c565b341561039a57600080fd5b6101f7610d12565b34156103ad57600080fd5b610138600160a060020a0360043516610d18565b34156103cc57600080fd5b61021f600160a060020a0360043516610f8b565b34156103eb57600080fd5b6101f7610fa9565b34156103fe57600080fd5b6101f7610faf565b341561041157600080fd5b610425600160a060020a0360043516610fb5565b604051901515815260200160405180910390f35b341561044457600080fd5b6101f7610fd6565b61013860048035600160a060020a03169060248035908101910135610fdc565b600160a060020a038083166000908152600160209081526040808320339094168352600490930190529081205483908390819010156104aa57600080fd5b600160a060020a0385166000908152600160205260409020600301546104d6908563ffffffff61121216565b600160a060020a0380871660009081526001602090815260408083206003810195909555339093168252600490930190925290205461051b908563ffffffff61121216565b600160a060020a038087166000908152600160209081526040808320339094168352600490930190522055600854610559904363ffffffff61122416565b600160a060020a03331660009081526020818152604080832084845290915290205490935061058e908563ffffffff61122416565b600160a060020a03331660008181526020818152604080832088845280835290832094909455918152905260019081018054909181016105ce838261123a565b5060009182526020909120018390557faa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2338686604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050505050565b61063c611263565b600380548060200260200160405190810160405280929190818152602001828054801561069257602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610674575b505050505090505b90565b6106a5611263565b6002600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561071e57602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610700575b50505050509050919050565b610732611263565b60008033600160a060020a0316600160a060020a0316815260200190815260200160002060010180548060200260200160405190810160405280929190818152602001828054801561069257602002820191906000526020600020905b81548152602001906001019080831161078f575050505050905090565b600160a060020a0391821660009081526001602090815260408083209390941682526004909201909152205490565b60038054829081106107e957fe5b600091825260209091200154600160a060020a0316905081565b6000828282821161081357600080fd5b438290101561082157600080fd5b600160a060020a0333166000908152602081815260408083208584529091528120541161084d57600080fd5b600160a060020a033316600090815260208190526040902060010180548391908390811061087757fe5b6000918252602090912001541461088d57600080fd5b600160a060020a033316600081815260208181526040808320898452808352908320805490849055938352919052600101805491945090859081106108ce57fe5b6000918252602082200155600160a060020a03331683156108fc0284604051600060405180830381858888f19350505050151561090a57600080fd5b7ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b5683386856040518084600160a060020a0316600160a060020a03168152602001838152602001828152602001935050505060405180910390a15050505050565b600160a060020a031660009081526001602052604090206003015490565b600160a060020a0382811660009081526001602052604090205483913381169116146109b357600080fd5b600160a060020a0383166000908152600160208190526040909120018280516109e0929160200190611275565b507f0e421c04ccd34fafbe77c6b2f9384de8c5c4795114325fedb698a6ce62b2d744338484604051600160a060020a0380851682528316602082015260606040820181815290820183818151815260200191508051906020019080838360005b83811015610a58578082015183820152602001610a40565b50505050905090810190601f168015610a855780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1505050565b600160a060020a038116600090815260016020526040902060020154819060ff161515610ac557600080fd5b600160a060020a038216600090815260016020526040902060030154610af1903463ffffffff61122416565b600160a060020a038084166000908152600160209081526040808320600381019590955533909316825260049093019092529020541515610b8757600160a060020a0382166000908152600260205260409020805460018101610b54838261123a565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790555b600160a060020a038083166000908152600160209081526040808320339094168352600490930190522054610bc2903463ffffffff61122416565b600160a060020a03808416600090815260016020908152604080832033948516845260040190915290819020929092557f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc918490349051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050565b610c4e611263565b6001600083600160a060020a0316600160a060020a031681526020019081526020016000206001018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561071e5780601f10610cdf5761010080835404028352916020019161071e565b820191906000526020600020905b815481529060010190602001808311610ced5750939695505050505050565b60045481565b60085481565b600160a060020a038181166000908152600160205260408120549091829182918591338216911614610d4957600080fd5b600160a060020a038516600090815260016020526040902060020154859060ff161515610d7557600080fd5b600160a060020a0386166000908152600160205260408120600201805460ff191690556004805460001901905594505b600354851015610e275785600160a060020a0316600386815481101515610dc857fe5b600091825260209091200154600160a060020a03161415610e1c576003805486908110610df157fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19169055610e27565b600190940193610da5565b600160a060020a038087166000818152600160208181526040808420339096168452600486018252832054939092529052600390910154909450610e71908563ffffffff61121216565b600160a060020a03808816600090815260016020908152604080832060038101959095553390931682526004909301909252812055600754610eb9904363ffffffff61122416565b600160a060020a033316600090815260208181526040808320848452909152902054909350610eee908563ffffffff61122416565b600160a060020a0333166000818152602081815260408083208884528083529083209490945591815290526001908101805490918101610f2e838261123a565b5060009182526020909120018390557f4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d33387604051600160a060020a039283168152911660208201526040908101905180910390a1505050505050565b600160a060020a039081166000908152600160205260409020541690565b60065481565b60075481565b600160a060020a031660009081526001602052604090206002015460ff1690565b60055481565b600554341015610feb57600080fd5b600160a060020a038316600090815260016020526040902060020154839060ff161561101657600080fd5b6003805460018101611028838261123a565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03861617905560806040519081016040528033600160a060020a0316815260200184848080601f016020809104026020016040519081016040528181529291906020840183838082843750505092845250506001602080840182905234604094850152600160a060020a03891660009081529190529190912090508151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0391909116178155602082015181600101908051611113929160200190611275565b50604082015160028201805460ff1916911515919091179055606082015160039091015550600160a060020a038085166000818152600160208181526040808420339096168452600495860182528084203490558554830190955592825260029092529190912080549091810161118a838261123a565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0386161790557f7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1338534604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b60008282111561121e57fe5b50900390565b60008282018381101561123357fe5b9392505050565b81548183558181151161125e5760008381526020902061125e9181019083016112f3565b505050565b60206040519081016040526000815290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106112b657805160ff19168380011785556112e3565b828001600101855582156112e3579182015b828111156112e35782518255916020019190600101906112c8565b506112ef9291506112f3565b5090565b61069a91905b808211156112ef57600081556001016112f95600a165627a7a72305820a422640f0a57494daef9fc6216d5369240b95deaca2773f8c354cdfdecc913940029` // 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, _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) + 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 } @@ -540,6 +337,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) @@ -618,30 +441,30 @@ func (_TomoValidator *TomoValidatorCallerSession) GetCandidateCap(_candidate com return _TomoValidator.Contract.GetCandidateCap(&_TomoValidator.CallOpts, _candidate) } -// GetCandidateNodeUrl is a free data retrieval call binding the contract method 0xda67b599. +// GetCandidateNodeId is a free data retrieval call binding the contract method 0x7d40257f. // -// Solidity: function getCandidateNodeUrl(_candidate address) constant returns(string) -func (_TomoValidator *TomoValidatorCaller) GetCandidateNodeUrl(opts *bind.CallOpts, _candidate common.Address) (string, error) { +// Solidity: function getCandidateNodeId(_candidate address) constant returns(string) +func (_TomoValidator *TomoValidatorCaller) GetCandidateNodeId(opts *bind.CallOpts, _candidate common.Address) (string, error) { var ( ret0 = new(string) ) out := ret0 - err := _TomoValidator.contract.Call(opts, out, "getCandidateNodeUrl", _candidate) + err := _TomoValidator.contract.Call(opts, out, "getCandidateNodeId", _candidate) return *ret0, err } -// GetCandidateNodeUrl is a free data retrieval call binding the contract method 0xda67b599. +// GetCandidateNodeId is a free data retrieval call binding the contract method 0x7d40257f. // -// Solidity: function getCandidateNodeUrl(_candidate address) constant returns(string) -func (_TomoValidator *TomoValidatorSession) GetCandidateNodeUrl(_candidate common.Address) (string, error) { - return _TomoValidator.Contract.GetCandidateNodeUrl(&_TomoValidator.CallOpts, _candidate) +// Solidity: function getCandidateNodeId(_candidate address) constant returns(string) +func (_TomoValidator *TomoValidatorSession) GetCandidateNodeId(_candidate common.Address) (string, error) { + return _TomoValidator.Contract.GetCandidateNodeId(&_TomoValidator.CallOpts, _candidate) } -// GetCandidateNodeUrl is a free data retrieval call binding the contract method 0xda67b599. +// GetCandidateNodeId is a free data retrieval call binding the contract method 0x7d40257f. // -// Solidity: function getCandidateNodeUrl(_candidate address) constant returns(string) -func (_TomoValidator *TomoValidatorCallerSession) GetCandidateNodeUrl(_candidate common.Address) (string, error) { - return _TomoValidator.Contract.GetCandidateNodeUrl(&_TomoValidator.CallOpts, _candidate) +// Solidity: function getCandidateNodeId(_candidate address) constant returns(string) +func (_TomoValidator *TomoValidatorCallerSession) GetCandidateNodeId(_candidate common.Address) (string, error) { + return _TomoValidator.Contract.GetCandidateNodeId(&_TomoValidator.CallOpts, _candidate) } // GetCandidateOwner is a free data retrieval call binding the contract method 0xb642facd. @@ -670,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[]) @@ -774,6 +571,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,25 +675,51 @@ func (_TomoValidator *TomoValidatorCallerSession) MinCandidateCap() (*big.Int, e return _TomoValidator.Contract.MinCandidateCap(&_TomoValidator.CallOpts) } -// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. +// VoterWithdrawDelay is a free data retrieval call binding the contract method 0xa9ff959e. // -// Solidity: function propose(_candidate address, _nodeUrl string) returns() -func (_TomoValidator *TomoValidatorTransactor) Propose(opts *bind.TransactOpts, _candidate common.Address, _nodeUrl string) (*types.Transaction, error) { - return _TomoValidator.contract.Transact(opts, "propose", _candidate, _nodeUrl) +// 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() -func (_TomoValidator *TomoValidatorSession) Propose(_candidate common.Address, _nodeUrl string) (*types.Transaction, error) { - return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts, _candidate, _nodeUrl) +// Solidity: function propose(_candidate address, _nodeId string) returns() +func (_TomoValidator *TomoValidatorTransactor) Propose(opts *bind.TransactOpts, _candidate common.Address, _nodeId string) (*types.Transaction, error) { + return _TomoValidator.contract.Transact(opts, "propose", _candidate, _nodeId) } // Propose is a paid mutator transaction binding the contract method 0xd6f0948c. // -// Solidity: function propose(_candidate address, _nodeUrl string) returns() -func (_TomoValidator *TomoValidatorTransactorSession) Propose(_candidate common.Address, _nodeUrl string) (*types.Transaction, error) { - return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts, _candidate, _nodeUrl) +// Solidity: function propose(_candidate address, _nodeId string) returns() +func (_TomoValidator *TomoValidatorSession) Propose(_candidate common.Address, _nodeId string) (*types.Transaction, error) { + return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts, _candidate, _nodeId) +} + +// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. +// +// Solidity: function propose(_candidate address, _nodeId string) returns() +func (_TomoValidator *TomoValidatorTransactorSession) Propose(_candidate common.Address, _nodeId string) (*types.Transaction, error) { + return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts, _candidate, _nodeId) } // Resign is a paid mutator transaction binding the contract method 0xae6e43f5. @@ -894,25 +743,25 @@ func (_TomoValidator *TomoValidatorTransactorSession) Resign(_candidate common.A return _TomoValidator.Contract.Resign(&_TomoValidator.TransactOpts, _candidate) } -// SetNodeUrl is a paid mutator transaction binding the contract method 0xa3ec7965. +// SetNodeId is a paid mutator transaction binding the contract method 0x6a000d74. // -// Solidity: function setNodeUrl(_candidate address, _nodeUrl string) returns() -func (_TomoValidator *TomoValidatorTransactor) SetNodeUrl(opts *bind.TransactOpts, _candidate common.Address, _nodeUrl string) (*types.Transaction, error) { - return _TomoValidator.contract.Transact(opts, "setNodeUrl", _candidate, _nodeUrl) +// Solidity: function setNodeId(_candidate address, _nodeId string) returns() +func (_TomoValidator *TomoValidatorTransactor) SetNodeId(opts *bind.TransactOpts, _candidate common.Address, _nodeId string) (*types.Transaction, error) { + return _TomoValidator.contract.Transact(opts, "setNodeId", _candidate, _nodeId) } -// SetNodeUrl is a paid mutator transaction binding the contract method 0xa3ec7965. +// SetNodeId is a paid mutator transaction binding the contract method 0x6a000d74. // -// Solidity: function setNodeUrl(_candidate address, _nodeUrl string) returns() -func (_TomoValidator *TomoValidatorSession) SetNodeUrl(_candidate common.Address, _nodeUrl string) (*types.Transaction, error) { - return _TomoValidator.Contract.SetNodeUrl(&_TomoValidator.TransactOpts, _candidate, _nodeUrl) +// Solidity: function setNodeId(_candidate address, _nodeId string) returns() +func (_TomoValidator *TomoValidatorSession) SetNodeId(_candidate common.Address, _nodeId string) (*types.Transaction, error) { + return _TomoValidator.Contract.SetNodeId(&_TomoValidator.TransactOpts, _candidate, _nodeId) } -// SetNodeUrl is a paid mutator transaction binding the contract method 0xa3ec7965. +// SetNodeId is a paid mutator transaction binding the contract method 0x6a000d74. // -// Solidity: function setNodeUrl(_candidate address, _nodeUrl string) returns() -func (_TomoValidator *TomoValidatorTransactorSession) SetNodeUrl(_candidate common.Address, _nodeUrl string) (*types.Transaction, error) { - return _TomoValidator.Contract.SetNodeUrl(&_TomoValidator.TransactOpts, _candidate, _nodeUrl) +// Solidity: function setNodeId(_candidate address, _nodeId string) returns() +func (_TomoValidator *TomoValidatorTransactorSession) SetNodeId(_candidate common.Address, _nodeId string) (*types.Transaction, error) { + return _TomoValidator.Contract.SetNodeId(&_TomoValidator.TransactOpts, _candidate, _nodeId) } // Unvote is a paid mutator transaction binding the contract method 0x02aa9be2. @@ -957,25 +806,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. @@ -1225,9 +1074,9 @@ func (_TomoValidator *TomoValidatorFilterer) WatchResign(opts *bind.WatchOpts, s }), nil } -// TomoValidatorSetNodeUrlIterator is returned from FilterSetNodeUrl and is used to iterate over the raw logs and unpacked data for SetNodeUrl events raised by the TomoValidator contract. -type TomoValidatorSetNodeUrlIterator struct { - Event *TomoValidatorSetNodeUrl // Event containing the contract specifics and raw log +// TomoValidatorSetNodeIdIterator is returned from FilterSetNodeId and is used to iterate over the raw logs and unpacked data for SetNodeId events raised by the TomoValidator contract. +type TomoValidatorSetNodeIdIterator struct { + Event *TomoValidatorSetNodeId // Event containing the contract specifics and raw log contract *bind.BoundContract // Generic contract to use for unpacking event data event string // Event name to use for unpacking event data @@ -1241,7 +1090,7 @@ type TomoValidatorSetNodeUrlIterator struct { // Next advances the iterator to the subsequent event, returning whether there // are any more events found. In case of a retrieval or parsing error, false is // returned and Error() can be queried for the exact failure. -func (it *TomoValidatorSetNodeUrlIterator) Next() bool { +func (it *TomoValidatorSetNodeIdIterator) Next() bool { // If the iterator failed, stop iterating if it.fail != nil { return false @@ -1250,7 +1099,7 @@ func (it *TomoValidatorSetNodeUrlIterator) Next() bool { if it.done { select { case log := <-it.logs: - it.Event = new(TomoValidatorSetNodeUrl) + it.Event = new(TomoValidatorSetNodeId) if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { it.fail = err return false @@ -1265,7 +1114,7 @@ func (it *TomoValidatorSetNodeUrlIterator) Next() bool { // Iterator still in progress, wait for either a data or an error event select { case log := <-it.logs: - it.Event = new(TomoValidatorSetNodeUrl) + it.Event = new(TomoValidatorSetNodeId) if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { it.fail = err return false @@ -1281,43 +1130,43 @@ func (it *TomoValidatorSetNodeUrlIterator) Next() bool { } // Error returns any retrieval or parsing error occurred during filtering. -func (it *TomoValidatorSetNodeUrlIterator) Error() error { +func (it *TomoValidatorSetNodeIdIterator) Error() error { return it.fail } // Close terminates the iteration process, releasing any pending underlying // resources. -func (it *TomoValidatorSetNodeUrlIterator) Close() error { +func (it *TomoValidatorSetNodeIdIterator) Close() error { it.sub.Unsubscribe() return nil } -// TomoValidatorSetNodeUrl represents a SetNodeUrl event raised by the TomoValidator contract. -type TomoValidatorSetNodeUrl struct { +// TomoValidatorSetNodeId represents a SetNodeId event raised by the TomoValidator contract. +type TomoValidatorSetNodeId struct { Owner common.Address Candidate common.Address - NodeUrl string + NodeId string Raw types.Log // Blockchain specific contextual infos } -// FilterSetNodeUrl is a free log retrieval operation binding the contract event 0x63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4. +// FilterSetNodeId is a free log retrieval operation binding the contract event 0x0e421c04ccd34fafbe77c6b2f9384de8c5c4795114325fedb698a6ce62b2d744. // -// Solidity: event SetNodeUrl(_owner address, _candidate address, _nodeUrl string) -func (_TomoValidator *TomoValidatorFilterer) FilterSetNodeUrl(opts *bind.FilterOpts) (*TomoValidatorSetNodeUrlIterator, error) { +// Solidity: event SetNodeId(_owner address, _candidate address, _nodeId string) +func (_TomoValidator *TomoValidatorFilterer) FilterSetNodeId(opts *bind.FilterOpts) (*TomoValidatorSetNodeIdIterator, error) { - logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "SetNodeUrl") + logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "SetNodeId") if err != nil { return nil, err } - return &TomoValidatorSetNodeUrlIterator{contract: _TomoValidator.contract, event: "SetNodeUrl", logs: logs, sub: sub}, nil + return &TomoValidatorSetNodeIdIterator{contract: _TomoValidator.contract, event: "SetNodeId", logs: logs, sub: sub}, nil } -// WatchSetNodeUrl is a free log subscription operation binding the contract event 0x63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4. +// WatchSetNodeId is a free log subscription operation binding the contract event 0x0e421c04ccd34fafbe77c6b2f9384de8c5c4795114325fedb698a6ce62b2d744. // -// Solidity: event SetNodeUrl(_owner address, _candidate address, _nodeUrl string) -func (_TomoValidator *TomoValidatorFilterer) WatchSetNodeUrl(opts *bind.WatchOpts, sink chan<- *TomoValidatorSetNodeUrl) (event.Subscription, error) { +// Solidity: event SetNodeId(_owner address, _candidate address, _nodeId string) +func (_TomoValidator *TomoValidatorFilterer) WatchSetNodeId(opts *bind.WatchOpts, sink chan<- *TomoValidatorSetNodeId) (event.Subscription, error) { - logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "SetNodeUrl") + logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "SetNodeId") if err != nil { return nil, err } @@ -1327,8 +1176,8 @@ func (_TomoValidator *TomoValidatorFilterer) WatchSetNodeUrl(opts *bind.WatchOpt select { case log := <-logs: // New log arrived, parse the event and forward to the user - event := new(TomoValidatorSetNodeUrl) - if err := _TomoValidator.contract.UnpackLog(event, "SetNodeUrl", log); err != nil { + event := new(TomoValidatorSetNodeId) + if err := _TomoValidator.contract.UnpackLog(event, "SetNodeId", log); err != nil { return err } event.Raw = log @@ -1666,15 +1515,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 +1533,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 0279bfc5ad..3e75806d15 100644 --- a/contracts/validator/validator.go +++ b/contracts/validator/validator.go @@ -42,8 +42,10 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address, }, nil } -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)) +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) + 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 9eb1bb21eb..c00df0514b 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -16,17 +16,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 ( @@ -46,12 +48,25 @@ func TestValidator(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) transactOpts := bind.NewKeyedTransactor(key) - _, 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) } contractBackend.Commit() + d := time.Now().Add(1000 * time.Millisecond) + 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 { + 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) @@ -76,7 +91,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)) + // 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) } @@ -124,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 {