From a095b84ec5a35cb3432380cc677d4e244b4a137f Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 28 Mar 2018 14:35:41 +0200 Subject: [PATCH 01/15] travis.yml: remove sudo requirement for PPA and Azure purge builders (#16404) This is supposed to fix the FTP upload issue according to travis-ci/travis-ci#9391. --- .travis.yml | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index cade11700f..40d940de0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,14 +47,12 @@ matrix: script: - go run build/ci.go lint - # This builder does the Ubuntu PPA and Linux Azure uploads + # This builder does the Ubuntu PPA upload - os: linux dist: trusty - sudo: required go: "1.10" env: - ubuntu-ppa - - azure-linux git: submodules: false # avoid cloning ethereum/tests addons: @@ -63,11 +61,25 @@ matrix: - devscripts - debhelper - dput - - gcc-multilib - fakeroot script: - # Build for the primary platforms that Trusty can manage - go run build/ci.go debsrc -signer "Go Ethereum Linux Builder " -upload ppa:ethereum/ethereum + + # This builder does the Linux Azure uploads + - os: linux + dist: trusty + sudo: required + go: "1.10" + env: + - azure-linux + git: + submodules: false # avoid cloning ethereum/tests + addons: + apt: + packages: + - gcc-multilib + script: + # Build for the primary platforms that Trusty can manage - go run build/ci.go install - go run build/ci.go archive -type tar -signer LINUX_SIGNING_KEY -upload gethstore/builds - go run build/ci.go install -arch 386 @@ -181,7 +193,6 @@ matrix: # This builder does the Azure archive purges to avoid accumulating junk - os: linux dist: trusty - sudo: required go: "1.10" env: - azure-purge From 2832a8059af8d21941f6de152a48c3781e2deadb Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Tue, 3 Apr 2018 16:08:53 +0700 Subject: [PATCH 02/15] geth: remove relOracle variable --- cmd/geth/main.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 061384d1b3..b7219f8880 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -46,8 +46,6 @@ const ( var ( // Git SHA1 commit hash of the release (set via linker flags) gitCommit = "" - // Ethereum address of the Geth release oracle. - relOracle = common.HexToAddress("0xfa7b9770ca4cb04296cac84f37736d4041251cdf") // The app that holds all commands and flags. app = utils.NewApp(gitCommit, "the go-ethereum command line interface") // flags that configure the node From c3cd2003a4a85cac6c5207a0e943c328c3bf7e00 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 3 Apr 2018 17:10:12 +0200 Subject: [PATCH 03/15] cmd/geth: remove unused import --- cmd/geth/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b7219f8880..d94154245f 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -28,7 +28,6 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/console" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethclient" From 43b0d1a20e443c02dbc6a35271a9833ae7eba015 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Mon, 9 Apr 2018 10:42:58 +0000 Subject: [PATCH 04/15] add support vim --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3e0009e167..f81ec22a3c 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,9 @@ profile.cov # VS Code .vscode +# Vim +.*.sw* + # dashboard /dashboard/assets/flow-typed /dashboard/assets/node_modules From 1d24f2f33dbc90954559df34629dbcf86a9c942e Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Tue, 10 Apr 2018 10:30:39 +0000 Subject: [PATCH 05/15] add validator contract --- .../validator/contract/TomoValidator.sol | 49 ++ .../contract/interfaces/IValidator.sol | 5 + .../validator/contract/libs/SafeMath.sol | 47 ++ contracts/validator/contract/validator.go | 560 ++++++++++++++++++ 4 files changed, 661 insertions(+) create mode 100644 contracts/validator/contract/TomoValidator.sol create mode 100644 contracts/validator/contract/interfaces/IValidator.sol create mode 100644 contracts/validator/contract/libs/SafeMath.sol create mode 100644 contracts/validator/contract/validator.go diff --git a/contracts/validator/contract/TomoValidator.sol b/contracts/validator/contract/TomoValidator.sol new file mode 100644 index 0000000000..513ed03c89 --- /dev/null +++ b/contracts/validator/contract/TomoValidator.sol @@ -0,0 +1,49 @@ +pragma solidity ^0.4.21; + +import "./interfaces/IValidator.sol"; +import "./libs/SafeMath.sol"; + +contract TomoValidator is IValidator { + using SafeMath for uint256; + + struct ValidatorState { + bool isValidator; + bool isCandidate; + uint256 cap; + } + + mapping(address => ValidatorState) validatorsState; + uint256 threshold = 1000 * 10** 18; // 1000 TOMO + + function TomoValidator(address[] _validators, uint256[] _caps) public { + + for (uint256 i = 0; i < _validators.length; i++) { + validatorsState[_validators[i]] = ValidatorState({ + isValidator: true, + isCandidate: true, + cap: _caps[i] + }); + } + + } + + function propose(address _candidate) external payable { + // only validator can propose a candidate + require(validatorsState[msg.sender].isValidator); + validatorsState[_candidate] = ValidatorState({ + isValidator: false, + isCandidate: true, + cap: msg.value + }); + + } + + function vote(address _candidate) public payable { + // only vote for candidate proposed by a validator + require(validatorsState[_candidate].isCandidate); + validatorsState[_candidate].cap = validatorsState[_candidate].cap.add(msg.value); + if (validatorsState[_candidate].cap >= threshold) { + validatorsState[_candidate].isValidator = true; + } + } +} diff --git a/contracts/validator/contract/interfaces/IValidator.sol b/contracts/validator/contract/interfaces/IValidator.sol new file mode 100644 index 0000000000..b4a07a5d30 --- /dev/null +++ b/contracts/validator/contract/interfaces/IValidator.sol @@ -0,0 +1,5 @@ +pragma solidity ^0.4.21; + +interface IValidator { + function propose(address) external payable; +} diff --git a/contracts/validator/contract/libs/SafeMath.sol b/contracts/validator/contract/libs/SafeMath.sol new file mode 100644 index 0000000000..9c9a2bd22f --- /dev/null +++ b/contracts/validator/contract/libs/SafeMath.sol @@ -0,0 +1,47 @@ +pragma solidity ^0.4.21; + +/** + * @title SafeMath + * @dev Math operations with safety checks that throw on error + */ +library SafeMath { + + /** + * @dev Multiplies two numbers, throws on overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + /** + * @dev Integer division of two numbers, truncating the quotient. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + // assert(b > 0); // Solidity automatically throws when dividing by 0 + // uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + return a / b; + } + + /** + * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + /** + * @dev Adds two numbers, throws on overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} diff --git a/contracts/validator/contract/validator.go b/contracts/validator/contract/validator.go new file mode 100644 index 0000000000..6c5db002bc --- /dev/null +++ b/contracts/validator/contract/validator.go @@ -0,0 +1,560 @@ +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package contract + +import ( + "math/big" + "strings" + + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" +) + +// IValidatorABI is the input ABI used to generate the binding from. +const IValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"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 0x01267951. +// +// Solidity: function propose( address) returns() +func (_IValidator *IValidatorTransactor) Propose(opts *bind.TransactOpts, arg0 common.Address) (*types.Transaction, error) { + return _IValidator.contract.Transact(opts, "propose", arg0) +} + +// Propose is a paid mutator transaction binding the contract method 0x01267951. +// +// Solidity: function propose( address) returns() +func (_IValidator *IValidatorSession) Propose(arg0 common.Address) (*types.Transaction, error) { + return _IValidator.Contract.Propose(&_IValidator.TransactOpts, arg0) +} + +// Propose is a paid mutator transaction binding the contract method 0x01267951. +// +// Solidity: function propose( address) returns() +func (_IValidator *IValidatorTransactorSession) Propose(arg0 common.Address) (*types.Transaction, error) { + return _IValidator.Contract.Propose(&_IValidator.TransactOpts, arg0) +} + +// SafeMathABI is the input ABI used to generate the binding from. +const SafeMathABI = "[]" + +// SafeMathBin is the compiled bytecode used for deploying new contracts. +const SafeMathBin = `0x604c602c600b82828239805160001a60731460008114601c57601e565bfe5b5030600052607381538281f30073000000000000000000000000000000000000000030146060604052600080fd00a165627a7a72305820b9407d48ebc7efee5c9f08b3b3a957df2939281f5913225e8c1291f069b900490029` + +// DeploySafeMath deploys a new Ethereum contract, binding an instance of SafeMath to it. +func DeploySafeMath(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *SafeMath, error) { + parsed, err := abi.JSON(strings.NewReader(SafeMathABI)) + if err != nil { + return common.Address{}, nil, nil, err + } + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(SafeMathBin), backend) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, tx, &SafeMath{SafeMathCaller: SafeMathCaller{contract: contract}, SafeMathTransactor: SafeMathTransactor{contract: contract}, SafeMathFilterer: SafeMathFilterer{contract: contract}}, nil +} + +// SafeMath is an auto generated Go binding around an Ethereum contract. +type SafeMath struct { + SafeMathCaller // Read-only binding to the contract + SafeMathTransactor // Write-only binding to the contract + SafeMathFilterer // Log filterer for contract events +} + +// SafeMathCaller is an auto generated read-only Go binding around an Ethereum contract. +type SafeMathCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// SafeMathTransactor is an auto generated write-only Go binding around an Ethereum contract. +type SafeMathTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// SafeMathFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type SafeMathFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// SafeMathSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type SafeMathSession struct { + Contract *SafeMath // 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 +} + +// SafeMathCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type SafeMathCallerSession struct { + Contract *SafeMathCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// SafeMathTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type SafeMathTransactorSession struct { + Contract *SafeMathTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// SafeMathRaw is an auto generated low-level Go binding around an Ethereum contract. +type SafeMathRaw struct { + Contract *SafeMath // Generic contract binding to access the raw methods on +} + +// SafeMathCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type SafeMathCallerRaw struct { + Contract *SafeMathCaller // Generic read-only contract binding to access the raw methods on +} + +// SafeMathTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type SafeMathTransactorRaw struct { + Contract *SafeMathTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewSafeMath creates a new instance of SafeMath, bound to a specific deployed contract. +func NewSafeMath(address common.Address, backend bind.ContractBackend) (*SafeMath, error) { + contract, err := bindSafeMath(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &SafeMath{SafeMathCaller: SafeMathCaller{contract: contract}, SafeMathTransactor: SafeMathTransactor{contract: contract}, SafeMathFilterer: SafeMathFilterer{contract: contract}}, nil +} + +// NewSafeMathCaller creates a new read-only instance of SafeMath, bound to a specific deployed contract. +func NewSafeMathCaller(address common.Address, caller bind.ContractCaller) (*SafeMathCaller, error) { + contract, err := bindSafeMath(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &SafeMathCaller{contract: contract}, nil +} + +// NewSafeMathTransactor creates a new write-only instance of SafeMath, bound to a specific deployed contract. +func NewSafeMathTransactor(address common.Address, transactor bind.ContractTransactor) (*SafeMathTransactor, error) { + contract, err := bindSafeMath(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &SafeMathTransactor{contract: contract}, nil +} + +// NewSafeMathFilterer creates a new log filterer instance of SafeMath, bound to a specific deployed contract. +func NewSafeMathFilterer(address common.Address, filterer bind.ContractFilterer) (*SafeMathFilterer, error) { + contract, err := bindSafeMath(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &SafeMathFilterer{contract: contract}, nil +} + +// bindSafeMath binds a generic wrapper to an already deployed contract. +func bindSafeMath(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(SafeMathABI)) + 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 (_SafeMath *SafeMathRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _SafeMath.Contract.SafeMathCaller.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 (_SafeMath *SafeMathRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _SafeMath.Contract.SafeMathTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_SafeMath *SafeMathRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _SafeMath.Contract.SafeMathTransactor.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 (_SafeMath *SafeMathCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _SafeMath.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 (_SafeMath *SafeMathTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _SafeMath.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _SafeMath.Contract.contract.Transact(opts, method, params...) +} + +// TomoValidatorABI is the input ABI used to generate the binding from. +const TomoValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_validators\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" + +// TomoValidatorBin is the compiled bytecode used for deploying new contracts. +const TomoValidatorBin = `0x6060604052683635c9adc5dea00000600155341561001c57600080fd5b6040516102ed3803806102ed83398101604052808051820191906020018051909101905060005b82518110156100eb576060604051908101604090815260018083526020830152810183838151811061007157fe5b90602001906020020151905260008085848151811061008c57fe5b90602001906020020151600160a060020a0316815260208101919091526040016000208151815460ff1916901515178155602082015181549015156101000261ff00199091161781556040820151600191820155919091019050610043565b5050506101f0806100fd6000396000f30060606040526004361061004b5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630126795181146100505780636dd7d8ea14610066575b600080fd5b610064600160a060020a036004351661007a565b005b610064600160a060020a0360043516610108565b600160a060020a03331660009081526020819052604090205460ff1615156100a157600080fd5b60606040519081016040908152600080835260016020808501919091523483850152600160a060020a0385168252819052208151815460ff1916901515178155602082015181549015156101000261ff001990911617815560408201516001909101555050565b600160a060020a038116600090815260208190526040902054610100900460ff16151561013457600080fd5b600160a060020a038116600090815260208190526040902060010154610160903463ffffffff6101ae16565b600160a060020a038216600090815260208190526040902060019081018290555490106101ab57600160a060020a0381166000908152602081905260409020805460ff191660011790555b50565b6000828201838110156101bd57fe5b93925050505600a165627a7a7230582022f965615b62147c104c686c2a37c0d96bf4b82497507420007f36a8c04a2a400029` + +// DeployTomoValidator deploys a new Ethereum contract, binding an instance of TomoValidator to it. +func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _validators []common.Address, _caps []*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, _validators, _caps) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, tx, &TomoValidator{TomoValidatorCaller: TomoValidatorCaller{contract: contract}, TomoValidatorTransactor: TomoValidatorTransactor{contract: contract}, TomoValidatorFilterer: TomoValidatorFilterer{contract: contract}}, nil +} + +// TomoValidator is an auto generated Go binding around an Ethereum contract. +type TomoValidator struct { + TomoValidatorCaller // Read-only binding to the contract + TomoValidatorTransactor // Write-only binding to the contract + TomoValidatorFilterer // Log filterer for contract events +} + +// TomoValidatorCaller is an auto generated read-only Go binding around an Ethereum contract. +type TomoValidatorCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// TomoValidatorTransactor is an auto generated write-only Go binding around an Ethereum contract. +type TomoValidatorTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// TomoValidatorFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type TomoValidatorFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// TomoValidatorSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type TomoValidatorSession struct { + Contract *TomoValidator // 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 +} + +// TomoValidatorCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type TomoValidatorCallerSession struct { + Contract *TomoValidatorCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// TomoValidatorTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type TomoValidatorTransactorSession struct { + Contract *TomoValidatorTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// TomoValidatorRaw is an auto generated low-level Go binding around an Ethereum contract. +type TomoValidatorRaw struct { + Contract *TomoValidator // Generic contract binding to access the raw methods on +} + +// TomoValidatorCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type TomoValidatorCallerRaw struct { + Contract *TomoValidatorCaller // Generic read-only contract binding to access the raw methods on +} + +// TomoValidatorTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type TomoValidatorTransactorRaw struct { + Contract *TomoValidatorTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewTomoValidator creates a new instance of TomoValidator, bound to a specific deployed contract. +func NewTomoValidator(address common.Address, backend bind.ContractBackend) (*TomoValidator, error) { + contract, err := bindTomoValidator(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &TomoValidator{TomoValidatorCaller: TomoValidatorCaller{contract: contract}, TomoValidatorTransactor: TomoValidatorTransactor{contract: contract}, TomoValidatorFilterer: TomoValidatorFilterer{contract: contract}}, nil +} + +// NewTomoValidatorCaller creates a new read-only instance of TomoValidator, bound to a specific deployed contract. +func NewTomoValidatorCaller(address common.Address, caller bind.ContractCaller) (*TomoValidatorCaller, error) { + contract, err := bindTomoValidator(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &TomoValidatorCaller{contract: contract}, nil +} + +// NewTomoValidatorTransactor creates a new write-only instance of TomoValidator, bound to a specific deployed contract. +func NewTomoValidatorTransactor(address common.Address, transactor bind.ContractTransactor) (*TomoValidatorTransactor, error) { + contract, err := bindTomoValidator(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &TomoValidatorTransactor{contract: contract}, nil +} + +// NewTomoValidatorFilterer creates a new log filterer instance of TomoValidator, bound to a specific deployed contract. +func NewTomoValidatorFilterer(address common.Address, filterer bind.ContractFilterer) (*TomoValidatorFilterer, error) { + contract, err := bindTomoValidator(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &TomoValidatorFilterer{contract: contract}, nil +} + +// bindTomoValidator binds a generic wrapper to an already deployed contract. +func bindTomoValidator(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(TomoValidatorABI)) + 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 (_TomoValidator *TomoValidatorRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _TomoValidator.Contract.TomoValidatorCaller.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 (_TomoValidator *TomoValidatorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _TomoValidator.Contract.TomoValidatorTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_TomoValidator *TomoValidatorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _TomoValidator.Contract.TomoValidatorTransactor.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 (_TomoValidator *TomoValidatorCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _TomoValidator.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 (_TomoValidator *TomoValidatorTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _TomoValidator.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_TomoValidator *TomoValidatorTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _TomoValidator.Contract.contract.Transact(opts, method, params...) +} + +// Propose is a paid mutator transaction binding the contract method 0x01267951. +// +// Solidity: function propose(_candidate address) returns() +func (_TomoValidator *TomoValidatorTransactor) Propose(opts *bind.TransactOpts, _candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.contract.Transact(opts, "propose", _candidate) +} + +// Propose is a paid mutator transaction binding the contract method 0x01267951. +// +// Solidity: function propose(_candidate address) returns() +func (_TomoValidator *TomoValidatorSession) Propose(_candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts, _candidate) +} + +// Propose is a paid mutator transaction binding the contract method 0x01267951. +// +// Solidity: function propose(_candidate address) returns() +func (_TomoValidator *TomoValidatorTransactorSession) Propose(_candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts, _candidate) +} + +// Vote is a paid mutator transaction binding the contract method 0x6dd7d8ea. +// +// Solidity: function vote(_candidate address) returns() +func (_TomoValidator *TomoValidatorTransactor) Vote(opts *bind.TransactOpts, _candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.contract.Transact(opts, "vote", _candidate) +} + +// Vote is a paid mutator transaction binding the contract method 0x6dd7d8ea. +// +// Solidity: function vote(_candidate address) returns() +func (_TomoValidator *TomoValidatorSession) Vote(_candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.Contract.Vote(&_TomoValidator.TransactOpts, _candidate) +} + +// Vote is a paid mutator transaction binding the contract method 0x6dd7d8ea. +// +// Solidity: function vote(_candidate address) returns() +func (_TomoValidator *TomoValidatorTransactorSession) Vote(_candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.Contract.Vote(&_TomoValidator.TransactOpts, _candidate) +} From 29a7cf8f2bb3645c7dc309abec34322de1bb34b4 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Fri, 13 Apr 2018 09:29:15 +0000 Subject: [PATCH 06/15] update validator smart contract --- .../validator/contract/TomoValidator.sol | 49 +++- contracts/validator/contract/validator.go | 233 +++++++++++++++++- 2 files changed, 279 insertions(+), 3 deletions(-) diff --git a/contracts/validator/contract/TomoValidator.sol b/contracts/validator/contract/TomoValidator.sol index 513ed03c89..4b9ed33fef 100644 --- a/contracts/validator/contract/TomoValidator.sol +++ b/contracts/validator/contract/TomoValidator.sol @@ -10,13 +10,18 @@ contract TomoValidator is IValidator { bool isValidator; bool isCandidate; uint256 cap; + mapping(address => uint256) voters; } mapping(address => ValidatorState) validatorsState; + address[] public validators; + address[] public candidates; uint256 threshold = 1000 * 10** 18; // 1000 TOMO function TomoValidator(address[] _validators, uint256[] _caps) public { - + validators = _validators; + candidates = _validators; + for (uint256 i = 0; i < _validators.length; i++) { validatorsState[_validators[i]] = ValidatorState({ isValidator: true, @@ -30,6 +35,9 @@ contract TomoValidator is IValidator { function propose(address _candidate) external payable { // only validator can propose a candidate require(validatorsState[msg.sender].isValidator); + if (!validatorsState[_candidate].isCandidate) { + candidates.push(_candidate); + } validatorsState[_candidate] = ValidatorState({ isValidator: false, isCandidate: true, @@ -43,7 +51,46 @@ contract TomoValidator is IValidator { require(validatorsState[_candidate].isCandidate); validatorsState[_candidate].cap = validatorsState[_candidate].cap.add(msg.value); if (validatorsState[_candidate].cap >= threshold) { + if (!validatorsState[_candidate].isValidator) { + validators.push(_candidate); + } validatorsState[_candidate].isValidator = true; + validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].add(msg.value); } } + + function getValidators() public view returns(address[]) { + return validators; + } + + function getCandidates() public view returns(address[]) { + return candidates; + } + + function getCandidateCap(address _candidate) public view returns(uint256) { + return validatorsState[_candidate].cap; + } + + function getVoterCap(address _candidate, address _voter) public view returns(uint256) { + return validatorsState[_candidate].voters[_voter]; + } + + function isValidator(address _candidate) public view returns(bool) { + return validatorsState[_candidate].isValidator; + } + + function isCandidate(address _candidate) public view returns(bool) { + return validatorsState[_candidate].isCandidate; + } + + function unvote(address _candidate, uint256 _cap) public { + // only unvote for candidate who does not become validator yet + require(!validatorsState[_candidate].isValidator); + require(validatorsState[_candidate].isCandidate); + require(validatorsState[_candidate].voters[msg.sender] >= _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); + } } diff --git a/contracts/validator/contract/validator.go b/contracts/validator/contract/validator.go index 6c5db002bc..593442a3f2 100644 --- a/contracts/validator/contract/validator.go +++ b/contracts/validator/contract/validator.go @@ -357,10 +357,10 @@ 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\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_validators\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" +const TomoValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"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\":\"_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\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"validators\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"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\":true,\"inputs\":[],\"name\":\"getValidators\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"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\":\"_candidate\",\"type\":\"address\"}],\"name\":\"isValidator\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_validators\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" // TomoValidatorBin is the compiled bytecode used for deploying new contracts. -const TomoValidatorBin = `0x6060604052683635c9adc5dea00000600155341561001c57600080fd5b6040516102ed3803806102ed83398101604052808051820191906020018051909101905060005b82518110156100eb576060604051908101604090815260018083526020830152810183838151811061007157fe5b90602001906020020151905260008085848151811061008c57fe5b90602001906020020151600160a060020a0316815260208101919091526040016000208151815460ff1916901515178155602082015181549015156101000261ff00199091161781556040820151600191820155919091019050610043565b5050506101f0806100fd6000396000f30060606040526004361061004b5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630126795181146100505780636dd7d8ea14610066575b600080fd5b610064600160a060020a036004351661007a565b005b610064600160a060020a0360043516610108565b600160a060020a03331660009081526020819052604090205460ff1615156100a157600080fd5b60606040519081016040908152600080835260016020808501919091523483850152600160a060020a0385168252819052208151815460ff1916901515178155602082015181549015156101000261ff001990911617815560408201516001909101555050565b600160a060020a038116600090815260208190526040902054610100900460ff16151561013457600080fd5b600160a060020a038116600090815260208190526040902060010154610160903463ffffffff6101ae16565b600160a060020a038216600090815260208190526040902060019081018290555490106101ab57600160a060020a0381166000908152602081905260409020805460ff191660011790555b50565b6000828201838110156101bd57fe5b93925050505600a165627a7a7230582022f965615b62147c104c686c2a37c0d96bf4b82497507420007f36a8c04a2a400029` +const TomoValidatorBin = `0x6060604052683635c9adc5dea00000600355341561001c57600080fd5b604051610a06380380610a068339810160405280805182019190602001805190910190506000600183805161005592916020019061011f565b50600283805161006992916020019061011f565b50600090505b8251811015610117576060604051908101604090815260018083526020830152810183838151811061009d57fe5b9060200190602002015190526000808584815181106100b857fe5b90602001906020020151600160a060020a0316815260208101919091526040016000208151815460ff1916901515178155602082015181549015156101000261ff0019909116178155604082015160019182015591909101905061006f565b5050506101ad565b828054828255906000526020600020908101928215610176579160200282015b828111156101765782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019061013f565b50610182929150610186565b5090565b6101aa91905b80821115610182578054600160a060020a031916815560010161018c565b90565b61084a806101bc6000396000f3006060604052600436106100ae5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630126795181146100b357806302aa9be2146100c957806306a49fce146100eb578063302b6872146101515780633477ee2e1461018857806335aa2e44146101ba57806358e7525f146101d05780636dd7d8ea146101ef578063b7ab4db514610203578063d51b9e9314610216578063facd743b14610249575b600080fd5b6100c7600160a060020a0360043516610268565b005b34156100d457600080fd5b6100c7600160a060020a0360043516602435610362565b34156100f657600080fd5b6100fe6104b6565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561013d578082015183820152602001610125565b505050509050019250505060405180910390f35b341561015c57600080fd5b610176600160a060020a036004358116906024351661051f565b60405190815260200160405180910390f35b341561019357600080fd5b61019e60043561054c565b604051600160a060020a03909116815260200160405180910390f35b34156101c557600080fd5b61019e600435610574565b34156101db57600080fd5b610176600160a060020a0360043516610582565b6100c7600160a060020a03600435166105a0565b341561020e57600080fd5b6100fe6106f6565b341561022157600080fd5b610235600160a060020a036004351661075c565b604051901515815260200160405180910390f35b341561025457600080fd5b610235600160a060020a036004351661077f565b600160a060020a03331660009081526020819052604090205460ff16151561028f57600080fd5b600160a060020a038116600090815260208190526040902054610100900460ff1615156102fb5760028054600181016102c883826107c5565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b60606040519081016040908152600080835260016020808501919091523483850152600160a060020a0385168252819052208151815460ff1916901515178155602082015181549015156101000261ff001990911617815560408201516001909101555050565b600160a060020a03821660009081526020819052604090205460ff161561038857600080fd5b600160a060020a038216600090815260208190526040902054610100900460ff1615156103b457600080fd5b600160a060020a03808316600090815260208181526040808320339094168352600290930190522054819010156103ea57600080fd5b600160a060020a038216600090815260208190526040902060010154610416908263ffffffff61079d16565b600160a060020a0380841660009081526020818152604080832060018101959095553390931682526002909301909252902054610459908263ffffffff61079d16565b600160a060020a0380841660009081526020818152604080832033909416808452600290940190915290819020929092559082156108fc0290839051600060405180830381858888f1935050505015156104b257600080fd5b5050565b6104be6107ee565b600280548060200260200160405190810160405280929190818152602001828054801561051457602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116104f6575b505050505090505b90565b600160a060020a039182166000908152602081815260408083209390941682526002909201909152205490565b600280548290811061055a57fe5b600091825260209091200154600160a060020a0316905081565b600180548290811061055a57fe5b600160a060020a031660009081526020819052604090206001015490565b600160a060020a038116600090815260208190526040902054610100900460ff1615156105cc57600080fd5b600160a060020a0381166000908152602081905260409020600101546105f8903463ffffffff6107af16565b600160a060020a038216600090815260208190526040902060010181905560035490106106f357600160a060020a03811660009081526020819052604090205460ff161515610685576001805480820161065283826107c5565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b600160a060020a03808216600090815260208181526040808320805460ff191660011781553390941683526002909301905220546106c9903463ffffffff6107af16565b600160a060020a038083166000908152602081815260408083203390941683526002909301905220555b50565b6106fe6107ee565b600180548060200260200160405190810160405280929190818152602001828054801561051457602002820191906000526020600020908154600160a060020a031681526001909101906020018083116104f6575050505050905090565b600160a060020a0316600090815260208190526040902054610100900460ff1690565b600160a060020a031660009081526020819052604090205460ff1690565b6000828211156107a957fe5b50900390565b6000828201838110156107be57fe5b9392505050565b8154818355818115116107e9576000838152602090206107e9918101908301610800565b505050565b60206040519081016040526000815290565b61051c91905b8082111561081a5760008155600101610806565b50905600a165627a7a723058202ad1e9fda0e95a1d0040266c6438e7a86b19a47ec3debbaaf3a2ce2608178ff50029` // DeployTomoValidator deploys a new Ethereum contract, binding an instance of TomoValidator to it. func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _validators []common.Address, _caps []*big.Int) (common.Address, *types.Transaction, *TomoValidator, error) { @@ -517,6 +517,214 @@ func (_TomoValidator *TomoValidatorTransactorRaw) Transact(opts *bind.TransactOp return _TomoValidator.Contract.contract.Transact(opts, method, params...) } +// Candidates is a free data retrieval call binding the contract method 0x3477ee2e. +// +// Solidity: function candidates( uint256) constant returns(address) +func (_TomoValidator *TomoValidatorCaller) Candidates(opts *bind.CallOpts, arg0 *big.Int) (common.Address, error) { + var ( + ret0 = new(common.Address) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "candidates", arg0) + return *ret0, err +} + +// Candidates is a free data retrieval call binding the contract method 0x3477ee2e. +// +// Solidity: function candidates( uint256) constant returns(address) +func (_TomoValidator *TomoValidatorSession) Candidates(arg0 *big.Int) (common.Address, error) { + return _TomoValidator.Contract.Candidates(&_TomoValidator.CallOpts, arg0) +} + +// Candidates is a free data retrieval call binding the contract method 0x3477ee2e. +// +// Solidity: function candidates( uint256) constant returns(address) +func (_TomoValidator *TomoValidatorCallerSession) Candidates(arg0 *big.Int) (common.Address, error) { + return _TomoValidator.Contract.Candidates(&_TomoValidator.CallOpts, arg0) +} + +// GetCandidateCap is a free data retrieval call binding the contract method 0x58e7525f. +// +// Solidity: function getCandidateCap(_candidate address) constant returns(uint256) +func (_TomoValidator *TomoValidatorCaller) GetCandidateCap(opts *bind.CallOpts, _candidate common.Address) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "getCandidateCap", _candidate) + return *ret0, err +} + +// GetCandidateCap is a free data retrieval call binding the contract method 0x58e7525f. +// +// Solidity: function getCandidateCap(_candidate address) constant returns(uint256) +func (_TomoValidator *TomoValidatorSession) GetCandidateCap(_candidate common.Address) (*big.Int, error) { + return _TomoValidator.Contract.GetCandidateCap(&_TomoValidator.CallOpts, _candidate) +} + +// GetCandidateCap is a free data retrieval call binding the contract method 0x58e7525f. +// +// Solidity: function getCandidateCap(_candidate address) constant returns(uint256) +func (_TomoValidator *TomoValidatorCallerSession) GetCandidateCap(_candidate common.Address) (*big.Int, error) { + return _TomoValidator.Contract.GetCandidateCap(&_TomoValidator.CallOpts, _candidate) +} + +// GetCandidates is a free data retrieval call binding the contract method 0x06a49fce. +// +// Solidity: function getCandidates() constant returns(address[]) +func (_TomoValidator *TomoValidatorCaller) GetCandidates(opts *bind.CallOpts) ([]common.Address, error) { + var ( + ret0 = new([]common.Address) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "getCandidates") + return *ret0, err +} + +// GetCandidates is a free data retrieval call binding the contract method 0x06a49fce. +// +// Solidity: function getCandidates() constant returns(address[]) +func (_TomoValidator *TomoValidatorSession) GetCandidates() ([]common.Address, error) { + return _TomoValidator.Contract.GetCandidates(&_TomoValidator.CallOpts) +} + +// GetCandidates is a free data retrieval call binding the contract method 0x06a49fce. +// +// Solidity: function getCandidates() constant returns(address[]) +func (_TomoValidator *TomoValidatorCallerSession) GetCandidates() ([]common.Address, error) { + return _TomoValidator.Contract.GetCandidates(&_TomoValidator.CallOpts) +} + +// GetValidators is a free data retrieval call binding the contract method 0xb7ab4db5. +// +// Solidity: function getValidators() constant returns(address[]) +func (_TomoValidator *TomoValidatorCaller) GetValidators(opts *bind.CallOpts) ([]common.Address, error) { + var ( + ret0 = new([]common.Address) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "getValidators") + return *ret0, err +} + +// GetValidators is a free data retrieval call binding the contract method 0xb7ab4db5. +// +// Solidity: function getValidators() constant returns(address[]) +func (_TomoValidator *TomoValidatorSession) GetValidators() ([]common.Address, error) { + return _TomoValidator.Contract.GetValidators(&_TomoValidator.CallOpts) +} + +// GetValidators is a free data retrieval call binding the contract method 0xb7ab4db5. +// +// Solidity: function getValidators() constant returns(address[]) +func (_TomoValidator *TomoValidatorCallerSession) GetValidators() ([]common.Address, error) { + return _TomoValidator.Contract.GetValidators(&_TomoValidator.CallOpts) +} + +// GetVoterCap is a free data retrieval call binding the contract method 0x302b6872. +// +// Solidity: function getVoterCap(_candidate address, _voter address) constant returns(uint256) +func (_TomoValidator *TomoValidatorCaller) GetVoterCap(opts *bind.CallOpts, _candidate common.Address, _voter common.Address) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "getVoterCap", _candidate, _voter) + return *ret0, err +} + +// GetVoterCap is a free data retrieval call binding the contract method 0x302b6872. +// +// Solidity: function getVoterCap(_candidate address, _voter address) constant returns(uint256) +func (_TomoValidator *TomoValidatorSession) GetVoterCap(_candidate common.Address, _voter common.Address) (*big.Int, error) { + return _TomoValidator.Contract.GetVoterCap(&_TomoValidator.CallOpts, _candidate, _voter) +} + +// GetVoterCap is a free data retrieval call binding the contract method 0x302b6872. +// +// Solidity: function getVoterCap(_candidate address, _voter address) constant returns(uint256) +func (_TomoValidator *TomoValidatorCallerSession) GetVoterCap(_candidate common.Address, _voter common.Address) (*big.Int, error) { + return _TomoValidator.Contract.GetVoterCap(&_TomoValidator.CallOpts, _candidate, _voter) +} + +// IsCandidate is a free data retrieval call binding the contract method 0xd51b9e93. +// +// Solidity: function isCandidate(_candidate address) constant returns(bool) +func (_TomoValidator *TomoValidatorCaller) IsCandidate(opts *bind.CallOpts, _candidate common.Address) (bool, error) { + var ( + ret0 = new(bool) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "isCandidate", _candidate) + return *ret0, err +} + +// IsCandidate is a free data retrieval call binding the contract method 0xd51b9e93. +// +// Solidity: function isCandidate(_candidate address) constant returns(bool) +func (_TomoValidator *TomoValidatorSession) IsCandidate(_candidate common.Address) (bool, error) { + return _TomoValidator.Contract.IsCandidate(&_TomoValidator.CallOpts, _candidate) +} + +// IsCandidate is a free data retrieval call binding the contract method 0xd51b9e93. +// +// Solidity: function isCandidate(_candidate address) constant returns(bool) +func (_TomoValidator *TomoValidatorCallerSession) IsCandidate(_candidate common.Address) (bool, error) { + return _TomoValidator.Contract.IsCandidate(&_TomoValidator.CallOpts, _candidate) +} + +// IsValidator is a free data retrieval call binding the contract method 0xfacd743b. +// +// Solidity: function isValidator(_candidate address) constant returns(bool) +func (_TomoValidator *TomoValidatorCaller) IsValidator(opts *bind.CallOpts, _candidate common.Address) (bool, error) { + var ( + ret0 = new(bool) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "isValidator", _candidate) + return *ret0, err +} + +// IsValidator is a free data retrieval call binding the contract method 0xfacd743b. +// +// Solidity: function isValidator(_candidate address) constant returns(bool) +func (_TomoValidator *TomoValidatorSession) IsValidator(_candidate common.Address) (bool, error) { + return _TomoValidator.Contract.IsValidator(&_TomoValidator.CallOpts, _candidate) +} + +// IsValidator is a free data retrieval call binding the contract method 0xfacd743b. +// +// Solidity: function isValidator(_candidate address) constant returns(bool) +func (_TomoValidator *TomoValidatorCallerSession) IsValidator(_candidate common.Address) (bool, error) { + return _TomoValidator.Contract.IsValidator(&_TomoValidator.CallOpts, _candidate) +} + +// Validators is a free data retrieval call binding the contract method 0x35aa2e44. +// +// Solidity: function validators( uint256) constant returns(address) +func (_TomoValidator *TomoValidatorCaller) Validators(opts *bind.CallOpts, arg0 *big.Int) (common.Address, error) { + var ( + ret0 = new(common.Address) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "validators", arg0) + return *ret0, err +} + +// Validators is a free data retrieval call binding the contract method 0x35aa2e44. +// +// Solidity: function validators( uint256) constant returns(address) +func (_TomoValidator *TomoValidatorSession) Validators(arg0 *big.Int) (common.Address, error) { + return _TomoValidator.Contract.Validators(&_TomoValidator.CallOpts, arg0) +} + +// Validators is a free data retrieval call binding the contract method 0x35aa2e44. +// +// Solidity: function validators( uint256) constant returns(address) +func (_TomoValidator *TomoValidatorCallerSession) Validators(arg0 *big.Int) (common.Address, error) { + return _TomoValidator.Contract.Validators(&_TomoValidator.CallOpts, arg0) +} + // Propose is a paid mutator transaction binding the contract method 0x01267951. // // Solidity: function propose(_candidate address) returns() @@ -538,6 +746,27 @@ func (_TomoValidator *TomoValidatorTransactorSession) Propose(_candidate common. return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts, _candidate) } +// Unvote is a paid mutator transaction binding the contract method 0x02aa9be2. +// +// Solidity: function unvote(_candidate address, _cap uint256) returns() +func (_TomoValidator *TomoValidatorTransactor) Unvote(opts *bind.TransactOpts, _candidate common.Address, _cap *big.Int) (*types.Transaction, error) { + return _TomoValidator.contract.Transact(opts, "unvote", _candidate, _cap) +} + +// Unvote is a paid mutator transaction binding the contract method 0x02aa9be2. +// +// Solidity: function unvote(_candidate address, _cap uint256) returns() +func (_TomoValidator *TomoValidatorSession) Unvote(_candidate common.Address, _cap *big.Int) (*types.Transaction, error) { + return _TomoValidator.Contract.Unvote(&_TomoValidator.TransactOpts, _candidate, _cap) +} + +// Unvote is a paid mutator transaction binding the contract method 0x02aa9be2. +// +// Solidity: function unvote(_candidate address, _cap uint256) returns() +func (_TomoValidator *TomoValidatorTransactorSession) Unvote(_candidate common.Address, _cap *big.Int) (*types.Transaction, error) { + return _TomoValidator.Contract.Unvote(&_TomoValidator.TransactOpts, _candidate, _cap) +} + // Vote is a paid mutator transaction binding the contract method 0x6dd7d8ea. // // Solidity: function vote(_candidate address) returns() From 53e2f7cd46df9f26601262a0f79e6d56a7ca9788 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Mon, 16 Apr 2018 12:04:27 +0000 Subject: [PATCH 07/15] add deploy script and test --- contracts/validator/validator.go | 41 +++++++++++++++++++++++++++ contracts/validator/validator_test.go | 32 +++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 contracts/validator/validator.go create mode 100644 contracts/validator/validator_test.go diff --git a/contracts/validator/validator.go b/contracts/validator/validator.go new file mode 100644 index 0000000000..2f13600620 --- /dev/null +++ b/contracts/validator/validator.go @@ -0,0 +1,41 @@ +package validator + +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/contracts/validator/contract" +) + +type Validator struct { + *contract.TomoValidatorSession + contractBackend bind.ContractBackend +} + +func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*Validator, error) { + validator, err := contract.NewTomoValidator(contractAddr, contractBackend) + if err != nil { + return nil, err + } + + return &Validator{ + &contract.TomoValidatorSession{ + Contract: validator, + TransactOpts: *transactOpts, + }, + contractBackend, + }, nil +} + +func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *Validator, error) { + validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, nil, nil) + if err != nil { + return validatorAddr, nil, err + } + + validator, err := NewValidator(transactOpts, validatorAddr, contractBackend) + if err != nil { + return validatorAddr, nil, err + } + + return validatorAddr, validator, nil +} diff --git a/contracts/validator/validator_test.go b/contracts/validator/validator_test.go new file mode 100644 index 0000000000..ef3124fa83 --- /dev/null +++ b/contracts/validator/validator_test.go @@ -0,0 +1,32 @@ +package validator + +import ( + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/crypto" +) + +var ( + key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + addr = crypto.PubkeyToAddress(key.PublicKey) +) + +func TestENS(t *testing.T) { + contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) + transactOpts := bind.NewKeyedTransactor(key) + + _, validator, err := DeployValidator(transactOpts, contractBackend) + if err != nil { + t.Fatalf("can't deploy root registry: %v", err) + } + contractBackend.Commit() + + if _, err := validator.GetValidators(); err != nil { + t.Fatalf("can't get validators: %v", err) + } + contractBackend.Commit() +} From 246d18729442b85a1563b73c3670c99daca508de Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Tue, 17 Apr 2018 07:23:26 +0000 Subject: [PATCH 08/15] get candidates list --- .../validator/contract/TomoValidator.sol | 39 ++------- contracts/validator/contract/validator.go | 86 +------------------ contracts/validator/validator.go | 5 +- contracts/validator/validator_test.go | 10 ++- 4 files changed, 23 insertions(+), 117 deletions(-) diff --git a/contracts/validator/contract/TomoValidator.sol b/contracts/validator/contract/TomoValidator.sol index 4b9ed33fef..e56fcf04e7 100644 --- a/contracts/validator/contract/TomoValidator.sol +++ b/contracts/validator/contract/TomoValidator.sol @@ -7,60 +7,45 @@ contract TomoValidator is IValidator { using SafeMath for uint256; struct ValidatorState { - bool isValidator; bool isCandidate; uint256 cap; mapping(address => uint256) voters; } mapping(address => ValidatorState) validatorsState; - address[] public validators; address[] public candidates; - uint256 threshold = 1000 * 10** 18; // 1000 TOMO + uint256 candidateCount = 0; - function TomoValidator(address[] _validators, uint256[] _caps) public { - validators = _validators; - candidates = _validators; + function TomoValidator(address[] _candidates, uint256[] _caps) public { + candidates = _candidates; - for (uint256 i = 0; i < _validators.length; i++) { - validatorsState[_validators[i]] = ValidatorState({ - isValidator: true, + for (uint256 i = 0; i < _candidates.length; i++) { + validatorsState[_candidates[i]] = ValidatorState({ isCandidate: true, cap: _caps[i] }); + candidateCount = candidateCount + 1; } } function propose(address _candidate) external payable { - // only validator can propose a candidate - require(validatorsState[msg.sender].isValidator); + // TOMO: only validator can propose a candidate if (!validatorsState[_candidate].isCandidate) { candidates.push(_candidate); } validatorsState[_candidate] = ValidatorState({ - isValidator: false, isCandidate: true, cap: msg.value }); - + candidateCount = candidateCount + 1; } function vote(address _candidate) public payable { // only vote for candidate proposed by a validator require(validatorsState[_candidate].isCandidate); validatorsState[_candidate].cap = validatorsState[_candidate].cap.add(msg.value); - if (validatorsState[_candidate].cap >= threshold) { - if (!validatorsState[_candidate].isValidator) { - validators.push(_candidate); - } - validatorsState[_candidate].isValidator = true; - validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].add(msg.value); - } - } - - function getValidators() public view returns(address[]) { - return validators; + validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].add(msg.value); } function getCandidates() public view returns(address[]) { @@ -75,17 +60,11 @@ contract TomoValidator is IValidator { return validatorsState[_candidate].voters[_voter]; } - function isValidator(address _candidate) public view returns(bool) { - return validatorsState[_candidate].isValidator; - } - function isCandidate(address _candidate) public view returns(bool) { return validatorsState[_candidate].isCandidate; } function unvote(address _candidate, uint256 _cap) public { - // only unvote for candidate who does not become validator yet - require(!validatorsState[_candidate].isValidator); require(validatorsState[_candidate].isCandidate); require(validatorsState[_candidate].voters[msg.sender] >= _cap); validatorsState[_candidate].cap = validatorsState[_candidate].cap.sub(_cap); diff --git a/contracts/validator/contract/validator.go b/contracts/validator/contract/validator.go index 593442a3f2..149822641d 100644 --- a/contracts/validator/contract/validator.go +++ b/contracts/validator/contract/validator.go @@ -357,18 +357,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\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"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\":\"_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\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"validators\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"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\":true,\"inputs\":[],\"name\":\"getValidators\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"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\":\"_candidate\",\"type\":\"address\"}],\"name\":\"isValidator\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_validators\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" +const TomoValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"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\":\"_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\":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\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"isCandidate\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_candidates\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" // TomoValidatorBin is the compiled bytecode used for deploying new contracts. -const TomoValidatorBin = `0x6060604052683635c9adc5dea00000600355341561001c57600080fd5b604051610a06380380610a068339810160405280805182019190602001805190910190506000600183805161005592916020019061011f565b50600283805161006992916020019061011f565b50600090505b8251811015610117576060604051908101604090815260018083526020830152810183838151811061009d57fe5b9060200190602002015190526000808584815181106100b857fe5b90602001906020020151600160a060020a0316815260208101919091526040016000208151815460ff1916901515178155602082015181549015156101000261ff0019909116178155604082015160019182015591909101905061006f565b5050506101ad565b828054828255906000526020600020908101928215610176579160200282015b828111156101765782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019061013f565b50610182929150610186565b5090565b6101aa91905b80821115610182578054600160a060020a031916815560010161018c565b90565b61084a806101bc6000396000f3006060604052600436106100ae5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630126795181146100b357806302aa9be2146100c957806306a49fce146100eb578063302b6872146101515780633477ee2e1461018857806335aa2e44146101ba57806358e7525f146101d05780636dd7d8ea146101ef578063b7ab4db514610203578063d51b9e9314610216578063facd743b14610249575b600080fd5b6100c7600160a060020a0360043516610268565b005b34156100d457600080fd5b6100c7600160a060020a0360043516602435610362565b34156100f657600080fd5b6100fe6104b6565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561013d578082015183820152602001610125565b505050509050019250505060405180910390f35b341561015c57600080fd5b610176600160a060020a036004358116906024351661051f565b60405190815260200160405180910390f35b341561019357600080fd5b61019e60043561054c565b604051600160a060020a03909116815260200160405180910390f35b34156101c557600080fd5b61019e600435610574565b34156101db57600080fd5b610176600160a060020a0360043516610582565b6100c7600160a060020a03600435166105a0565b341561020e57600080fd5b6100fe6106f6565b341561022157600080fd5b610235600160a060020a036004351661075c565b604051901515815260200160405180910390f35b341561025457600080fd5b610235600160a060020a036004351661077f565b600160a060020a03331660009081526020819052604090205460ff16151561028f57600080fd5b600160a060020a038116600090815260208190526040902054610100900460ff1615156102fb5760028054600181016102c883826107c5565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b60606040519081016040908152600080835260016020808501919091523483850152600160a060020a0385168252819052208151815460ff1916901515178155602082015181549015156101000261ff001990911617815560408201516001909101555050565b600160a060020a03821660009081526020819052604090205460ff161561038857600080fd5b600160a060020a038216600090815260208190526040902054610100900460ff1615156103b457600080fd5b600160a060020a03808316600090815260208181526040808320339094168352600290930190522054819010156103ea57600080fd5b600160a060020a038216600090815260208190526040902060010154610416908263ffffffff61079d16565b600160a060020a0380841660009081526020818152604080832060018101959095553390931682526002909301909252902054610459908263ffffffff61079d16565b600160a060020a0380841660009081526020818152604080832033909416808452600290940190915290819020929092559082156108fc0290839051600060405180830381858888f1935050505015156104b257600080fd5b5050565b6104be6107ee565b600280548060200260200160405190810160405280929190818152602001828054801561051457602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116104f6575b505050505090505b90565b600160a060020a039182166000908152602081815260408083209390941682526002909201909152205490565b600280548290811061055a57fe5b600091825260209091200154600160a060020a0316905081565b600180548290811061055a57fe5b600160a060020a031660009081526020819052604090206001015490565b600160a060020a038116600090815260208190526040902054610100900460ff1615156105cc57600080fd5b600160a060020a0381166000908152602081905260409020600101546105f8903463ffffffff6107af16565b600160a060020a038216600090815260208190526040902060010181905560035490106106f357600160a060020a03811660009081526020819052604090205460ff161515610685576001805480820161065283826107c5565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b600160a060020a03808216600090815260208181526040808320805460ff191660011781553390941683526002909301905220546106c9903463ffffffff6107af16565b600160a060020a038083166000908152602081815260408083203390941683526002909301905220555b50565b6106fe6107ee565b600180548060200260200160405190810160405280929190818152602001828054801561051457602002820191906000526020600020908154600160a060020a031681526001909101906020018083116104f6575050505050905090565b600160a060020a0316600090815260208190526040902054610100900460ff1690565b600160a060020a031660009081526020819052604090205460ff1690565b6000828211156107a957fe5b50900390565b6000828201838110156107be57fe5b9392505050565b8154818355818115116107e9576000838152602090206107e9918101908301610800565b505050565b60206040519081016040526000815290565b61051c91905b8082111561081a5760008155600101610806565b50905600a165627a7a723058202ad1e9fda0e95a1d0040266c6438e7a86b19a47ec3debbaaf3a2ce2608178ff50029` +const TomoValidatorBin = `0x60606040526000600255341561001457600080fd5b6040516107d63803806107d68339810160405280805182019190602001805190910190506000600183805161004d9291602001906100ec565b50600090505b82518110156100e45760408051908101604052600181526020810183838151811061007a57fe5b90602001906020020151905260008085848151811061009557fe5b90602001906020020151600160a060020a0316815260208101919091526040016000208151815460ff191690151517815560208201516001918201556002805482019055919091019050610053565b50505061017a565b828054828255906000526020600020908101928215610143579160200282015b828111156101435782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019061010c565b5061014f929150610153565b5090565b61017791905b8082111561014f578054600160a060020a0319168155600101610159565b90565b61064d806101896000396000f30060606040526004361061008d5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166301267951811461009257806302aa9be2146100a857806306a49fce146100ca578063302b6872146101305780633477ee2e1461016757806358e7525f146101995780636dd7d8ea146101b8578063d51b9e93146101cc575b600080fd5b6100a6600160a060020a03600435166101ff565b005b34156100b357600080fd5b6100a6600160a060020a03600435166024356102b9565b34156100d557600080fd5b6100dd6103e2565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561011c578082015183820152602001610104565b505050509050019250505060405180910390f35b341561013b57600080fd5b610155600160a060020a036004358116906024351661044b565b60405190815260200160405180910390f35b341561017257600080fd5b61017d600435610478565b604051600160a060020a03909116815260200160405180910390f35b34156101a457600080fd5b610155600160a060020a03600435166104a0565b6100a6600160a060020a03600435166104be565b34156101d757600080fd5b6101eb600160a060020a0360043516610582565b604051901515815260200160405180910390f35b600160a060020a03811660009081526020819052604090205460ff161515610265576001805480820161023283826105c8565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b6040805190810160409081526001825234602080840191909152600160a060020a038416600090815290819052208151815460ff191690151517815560208201516001918201556002805490910190555050565b600160a060020a03821660009081526020819052604090205460ff1615156102e057600080fd5b600160a060020a038083166000908152602081815260408083203390941683526002909301905220548190101561031657600080fd5b600160a060020a038216600090815260208190526040902060010154610342908263ffffffff6105a016565b600160a060020a0380841660009081526020818152604080832060018101959095553390931682526002909301909252902054610385908263ffffffff6105a016565b600160a060020a0380841660009081526020818152604080832033909416808452600290940190915290819020929092559082156108fc0290839051600060405180830381858888f1935050505015156103de57600080fd5b5050565b6103ea6105f1565b600180548060200260200160405190810160405280929190818152602001828054801561044057602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610422575b505050505090505b90565b600160a060020a039182166000908152602081815260408083209390941682526002909201909152205490565b600180548290811061048657fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a031660009081526020819052604090206001015490565b600160a060020a03811660009081526020819052604090205460ff1615156104e557600080fd5b600160a060020a038116600090815260208190526040902060010154610511903463ffffffff6105b216565b600160a060020a0380831660009081526020818152604080832060018101959095553390931682526002909301909252902054610554903463ffffffff6105b216565b600160a060020a03918216600090815260208181526040808320339095168352600290940190529190912055565b600160a060020a031660009081526020819052604090205460ff1690565b6000828211156105ac57fe5b50900390565b6000828201838110156105c157fe5b9392505050565b8154818355818115116105ec576000838152602090206105ec918101908301610603565b505050565b60206040519081016040526000815290565b61044891905b8082111561061d5760008155600101610609565b50905600a165627a7a723058204f35ebf7b5775f52742c989407a76898f3dcbfa948c7b047bd1768f7a5e1f2130029` // DeployTomoValidator deploys a new Ethereum contract, binding an instance of TomoValidator to it. -func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _validators []common.Address, _caps []*big.Int) (common.Address, *types.Transaction, *TomoValidator, error) { +func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _candidates []common.Address, _caps []*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, _validators, _caps) + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TomoValidatorBin), backend, _candidates, _caps) if err != nil { return common.Address{}, nil, nil, err } @@ -595,32 +595,6 @@ func (_TomoValidator *TomoValidatorCallerSession) GetCandidates() ([]common.Addr return _TomoValidator.Contract.GetCandidates(&_TomoValidator.CallOpts) } -// GetValidators is a free data retrieval call binding the contract method 0xb7ab4db5. -// -// Solidity: function getValidators() constant returns(address[]) -func (_TomoValidator *TomoValidatorCaller) GetValidators(opts *bind.CallOpts) ([]common.Address, error) { - var ( - ret0 = new([]common.Address) - ) - out := ret0 - err := _TomoValidator.contract.Call(opts, out, "getValidators") - return *ret0, err -} - -// GetValidators is a free data retrieval call binding the contract method 0xb7ab4db5. -// -// Solidity: function getValidators() constant returns(address[]) -func (_TomoValidator *TomoValidatorSession) GetValidators() ([]common.Address, error) { - return _TomoValidator.Contract.GetValidators(&_TomoValidator.CallOpts) -} - -// GetValidators is a free data retrieval call binding the contract method 0xb7ab4db5. -// -// Solidity: function getValidators() constant returns(address[]) -func (_TomoValidator *TomoValidatorCallerSession) GetValidators() ([]common.Address, error) { - return _TomoValidator.Contract.GetValidators(&_TomoValidator.CallOpts) -} - // GetVoterCap is a free data retrieval call binding the contract method 0x302b6872. // // Solidity: function getVoterCap(_candidate address, _voter address) constant returns(uint256) @@ -673,58 +647,6 @@ func (_TomoValidator *TomoValidatorCallerSession) IsCandidate(_candidate common. return _TomoValidator.Contract.IsCandidate(&_TomoValidator.CallOpts, _candidate) } -// IsValidator is a free data retrieval call binding the contract method 0xfacd743b. -// -// Solidity: function isValidator(_candidate address) constant returns(bool) -func (_TomoValidator *TomoValidatorCaller) IsValidator(opts *bind.CallOpts, _candidate common.Address) (bool, error) { - var ( - ret0 = new(bool) - ) - out := ret0 - err := _TomoValidator.contract.Call(opts, out, "isValidator", _candidate) - return *ret0, err -} - -// IsValidator is a free data retrieval call binding the contract method 0xfacd743b. -// -// Solidity: function isValidator(_candidate address) constant returns(bool) -func (_TomoValidator *TomoValidatorSession) IsValidator(_candidate common.Address) (bool, error) { - return _TomoValidator.Contract.IsValidator(&_TomoValidator.CallOpts, _candidate) -} - -// IsValidator is a free data retrieval call binding the contract method 0xfacd743b. -// -// Solidity: function isValidator(_candidate address) constant returns(bool) -func (_TomoValidator *TomoValidatorCallerSession) IsValidator(_candidate common.Address) (bool, error) { - return _TomoValidator.Contract.IsValidator(&_TomoValidator.CallOpts, _candidate) -} - -// Validators is a free data retrieval call binding the contract method 0x35aa2e44. -// -// Solidity: function validators( uint256) constant returns(address) -func (_TomoValidator *TomoValidatorCaller) Validators(opts *bind.CallOpts, arg0 *big.Int) (common.Address, error) { - var ( - ret0 = new(common.Address) - ) - out := ret0 - err := _TomoValidator.contract.Call(opts, out, "validators", arg0) - return *ret0, err -} - -// Validators is a free data retrieval call binding the contract method 0x35aa2e44. -// -// Solidity: function validators( uint256) constant returns(address) -func (_TomoValidator *TomoValidatorSession) Validators(arg0 *big.Int) (common.Address, error) { - return _TomoValidator.Contract.Validators(&_TomoValidator.CallOpts, arg0) -} - -// Validators is a free data retrieval call binding the contract method 0x35aa2e44. -// -// Solidity: function validators( uint256) constant returns(address) -func (_TomoValidator *TomoValidatorCallerSession) Validators(arg0 *big.Int) (common.Address, error) { - return _TomoValidator.Contract.Validators(&_TomoValidator.CallOpts, arg0) -} - // Propose is a paid mutator transaction binding the contract method 0x01267951. // // Solidity: function propose(_candidate address) returns() diff --git a/contracts/validator/validator.go b/contracts/validator/validator.go index 2f13600620..e3ae547855 100644 --- a/contracts/validator/validator.go +++ b/contracts/validator/validator.go @@ -4,6 +4,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/contracts/validator/contract" + "math/big" ) type Validator struct { @@ -26,8 +27,8 @@ 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, nil, nil) +func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, candidates []common.Address, caps []*big.Int) (common.Address, *Validator, error) { + validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, candidates, caps) if err != nil { return validatorAddr, nil, err } diff --git a/contracts/validator/validator_test.go b/contracts/validator/validator_test.go index ef3124fa83..db89b836ba 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -4,8 +4,10 @@ import ( "math/big" "testing" + "fmt" "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" ) @@ -19,14 +21,16 @@ func TestENS(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) transactOpts := bind.NewKeyedTransactor(key) - _, validator, err := DeployValidator(transactOpts, contractBackend) + _, validator, err := DeployValidator(transactOpts, contractBackend, []common.Address{addr}, []*big.Int{big.NewInt(0)}) if err != nil { t.Fatalf("can't deploy root registry: %v", err) } contractBackend.Commit() - if _, err := validator.GetValidators(); err != nil { - t.Fatalf("can't get validators: %v", err) + candidates, err := validator.GetCandidates() + if err != nil { + t.Fatalf("can't get candidates: %v", err) } + fmt.Println("candidates", candidates) contractBackend.Commit() } From d9ef1c4b90120fc3cfe920bc18aa40b9c4c191b4 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Tue, 17 Apr 2018 07:38:49 +0000 Subject: [PATCH 09/15] correct test log --- contracts/validator/validator_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contracts/validator/validator_test.go b/contracts/validator/validator_test.go index db89b836ba..3d97e3c451 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -4,7 +4,6 @@ import ( "math/big" "testing" - "fmt" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/common" @@ -17,7 +16,7 @@ var ( addr = crypto.PubkeyToAddress(key.PublicKey) ) -func TestENS(t *testing.T) { +func TestValidator(t *testing.T) { contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) transactOpts := bind.NewKeyedTransactor(key) @@ -31,6 +30,10 @@ func TestENS(t *testing.T) { if err != nil { t.Fatalf("can't get candidates: %v", err) } - fmt.Println("candidates", candidates) + t.Log("candidates", candidates) + for _, it := range candidates { + cap, _ := validator.GetCandidateCap(it) + t.Log("candidate", it.String(), "cap", cap) + } contractBackend.Commit() } From 101b4e3840e56cfdb5e93373877e476956f2697c Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Thu, 19 Apr 2018 03:48:18 +0000 Subject: [PATCH 10/15] update smart contract following new consensus --- .../validator/contract/TomoValidator.sol | 24 +- .../contract/interfaces/IValidator.sol | 3 +- contracts/validator/contract/validator.go | 401 ++++++++++++++++-- 3 files changed, 392 insertions(+), 36 deletions(-) diff --git a/contracts/validator/contract/TomoValidator.sol b/contracts/validator/contract/TomoValidator.sol index e56fcf04e7..5315bb0b22 100644 --- a/contracts/validator/contract/TomoValidator.sol +++ b/contracts/validator/contract/TomoValidator.sol @@ -6,6 +6,9 @@ import "./libs/SafeMath.sol"; contract TomoValidator is IValidator { using SafeMath for uint256; + event Vote(address _candidate, uint256 _cap); + event Unvote(address _candidate, uint256 _cap); + struct ValidatorState { bool isCandidate; uint256 cap; @@ -15,6 +18,9 @@ contract TomoValidator is IValidator { mapping(address => ValidatorState) validatorsState; address[] public candidates; uint256 candidateCount = 0; + uint256 public constant minCandidateCap = 10000 ether; + uint256 public constant maxCandidateNumber = 500; + uint256 public constant maxValidatorNumber = 99; function TomoValidator(address[] _candidates, uint256[] _caps) public { candidates = _candidates; @@ -29,23 +35,24 @@ contract TomoValidator is IValidator { } - function propose(address _candidate) external payable { - // TOMO: only validator can propose a candidate - if (!validatorsState[_candidate].isCandidate) { - candidates.push(_candidate); - } - validatorsState[_candidate] = ValidatorState({ + function propose() external payable { + // anyone can deposit 10000 TOMO to become a candidate + require(msg.value >= minCandidateCap); + require(!validatorsState[msg.sender].isCandidate); + require(candidateCount <= maxCandidateNumber); + candidates.push(msg.sender); + validatorsState[msg.sender] = ValidatorState({ isCandidate: true, cap: msg.value }); candidateCount = candidateCount + 1; } - function vote(address _candidate) public payable { - // only vote for candidate proposed by a validator + function vote(address _candidate) external payable { require(validatorsState[_candidate].isCandidate); validatorsState[_candidate].cap = validatorsState[_candidate].cap.add(msg.value); validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].add(msg.value); + emit Vote(_candidate, msg.value); } function getCandidates() public view returns(address[]) { @@ -71,5 +78,6 @@ contract TomoValidator is IValidator { validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].sub(_cap); // refunding to user after unvoting msg.sender.transfer(_cap); + emit Unvote(_candidate, _cap); } } diff --git a/contracts/validator/contract/interfaces/IValidator.sol b/contracts/validator/contract/interfaces/IValidator.sol index b4a07a5d30..9d216af6d4 100644 --- a/contracts/validator/contract/interfaces/IValidator.sol +++ b/contracts/validator/contract/interfaces/IValidator.sol @@ -1,5 +1,6 @@ pragma solidity ^0.4.21; interface IValidator { - function propose(address) external payable; + function propose() external payable; + function vote(address) external payable; } diff --git a/contracts/validator/contract/validator.go b/contracts/validator/contract/validator.go index 149822641d..be61ee0c4f 100644 --- a/contracts/validator/contract/validator.go +++ b/contracts/validator/contract/validator.go @@ -7,14 +7,16 @@ import ( "math/big" "strings" + ethereum "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "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\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"}]" +const IValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"}]" // IValidatorBin is the compiled bytecode used for deploying new contracts. const IValidatorBin = `0x` @@ -174,25 +176,46 @@ func (_IValidator *IValidatorTransactorRaw) Transact(opts *bind.TransactOpts, me return _IValidator.Contract.contract.Transact(opts, method, params...) } -// Propose is a paid mutator transaction binding the contract method 0x01267951. +// Propose is a paid mutator transaction binding the contract method 0xc198f8ba. // -// Solidity: function propose( address) returns() -func (_IValidator *IValidatorTransactor) Propose(opts *bind.TransactOpts, arg0 common.Address) (*types.Transaction, error) { - return _IValidator.contract.Transact(opts, "propose", arg0) +// Solidity: function propose() returns() +func (_IValidator *IValidatorTransactor) Propose(opts *bind.TransactOpts) (*types.Transaction, error) { + return _IValidator.contract.Transact(opts, "propose") } -// Propose is a paid mutator transaction binding the contract method 0x01267951. +// Propose is a paid mutator transaction binding the contract method 0xc198f8ba. // -// Solidity: function propose( address) returns() -func (_IValidator *IValidatorSession) Propose(arg0 common.Address) (*types.Transaction, error) { - return _IValidator.Contract.Propose(&_IValidator.TransactOpts, arg0) +// Solidity: function propose() returns() +func (_IValidator *IValidatorSession) Propose() (*types.Transaction, error) { + return _IValidator.Contract.Propose(&_IValidator.TransactOpts) } -// Propose is a paid mutator transaction binding the contract method 0x01267951. +// Propose is a paid mutator transaction binding the contract method 0xc198f8ba. // -// Solidity: function propose( address) returns() -func (_IValidator *IValidatorTransactorSession) Propose(arg0 common.Address) (*types.Transaction, error) { - return _IValidator.Contract.Propose(&_IValidator.TransactOpts, arg0) +// Solidity: function propose() returns() +func (_IValidator *IValidatorTransactorSession) Propose() (*types.Transaction, error) { + return _IValidator.Contract.Propose(&_IValidator.TransactOpts) +} + +// 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. @@ -357,10 +380,10 @@ 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\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"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\":\"_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\":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\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"isCandidate\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_candidates\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" +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\":\"_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\":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\":true,\"inputs\":[],\"name\":\"maxCandidateNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"maxValidatorNumber\",\"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\"},{\"inputs\":[{\"name\":\"_candidates\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Vote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Unvote\",\"type\":\"event\"}]" // TomoValidatorBin is the compiled bytecode used for deploying new contracts. -const TomoValidatorBin = `0x60606040526000600255341561001457600080fd5b6040516107d63803806107d68339810160405280805182019190602001805190910190506000600183805161004d9291602001906100ec565b50600090505b82518110156100e45760408051908101604052600181526020810183838151811061007a57fe5b90602001906020020151905260008085848151811061009557fe5b90602001906020020151600160a060020a0316815260208101919091526040016000208151815460ff191690151517815560208201516001918201556002805482019055919091019050610053565b50505061017a565b828054828255906000526020600020908101928215610143579160200282015b828111156101435782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019061010c565b5061014f929150610153565b5090565b61017791905b8082111561014f578054600160a060020a0319168155600101610159565b90565b61064d806101896000396000f30060606040526004361061008d5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166301267951811461009257806302aa9be2146100a857806306a49fce146100ca578063302b6872146101305780633477ee2e1461016757806358e7525f146101995780636dd7d8ea146101b8578063d51b9e93146101cc575b600080fd5b6100a6600160a060020a03600435166101ff565b005b34156100b357600080fd5b6100a6600160a060020a03600435166024356102b9565b34156100d557600080fd5b6100dd6103e2565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561011c578082015183820152602001610104565b505050509050019250505060405180910390f35b341561013b57600080fd5b610155600160a060020a036004358116906024351661044b565b60405190815260200160405180910390f35b341561017257600080fd5b61017d600435610478565b604051600160a060020a03909116815260200160405180910390f35b34156101a457600080fd5b610155600160a060020a03600435166104a0565b6100a6600160a060020a03600435166104be565b34156101d757600080fd5b6101eb600160a060020a0360043516610582565b604051901515815260200160405180910390f35b600160a060020a03811660009081526020819052604090205460ff161515610265576001805480820161023283826105c8565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b6040805190810160409081526001825234602080840191909152600160a060020a038416600090815290819052208151815460ff191690151517815560208201516001918201556002805490910190555050565b600160a060020a03821660009081526020819052604090205460ff1615156102e057600080fd5b600160a060020a038083166000908152602081815260408083203390941683526002909301905220548190101561031657600080fd5b600160a060020a038216600090815260208190526040902060010154610342908263ffffffff6105a016565b600160a060020a0380841660009081526020818152604080832060018101959095553390931682526002909301909252902054610385908263ffffffff6105a016565b600160a060020a0380841660009081526020818152604080832033909416808452600290940190915290819020929092559082156108fc0290839051600060405180830381858888f1935050505015156103de57600080fd5b5050565b6103ea6105f1565b600180548060200260200160405190810160405280929190818152602001828054801561044057602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610422575b505050505090505b90565b600160a060020a039182166000908152602081815260408083209390941682526002909201909152205490565b600180548290811061048657fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a031660009081526020819052604090206001015490565b600160a060020a03811660009081526020819052604090205460ff1615156104e557600080fd5b600160a060020a038116600090815260208190526040902060010154610511903463ffffffff6105b216565b600160a060020a0380831660009081526020818152604080832060018101959095553390931682526002909301909252902054610554903463ffffffff6105b216565b600160a060020a03918216600090815260208181526040808320339095168352600290940190529190912055565b600160a060020a031660009081526020819052604090205460ff1690565b6000828211156105ac57fe5b50900390565b6000828201838110156105c157fe5b9392505050565b8154818355818115116105ec576000838152602090206105ec918101908301610603565b505050565b60206040519081016040526000815290565b61044891905b8082111561061d5760008155600101610609565b50905600a165627a7a723058204f35ebf7b5775f52742c989407a76898f3dcbfa948c7b047bd1768f7a5e1f2130029` +const TomoValidatorBin = `0x60606040526000600255341561001457600080fd5b6040516108f43803806108f48339810160405280805182019190602001805190910190506000600183805161004d9291602001906100ec565b50600090505b82518110156100e45760408051908101604052600181526020810183838151811061007a57fe5b90602001906020020151905260008085848151811061009557fe5b90602001906020020151600160a060020a0316815260208101919091526040016000208151815460ff191690151517815560208201516001918201556002805482019055919091019050610053565b50505061017a565b828054828255906000526020600020908101928215610143579160200282015b828111156101435782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019061010c565b5061014f929150610153565b5090565b61017791905b8082111561014f578054600160a060020a0319168155600101610159565b90565b61076b806101896000396000f3006060604052600436106100ae5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302aa9be281146100b357806306a49fce146100d7578063302b68721461013d5780633477ee2e1461017457806358e7525f146101a65780636dd7d8ea146101c55780638198a8dc146101d9578063c198f8ba146101ec578063d09f1ab4146101f4578063d51b9e9314610207578063d55b7dff1461023a575b600080fd5b34156100be57600080fd5b6100d5600160a060020a036004351660243561024d565b005b34156100e257600080fd5b6100ea6103ba565b60405160208082528190810183818151815260200191508051906020019060200280838360005b83811015610129578082015183820152602001610111565b505050509050019250505060405180910390f35b341561014857600080fd5b610162600160a060020a0360043581169060243516610423565b60405190815260200160405180910390f35b341561017f57600080fd5b61018a600435610450565b604051600160a060020a03909116815260200160405180910390f35b34156101b157600080fd5b610162600160a060020a0360043516610478565b6100d5600160a060020a0360043516610496565b34156101e457600080fd5b6101626105a2565b6100d56105a8565b34156101ff57600080fd5b61016261068d565b341561021257600080fd5b610226600160a060020a0360043516610692565b604051901515815260200160405180910390f35b341561024557600080fd5b6101626106b0565b600160a060020a03821660009081526020819052604090205460ff16151561027457600080fd5b600160a060020a03808316600090815260208181526040808320339094168352600290930190522054819010156102aa57600080fd5b600160a060020a0382166000908152602081905260409020600101546102d6908263ffffffff6106be16565b600160a060020a0380841660009081526020818152604080832060018101959095553390931682526002909301909252902054610319908263ffffffff6106be16565b600160a060020a0380841660009081526020818152604080832033909416808452600290940190915290819020929092559082156108fc0290839051600060405180830381858888f19350505050151561037257600080fd5b7f23ae40ca85f8a7c921ebb4269dc9a81e8a6de8dba614752927e0ff39341392fc8282604051600160a060020a03909216825260208201526040908101905180910390a15050565b6103c26106e6565b600180548060200260200160405190810160405280929190818152602001828054801561041857602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116103fa575b505050505090505b90565b600160a060020a039182166000908152602081815260408083209390941682526002909201909152205490565b600180548290811061045e57fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a031660009081526020819052604090206001015490565b600160a060020a03811660009081526020819052604090205460ff1615156104bd57600080fd5b600160a060020a0381166000908152602081905260409020600101546104e9903463ffffffff6106d016565b600160a060020a038083166000908152602081815260408083206001810195909555339093168252600290930190925290205461052c903463ffffffff6106d016565b600160a060020a0380831660009081526020818152604080832033909416835260029093019052819020919091557ff668ead05c744b9178e571d2edb452e72baf6529c8d72160e64e59b50d865bd0908290349051600160a060020a03909216825260208201526040908101905180910390a150565b6101f481565b69021e19e0c9bab24000003410156105bf57600080fd5b600160a060020a03331660009081526020819052604090205460ff16156105e557600080fd5b6002546101f49011156105f757600080fd5b6001805480820161060883826106f8565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790556040805190810160409081526001825234602080840191909152600160a060020a033316600090815290819052208151815460ff1916901515178155602082015160019182015560028054909101905550565b606381565b600160a060020a031660009081526020819052604090205460ff1690565b69021e19e0c9bab240000081565b6000828211156106ca57fe5b50900390565b6000828201838110156106df57fe5b9392505050565b60206040519081016040526000815290565b81548183558181151161071c5760008381526020902061071c918101908301610721565b505050565b61042091905b8082111561073b5760008155600101610727565b50905600a165627a7a72305820b31a90944fa6d48f577167e8fa11fd3d187b9e72442ec372e0144b82a4fa773c0029` // DeployTomoValidator deploys a new Ethereum contract, binding an instance of TomoValidator to it. func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _candidates []common.Address, _caps []*big.Int) (common.Address, *types.Transaction, *TomoValidator, error) { @@ -647,25 +670,103 @@ func (_TomoValidator *TomoValidatorCallerSession) IsCandidate(_candidate common. return _TomoValidator.Contract.IsCandidate(&_TomoValidator.CallOpts, _candidate) } -// Propose is a paid mutator transaction binding the contract method 0x01267951. +// MaxCandidateNumber is a free data retrieval call binding the contract method 0x8198a8dc. // -// Solidity: function propose(_candidate address) returns() -func (_TomoValidator *TomoValidatorTransactor) Propose(opts *bind.TransactOpts, _candidate common.Address) (*types.Transaction, error) { - return _TomoValidator.contract.Transact(opts, "propose", _candidate) +// Solidity: function maxCandidateNumber() constant returns(uint256) +func (_TomoValidator *TomoValidatorCaller) MaxCandidateNumber(opts *bind.CallOpts) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "maxCandidateNumber") + return *ret0, err } -// Propose is a paid mutator transaction binding the contract method 0x01267951. +// MaxCandidateNumber is a free data retrieval call binding the contract method 0x8198a8dc. // -// Solidity: function propose(_candidate address) returns() -func (_TomoValidator *TomoValidatorSession) Propose(_candidate common.Address) (*types.Transaction, error) { - return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts, _candidate) +// Solidity: function maxCandidateNumber() constant returns(uint256) +func (_TomoValidator *TomoValidatorSession) MaxCandidateNumber() (*big.Int, error) { + return _TomoValidator.Contract.MaxCandidateNumber(&_TomoValidator.CallOpts) } -// Propose is a paid mutator transaction binding the contract method 0x01267951. +// MaxCandidateNumber is a free data retrieval call binding the contract method 0x8198a8dc. // -// Solidity: function propose(_candidate address) returns() -func (_TomoValidator *TomoValidatorTransactorSession) Propose(_candidate common.Address) (*types.Transaction, error) { - return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts, _candidate) +// Solidity: function maxCandidateNumber() constant returns(uint256) +func (_TomoValidator *TomoValidatorCallerSession) MaxCandidateNumber() (*big.Int, error) { + return _TomoValidator.Contract.MaxCandidateNumber(&_TomoValidator.CallOpts) +} + +// MaxValidatorNumber is a free data retrieval call binding the contract method 0xd09f1ab4. +// +// Solidity: function maxValidatorNumber() constant returns(uint256) +func (_TomoValidator *TomoValidatorCaller) MaxValidatorNumber(opts *bind.CallOpts) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "maxValidatorNumber") + return *ret0, err +} + +// MaxValidatorNumber is a free data retrieval call binding the contract method 0xd09f1ab4. +// +// Solidity: function maxValidatorNumber() constant returns(uint256) +func (_TomoValidator *TomoValidatorSession) MaxValidatorNumber() (*big.Int, error) { + return _TomoValidator.Contract.MaxValidatorNumber(&_TomoValidator.CallOpts) +} + +// MaxValidatorNumber is a free data retrieval call binding the contract method 0xd09f1ab4. +// +// Solidity: function maxValidatorNumber() constant returns(uint256) +func (_TomoValidator *TomoValidatorCallerSession) MaxValidatorNumber() (*big.Int, error) { + return _TomoValidator.Contract.MaxValidatorNumber(&_TomoValidator.CallOpts) +} + +// MinCandidateCap is a free data retrieval call binding the contract method 0xd55b7dff. +// +// Solidity: function minCandidateCap() constant returns(uint256) +func (_TomoValidator *TomoValidatorCaller) MinCandidateCap(opts *bind.CallOpts) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "minCandidateCap") + return *ret0, err +} + +// MinCandidateCap is a free data retrieval call binding the contract method 0xd55b7dff. +// +// Solidity: function minCandidateCap() constant returns(uint256) +func (_TomoValidator *TomoValidatorSession) MinCandidateCap() (*big.Int, error) { + return _TomoValidator.Contract.MinCandidateCap(&_TomoValidator.CallOpts) +} + +// MinCandidateCap is a free data retrieval call binding the contract method 0xd55b7dff. +// +// Solidity: function minCandidateCap() constant returns(uint256) +func (_TomoValidator *TomoValidatorCallerSession) MinCandidateCap() (*big.Int, error) { + return _TomoValidator.Contract.MinCandidateCap(&_TomoValidator.CallOpts) +} + +// Propose is a paid mutator transaction binding the contract method 0xc198f8ba. +// +// Solidity: function propose() returns() +func (_TomoValidator *TomoValidatorTransactor) Propose(opts *bind.TransactOpts) (*types.Transaction, error) { + return _TomoValidator.contract.Transact(opts, "propose") +} + +// Propose is a paid mutator transaction binding the contract method 0xc198f8ba. +// +// Solidity: function propose() returns() +func (_TomoValidator *TomoValidatorSession) Propose() (*types.Transaction, error) { + return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts) +} + +// Propose is a paid mutator transaction binding the contract method 0xc198f8ba. +// +// Solidity: function propose() returns() +func (_TomoValidator *TomoValidatorTransactorSession) Propose() (*types.Transaction, error) { + return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts) } // Unvote is a paid mutator transaction binding the contract method 0x02aa9be2. @@ -709,3 +810,249 @@ func (_TomoValidator *TomoValidatorSession) Vote(_candidate common.Address) (*ty func (_TomoValidator *TomoValidatorTransactorSession) Vote(_candidate common.Address) (*types.Transaction, error) { return _TomoValidator.Contract.Vote(&_TomoValidator.TransactOpts, _candidate) } + +// TomoValidatorUnvoteIterator is returned from FilterUnvote and is used to iterate over the raw logs and unpacked data for Unvote events raised by the TomoValidator contract. +type TomoValidatorUnvoteIterator struct { + Event *TomoValidatorUnvote // 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 + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// 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 *TomoValidatorUnvoteIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(TomoValidatorUnvote) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(TomoValidatorUnvote) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *TomoValidatorUnvoteIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *TomoValidatorUnvoteIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// TomoValidatorUnvote represents a Unvote event raised by the TomoValidator contract. +type TomoValidatorUnvote struct { + Candidate common.Address + Cap *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterUnvote is a free log retrieval operation binding the contract event 0x23ae40ca85f8a7c921ebb4269dc9a81e8a6de8dba614752927e0ff39341392fc. +// +// Solidity: event Unvote(_candidate address, _cap uint256) +func (_TomoValidator *TomoValidatorFilterer) FilterUnvote(opts *bind.FilterOpts) (*TomoValidatorUnvoteIterator, error) { + + logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Unvote") + if err != nil { + return nil, err + } + return &TomoValidatorUnvoteIterator{contract: _TomoValidator.contract, event: "Unvote", logs: logs, sub: sub}, nil +} + +// WatchUnvote is a free log subscription operation binding the contract event 0x23ae40ca85f8a7c921ebb4269dc9a81e8a6de8dba614752927e0ff39341392fc. +// +// Solidity: event Unvote(_candidate address, _cap uint256) +func (_TomoValidator *TomoValidatorFilterer) WatchUnvote(opts *bind.WatchOpts, sink chan<- *TomoValidatorUnvote) (event.Subscription, error) { + + logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Unvote") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(TomoValidatorUnvote) + if err := _TomoValidator.contract.UnpackLog(event, "Unvote", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// TomoValidatorVoteIterator is returned from FilterVote and is used to iterate over the raw logs and unpacked data for Vote events raised by the TomoValidator contract. +type TomoValidatorVoteIterator struct { + Event *TomoValidatorVote // 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 + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// 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 *TomoValidatorVoteIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(TomoValidatorVote) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(TomoValidatorVote) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *TomoValidatorVoteIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *TomoValidatorVoteIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// TomoValidatorVote represents a Vote event raised by the TomoValidator contract. +type TomoValidatorVote struct { + Candidate common.Address + Cap *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterVote is a free log retrieval operation binding the contract event 0xf668ead05c744b9178e571d2edb452e72baf6529c8d72160e64e59b50d865bd0. +// +// Solidity: event Vote(_candidate address, _cap uint256) +func (_TomoValidator *TomoValidatorFilterer) FilterVote(opts *bind.FilterOpts) (*TomoValidatorVoteIterator, error) { + + logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Vote") + if err != nil { + return nil, err + } + return &TomoValidatorVoteIterator{contract: _TomoValidator.contract, event: "Vote", logs: logs, sub: sub}, nil +} + +// WatchVote is a free log subscription operation binding the contract event 0xf668ead05c744b9178e571d2edb452e72baf6529c8d72160e64e59b50d865bd0. +// +// Solidity: event Vote(_candidate address, _cap uint256) +func (_TomoValidator *TomoValidatorFilterer) WatchVote(opts *bind.WatchOpts, sink chan<- *TomoValidatorVote) (event.Subscription, error) { + + logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Vote") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(TomoValidatorVote) + if err := _TomoValidator.contract.UnpackLog(event, "Vote", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} From 51bac6108a326eeacdd97132c1d723b46cffe583 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Tue, 24 Apr 2018 08:27:10 +0000 Subject: [PATCH 11/15] update list of voters --- .../validator/contract/TomoValidator.sol | 30 +- contracts/validator/contract/validator.go | 297 +++++++++++++++++- 2 files changed, 324 insertions(+), 3 deletions(-) diff --git a/contracts/validator/contract/TomoValidator.sol b/contracts/validator/contract/TomoValidator.sol index 5315bb0b22..0e7f1be5f1 100644 --- a/contracts/validator/contract/TomoValidator.sol +++ b/contracts/validator/contract/TomoValidator.sol @@ -8,6 +8,8 @@ contract TomoValidator is IValidator { event Vote(address _candidate, uint256 _cap); event Unvote(address _candidate, uint256 _cap); + event Propose(address _candidate, uint256 _cap); + event Retire(address _candidate, uint256 _cap); struct ValidatorState { bool isCandidate; @@ -16,6 +18,7 @@ contract TomoValidator is IValidator { } mapping(address => ValidatorState) validatorsState; + mapping(address => address[]) voters; address[] public candidates; uint256 candidateCount = 0; uint256 public constant minCandidateCap = 10000 ether; @@ -45,13 +48,16 @@ contract TomoValidator is IValidator { isCandidate: true, cap: msg.value }); + validatorsState[msg.sender].voters[msg.sender] = msg.value; candidateCount = candidateCount + 1; + emit Propose(msg.sender, msg.value); } function vote(address _candidate) external payable { require(validatorsState[_candidate].isCandidate); validatorsState[_candidate].cap = validatorsState[_candidate].cap.add(msg.value); validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].add(msg.value); + voters[_candidate].push(msg.sender); emit Vote(_candidate, msg.value); } @@ -67,12 +73,15 @@ contract TomoValidator is IValidator { return validatorsState[_candidate].voters[_voter]; } + function getVoters(address _candidate) public view returns(address[]) { + return voters[_candidate]; + } + function isCandidate(address _candidate) public view returns(bool) { return validatorsState[_candidate].isCandidate; } function unvote(address _candidate, uint256 _cap) public { - require(validatorsState[_candidate].isCandidate); require(validatorsState[_candidate].voters[msg.sender] >= _cap); validatorsState[_candidate].cap = validatorsState[_candidate].cap.sub(_cap); validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].sub(_cap); @@ -80,4 +89,23 @@ contract TomoValidator is IValidator { msg.sender.transfer(_cap); emit Unvote(_candidate, _cap); } + + function retire() public { + require(validatorsState[msg.sender].isCandidate); + uint256 cap = validatorsState[msg.sender].voters[msg.sender]; + validatorsState[msg.sender].cap = validatorsState[msg.sender].cap.sub(cap); + validatorsState[msg.sender].voters[msg.sender] = 0; + validatorsState[msg.sender].isCandidate = false; + candidateCount = candidateCount - 1; + for (uint256 i = 0; i < candidates.length; i++) { + if (candidates[i] == msg.sender) { + delete candidates[i]; + break; + } + } + // refunding to user after retiring + msg.sender.transfer(cap); + emit Retire(msg.sender, cap); + } + } diff --git a/contracts/validator/contract/validator.go b/contracts/validator/contract/validator.go index be61ee0c4f..3559da8fcd 100644 --- a/contracts/validator/contract/validator.go +++ b/contracts/validator/contract/validator.go @@ -380,10 +380,10 @@ 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\":\"_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\":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\":true,\"inputs\":[],\"name\":\"maxCandidateNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"maxValidatorNumber\",\"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\"},{\"inputs\":[{\"name\":\"_candidates\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Vote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Unvote\",\"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\":\"_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\":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\":true,\"inputs\":[],\"name\":\"maxCandidateNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"retire\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"maxValidatorNumber\",\"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\"},{\"inputs\":[{\"name\":\"_candidates\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Vote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Unvote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Propose\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Retire\",\"type\":\"event\"}]" // TomoValidatorBin is the compiled bytecode used for deploying new contracts. -const TomoValidatorBin = `0x60606040526000600255341561001457600080fd5b6040516108f43803806108f48339810160405280805182019190602001805190910190506000600183805161004d9291602001906100ec565b50600090505b82518110156100e45760408051908101604052600181526020810183838151811061007a57fe5b90602001906020020151905260008085848151811061009557fe5b90602001906020020151600160a060020a0316815260208101919091526040016000208151815460ff191690151517815560208201516001918201556002805482019055919091019050610053565b50505061017a565b828054828255906000526020600020908101928215610143579160200282015b828111156101435782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019061010c565b5061014f929150610153565b5090565b61017791905b8082111561014f578054600160a060020a0319168155600101610159565b90565b61076b806101896000396000f3006060604052600436106100ae5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302aa9be281146100b357806306a49fce146100d7578063302b68721461013d5780633477ee2e1461017457806358e7525f146101a65780636dd7d8ea146101c55780638198a8dc146101d9578063c198f8ba146101ec578063d09f1ab4146101f4578063d51b9e9314610207578063d55b7dff1461023a575b600080fd5b34156100be57600080fd5b6100d5600160a060020a036004351660243561024d565b005b34156100e257600080fd5b6100ea6103ba565b60405160208082528190810183818151815260200191508051906020019060200280838360005b83811015610129578082015183820152602001610111565b505050509050019250505060405180910390f35b341561014857600080fd5b610162600160a060020a0360043581169060243516610423565b60405190815260200160405180910390f35b341561017f57600080fd5b61018a600435610450565b604051600160a060020a03909116815260200160405180910390f35b34156101b157600080fd5b610162600160a060020a0360043516610478565b6100d5600160a060020a0360043516610496565b34156101e457600080fd5b6101626105a2565b6100d56105a8565b34156101ff57600080fd5b61016261068d565b341561021257600080fd5b610226600160a060020a0360043516610692565b604051901515815260200160405180910390f35b341561024557600080fd5b6101626106b0565b600160a060020a03821660009081526020819052604090205460ff16151561027457600080fd5b600160a060020a03808316600090815260208181526040808320339094168352600290930190522054819010156102aa57600080fd5b600160a060020a0382166000908152602081905260409020600101546102d6908263ffffffff6106be16565b600160a060020a0380841660009081526020818152604080832060018101959095553390931682526002909301909252902054610319908263ffffffff6106be16565b600160a060020a0380841660009081526020818152604080832033909416808452600290940190915290819020929092559082156108fc0290839051600060405180830381858888f19350505050151561037257600080fd5b7f23ae40ca85f8a7c921ebb4269dc9a81e8a6de8dba614752927e0ff39341392fc8282604051600160a060020a03909216825260208201526040908101905180910390a15050565b6103c26106e6565b600180548060200260200160405190810160405280929190818152602001828054801561041857602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116103fa575b505050505090505b90565b600160a060020a039182166000908152602081815260408083209390941682526002909201909152205490565b600180548290811061045e57fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a031660009081526020819052604090206001015490565b600160a060020a03811660009081526020819052604090205460ff1615156104bd57600080fd5b600160a060020a0381166000908152602081905260409020600101546104e9903463ffffffff6106d016565b600160a060020a038083166000908152602081815260408083206001810195909555339093168252600290930190925290205461052c903463ffffffff6106d016565b600160a060020a0380831660009081526020818152604080832033909416835260029093019052819020919091557ff668ead05c744b9178e571d2edb452e72baf6529c8d72160e64e59b50d865bd0908290349051600160a060020a03909216825260208201526040908101905180910390a150565b6101f481565b69021e19e0c9bab24000003410156105bf57600080fd5b600160a060020a03331660009081526020819052604090205460ff16156105e557600080fd5b6002546101f49011156105f757600080fd5b6001805480820161060883826106f8565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790556040805190810160409081526001825234602080840191909152600160a060020a033316600090815290819052208151815460ff1916901515178155602082015160019182015560028054909101905550565b606381565b600160a060020a031660009081526020819052604090205460ff1690565b69021e19e0c9bab240000081565b6000828211156106ca57fe5b50900390565b6000828201838110156106df57fe5b9392505050565b60206040519081016040526000815290565b81548183558181151161071c5760008381526020902061071c918101908301610721565b505050565b61042091905b8082111561073b5760008155600101610727565b50905600a165627a7a72305820b31a90944fa6d48f577167e8fa11fd3d187b9e72442ec372e0144b82a4fa773c0029` +const TomoValidatorBin = `0x60606040526000600355341561001457600080fd5b604051610c00380380610c008339810160405280805182019190602001805190910190506000600283805161004d9291602001906100ec565b50600090505b82518110156100e45760408051908101604052600181526020810183838151811061007a57fe5b90602001906020020151905260008085848151811061009557fe5b90602001906020020151600160a060020a0316815260208101919091526040016000208151815460ff191690151517815560208201516001918201556003805482019055919091019050610053565b50505061017a565b828054828255906000526020600020908101928215610143579160200282015b828111156101435782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019061010c565b5061014f929150610153565b5090565b61017791905b8082111561014f578054600160a060020a0319168155600101610159565b90565b610a77806101896000396000f3006060604052600436106100c45763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302aa9be281146100c957806306a49fce146100ed5780632d15cc0414610153578063302b6872146101725780633477ee2e146101a957806358e7525f146101db5780636dd7d8ea146101fa5780638198a8dc1461020e578063a4874d7714610221578063c198f8ba14610234578063d09f1ab41461023c578063d51b9e931461024f578063d55b7dff14610282575b600080fd5b34156100d457600080fd5b6100eb600160a060020a0360043516602435610295565b005b34156100f857600080fd5b6101006103db565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561013f578082015183820152602001610127565b505050509050019250505060405180910390f35b341561015e57600080fd5b610100600160a060020a0360043516610444565b341561017d57600080fd5b610197600160a060020a03600435811690602435166104d1565b60405190815260200160405180910390f35b34156101b457600080fd5b6101bf6004356104fe565b604051600160a060020a03909116815260200160405180910390f35b34156101e657600080fd5b610197600160a060020a0360043516610526565b6100eb600160a060020a0360043516610544565b341561021957600080fd5b61019761069b565b341561022c57600080fd5b6100eb6106a1565b6100eb610845565b341561024757600080fd5b610197610999565b341561025a57600080fd5b61026e600160a060020a036004351661099e565b604051901515815260200160405180910390f35b341561028d57600080fd5b6101976109bc565b600160a060020a03808316600090815260208181526040808320339094168352600290930190522054819010156102cb57600080fd5b600160a060020a0382166000908152602081905260409020600101546102f7908263ffffffff6109ca16565b600160a060020a038084166000908152602081815260408083206001810195909555339093168252600290930190925290205461033a908263ffffffff6109ca16565b600160a060020a0380841660009081526020818152604080832033909416808452600290940190915290819020929092559082156108fc0290839051600060405180830381858888f19350505050151561039357600080fd5b7f23ae40ca85f8a7c921ebb4269dc9a81e8a6de8dba614752927e0ff39341392fc8282604051600160a060020a03909216825260208201526040908101905180910390a15050565b6103e36109f2565b600280548060200260200160405190810160405280929190818152602001828054801561043957602002820191906000526020600020905b8154600160a060020a0316815260019091019060200180831161041b575b505050505090505b90565b61044c6109f2565b6001600083600160a060020a0316600160a060020a031681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156104c557602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116104a7575b50505050509050919050565b600160a060020a039182166000908152602081815260408083209390941682526002909201909152205490565b600280548290811061050c57fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a031660009081526020819052604090206001015490565b600160a060020a03811660009081526020819052604090205460ff16151561056b57600080fd5b600160a060020a038116600090815260208190526040902060010154610597903463ffffffff6109dc16565b600160a060020a03808316600090815260208181526040808320600181019590955533909316825260029093019092529020546105da903463ffffffff6109dc16565b600160a060020a038083166000818152602081815260408083203390951683526002909401815283822094909455908152600192839052208054909181016106228382610a04565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790557ff668ead05c744b9178e571d2edb452e72baf6529c8d72160e64e59b50d865bd08134604051600160a060020a03909216825260208201526040908101905180910390a150565b6101f481565b600160a060020a033316600090815260208190526040812054819060ff1615156106ca57600080fd5b600160a060020a033316600090815260208181526040808320600281018352908320549290915260010154909250610708908363ffffffff6109ca16565b600160a060020a03331660009081526020818152604080832060018101949094556002840182528220829055819052815460ff19169091556003805460001901905590505b6002548110156107cc5733600160a060020a031660028281548110151561077057fe5b600091825260209091200154600160a060020a031614156107c457600280548290811061079957fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191690556107cc565b60010161074d565b600160a060020a03331682156108fc0283604051600060405180830381858888f1935050505015156107fd57600080fd5b7f82b89ed824b293574a2cca050e6e27837b60436d911352f8dca203a9cd35241c3383604051600160a060020a03909216825260208201526040908101905180910390a15050565b69021e19e0c9bab240000034101561085c57600080fd5b600160a060020a03331660009081526020819052604090205460ff161561088257600080fd5b6003546101f490111561089457600080fd5b60028054600181016108a68382610a04565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790556040805190810160409081526001825234602080840191909152600160a060020a033316600090815290819052208151815460ff1916901515178155602082015160019182015533600160a060020a038116600090815260208181526040808320600201909152908190203490819055600380549094019093557f42681fc159c671d489c99c06f4693d03a705a21df2fbb2b84eedda79e0db4cff935090919051600160a060020a03909216825260208201526040908101905180910390a1565b606381565b600160a060020a031660009081526020819052604090205460ff1690565b69021e19e0c9bab240000081565b6000828211156109d657fe5b50900390565b6000828201838110156109eb57fe5b9392505050565b60206040519081016040526000815290565b815481835581811511610a2857600083815260209020610a28918101908301610a2d565b505050565b61044191905b80821115610a475760008155600101610a33565b50905600a165627a7a7230582080c308e459c6cbc6e91ffb692f7e77a6ff3985db345631c572a5e453588bc56c0029` // DeployTomoValidator deploys a new Ethereum contract, binding an instance of TomoValidator to it. func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _candidates []common.Address, _caps []*big.Int) (common.Address, *types.Transaction, *TomoValidator, error) { @@ -644,6 +644,32 @@ func (_TomoValidator *TomoValidatorCallerSession) GetVoterCap(_candidate common. return _TomoValidator.Contract.GetVoterCap(&_TomoValidator.CallOpts, _candidate, _voter) } +// GetVoters is a free data retrieval call binding the contract method 0x2d15cc04. +// +// Solidity: function getVoters(_candidate address) constant returns(address[]) +func (_TomoValidator *TomoValidatorCaller) GetVoters(opts *bind.CallOpts, _candidate common.Address) ([]common.Address, error) { + var ( + ret0 = new([]common.Address) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "getVoters", _candidate) + return *ret0, err +} + +// GetVoters is a free data retrieval call binding the contract method 0x2d15cc04. +// +// Solidity: function getVoters(_candidate address) constant returns(address[]) +func (_TomoValidator *TomoValidatorSession) GetVoters(_candidate common.Address) ([]common.Address, error) { + return _TomoValidator.Contract.GetVoters(&_TomoValidator.CallOpts, _candidate) +} + +// GetVoters is a free data retrieval call binding the contract method 0x2d15cc04. +// +// Solidity: function getVoters(_candidate address) constant returns(address[]) +func (_TomoValidator *TomoValidatorCallerSession) GetVoters(_candidate common.Address) ([]common.Address, error) { + return _TomoValidator.Contract.GetVoters(&_TomoValidator.CallOpts, _candidate) +} + // IsCandidate is a free data retrieval call binding the contract method 0xd51b9e93. // // Solidity: function isCandidate(_candidate address) constant returns(bool) @@ -769,6 +795,27 @@ func (_TomoValidator *TomoValidatorTransactorSession) Propose() (*types.Transact return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts) } +// Retire is a paid mutator transaction binding the contract method 0xa4874d77. +// +// Solidity: function retire() returns() +func (_TomoValidator *TomoValidatorTransactor) Retire(opts *bind.TransactOpts) (*types.Transaction, error) { + return _TomoValidator.contract.Transact(opts, "retire") +} + +// Retire is a paid mutator transaction binding the contract method 0xa4874d77. +// +// Solidity: function retire() returns() +func (_TomoValidator *TomoValidatorSession) Retire() (*types.Transaction, error) { + return _TomoValidator.Contract.Retire(&_TomoValidator.TransactOpts) +} + +// Retire is a paid mutator transaction binding the contract method 0xa4874d77. +// +// Solidity: function retire() returns() +func (_TomoValidator *TomoValidatorTransactorSession) Retire() (*types.Transaction, error) { + return _TomoValidator.Contract.Retire(&_TomoValidator.TransactOpts) +} + // Unvote is a paid mutator transaction binding the contract method 0x02aa9be2. // // Solidity: function unvote(_candidate address, _cap uint256) returns() @@ -811,6 +858,252 @@ func (_TomoValidator *TomoValidatorTransactorSession) Vote(_candidate common.Add return _TomoValidator.Contract.Vote(&_TomoValidator.TransactOpts, _candidate) } +// 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. +type TomoValidatorProposeIterator struct { + Event *TomoValidatorPropose // 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 + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// 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 *TomoValidatorProposeIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(TomoValidatorPropose) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(TomoValidatorPropose) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *TomoValidatorProposeIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *TomoValidatorProposeIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// TomoValidatorPropose represents a Propose event raised by the TomoValidator contract. +type TomoValidatorPropose struct { + Candidate common.Address + Cap *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterPropose is a free log retrieval operation binding the contract event 0x42681fc159c671d489c99c06f4693d03a705a21df2fbb2b84eedda79e0db4cff. +// +// Solidity: event Propose(_candidate address, _cap uint256) +func (_TomoValidator *TomoValidatorFilterer) FilterPropose(opts *bind.FilterOpts) (*TomoValidatorProposeIterator, error) { + + logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Propose") + if err != nil { + return nil, err + } + return &TomoValidatorProposeIterator{contract: _TomoValidator.contract, event: "Propose", logs: logs, sub: sub}, nil +} + +// WatchPropose is a free log subscription operation binding the contract event 0x42681fc159c671d489c99c06f4693d03a705a21df2fbb2b84eedda79e0db4cff. +// +// Solidity: event Propose(_candidate address, _cap uint256) +func (_TomoValidator *TomoValidatorFilterer) WatchPropose(opts *bind.WatchOpts, sink chan<- *TomoValidatorPropose) (event.Subscription, error) { + + logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Propose") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(TomoValidatorPropose) + if err := _TomoValidator.contract.UnpackLog(event, "Propose", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// TomoValidatorRetireIterator is returned from FilterRetire and is used to iterate over the raw logs and unpacked data for Retire events raised by the TomoValidator contract. +type TomoValidatorRetireIterator struct { + Event *TomoValidatorRetire // 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 + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// 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 *TomoValidatorRetireIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(TomoValidatorRetire) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(TomoValidatorRetire) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *TomoValidatorRetireIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *TomoValidatorRetireIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// TomoValidatorRetire represents a Retire event raised by the TomoValidator contract. +type TomoValidatorRetire struct { + Candidate common.Address + Cap *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterRetire is a free log retrieval operation binding the contract event 0x82b89ed824b293574a2cca050e6e27837b60436d911352f8dca203a9cd35241c. +// +// Solidity: event Retire(_candidate address, _cap uint256) +func (_TomoValidator *TomoValidatorFilterer) FilterRetire(opts *bind.FilterOpts) (*TomoValidatorRetireIterator, error) { + + logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Retire") + if err != nil { + return nil, err + } + return &TomoValidatorRetireIterator{contract: _TomoValidator.contract, event: "Retire", logs: logs, sub: sub}, nil +} + +// WatchRetire is a free log subscription operation binding the contract event 0x82b89ed824b293574a2cca050e6e27837b60436d911352f8dca203a9cd35241c. +// +// Solidity: event Retire(_candidate address, _cap uint256) +func (_TomoValidator *TomoValidatorFilterer) WatchRetire(opts *bind.WatchOpts, sink chan<- *TomoValidatorRetire) (event.Subscription, error) { + + logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Retire") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(TomoValidatorRetire) + if err := _TomoValidator.contract.UnpackLog(event, "Retire", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + // TomoValidatorUnvoteIterator is returned from FilterUnvote and is used to iterate over the raw logs and unpacked data for Unvote events raised by the TomoValidator contract. type TomoValidatorUnvoteIterator struct { Event *TomoValidatorUnvote // Event containing the contract specifics and raw log From 0d7583ea316275da9caf61d62dc2736b5b9127d4 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Thu, 31 May 2018 08:46:54 +0000 Subject: [PATCH 12/15] updatp contract, return old code --- .../validator/contract/TomoValidator.sol | 132 +++-- .../contract/interfaces/IValidator.sol | 2 +- contracts/validator/contract/validator.go | 543 ++++++++++++++---- contracts/validator/validator_test.go | 3 +- 4 files changed, 545 insertions(+), 135 deletions(-) diff --git a/contracts/validator/contract/TomoValidator.sol b/contracts/validator/contract/TomoValidator.sol index 0e7f1be5f1..49668cbba6 100644 --- a/contracts/validator/contract/TomoValidator.sol +++ b/contracts/validator/contract/TomoValidator.sol @@ -6,14 +6,19 @@ import "./libs/SafeMath.sol"; contract TomoValidator is IValidator { using SafeMath for uint256; - event Vote(address _candidate, uint256 _cap); - event Unvote(address _candidate, uint256 _cap); - event Propose(address _candidate, uint256 _cap); - event Retire(address _candidate, uint256 _cap); + event Vote(address _voter, address _candidate, uint256 _cap); + event Unvote(address _voter, address _candidate, uint256 _cap); + event Propose(address _backer, address _candidate, uint256 _cap); + event Resign(address _backer, address _candidate); + event SetNodeUrl(address _backer, address _candidate, string _nodeUrl); + event Withdraw(address _backer, address _candidate, uint256 _cap); struct ValidatorState { + address backer; + string nodeUrl; bool isCandidate; uint256 cap; + uint256 withdrawBlockNumber; mapping(address => uint256) voters; } @@ -21,16 +26,55 @@ contract TomoValidator is IValidator { mapping(address => address[]) voters; address[] public candidates; uint256 candidateCount = 0; - uint256 public constant minCandidateCap = 10000 ether; - uint256 public constant maxCandidateNumber = 500; + uint256 public constant minCandidateCap = 50000 ether; uint256 public constant maxValidatorNumber = 99; + modifier onlyValidCandidateCap { + // anyone can deposit 10000 TOMO to become a candidate + require(msg.value >= minCandidateCap); + _; + } + + modifier onlyBacker(address _candidate) { + require(validatorsState[_candidate].backer == msg.sender); + _; + } + + modifier onlyCandidate(address _candidate) { + require(validatorsState[_candidate].isCandidate); + _; + } + + modifier onlyAlreadyResigned(address _candidate) { + require(validatorsState[_candidate].withdrawBlockNumber > 0); + require(block.number >= validatorsState[_candidate].withdrawBlockNumber); + _; + } + + modifier onlyValidCandidate (address _candidate) { + require(validatorsState[_candidate].isCandidate); + _; + } + + modifier onlyNotCandidate (address _candidate) { + require(!validatorsState[_candidate].isCandidate); + _; + } + + modifier onlyValidVote (address _candidate, uint256 _cap) { + require(validatorsState[_candidate].voters[msg.sender] >= _cap); + _; + } + function TomoValidator(address[] _candidates, uint256[] _caps) public { candidates = _candidates; for (uint256 i = 0; i < _candidates.length; i++) { validatorsState[_candidates[i]] = ValidatorState({ + backer: msg.sender, + nodeUrl: '', isCandidate: true, + withdrawBlockNumber: 0, cap: _caps[i] }); candidateCount = candidateCount + 1; @@ -38,37 +82,49 @@ contract TomoValidator is IValidator { } - function propose() external payable { - // anyone can deposit 10000 TOMO to become a candidate - require(msg.value >= minCandidateCap); - require(!validatorsState[msg.sender].isCandidate); - require(candidateCount <= maxCandidateNumber); - candidates.push(msg.sender); - validatorsState[msg.sender] = ValidatorState({ + function propose(address _candidate, string _nodeUrl) external payable onlyValidCandidateCap onlyNotCandidate(_candidate) { + candidates.push(_candidate); + validatorsState[_candidate] = ValidatorState({ + backer: msg.sender, + nodeUrl: _nodeUrl, isCandidate: true, + withdrawBlockNumber: 0, cap: msg.value }); - validatorsState[msg.sender].voters[msg.sender] = msg.value; + validatorsState[_candidate].voters[msg.sender] = msg.value; candidateCount = candidateCount + 1; - emit Propose(msg.sender, msg.value); + emit Propose(msg.sender, _candidate, msg.value); } - function vote(address _candidate) external payable { - require(validatorsState[_candidate].isCandidate); + function vote(address _candidate) external payable onlyValidCandidate(_candidate) { validatorsState[_candidate].cap = validatorsState[_candidate].cap.add(msg.value); + if (validatorsState[_candidate].voters[msg.sender] == 0) { + voters[_candidate].push(msg.sender); + } validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].add(msg.value); - voters[_candidate].push(msg.sender); - emit Vote(_candidate, msg.value); + emit Vote(msg.sender, _candidate, msg.value); } function getCandidates() public view returns(address[]) { - return candidates; + return candidates; } function getCandidateCap(address _candidate) public view returns(uint256) { return validatorsState[_candidate].cap; } + function getCandidateNodeUrl(address _candidate) public view returns(string) { + return validatorsState[_candidate].nodeUrl; + } + + function getCandidateBacker(address _candidate) public view returns(address) { + return validatorsState[_candidate].backer; + } + + 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]; } @@ -78,34 +134,42 @@ contract TomoValidator is IValidator { } function isCandidate(address _candidate) public view returns(bool) { - return validatorsState[_candidate].isCandidate; + return validatorsState[_candidate].isCandidate; } - function unvote(address _candidate, uint256 _cap) public { - require(validatorsState[_candidate].voters[msg.sender] >= _cap); + 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); - emit Unvote(_candidate, _cap); + emit Unvote(msg.sender, _candidate, _cap); } - function retire() public { - require(validatorsState[msg.sender].isCandidate); - uint256 cap = validatorsState[msg.sender].voters[msg.sender]; - validatorsState[msg.sender].cap = validatorsState[msg.sender].cap.sub(cap); - validatorsState[msg.sender].voters[msg.sender] = 0; - validatorsState[msg.sender].isCandidate = false; + function setNodeUrl(address _candidate, string _nodeUrl) public onlyBacker(_candidate) { + validatorsState[_candidate].nodeUrl = _nodeUrl; + emit SetNodeUrl(msg.sender, _candidate, _nodeUrl); + } + + function resign(address _candidate) public onlyBacker(_candidate) onlyCandidate(_candidate) { + validatorsState[_candidate].isCandidate = false; candidateCount = candidateCount - 1; for (uint256 i = 0; i < candidates.length; i++) { - if (candidates[i] == msg.sender) { + if (candidates[i] == _candidate) { delete candidates[i]; break; } } - // refunding to user after retiring - msg.sender.transfer(cap); - emit Retire(msg.sender, cap); + // refunding after retiring 100 blocks + validatorsState[_candidate].withdrawBlockNumber = validatorsState[_candidate].withdrawBlockNumber.add(block.number).add(100); + emit Resign(msg.sender, _candidate); } + function withdraw(address _candidate) public onlyBacker(_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; + msg.sender.transfer(cap); + emit Withdraw(msg.sender, _candidate, cap); + } } diff --git a/contracts/validator/contract/interfaces/IValidator.sol b/contracts/validator/contract/interfaces/IValidator.sol index 9d216af6d4..5f2c00061a 100644 --- a/contracts/validator/contract/interfaces/IValidator.sol +++ b/contracts/validator/contract/interfaces/IValidator.sol @@ -1,6 +1,6 @@ pragma solidity ^0.4.21; interface IValidator { - function propose() external payable; + function propose(address, string) external payable; function vote(address) external payable; } diff --git a/contracts/validator/contract/validator.go b/contracts/validator/contract/validator.go index 3559da8fcd..834fec6ce5 100644 --- a/contracts/validator/contract/validator.go +++ b/contracts/validator/contract/validator.go @@ -16,7 +16,7 @@ import ( ) // 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\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"}]" +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` @@ -176,25 +176,25 @@ func (_IValidator *IValidatorTransactorRaw) Transact(opts *bind.TransactOpts, me return _IValidator.Contract.contract.Transact(opts, method, params...) } -// Propose is a paid mutator transaction binding the contract method 0xc198f8ba. +// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. // -// Solidity: function propose() returns() -func (_IValidator *IValidatorTransactor) Propose(opts *bind.TransactOpts) (*types.Transaction, error) { - return _IValidator.contract.Transact(opts, "propose") +// 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 0xc198f8ba. +// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. // -// Solidity: function propose() returns() -func (_IValidator *IValidatorSession) Propose() (*types.Transaction, error) { - return _IValidator.Contract.Propose(&_IValidator.TransactOpts) +// 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 0xc198f8ba. +// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. // -// Solidity: function propose() returns() -func (_IValidator *IValidatorTransactorSession) Propose() (*types.Transaction, error) { - return _IValidator.Contract.Propose(&_IValidator.TransactOpts) +// 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. @@ -380,10 +380,10 @@ 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\":\"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\":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\":true,\"inputs\":[],\"name\":\"maxCandidateNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"retire\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"maxValidatorNumber\",\"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\"},{\"inputs\":[{\"name\":\"_candidates\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Vote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Unvote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Propose\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Retire\",\"type\":\"event\"}]" +const TomoValidatorABI = "[{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateBacker\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"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\":\"maxValidatorNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"isCandidate\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"minCandidateCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateNodeUrl\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_candidates\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"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\":\"_backer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Propose\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_backer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"Resign\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_backer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"SetNodeUrl\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_backer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Withdraw\",\"type\":\"event\"}]" // TomoValidatorBin is the compiled bytecode used for deploying new contracts. -const TomoValidatorBin = `0x60606040526000600355341561001457600080fd5b604051610c00380380610c008339810160405280805182019190602001805190910190506000600283805161004d9291602001906100ec565b50600090505b82518110156100e45760408051908101604052600181526020810183838151811061007a57fe5b90602001906020020151905260008085848151811061009557fe5b90602001906020020151600160a060020a0316815260208101919091526040016000208151815460ff191690151517815560208201516001918201556003805482019055919091019050610053565b50505061017a565b828054828255906000526020600020908101928215610143579160200282015b828111156101435782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019061010c565b5061014f929150610153565b5090565b61017791905b8082111561014f578054600160a060020a0319168155600101610159565b90565b610a77806101896000396000f3006060604052600436106100c45763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302aa9be281146100c957806306a49fce146100ed5780632d15cc0414610153578063302b6872146101725780633477ee2e146101a957806358e7525f146101db5780636dd7d8ea146101fa5780638198a8dc1461020e578063a4874d7714610221578063c198f8ba14610234578063d09f1ab41461023c578063d51b9e931461024f578063d55b7dff14610282575b600080fd5b34156100d457600080fd5b6100eb600160a060020a0360043516602435610295565b005b34156100f857600080fd5b6101006103db565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561013f578082015183820152602001610127565b505050509050019250505060405180910390f35b341561015e57600080fd5b610100600160a060020a0360043516610444565b341561017d57600080fd5b610197600160a060020a03600435811690602435166104d1565b60405190815260200160405180910390f35b34156101b457600080fd5b6101bf6004356104fe565b604051600160a060020a03909116815260200160405180910390f35b34156101e657600080fd5b610197600160a060020a0360043516610526565b6100eb600160a060020a0360043516610544565b341561021957600080fd5b61019761069b565b341561022c57600080fd5b6100eb6106a1565b6100eb610845565b341561024757600080fd5b610197610999565b341561025a57600080fd5b61026e600160a060020a036004351661099e565b604051901515815260200160405180910390f35b341561028d57600080fd5b6101976109bc565b600160a060020a03808316600090815260208181526040808320339094168352600290930190522054819010156102cb57600080fd5b600160a060020a0382166000908152602081905260409020600101546102f7908263ffffffff6109ca16565b600160a060020a038084166000908152602081815260408083206001810195909555339093168252600290930190925290205461033a908263ffffffff6109ca16565b600160a060020a0380841660009081526020818152604080832033909416808452600290940190915290819020929092559082156108fc0290839051600060405180830381858888f19350505050151561039357600080fd5b7f23ae40ca85f8a7c921ebb4269dc9a81e8a6de8dba614752927e0ff39341392fc8282604051600160a060020a03909216825260208201526040908101905180910390a15050565b6103e36109f2565b600280548060200260200160405190810160405280929190818152602001828054801561043957602002820191906000526020600020905b8154600160a060020a0316815260019091019060200180831161041b575b505050505090505b90565b61044c6109f2565b6001600083600160a060020a0316600160a060020a031681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156104c557602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116104a7575b50505050509050919050565b600160a060020a039182166000908152602081815260408083209390941682526002909201909152205490565b600280548290811061050c57fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a031660009081526020819052604090206001015490565b600160a060020a03811660009081526020819052604090205460ff16151561056b57600080fd5b600160a060020a038116600090815260208190526040902060010154610597903463ffffffff6109dc16565b600160a060020a03808316600090815260208181526040808320600181019590955533909316825260029093019092529020546105da903463ffffffff6109dc16565b600160a060020a038083166000818152602081815260408083203390951683526002909401815283822094909455908152600192839052208054909181016106228382610a04565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790557ff668ead05c744b9178e571d2edb452e72baf6529c8d72160e64e59b50d865bd08134604051600160a060020a03909216825260208201526040908101905180910390a150565b6101f481565b600160a060020a033316600090815260208190526040812054819060ff1615156106ca57600080fd5b600160a060020a033316600090815260208181526040808320600281018352908320549290915260010154909250610708908363ffffffff6109ca16565b600160a060020a03331660009081526020818152604080832060018101949094556002840182528220829055819052815460ff19169091556003805460001901905590505b6002548110156107cc5733600160a060020a031660028281548110151561077057fe5b600091825260209091200154600160a060020a031614156107c457600280548290811061079957fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191690556107cc565b60010161074d565b600160a060020a03331682156108fc0283604051600060405180830381858888f1935050505015156107fd57600080fd5b7f82b89ed824b293574a2cca050e6e27837b60436d911352f8dca203a9cd35241c3383604051600160a060020a03909216825260208201526040908101905180910390a15050565b69021e19e0c9bab240000034101561085c57600080fd5b600160a060020a03331660009081526020819052604090205460ff161561088257600080fd5b6003546101f490111561089457600080fd5b60028054600181016108a68382610a04565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790556040805190810160409081526001825234602080840191909152600160a060020a033316600090815290819052208151815460ff1916901515178155602082015160019182015533600160a060020a038116600090815260208181526040808320600201909152908190203490819055600380549094019093557f42681fc159c671d489c99c06f4693d03a705a21df2fbb2b84eedda79e0db4cff935090919051600160a060020a03909216825260208201526040908101905180910390a1565b606381565b600160a060020a031660009081526020819052604090205460ff1690565b69021e19e0c9bab240000081565b6000828211156109d657fe5b50900390565b6000828201838110156109eb57fe5b9392505050565b60206040519081016040526000815290565b815481835581811511610a2857600083815260209020610a28918101908301610a2d565b505050565b61044191905b80821115610a475760008155600101610a33565b50905600a165627a7a7230582080c308e459c6cbc6e91ffb692f7e77a6ff3985db345631c572a5e453588bc56c0029` +const TomoValidatorBin = `0x6060604052600060035534156200001557600080fd5b6040516200142838038062001428833981016040528080518201919060200180519091019050600060028380516200005292916020019062000171565b50600090505b8251811015620001685760a06040519081016040528033600160a060020a0316815260200160206040519081016040908152600082529082526001602083015201838381518110620000a657fe5b9060200190602002015181526020016000815250600080858481518110620000ca57fe5b90602001906020020151600160a060020a03168152602081019190915260400160002081518154600160a060020a031916600160a060020a039190911617815560208201518160010190805162000126929160200190620001dd565b50604082015160028201805460ff1916911515919091179055606082015181600301556080820151600490910155506003805460019081019091550162000058565b505050620002a5565b828054828255906000526020600020908101928215620001cb579160200282015b82811115620001cb5782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019062000192565b50620001d99291506200025e565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200022057805160ff191683800117855562000250565b8280016001018555821562000250579182015b828111156200025057825182559160200191906001019062000233565b50620001d992915062000288565b6200028591905b80821115620001d9578054600160a060020a031916815560010162000265565b90565b6200028591905b80821115620001d957600081556001016200028f565b61117380620002b56000396000f3006060604052600436106100ef5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041662a9550181146100f457806302aa9be21461012f57806306a49fce1461015357806328265294146101b95780632d15cc04146101ea578063302b6872146102095780633477ee2e1461022e57806351cff8d91461024457806358e7525f146102635780636dd7d8ea14610282578063a3ec796514610296578063ae6e43f5146102f5578063d09f1ab414610314578063d51b9e9314610327578063d55b7dff1461035a578063d6f0948c1461036d578063da67b5991461038d575b600080fd5b34156100ff57600080fd5b610113600160a060020a0360043516610423565b604051600160a060020a03909116815260200160405180910390f35b341561013a57600080fd5b610151600160a060020a0360043516602435610441565b005b341561015e57600080fd5b610166610599565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156101a557808201518382015260200161018d565b505050509050019250505060405180910390f35b34156101c457600080fd5b6101d8600160a060020a0360043516610602565b60405190815260200160405180910390f35b34156101f557600080fd5b610166600160a060020a0360043516610620565b341561021457600080fd5b6101d8600160a060020a03600435811690602435166106ad565b341561023957600080fd5b6101136004356106da565b341561024f57600080fd5b610151600160a060020a0360043516610702565b341561026e57600080fd5b6101d8600160a060020a03600435166108b3565b610151600160a060020a03600435166108d1565b34156102a157600080fd5b61015160048035600160a060020a03169060446024803590810190830135806020601f82018190048102016040519081016040528181529291906020840183838082843750949650610a7b95505050505050565b341561030057600080fd5b610151600160a060020a0360043516610b8b565b341561031f57600080fd5b6101d8610d4c565b341561033257600080fd5b610346600160a060020a0360043516610d51565b604051901515815260200160405180910390f35b341561036557600080fd5b6101d8610d72565b61015160048035600160a060020a03169060248035908101910135610d80565b341561039857600080fd5b6103ac600160a060020a0360043516610f87565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156103e85780820151838201526020016103d0565b50505050905090810190601f1680156104155780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600160a060020a039081166000908152602081905260409020541690565b600160a060020a03808316600090815260208181526040808320339094168352600590930190522054829082908190101561047b57600080fd5b600160a060020a0384166000908152602081905260409020600301546104a7908463ffffffff61104c16565b600160a060020a03808616600090815260208181526040808320600381019590955533909316825260059093019092529020546104ea908463ffffffff61104c16565b600160a060020a0380861660009081526020818152604080832033909416808452600590940190915290819020929092559084156108fc0290859051600060405180830381858888f19350505050151561054357600080fd5b7faa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2338585604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b6105a1611074565b60028054806020026020016040519081016040528092919081815260200182805480156105f757602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116105d9575b505050505090505b90565b600160a060020a031660009081526020819052604090206004015490565b610628611074565b6001600083600160a060020a0316600160a060020a031681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156106a157602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610683575b50505050509050919050565b600160a060020a039182166000908152602081815260408083209390941682526005909201909152205490565b60028054829081106106e857fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a038181166000908152602081905260408120549091839133821691161461072f57600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff161561075a57600080fd5b600160a060020a0384166000908152602081905260408120600401548591901161078357600080fd5b600160a060020a0381166000908152602081905260409020600401544310156107ab57600080fd5b600160a060020a03808616600081815260208181526040808320339095168352600585018252822054928252526003909101549094506107f1908563ffffffff61104c16565b600160a060020a0380871660008181526020818152604080832060038101969096553390941680835260058601825284832083905592825281905260049093019290925585156108fc0290869051600060405180830381858888f19350505050151561085c57600080fd5b7f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb338686604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050505050565b600160a060020a031660009081526020819052604090206003015490565b600160a060020a038116600090815260208190526040902060020154819060ff1615156108fd57600080fd5b600160a060020a038216600090815260208190526040902060030154610929903463ffffffff61105e16565b600160a060020a038084166000908152602081815260408083206003810195909555339093168252600590930190925290205415156109c057600160a060020a038216600090815260016020819052604090912080549091810161098d8382611086565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790555b600160a060020a038083166000908152602081815260408083203390941683526005909301905220546109f9903463ffffffff61105e16565b600160a060020a0380841660009081526020818152604080832033948516845260050190915290819020929092557f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc918490349051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050565b600160a060020a038281166000908152602081905260409020548391338116911614610aa657600080fd5b600160a060020a0383166000908152602081905260409020600101828051610ad29291602001906110af565b507f63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4338484604051600160a060020a0380851682528316602082015260606040820181815290820183818151815260200191508051906020019080838360005b83811015610b4a578082015183820152602001610b32565b50505050905090810190601f168015610b775780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1505050565b600160a060020a0381811660009081526020819052604081205490918391338216911614610bb857600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff161515610be457600080fd5b600160a060020a0384166000908152602081905260408120600201805460ff191690556003805460001901905592505b600254831015610c965783600160a060020a0316600284815481101515610c3757fe5b600091825260209091200154600160a060020a03161415610c8b576002805484908110610c6057fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19169055610c96565b600190920191610c14565b600160a060020a038416600090815260208190526040902060040154610cd590606490610cc9904363ffffffff61105e16565b9063ffffffff61105e16565b60008086600160a060020a0316600160a060020a03168152602001908152602001600020600401819055507f4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d33385604051600160a060020a039283168152911660208201526040908101905180910390a150505050565b606381565b600160a060020a031660009081526020819052604090206002015460ff1690565b690a968163f0a57b40000081565b690a968163f0a57b400000341015610d9757600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff1615610dc257600080fd5b6002805460018101610dd48382611086565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03861617905560a06040519081016040528033600160a060020a0316815260200184848080601f0160208091040260200160405190810160405281815292919060208401838380828437505050928452505060016020808401919091523460408085019190915260006060909401849052600160a060020a03891684529083905290912090508151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0391909116178155602082015181600101908051610eca9291602001906110af565b50604082015160028201805460ff191691151591909117905560608201518160030155608082015160049091015550600160a060020a038085166000908152602081815260408083203394851684526005019091529081902034908190556003805460010190557f7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1929187919051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b610f8f611074565b60008083600160a060020a0316600160a060020a031681526020019081526020016000206001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106a15780601f1061101f576101008083540402835291602001916106a1565b820191906000526020600020905b81548152906001019060200180831161102d5750939695505050505050565b60008282111561105857fe5b50900390565b60008282018381101561106d57fe5b9392505050565b60206040519081016040526000815290565b8154818355818115116110aa576000838152602090206110aa91810190830161112d565b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106110f057805160ff191683800117855561111d565b8280016001018555821561111d579182015b8281111561111d578251825591602001919060010190611102565b5061112992915061112d565b5090565b6105ff91905b8082111561112957600081556001016111335600a165627a7a72305820d2d4c6e641bc033beae9eb0c9fca10f5c9c68a746bc1b0099a8da4c99a3532d30029` // DeployTomoValidator deploys a new Ethereum contract, binding an instance of TomoValidator to it. func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _candidates []common.Address, _caps []*big.Int) (common.Address, *types.Transaction, *TomoValidator, error) { @@ -566,6 +566,32 @@ func (_TomoValidator *TomoValidatorCallerSession) Candidates(arg0 *big.Int) (com return _TomoValidator.Contract.Candidates(&_TomoValidator.CallOpts, arg0) } +// GetCandidateBacker is a free data retrieval call binding the contract method 0x00a95501. +// +// Solidity: function getCandidateBacker(_candidate address) constant returns(address) +func (_TomoValidator *TomoValidatorCaller) GetCandidateBacker(opts *bind.CallOpts, _candidate common.Address) (common.Address, error) { + var ( + ret0 = new(common.Address) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "getCandidateBacker", _candidate) + return *ret0, err +} + +// GetCandidateBacker is a free data retrieval call binding the contract method 0x00a95501. +// +// Solidity: function getCandidateBacker(_candidate address) constant returns(address) +func (_TomoValidator *TomoValidatorSession) GetCandidateBacker(_candidate common.Address) (common.Address, error) { + return _TomoValidator.Contract.GetCandidateBacker(&_TomoValidator.CallOpts, _candidate) +} + +// GetCandidateBacker is a free data retrieval call binding the contract method 0x00a95501. +// +// Solidity: function getCandidateBacker(_candidate address) constant returns(address) +func (_TomoValidator *TomoValidatorCallerSession) GetCandidateBacker(_candidate common.Address) (common.Address, error) { + return _TomoValidator.Contract.GetCandidateBacker(&_TomoValidator.CallOpts, _candidate) +} + // GetCandidateCap is a free data retrieval call binding the contract method 0x58e7525f. // // Solidity: function getCandidateCap(_candidate address) constant returns(uint256) @@ -592,6 +618,58 @@ 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. +// +// Solidity: function getCandidateNodeUrl(_candidate address) constant returns(string) +func (_TomoValidator *TomoValidatorCaller) GetCandidateNodeUrl(opts *bind.CallOpts, _candidate common.Address) (string, error) { + var ( + ret0 = new(string) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "getCandidateNodeUrl", _candidate) + return *ret0, err +} + +// GetCandidateNodeUrl is a free data retrieval call binding the contract method 0xda67b599. +// +// Solidity: function getCandidateNodeUrl(_candidate address) constant returns(string) +func (_TomoValidator *TomoValidatorSession) GetCandidateNodeUrl(_candidate common.Address) (string, error) { + return _TomoValidator.Contract.GetCandidateNodeUrl(&_TomoValidator.CallOpts, _candidate) +} + +// GetCandidateNodeUrl is a free data retrieval call binding the contract method 0xda67b599. +// +// Solidity: function getCandidateNodeUrl(_candidate address) constant returns(string) +func (_TomoValidator *TomoValidatorCallerSession) GetCandidateNodeUrl(_candidate common.Address) (string, error) { + return _TomoValidator.Contract.GetCandidateNodeUrl(&_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[]) @@ -696,32 +774,6 @@ func (_TomoValidator *TomoValidatorCallerSession) IsCandidate(_candidate common. return _TomoValidator.Contract.IsCandidate(&_TomoValidator.CallOpts, _candidate) } -// MaxCandidateNumber is a free data retrieval call binding the contract method 0x8198a8dc. -// -// Solidity: function maxCandidateNumber() constant returns(uint256) -func (_TomoValidator *TomoValidatorCaller) MaxCandidateNumber(opts *bind.CallOpts) (*big.Int, error) { - var ( - ret0 = new(*big.Int) - ) - out := ret0 - err := _TomoValidator.contract.Call(opts, out, "maxCandidateNumber") - return *ret0, err -} - -// MaxCandidateNumber is a free data retrieval call binding the contract method 0x8198a8dc. -// -// Solidity: function maxCandidateNumber() constant returns(uint256) -func (_TomoValidator *TomoValidatorSession) MaxCandidateNumber() (*big.Int, error) { - return _TomoValidator.Contract.MaxCandidateNumber(&_TomoValidator.CallOpts) -} - -// MaxCandidateNumber is a free data retrieval call binding the contract method 0x8198a8dc. -// -// Solidity: function maxCandidateNumber() constant returns(uint256) -func (_TomoValidator *TomoValidatorCallerSession) MaxCandidateNumber() (*big.Int, error) { - return _TomoValidator.Contract.MaxCandidateNumber(&_TomoValidator.CallOpts) -} - // MaxValidatorNumber is a free data retrieval call binding the contract method 0xd09f1ab4. // // Solidity: function maxValidatorNumber() constant returns(uint256) @@ -774,46 +826,67 @@ func (_TomoValidator *TomoValidatorCallerSession) MinCandidateCap() (*big.Int, e return _TomoValidator.Contract.MinCandidateCap(&_TomoValidator.CallOpts) } -// Propose is a paid mutator transaction binding the contract method 0xc198f8ba. +// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. // -// Solidity: function propose() returns() -func (_TomoValidator *TomoValidatorTransactor) Propose(opts *bind.TransactOpts) (*types.Transaction, error) { - return _TomoValidator.contract.Transact(opts, "propose") +// 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) } -// Propose is a paid mutator transaction binding the contract method 0xc198f8ba. +// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. // -// Solidity: function propose() returns() -func (_TomoValidator *TomoValidatorSession) Propose() (*types.Transaction, error) { - return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts) +// 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) } -// Propose is a paid mutator transaction binding the contract method 0xc198f8ba. +// Propose is a paid mutator transaction binding the contract method 0xd6f0948c. // -// Solidity: function propose() returns() -func (_TomoValidator *TomoValidatorTransactorSession) Propose() (*types.Transaction, error) { - return _TomoValidator.Contract.Propose(&_TomoValidator.TransactOpts) +// 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) } -// Retire is a paid mutator transaction binding the contract method 0xa4874d77. +// Resign is a paid mutator transaction binding the contract method 0xae6e43f5. // -// Solidity: function retire() returns() -func (_TomoValidator *TomoValidatorTransactor) Retire(opts *bind.TransactOpts) (*types.Transaction, error) { - return _TomoValidator.contract.Transact(opts, "retire") +// Solidity: function resign(_candidate address) returns() +func (_TomoValidator *TomoValidatorTransactor) Resign(opts *bind.TransactOpts, _candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.contract.Transact(opts, "resign", _candidate) } -// Retire is a paid mutator transaction binding the contract method 0xa4874d77. +// Resign is a paid mutator transaction binding the contract method 0xae6e43f5. // -// Solidity: function retire() returns() -func (_TomoValidator *TomoValidatorSession) Retire() (*types.Transaction, error) { - return _TomoValidator.Contract.Retire(&_TomoValidator.TransactOpts) +// Solidity: function resign(_candidate address) returns() +func (_TomoValidator *TomoValidatorSession) Resign(_candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.Contract.Resign(&_TomoValidator.TransactOpts, _candidate) } -// Retire is a paid mutator transaction binding the contract method 0xa4874d77. +// Resign is a paid mutator transaction binding the contract method 0xae6e43f5. // -// Solidity: function retire() returns() -func (_TomoValidator *TomoValidatorTransactorSession) Retire() (*types.Transaction, error) { - return _TomoValidator.Contract.Retire(&_TomoValidator.TransactOpts) +// Solidity: function resign(_candidate address) returns() +func (_TomoValidator *TomoValidatorTransactorSession) Resign(_candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.Contract.Resign(&_TomoValidator.TransactOpts, _candidate) +} + +// SetNodeUrl is a paid mutator transaction binding the contract method 0xa3ec7965. +// +// 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) +} + +// SetNodeUrl is a paid mutator transaction binding the contract method 0xa3ec7965. +// +// 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) +} + +// SetNodeUrl is a paid mutator transaction binding the contract method 0xa3ec7965. +// +// 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) } // Unvote is a paid mutator transaction binding the contract method 0x02aa9be2. @@ -858,6 +931,27 @@ 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. +// +// 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) +} + +// Withdraw is a paid mutator transaction binding the contract method 0x51cff8d9. +// +// Solidity: function withdraw(_candidate address) returns() +func (_TomoValidator *TomoValidatorSession) Withdraw(_candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.Contract.Withdraw(&_TomoValidator.TransactOpts, _candidate) +} + +// Withdraw is a paid mutator transaction binding the contract method 0x51cff8d9. +// +// Solidity: function withdraw(_candidate address) returns() +func (_TomoValidator *TomoValidatorTransactorSession) Withdraw(_candidate common.Address) (*types.Transaction, error) { + return _TomoValidator.Contract.Withdraw(&_TomoValidator.TransactOpts, _candidate) +} + // 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. type TomoValidatorProposeIterator struct { Event *TomoValidatorPropose // Event containing the contract specifics and raw log @@ -927,14 +1021,15 @@ func (it *TomoValidatorProposeIterator) Close() error { // TomoValidatorPropose represents a Propose event raised by the TomoValidator contract. type TomoValidatorPropose struct { + Backer common.Address Candidate common.Address Cap *big.Int Raw types.Log // Blockchain specific contextual infos } -// FilterPropose is a free log retrieval operation binding the contract event 0x42681fc159c671d489c99c06f4693d03a705a21df2fbb2b84eedda79e0db4cff. +// FilterPropose is a free log retrieval operation binding the contract event 0x7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1. // -// Solidity: event Propose(_candidate address, _cap uint256) +// Solidity: event Propose(_backer address, _candidate address, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) FilterPropose(opts *bind.FilterOpts) (*TomoValidatorProposeIterator, error) { logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Propose") @@ -944,9 +1039,9 @@ func (_TomoValidator *TomoValidatorFilterer) FilterPropose(opts *bind.FilterOpts return &TomoValidatorProposeIterator{contract: _TomoValidator.contract, event: "Propose", logs: logs, sub: sub}, nil } -// WatchPropose is a free log subscription operation binding the contract event 0x42681fc159c671d489c99c06f4693d03a705a21df2fbb2b84eedda79e0db4cff. +// WatchPropose is a free log subscription operation binding the contract event 0x7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1. // -// Solidity: event Propose(_candidate address, _cap uint256) +// Solidity: event Propose(_backer address, _candidate address, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) WatchPropose(opts *bind.WatchOpts, sink chan<- *TomoValidatorPropose) (event.Subscription, error) { logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Propose") @@ -981,9 +1076,9 @@ func (_TomoValidator *TomoValidatorFilterer) WatchPropose(opts *bind.WatchOpts, }), nil } -// TomoValidatorRetireIterator is returned from FilterRetire and is used to iterate over the raw logs and unpacked data for Retire events raised by the TomoValidator contract. -type TomoValidatorRetireIterator struct { - Event *TomoValidatorRetire // Event containing the contract specifics and raw log +// TomoValidatorResignIterator is returned from FilterResign and is used to iterate over the raw logs and unpacked data for Resign events raised by the TomoValidator contract. +type TomoValidatorResignIterator struct { + Event *TomoValidatorResign // 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 @@ -997,7 +1092,7 @@ type TomoValidatorRetireIterator 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 *TomoValidatorRetireIterator) Next() bool { +func (it *TomoValidatorResignIterator) Next() bool { // If the iterator failed, stop iterating if it.fail != nil { return false @@ -1006,7 +1101,7 @@ func (it *TomoValidatorRetireIterator) Next() bool { if it.done { select { case log := <-it.logs: - it.Event = new(TomoValidatorRetire) + it.Event = new(TomoValidatorResign) if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { it.fail = err return false @@ -1021,7 +1116,7 @@ func (it *TomoValidatorRetireIterator) Next() bool { // Iterator still in progress, wait for either a data or an error event select { case log := <-it.logs: - it.Event = new(TomoValidatorRetire) + it.Event = new(TomoValidatorResign) if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { it.fail = err return false @@ -1037,42 +1132,42 @@ func (it *TomoValidatorRetireIterator) Next() bool { } // Error returns any retrieval or parsing error occurred during filtering. -func (it *TomoValidatorRetireIterator) Error() error { +func (it *TomoValidatorResignIterator) Error() error { return it.fail } // Close terminates the iteration process, releasing any pending underlying // resources. -func (it *TomoValidatorRetireIterator) Close() error { +func (it *TomoValidatorResignIterator) Close() error { it.sub.Unsubscribe() return nil } -// TomoValidatorRetire represents a Retire event raised by the TomoValidator contract. -type TomoValidatorRetire struct { +// TomoValidatorResign represents a Resign event raised by the TomoValidator contract. +type TomoValidatorResign struct { + Backer common.Address Candidate common.Address - Cap *big.Int Raw types.Log // Blockchain specific contextual infos } -// FilterRetire is a free log retrieval operation binding the contract event 0x82b89ed824b293574a2cca050e6e27837b60436d911352f8dca203a9cd35241c. +// FilterResign is a free log retrieval operation binding the contract event 0x4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d3. // -// Solidity: event Retire(_candidate address, _cap uint256) -func (_TomoValidator *TomoValidatorFilterer) FilterRetire(opts *bind.FilterOpts) (*TomoValidatorRetireIterator, error) { +// Solidity: event Resign(_backer address, _candidate address) +func (_TomoValidator *TomoValidatorFilterer) FilterResign(opts *bind.FilterOpts) (*TomoValidatorResignIterator, error) { - logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Retire") + logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Resign") if err != nil { return nil, err } - return &TomoValidatorRetireIterator{contract: _TomoValidator.contract, event: "Retire", logs: logs, sub: sub}, nil + return &TomoValidatorResignIterator{contract: _TomoValidator.contract, event: "Resign", logs: logs, sub: sub}, nil } -// WatchRetire is a free log subscription operation binding the contract event 0x82b89ed824b293574a2cca050e6e27837b60436d911352f8dca203a9cd35241c. +// WatchResign is a free log subscription operation binding the contract event 0x4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d3. // -// Solidity: event Retire(_candidate address, _cap uint256) -func (_TomoValidator *TomoValidatorFilterer) WatchRetire(opts *bind.WatchOpts, sink chan<- *TomoValidatorRetire) (event.Subscription, error) { +// Solidity: event Resign(_backer address, _candidate address) +func (_TomoValidator *TomoValidatorFilterer) WatchResign(opts *bind.WatchOpts, sink chan<- *TomoValidatorResign) (event.Subscription, error) { - logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Retire") + logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Resign") if err != nil { return nil, err } @@ -1082,8 +1177,132 @@ func (_TomoValidator *TomoValidatorFilterer) WatchRetire(opts *bind.WatchOpts, s select { case log := <-logs: // New log arrived, parse the event and forward to the user - event := new(TomoValidatorRetire) - if err := _TomoValidator.contract.UnpackLog(event, "Retire", log); err != nil { + event := new(TomoValidatorResign) + if err := _TomoValidator.contract.UnpackLog(event, "Resign", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), 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 + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// 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 { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(TomoValidatorSetNodeUrl) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(TomoValidatorSetNodeUrl) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *TomoValidatorSetNodeUrlIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *TomoValidatorSetNodeUrlIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// TomoValidatorSetNodeUrl represents a SetNodeUrl event raised by the TomoValidator contract. +type TomoValidatorSetNodeUrl struct { + Backer common.Address + Candidate common.Address + NodeUrl string + Raw types.Log // Blockchain specific contextual infos +} + +// FilterSetNodeUrl is a free log retrieval operation binding the contract event 0x63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4. +// +// Solidity: event SetNodeUrl(_backer address, _candidate address, _nodeUrl string) +func (_TomoValidator *TomoValidatorFilterer) FilterSetNodeUrl(opts *bind.FilterOpts) (*TomoValidatorSetNodeUrlIterator, error) { + + logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "SetNodeUrl") + if err != nil { + return nil, err + } + return &TomoValidatorSetNodeUrlIterator{contract: _TomoValidator.contract, event: "SetNodeUrl", logs: logs, sub: sub}, nil +} + +// WatchSetNodeUrl is a free log subscription operation binding the contract event 0x63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4. +// +// Solidity: event SetNodeUrl(_backer address, _candidate address, _nodeUrl string) +func (_TomoValidator *TomoValidatorFilterer) WatchSetNodeUrl(opts *bind.WatchOpts, sink chan<- *TomoValidatorSetNodeUrl) (event.Subscription, error) { + + logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "SetNodeUrl") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + 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 { return err } event.Raw = log @@ -1173,14 +1392,15 @@ func (it *TomoValidatorUnvoteIterator) Close() error { // TomoValidatorUnvote represents a Unvote event raised by the TomoValidator contract. type TomoValidatorUnvote struct { + Voter common.Address Candidate common.Address Cap *big.Int Raw types.Log // Blockchain specific contextual infos } -// FilterUnvote is a free log retrieval operation binding the contract event 0x23ae40ca85f8a7c921ebb4269dc9a81e8a6de8dba614752927e0ff39341392fc. +// FilterUnvote is a free log retrieval operation binding the contract event 0xaa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2. // -// Solidity: event Unvote(_candidate address, _cap uint256) +// Solidity: event Unvote(_voter address, _candidate address, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) FilterUnvote(opts *bind.FilterOpts) (*TomoValidatorUnvoteIterator, error) { logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Unvote") @@ -1190,9 +1410,9 @@ func (_TomoValidator *TomoValidatorFilterer) FilterUnvote(opts *bind.FilterOpts) return &TomoValidatorUnvoteIterator{contract: _TomoValidator.contract, event: "Unvote", logs: logs, sub: sub}, nil } -// WatchUnvote is a free log subscription operation binding the contract event 0x23ae40ca85f8a7c921ebb4269dc9a81e8a6de8dba614752927e0ff39341392fc. +// WatchUnvote is a free log subscription operation binding the contract event 0xaa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2. // -// Solidity: event Unvote(_candidate address, _cap uint256) +// Solidity: event Unvote(_voter address, _candidate address, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) WatchUnvote(opts *bind.WatchOpts, sink chan<- *TomoValidatorUnvote) (event.Subscription, error) { logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Unvote") @@ -1296,14 +1516,15 @@ func (it *TomoValidatorVoteIterator) Close() error { // TomoValidatorVote represents a Vote event raised by the TomoValidator contract. type TomoValidatorVote struct { + Voter common.Address Candidate common.Address Cap *big.Int Raw types.Log // Blockchain specific contextual infos } -// FilterVote is a free log retrieval operation binding the contract event 0xf668ead05c744b9178e571d2edb452e72baf6529c8d72160e64e59b50d865bd0. +// FilterVote is a free log retrieval operation binding the contract event 0x66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc. // -// Solidity: event Vote(_candidate address, _cap uint256) +// Solidity: event Vote(_voter address, _candidate address, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) FilterVote(opts *bind.FilterOpts) (*TomoValidatorVoteIterator, error) { logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Vote") @@ -1313,9 +1534,9 @@ func (_TomoValidator *TomoValidatorFilterer) FilterVote(opts *bind.FilterOpts) ( return &TomoValidatorVoteIterator{contract: _TomoValidator.contract, event: "Vote", logs: logs, sub: sub}, nil } -// WatchVote is a free log subscription operation binding the contract event 0xf668ead05c744b9178e571d2edb452e72baf6529c8d72160e64e59b50d865bd0. +// WatchVote is a free log subscription operation binding the contract event 0x66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc. // -// Solidity: event Vote(_candidate address, _cap uint256) +// Solidity: event Vote(_voter address, _candidate address, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) WatchVote(opts *bind.WatchOpts, sink chan<- *TomoValidatorVote) (event.Subscription, error) { logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Vote") @@ -1349,3 +1570,127 @@ func (_TomoValidator *TomoValidatorFilterer) WatchVote(opts *bind.WatchOpts, sin } }), nil } + +// TomoValidatorWithdrawIterator is returned from FilterWithdraw and is used to iterate over the raw logs and unpacked data for Withdraw events raised by the TomoValidator contract. +type TomoValidatorWithdrawIterator struct { + Event *TomoValidatorWithdraw // 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 + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// 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 *TomoValidatorWithdrawIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(TomoValidatorWithdraw) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(TomoValidatorWithdraw) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *TomoValidatorWithdrawIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *TomoValidatorWithdrawIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// TomoValidatorWithdraw represents a Withdraw event raised by the TomoValidator contract. +type TomoValidatorWithdraw struct { + Backer common.Address + Candidate common.Address + Cap *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterWithdraw is a free log retrieval operation binding the contract event 0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb. +// +// Solidity: event Withdraw(_backer address, _candidate address, _cap uint256) +func (_TomoValidator *TomoValidatorFilterer) FilterWithdraw(opts *bind.FilterOpts) (*TomoValidatorWithdrawIterator, error) { + + logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Withdraw") + if err != nil { + return nil, err + } + return &TomoValidatorWithdrawIterator{contract: _TomoValidator.contract, event: "Withdraw", logs: logs, sub: sub}, nil +} + +// WatchWithdraw is a free log subscription operation binding the contract event 0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb. +// +// Solidity: event Withdraw(_backer address, _candidate address, _cap uint256) +func (_TomoValidator *TomoValidatorFilterer) WatchWithdraw(opts *bind.WatchOpts, sink chan<- *TomoValidatorWithdraw) (event.Subscription, error) { + + logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Withdraw") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(TomoValidatorWithdraw) + if err := _TomoValidator.contract.UnpackLog(event, "Withdraw", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} diff --git a/contracts/validator/validator_test.go b/contracts/validator/validator_test.go index 3d97e3c451..0d6f4c5108 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -30,10 +30,11 @@ func TestValidator(t *testing.T) { if err != nil { t.Fatalf("can't get candidates: %v", err) } - t.Log("candidates", candidates) for _, it := range candidates { cap, _ := validator.GetCandidateCap(it) t.Log("candidate", it.String(), "cap", cap) + backer, _ := validator.GetCandidateBacker(it) + t.Log("candidate", it.String(), "backer", backer.String()) } contractBackend.Commit() } From 10f83d824ac820174b1517f74f0e9b4ea58c57a2 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Mon, 11 Jun 2018 05:18:00 +0000 Subject: [PATCH 13/15] update latest validator contract --- .../validator/contract/TomoValidator.sol | 35 +++--- contracts/validator/contract/validator.go | 106 +++++++++++------- contracts/validator/validator_test.go | 4 +- 3 files changed, 86 insertions(+), 59 deletions(-) diff --git a/contracts/validator/contract/TomoValidator.sol b/contracts/validator/contract/TomoValidator.sol index 49668cbba6..6364666753 100644 --- a/contracts/validator/contract/TomoValidator.sol +++ b/contracts/validator/contract/TomoValidator.sol @@ -8,13 +8,13 @@ contract TomoValidator is IValidator { event Vote(address _voter, address _candidate, uint256 _cap); event Unvote(address _voter, address _candidate, uint256 _cap); - event Propose(address _backer, address _candidate, uint256 _cap); - event Resign(address _backer, address _candidate); - event SetNodeUrl(address _backer, address _candidate, string _nodeUrl); - event Withdraw(address _backer, 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); struct ValidatorState { - address backer; + address owner; string nodeUrl; bool isCandidate; uint256 cap; @@ -28,15 +28,16 @@ contract TomoValidator is IValidator { uint256 candidateCount = 0; uint256 public constant minCandidateCap = 50000 ether; uint256 public constant maxValidatorNumber = 99; + uint256 public constant candidateWithdrawDelay = 100; // blocks modifier onlyValidCandidateCap { - // anyone can deposit 10000 TOMO to become a candidate + // anyone can deposit X TOMO to become a candidate require(msg.value >= minCandidateCap); _; } - modifier onlyBacker(address _candidate) { - require(validatorsState[_candidate].backer == msg.sender); + modifier onlyOwner(address _candidate) { + require(validatorsState[_candidate].owner == msg.sender); _; } @@ -71,7 +72,7 @@ contract TomoValidator is IValidator { for (uint256 i = 0; i < _candidates.length; i++) { validatorsState[_candidates[i]] = ValidatorState({ - backer: msg.sender, + owner: msg.sender, nodeUrl: '', isCandidate: true, withdrawBlockNumber: 0, @@ -85,7 +86,7 @@ contract TomoValidator is IValidator { function propose(address _candidate, string _nodeUrl) external payable onlyValidCandidateCap onlyNotCandidate(_candidate) { candidates.push(_candidate); validatorsState[_candidate] = ValidatorState({ - backer: msg.sender, + owner: msg.sender, nodeUrl: _nodeUrl, isCandidate: true, withdrawBlockNumber: 0, @@ -117,8 +118,8 @@ contract TomoValidator is IValidator { return validatorsState[_candidate].nodeUrl; } - function getCandidateBacker(address _candidate) public view returns(address) { - return validatorsState[_candidate].backer; + function getCandidateOwner(address _candidate) public view returns(address) { + return validatorsState[_candidate].owner; } function getCandidateWithdrawBlockNumber(address _candidate) public view returns(uint256) { @@ -145,12 +146,12 @@ contract TomoValidator is IValidator { emit Unvote(msg.sender, _candidate, _cap); } - function setNodeUrl(address _candidate, string _nodeUrl) public onlyBacker(_candidate) { + function setNodeUrl(address _candidate, string _nodeUrl) public onlyOwner(_candidate) { validatorsState[_candidate].nodeUrl = _nodeUrl; emit SetNodeUrl(msg.sender, _candidate, _nodeUrl); } - function resign(address _candidate) public onlyBacker(_candidate) onlyCandidate(_candidate) { + function resign(address _candidate) public onlyOwner(_candidate) onlyCandidate(_candidate) { validatorsState[_candidate].isCandidate = false; candidateCount = candidateCount - 1; for (uint256 i = 0; i < candidates.length; i++) { @@ -159,12 +160,12 @@ contract TomoValidator is IValidator { break; } } - // refunding after retiring 100 blocks - validatorsState[_candidate].withdrawBlockNumber = validatorsState[_candidate].withdrawBlockNumber.add(block.number).add(100); + // 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 onlyBacker(_candidate) onlyNotCandidate(_candidate) onlyAlreadyResigned(_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; diff --git a/contracts/validator/contract/validator.go b/contracts/validator/contract/validator.go index 834fec6ce5..cc848dd469 100644 --- a/contracts/validator/contract/validator.go +++ b/contracts/validator/contract/validator.go @@ -380,10 +380,10 @@ func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method } // TomoValidatorABI is the input ABI used to generate the binding from. -const TomoValidatorABI = "[{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateBacker\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"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\":\"maxValidatorNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"isCandidate\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"minCandidateCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"propose\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateNodeUrl\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_candidates\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"type\":\"uint256[]\"}],\"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\":\"_backer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Propose\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_backer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"Resign\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_backer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_nodeUrl\",\"type\":\"string\"}],\"name\":\"SetNodeUrl\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_backer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"Withdraw\",\"type\":\"event\"}]" +const TomoValidatorABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"},{\"name\":\"_cap\",\"type\":\"uint256\"}],\"name\":\"unvote\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getCandidates\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getCandidateWithdrawBlockNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"getVoters\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_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\":\"_candidates\",\"type\":\"address[]\"},{\"name\":\"_caps\",\"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\"}]" // TomoValidatorBin is the compiled bytecode used for deploying new contracts. -const TomoValidatorBin = `0x6060604052600060035534156200001557600080fd5b6040516200142838038062001428833981016040528080518201919060200180519091019050600060028380516200005292916020019062000171565b50600090505b8251811015620001685760a06040519081016040528033600160a060020a0316815260200160206040519081016040908152600082529082526001602083015201838381518110620000a657fe5b9060200190602002015181526020016000815250600080858481518110620000ca57fe5b90602001906020020151600160a060020a03168152602081019190915260400160002081518154600160a060020a031916600160a060020a039190911617815560208201518160010190805162000126929160200190620001dd565b50604082015160028201805460ff1916911515919091179055606082015181600301556080820151600490910155506003805460019081019091550162000058565b505050620002a5565b828054828255906000526020600020908101928215620001cb579160200282015b82811115620001cb5782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019062000192565b50620001d99291506200025e565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200022057805160ff191683800117855562000250565b8280016001018555821562000250579182015b828111156200025057825182559160200191906001019062000233565b50620001d992915062000288565b6200028591905b80821115620001d9578054600160a060020a031916815560010162000265565b90565b6200028591905b80821115620001d957600081556001016200028f565b61117380620002b56000396000f3006060604052600436106100ef5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041662a9550181146100f457806302aa9be21461012f57806306a49fce1461015357806328265294146101b95780632d15cc04146101ea578063302b6872146102095780633477ee2e1461022e57806351cff8d91461024457806358e7525f146102635780636dd7d8ea14610282578063a3ec796514610296578063ae6e43f5146102f5578063d09f1ab414610314578063d51b9e9314610327578063d55b7dff1461035a578063d6f0948c1461036d578063da67b5991461038d575b600080fd5b34156100ff57600080fd5b610113600160a060020a0360043516610423565b604051600160a060020a03909116815260200160405180910390f35b341561013a57600080fd5b610151600160a060020a0360043516602435610441565b005b341561015e57600080fd5b610166610599565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156101a557808201518382015260200161018d565b505050509050019250505060405180910390f35b34156101c457600080fd5b6101d8600160a060020a0360043516610602565b60405190815260200160405180910390f35b34156101f557600080fd5b610166600160a060020a0360043516610620565b341561021457600080fd5b6101d8600160a060020a03600435811690602435166106ad565b341561023957600080fd5b6101136004356106da565b341561024f57600080fd5b610151600160a060020a0360043516610702565b341561026e57600080fd5b6101d8600160a060020a03600435166108b3565b610151600160a060020a03600435166108d1565b34156102a157600080fd5b61015160048035600160a060020a03169060446024803590810190830135806020601f82018190048102016040519081016040528181529291906020840183838082843750949650610a7b95505050505050565b341561030057600080fd5b610151600160a060020a0360043516610b8b565b341561031f57600080fd5b6101d8610d4c565b341561033257600080fd5b610346600160a060020a0360043516610d51565b604051901515815260200160405180910390f35b341561036557600080fd5b6101d8610d72565b61015160048035600160a060020a03169060248035908101910135610d80565b341561039857600080fd5b6103ac600160a060020a0360043516610f87565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156103e85780820151838201526020016103d0565b50505050905090810190601f1680156104155780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600160a060020a039081166000908152602081905260409020541690565b600160a060020a03808316600090815260208181526040808320339094168352600590930190522054829082908190101561047b57600080fd5b600160a060020a0384166000908152602081905260409020600301546104a7908463ffffffff61104c16565b600160a060020a03808616600090815260208181526040808320600381019590955533909316825260059093019092529020546104ea908463ffffffff61104c16565b600160a060020a0380861660009081526020818152604080832033909416808452600590940190915290819020929092559084156108fc0290859051600060405180830381858888f19350505050151561054357600080fd5b7faa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2338585604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b6105a1611074565b60028054806020026020016040519081016040528092919081815260200182805480156105f757602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116105d9575b505050505090505b90565b600160a060020a031660009081526020819052604090206004015490565b610628611074565b6001600083600160a060020a0316600160a060020a031681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156106a157602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610683575b50505050509050919050565b600160a060020a039182166000908152602081815260408083209390941682526005909201909152205490565b60028054829081106106e857fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a038181166000908152602081905260408120549091839133821691161461072f57600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff161561075a57600080fd5b600160a060020a0384166000908152602081905260408120600401548591901161078357600080fd5b600160a060020a0381166000908152602081905260409020600401544310156107ab57600080fd5b600160a060020a03808616600081815260208181526040808320339095168352600585018252822054928252526003909101549094506107f1908563ffffffff61104c16565b600160a060020a0380871660008181526020818152604080832060038101969096553390941680835260058601825284832083905592825281905260049093019290925585156108fc0290869051600060405180830381858888f19350505050151561085c57600080fd5b7f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb338686604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050505050565b600160a060020a031660009081526020819052604090206003015490565b600160a060020a038116600090815260208190526040902060020154819060ff1615156108fd57600080fd5b600160a060020a038216600090815260208190526040902060030154610929903463ffffffff61105e16565b600160a060020a038084166000908152602081815260408083206003810195909555339093168252600590930190925290205415156109c057600160a060020a038216600090815260016020819052604090912080549091810161098d8382611086565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790555b600160a060020a038083166000908152602081815260408083203390941683526005909301905220546109f9903463ffffffff61105e16565b600160a060020a0380841660009081526020818152604080832033948516845260050190915290819020929092557f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc918490349051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050565b600160a060020a038281166000908152602081905260409020548391338116911614610aa657600080fd5b600160a060020a0383166000908152602081905260409020600101828051610ad29291602001906110af565b507f63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4338484604051600160a060020a0380851682528316602082015260606040820181815290820183818151815260200191508051906020019080838360005b83811015610b4a578082015183820152602001610b32565b50505050905090810190601f168015610b775780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1505050565b600160a060020a0381811660009081526020819052604081205490918391338216911614610bb857600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff161515610be457600080fd5b600160a060020a0384166000908152602081905260408120600201805460ff191690556003805460001901905592505b600254831015610c965783600160a060020a0316600284815481101515610c3757fe5b600091825260209091200154600160a060020a03161415610c8b576002805484908110610c6057fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19169055610c96565b600190920191610c14565b600160a060020a038416600090815260208190526040902060040154610cd590606490610cc9904363ffffffff61105e16565b9063ffffffff61105e16565b60008086600160a060020a0316600160a060020a03168152602001908152602001600020600401819055507f4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d33385604051600160a060020a039283168152911660208201526040908101905180910390a150505050565b606381565b600160a060020a031660009081526020819052604090206002015460ff1690565b690a968163f0a57b40000081565b690a968163f0a57b400000341015610d9757600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff1615610dc257600080fd5b6002805460018101610dd48382611086565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03861617905560a06040519081016040528033600160a060020a0316815260200184848080601f0160208091040260200160405190810160405281815292919060208401838380828437505050928452505060016020808401919091523460408085019190915260006060909401849052600160a060020a03891684529083905290912090508151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0391909116178155602082015181600101908051610eca9291602001906110af565b50604082015160028201805460ff191691151591909117905560608201518160030155608082015160049091015550600160a060020a038085166000908152602081815260408083203394851684526005019091529081902034908190556003805460010190557f7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1929187919051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b610f8f611074565b60008083600160a060020a0316600160a060020a031681526020019081526020016000206001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106a15780601f1061101f576101008083540402835291602001916106a1565b820191906000526020600020905b81548152906001019060200180831161102d5750939695505050505050565b60008282111561105857fe5b50900390565b60008282018381101561106d57fe5b9392505050565b60206040519081016040526000815290565b8154818355818115116110aa576000838152602090206110aa91810190830161112d565b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106110f057805160ff191683800117855561111d565b8280016001018555821561111d579182015b8281111561111d578251825591602001919060010190611102565b5061112992915061112d565b5090565b6105ff91905b8082111561112957600081556001016111335600a165627a7a72305820d2d4c6e641bc033beae9eb0c9fca10f5c9c68a746bc1b0099a8da4c99a3532d30029` +const TomoValidatorBin = `0x6060604052600060035534156200001557600080fd5b6040516200144c3803806200144c833981016040528080518201919060200180519091019050600060028380516200005292916020019062000171565b50600090505b8251811015620001685760a06040519081016040528033600160a060020a0316815260200160206040519081016040908152600082529082526001602083015201838381518110620000a657fe5b9060200190602002015181526020016000815250600080858481518110620000ca57fe5b90602001906020020151600160a060020a03168152602081019190915260400160002081518154600160a060020a031916600160a060020a039190911617815560208201518160010190805162000126929160200190620001dd565b50604082015160028201805460ff1916911515919091179055606082015181600301556080820151600490910155506003805460019081019091550162000058565b505050620002a5565b828054828255906000526020600020908101928215620001cb579160200282015b82811115620001cb5782518254600160a060020a031916600160a060020a03919091161782556020929092019160019091019062000192565b50620001d99291506200025e565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200022057805160ff191683800117855562000250565b8280016001018555821562000250579182015b828111156200025057825182559160200191906001019062000233565b50620001d992915062000288565b6200028591905b80821115620001d9578054600160a060020a031916815560010162000265565b90565b6200028591905b80821115620001d957600081556001016200028f565b61119780620002b56000396000f3006060604052600436106100fb5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302aa9be2811461010057806306a49fce14610124578063282652941461018a5780632d15cc04146101bb578063302b6872146101da5780633477ee2e146101ff57806351cff8d91461023157806358e7525f146102505780636dd7d8ea1461026f578063a3ec796514610283578063ae6e43f5146102e2578063b642facd14610301578063d09f1ab414610320578063d161c76714610333578063d51b9e9314610346578063d55b7dff14610379578063d6f0948c1461038c578063da67b599146103ac575b600080fd5b341561010b57600080fd5b610122600160a060020a0360043516602435610442565b005b341561012f57600080fd5b61013761059a565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561017657808201518382015260200161015e565b505050509050019250505060405180910390f35b341561019557600080fd5b6101a9600160a060020a0360043516610603565b60405190815260200160405180910390f35b34156101c657600080fd5b610137600160a060020a0360043516610621565b34156101e557600080fd5b6101a9600160a060020a03600435811690602435166106ae565b341561020a57600080fd5b6102156004356106db565b604051600160a060020a03909116815260200160405180910390f35b341561023c57600080fd5b610122600160a060020a0360043516610703565b341561025b57600080fd5b6101a9600160a060020a03600435166108b4565b610122600160a060020a03600435166108d2565b341561028e57600080fd5b61012260048035600160a060020a03169060446024803590810190830135806020601f82018190048102016040519081016040528181529291906020840183838082843750949650610a7c95505050505050565b34156102ed57600080fd5b610122600160a060020a0360043516610b8c565b341561030c57600080fd5b610215600160a060020a0360043516610d4d565b341561032b57600080fd5b6101a9610d6b565b341561033e57600080fd5b6101a9610d70565b341561035157600080fd5b610365600160a060020a0360043516610d75565b604051901515815260200160405180910390f35b341561038457600080fd5b6101a9610d96565b61012260048035600160a060020a03169060248035908101910135610da4565b34156103b757600080fd5b6103cb600160a060020a0360043516610fab565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156104075780820151838201526020016103ef565b50505050905090810190601f1680156104345780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600160a060020a03808316600090815260208181526040808320339094168352600590930190522054829082908190101561047c57600080fd5b600160a060020a0384166000908152602081905260409020600301546104a8908463ffffffff61107016565b600160a060020a03808616600090815260208181526040808320600381019590955533909316825260059093019092529020546104eb908463ffffffff61107016565b600160a060020a0380861660009081526020818152604080832033909416808452600590940190915290819020929092559084156108fc0290859051600060405180830381858888f19350505050151561054457600080fd5b7faa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2338585604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b6105a2611098565b60028054806020026020016040519081016040528092919081815260200182805480156105f857602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116105da575b505050505090505b90565b600160a060020a031660009081526020819052604090206004015490565b610629611098565b6001600083600160a060020a0316600160a060020a031681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156106a257602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610684575b50505050509050919050565b600160a060020a039182166000908152602081815260408083209390941682526005909201909152205490565b60028054829081106106e957fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a038181166000908152602081905260408120549091839133821691161461073057600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff161561075b57600080fd5b600160a060020a0384166000908152602081905260408120600401548591901161078457600080fd5b600160a060020a0381166000908152602081905260409020600401544310156107ac57600080fd5b600160a060020a03808616600081815260208181526040808320339095168352600585018252822054928252526003909101549094506107f2908563ffffffff61107016565b600160a060020a0380871660008181526020818152604080832060038101969096553390941680835260058601825284832083905592825281905260049093019290925585156108fc0290869051600060405180830381858888f19350505050151561085d57600080fd5b7f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb338686604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050505050565b600160a060020a031660009081526020819052604090206003015490565b600160a060020a038116600090815260208190526040902060020154819060ff1615156108fe57600080fd5b600160a060020a03821660009081526020819052604090206003015461092a903463ffffffff61108216565b600160a060020a038084166000908152602081815260408083206003810195909555339093168252600590930190925290205415156109c157600160a060020a038216600090815260016020819052604090912080549091810161098e83826110aa565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff191633600160a060020a03161790555b600160a060020a038083166000908152602081815260408083203390941683526005909301905220546109fa903463ffffffff61108216565b600160a060020a0380841660009081526020818152604080832033948516845260050190915290819020929092557f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc918490349051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050565b600160a060020a038281166000908152602081905260409020548391338116911614610aa757600080fd5b600160a060020a0383166000908152602081905260409020600101828051610ad39291602001906110d3565b507f63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4338484604051600160a060020a0380851682528316602082015260606040820181815290820183818151815260200191508051906020019080838360005b83811015610b4b578082015183820152602001610b33565b50505050905090810190601f168015610b785780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1505050565b600160a060020a0381811660009081526020819052604081205490918391338216911614610bb957600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff161515610be557600080fd5b600160a060020a0384166000908152602081905260408120600201805460ff191690556003805460001901905592505b600254831015610c975783600160a060020a0316600284815481101515610c3857fe5b600091825260209091200154600160a060020a03161415610c8c576002805484908110610c6157fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19169055610c97565b600190920191610c15565b600160a060020a038416600090815260208190526040902060040154610cd690606490610cca904363ffffffff61108216565b9063ffffffff61108216565b60008086600160a060020a0316600160a060020a03168152602001908152602001600020600401819055507f4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d33385604051600160a060020a039283168152911660208201526040908101905180910390a150505050565b600160a060020a039081166000908152602081905260409020541690565b606381565b606481565b600160a060020a031660009081526020819052604090206002015460ff1690565b690a968163f0a57b40000081565b690a968163f0a57b400000341015610dbb57600080fd5b600160a060020a038316600090815260208190526040902060020154839060ff1615610de657600080fd5b6002805460018101610df883826110aa565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03861617905560a06040519081016040528033600160a060020a0316815260200184848080601f0160208091040260200160405190810160405281815292919060208401838380828437505050928452505060016020808401919091523460408085019190915260006060909401849052600160a060020a03891684529083905290912090508151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0391909116178155602082015181600101908051610eee9291602001906110d3565b50604082015160028201805460ff191691151591909117905560608201518160030155608082015160049091015550600160a060020a038085166000908152602081815260408083203394851684526005019091529081902034908190556003805460010190557f7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1929187919051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a150505050565b610fb3611098565b60008083600160a060020a0316600160a060020a031681526020019081526020016000206001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106a25780601f10611043576101008083540402835291602001916106a2565b820191906000526020600020905b8154815290600101906020018083116110515750939695505050505050565b60008282111561107c57fe5b50900390565b60008282018381101561109157fe5b9392505050565b60206040519081016040526000815290565b8154818355818115116110ce576000838152602090206110ce918101908301611151565b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061111457805160ff1916838001178555611141565b82800160010185558215611141579182015b82811115611141578251825591602001919060010190611126565b5061114d929150611151565b5090565b61060091905b8082111561114d57600081556001016111575600a165627a7a723058207dd61e3603de213ecbfbe51aaea6f960b2920c475048e55de0d1b16fd89c7a900029` // DeployTomoValidator deploys a new Ethereum contract, binding an instance of TomoValidator to it. func DeployTomoValidator(auth *bind.TransactOpts, backend bind.ContractBackend, _candidates []common.Address, _caps []*big.Int) (common.Address, *types.Transaction, *TomoValidator, error) { @@ -540,6 +540,32 @@ func (_TomoValidator *TomoValidatorTransactorRaw) Transact(opts *bind.TransactOp return _TomoValidator.Contract.contract.Transact(opts, method, params...) } +// CandidateWithdrawDelay is a free data retrieval call binding the contract method 0xd161c767. +// +// Solidity: function candidateWithdrawDelay() constant returns(uint256) +func (_TomoValidator *TomoValidatorCaller) CandidateWithdrawDelay(opts *bind.CallOpts) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "candidateWithdrawDelay") + return *ret0, err +} + +// CandidateWithdrawDelay is a free data retrieval call binding the contract method 0xd161c767. +// +// Solidity: function candidateWithdrawDelay() constant returns(uint256) +func (_TomoValidator *TomoValidatorSession) CandidateWithdrawDelay() (*big.Int, error) { + return _TomoValidator.Contract.CandidateWithdrawDelay(&_TomoValidator.CallOpts) +} + +// CandidateWithdrawDelay is a free data retrieval call binding the contract method 0xd161c767. +// +// Solidity: function candidateWithdrawDelay() constant returns(uint256) +func (_TomoValidator *TomoValidatorCallerSession) CandidateWithdrawDelay() (*big.Int, error) { + return _TomoValidator.Contract.CandidateWithdrawDelay(&_TomoValidator.CallOpts) +} + // Candidates is a free data retrieval call binding the contract method 0x3477ee2e. // // Solidity: function candidates( uint256) constant returns(address) @@ -566,32 +592,6 @@ func (_TomoValidator *TomoValidatorCallerSession) Candidates(arg0 *big.Int) (com return _TomoValidator.Contract.Candidates(&_TomoValidator.CallOpts, arg0) } -// GetCandidateBacker is a free data retrieval call binding the contract method 0x00a95501. -// -// Solidity: function getCandidateBacker(_candidate address) constant returns(address) -func (_TomoValidator *TomoValidatorCaller) GetCandidateBacker(opts *bind.CallOpts, _candidate common.Address) (common.Address, error) { - var ( - ret0 = new(common.Address) - ) - out := ret0 - err := _TomoValidator.contract.Call(opts, out, "getCandidateBacker", _candidate) - return *ret0, err -} - -// GetCandidateBacker is a free data retrieval call binding the contract method 0x00a95501. -// -// Solidity: function getCandidateBacker(_candidate address) constant returns(address) -func (_TomoValidator *TomoValidatorSession) GetCandidateBacker(_candidate common.Address) (common.Address, error) { - return _TomoValidator.Contract.GetCandidateBacker(&_TomoValidator.CallOpts, _candidate) -} - -// GetCandidateBacker is a free data retrieval call binding the contract method 0x00a95501. -// -// Solidity: function getCandidateBacker(_candidate address) constant returns(address) -func (_TomoValidator *TomoValidatorCallerSession) GetCandidateBacker(_candidate common.Address) (common.Address, error) { - return _TomoValidator.Contract.GetCandidateBacker(&_TomoValidator.CallOpts, _candidate) -} - // GetCandidateCap is a free data retrieval call binding the contract method 0x58e7525f. // // Solidity: function getCandidateCap(_candidate address) constant returns(uint256) @@ -644,6 +644,32 @@ func (_TomoValidator *TomoValidatorCallerSession) GetCandidateNodeUrl(_candidate return _TomoValidator.Contract.GetCandidateNodeUrl(&_TomoValidator.CallOpts, _candidate) } +// GetCandidateOwner is a free data retrieval call binding the contract method 0xb642facd. +// +// Solidity: function getCandidateOwner(_candidate address) constant returns(address) +func (_TomoValidator *TomoValidatorCaller) GetCandidateOwner(opts *bind.CallOpts, _candidate common.Address) (common.Address, error) { + var ( + ret0 = new(common.Address) + ) + out := ret0 + err := _TomoValidator.contract.Call(opts, out, "getCandidateOwner", _candidate) + return *ret0, err +} + +// GetCandidateOwner is a free data retrieval call binding the contract method 0xb642facd. +// +// Solidity: function getCandidateOwner(_candidate address) constant returns(address) +func (_TomoValidator *TomoValidatorSession) GetCandidateOwner(_candidate common.Address) (common.Address, error) { + return _TomoValidator.Contract.GetCandidateOwner(&_TomoValidator.CallOpts, _candidate) +} + +// GetCandidateOwner is a free data retrieval call binding the contract method 0xb642facd. +// +// Solidity: function getCandidateOwner(_candidate address) constant returns(address) +func (_TomoValidator *TomoValidatorCallerSession) GetCandidateOwner(_candidate common.Address) (common.Address, error) { + 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) @@ -1021,7 +1047,7 @@ func (it *TomoValidatorProposeIterator) Close() error { // TomoValidatorPropose represents a Propose event raised by the TomoValidator contract. type TomoValidatorPropose struct { - Backer common.Address + Owner common.Address Candidate common.Address Cap *big.Int Raw types.Log // Blockchain specific contextual infos @@ -1029,7 +1055,7 @@ type TomoValidatorPropose struct { // FilterPropose is a free log retrieval operation binding the contract event 0x7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1. // -// Solidity: event Propose(_backer address, _candidate address, _cap uint256) +// Solidity: event Propose(_owner address, _candidate address, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) FilterPropose(opts *bind.FilterOpts) (*TomoValidatorProposeIterator, error) { logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Propose") @@ -1041,7 +1067,7 @@ func (_TomoValidator *TomoValidatorFilterer) FilterPropose(opts *bind.FilterOpts // WatchPropose is a free log subscription operation binding the contract event 0x7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1. // -// Solidity: event Propose(_backer address, _candidate address, _cap uint256) +// Solidity: event Propose(_owner address, _candidate address, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) WatchPropose(opts *bind.WatchOpts, sink chan<- *TomoValidatorPropose) (event.Subscription, error) { logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Propose") @@ -1145,14 +1171,14 @@ func (it *TomoValidatorResignIterator) Close() error { // TomoValidatorResign represents a Resign event raised by the TomoValidator contract. type TomoValidatorResign struct { - Backer common.Address + Owner common.Address Candidate common.Address Raw types.Log // Blockchain specific contextual infos } // FilterResign is a free log retrieval operation binding the contract event 0x4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d3. // -// Solidity: event Resign(_backer address, _candidate address) +// Solidity: event Resign(_owner address, _candidate address) func (_TomoValidator *TomoValidatorFilterer) FilterResign(opts *bind.FilterOpts) (*TomoValidatorResignIterator, error) { logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Resign") @@ -1164,7 +1190,7 @@ func (_TomoValidator *TomoValidatorFilterer) FilterResign(opts *bind.FilterOpts) // WatchResign is a free log subscription operation binding the contract event 0x4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d3. // -// Solidity: event Resign(_backer address, _candidate address) +// Solidity: event Resign(_owner address, _candidate address) func (_TomoValidator *TomoValidatorFilterer) WatchResign(opts *bind.WatchOpts, sink chan<- *TomoValidatorResign) (event.Subscription, error) { logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "Resign") @@ -1268,7 +1294,7 @@ func (it *TomoValidatorSetNodeUrlIterator) Close() error { // TomoValidatorSetNodeUrl represents a SetNodeUrl event raised by the TomoValidator contract. type TomoValidatorSetNodeUrl struct { - Backer common.Address + Owner common.Address Candidate common.Address NodeUrl string Raw types.Log // Blockchain specific contextual infos @@ -1276,7 +1302,7 @@ type TomoValidatorSetNodeUrl struct { // FilterSetNodeUrl is a free log retrieval operation binding the contract event 0x63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4. // -// Solidity: event SetNodeUrl(_backer address, _candidate address, _nodeUrl string) +// Solidity: event SetNodeUrl(_owner address, _candidate address, _nodeUrl string) func (_TomoValidator *TomoValidatorFilterer) FilterSetNodeUrl(opts *bind.FilterOpts) (*TomoValidatorSetNodeUrlIterator, error) { logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "SetNodeUrl") @@ -1288,7 +1314,7 @@ func (_TomoValidator *TomoValidatorFilterer) FilterSetNodeUrl(opts *bind.FilterO // WatchSetNodeUrl is a free log subscription operation binding the contract event 0x63f303264cd4b7a198f0163f96e0b6b1f972f9b73359a70c44241b862879d8a4. // -// Solidity: event SetNodeUrl(_backer address, _candidate address, _nodeUrl string) +// Solidity: event SetNodeUrl(_owner address, _candidate address, _nodeUrl string) func (_TomoValidator *TomoValidatorFilterer) WatchSetNodeUrl(opts *bind.WatchOpts, sink chan<- *TomoValidatorSetNodeUrl) (event.Subscription, error) { logs, sub, err := _TomoValidator.contract.WatchLogs(opts, "SetNodeUrl") @@ -1640,7 +1666,7 @@ func (it *TomoValidatorWithdrawIterator) Close() error { // TomoValidatorWithdraw represents a Withdraw event raised by the TomoValidator contract. type TomoValidatorWithdraw struct { - Backer common.Address + Owner common.Address Candidate common.Address Cap *big.Int Raw types.Log // Blockchain specific contextual infos @@ -1648,7 +1674,7 @@ type TomoValidatorWithdraw struct { // FilterWithdraw is a free log retrieval operation binding the contract event 0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb. // -// Solidity: event Withdraw(_backer address, _candidate address, _cap uint256) +// Solidity: event Withdraw(_owner address, _candidate address, _cap uint256) func (_TomoValidator *TomoValidatorFilterer) FilterWithdraw(opts *bind.FilterOpts) (*TomoValidatorWithdrawIterator, error) { logs, sub, err := _TomoValidator.contract.FilterLogs(opts, "Withdraw") @@ -1660,7 +1686,7 @@ func (_TomoValidator *TomoValidatorFilterer) FilterWithdraw(opts *bind.FilterOpt // WatchWithdraw is a free log subscription operation binding the contract event 0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb. // -// Solidity: event Withdraw(_backer address, _candidate address, _cap uint256) +// Solidity: event Withdraw(_owner address, _candidate address, _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_test.go b/contracts/validator/validator_test.go index 0d6f4c5108..e7cf3c88a9 100644 --- a/contracts/validator/validator_test.go +++ b/contracts/validator/validator_test.go @@ -33,8 +33,8 @@ func TestValidator(t *testing.T) { for _, it := range candidates { cap, _ := validator.GetCandidateCap(it) t.Log("candidate", it.String(), "cap", cap) - backer, _ := validator.GetCandidateBacker(it) - t.Log("candidate", it.String(), "backer", backer.String()) + owner, _ := validator.GetCandidateOwner(it) + t.Log("candidate", it.String(), "validator owner", owner.String()) } contractBackend.Commit() } From 8ac69e17bc8cfa7a2b3acf61df3a4ad938e2581b Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Wed, 13 Jun 2018 10:34:30 +0000 Subject: [PATCH 14/15] add Block Signer Smart contract --- contracts/blocksigner/blocksigner.go | 41 ++ contracts/blocksigner/blocksigner_test.go | 36 ++ .../blocksigner/contract/BlockSigner.sol | 24 + contracts/blocksigner/contract/blocksigner.go | 508 ++++++++++++++++++ .../blocksigner/contract/libs/SafeMath.sol | 47 ++ 5 files changed, 656 insertions(+) create mode 100644 contracts/blocksigner/blocksigner.go create mode 100644 contracts/blocksigner/blocksigner_test.go create mode 100644 contracts/blocksigner/contract/BlockSigner.sol create mode 100644 contracts/blocksigner/contract/blocksigner.go create mode 100644 contracts/blocksigner/contract/libs/SafeMath.sol diff --git a/contracts/blocksigner/blocksigner.go b/contracts/blocksigner/blocksigner.go new file mode 100644 index 0000000000..f23cfbd669 --- /dev/null +++ b/contracts/blocksigner/blocksigner.go @@ -0,0 +1,41 @@ +package blocksigner + +import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/contracts/blocksigner/contract" +) + +type BlockSigner struct { + *contract.BlockSignerSession + contractBackend bind.ContractBackend +} + +func NewBlockSigner(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*BlockSigner, error) { + blockSigner, err := contract.NewBlockSigner(contractAddr, contractBackend) + if err != nil { + return nil, err + } + + return &BlockSigner{ + &contract.BlockSignerSession{ + Contract: blockSigner, + TransactOpts: *transactOpts, + }, + contractBackend, + }, nil +} + +func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *BlockSigner, error) { + blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend) + if err != nil { + return blockSignerAddr, nil, err + } + + blockSigner, err := NewBlockSigner(transactOpts, blockSignerAddr, contractBackend) + if err != nil { + return blockSignerAddr, nil, err + } + + return blockSignerAddr, blockSigner, nil +} diff --git a/contracts/blocksigner/blocksigner_test.go b/contracts/blocksigner/blocksigner_test.go new file mode 100644 index 0000000000..16c6128aba --- /dev/null +++ b/contracts/blocksigner/blocksigner_test.go @@ -0,0 +1,36 @@ +package blocksigner + +import ( + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/crypto" +) + +var ( + key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + addr = crypto.PubkeyToAddress(key.PublicKey) +) + +func TestBlockSigner(t *testing.T) { + contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}) + transactOpts := bind.NewKeyedTransactor(key) + + _, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend) + if err != nil { + t.Fatalf("can't deploy root registry: %v", err) + } + contractBackend.Commit() + + signers, err := blockSigner.GetSigners(big.NewInt(0)) + if err != nil { + t.Fatalf("can't get candidates: %v", err) + } + for _, it := range signers { + t.Log("signer", it.String()) + } + contractBackend.Commit() +} diff --git a/contracts/blocksigner/contract/BlockSigner.sol b/contracts/blocksigner/contract/BlockSigner.sol new file mode 100644 index 0000000000..d902d190a0 --- /dev/null +++ b/contracts/blocksigner/contract/BlockSigner.sol @@ -0,0 +1,24 @@ +pragma solidity ^0.4.21; + +import "./libs/SafeMath.sol"; + +contract BlockSigner { + using SafeMath for uint256; + + event Sign(address _signer, uint256 blockNumber); + + mapping(uint256 => address[]) blockSigners; + + function sign(uint256 _blockNumber) external { + // consensus should validate all senders are validators, gas = 0 + require(block.number >= _blockNumber); + require(block.number <= _blockNumber.add(990 * 2)); + blockSigners[_blockNumber].push(msg.sender); + + emit Sign(msg.sender, _blockNumber); + } + + function getSigners(uint256 _blockNumber) public view returns(address[]) { + return blockSigners[_blockNumber]; + } +} diff --git a/contracts/blocksigner/contract/blocksigner.go b/contracts/blocksigner/contract/blocksigner.go new file mode 100644 index 0000000000..392e7410c2 --- /dev/null +++ b/contracts/blocksigner/contract/blocksigner.go @@ -0,0 +1,508 @@ +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package contract + +import ( + "math/big" + "strings" + + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" +) + +// BlockSignerABI is the input ABI used to generate the binding from. +const BlockSignerABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"}],\"name\":\"sign\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"}],\"name\":\"getSigners\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_signer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"blockNumber\",\"type\":\"uint256\"}],\"name\":\"Sign\",\"type\":\"event\"}]" + +// BlockSignerBin is the compiled bytecode used for deploying new contracts. +const BlockSignerBin = `0x6060604052341561000f57600080fd5b6102d88061001e6000396000f30060606040526004361061004b5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632fb1b25f8114610050578063dfceceae14610068575b600080fd5b341561005b57600080fd5b6100666004356100d1565b005b341561007357600080fd5b61007e6004356101b3565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100bd5780820151838201526020016100a5565b505050509050019250505060405180910390f35b43819010156100df57600080fd5b6100f1816107bc63ffffffff61023a16565b4311156100fd57600080fd5b600081815260208190526040902080546001810161011b8382610250565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19163373ffffffffffffffffffffffffffffffffffffffff8116919091179091557f9a10b6124411386407c4a174729b856d293832181c352e98b5cb316b96cd3059908260405173ffffffffffffffffffffffffffffffffffffffff909216825260208201526040908101905180910390a150565b6101bb610279565b60008083815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561022e57602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610203575b50505050509050919050565b60008282018381101561024957fe5b9392505050565b8154818355818115116102745760008381526020902061027491810190830161028b565b505050565b60206040519081016040526000815290565b6102a991905b808211156102a55760008155600101610291565b5090565b905600a165627a7a723058202122aa6936b95136c1c3d903171e9967879db0166a672dd0a376ba5e2b340a6a0029` + +// DeployBlockSigner deploys a new Ethereum contract, binding an instance of BlockSigner to it. +func DeployBlockSigner(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *BlockSigner, error) { + parsed, err := abi.JSON(strings.NewReader(BlockSignerABI)) + if err != nil { + return common.Address{}, nil, nil, err + } + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(BlockSignerBin), backend) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, tx, &BlockSigner{BlockSignerCaller: BlockSignerCaller{contract: contract}, BlockSignerTransactor: BlockSignerTransactor{contract: contract}, BlockSignerFilterer: BlockSignerFilterer{contract: contract}}, nil +} + +// BlockSigner is an auto generated Go binding around an Ethereum contract. +type BlockSigner struct { + BlockSignerCaller // Read-only binding to the contract + BlockSignerTransactor // Write-only binding to the contract + BlockSignerFilterer // Log filterer for contract events +} + +// BlockSignerCaller is an auto generated read-only Go binding around an Ethereum contract. +type BlockSignerCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// BlockSignerTransactor is an auto generated write-only Go binding around an Ethereum contract. +type BlockSignerTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// BlockSignerFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type BlockSignerFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// BlockSignerSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type BlockSignerSession struct { + Contract *BlockSigner // 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 +} + +// BlockSignerCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type BlockSignerCallerSession struct { + Contract *BlockSignerCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// BlockSignerTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type BlockSignerTransactorSession struct { + Contract *BlockSignerTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// BlockSignerRaw is an auto generated low-level Go binding around an Ethereum contract. +type BlockSignerRaw struct { + Contract *BlockSigner // Generic contract binding to access the raw methods on +} + +// BlockSignerCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type BlockSignerCallerRaw struct { + Contract *BlockSignerCaller // Generic read-only contract binding to access the raw methods on +} + +// BlockSignerTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type BlockSignerTransactorRaw struct { + Contract *BlockSignerTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewBlockSigner creates a new instance of BlockSigner, bound to a specific deployed contract. +func NewBlockSigner(address common.Address, backend bind.ContractBackend) (*BlockSigner, error) { + contract, err := bindBlockSigner(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &BlockSigner{BlockSignerCaller: BlockSignerCaller{contract: contract}, BlockSignerTransactor: BlockSignerTransactor{contract: contract}, BlockSignerFilterer: BlockSignerFilterer{contract: contract}}, nil +} + +// NewBlockSignerCaller creates a new read-only instance of BlockSigner, bound to a specific deployed contract. +func NewBlockSignerCaller(address common.Address, caller bind.ContractCaller) (*BlockSignerCaller, error) { + contract, err := bindBlockSigner(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &BlockSignerCaller{contract: contract}, nil +} + +// NewBlockSignerTransactor creates a new write-only instance of BlockSigner, bound to a specific deployed contract. +func NewBlockSignerTransactor(address common.Address, transactor bind.ContractTransactor) (*BlockSignerTransactor, error) { + contract, err := bindBlockSigner(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &BlockSignerTransactor{contract: contract}, nil +} + +// NewBlockSignerFilterer creates a new log filterer instance of BlockSigner, bound to a specific deployed contract. +func NewBlockSignerFilterer(address common.Address, filterer bind.ContractFilterer) (*BlockSignerFilterer, error) { + contract, err := bindBlockSigner(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &BlockSignerFilterer{contract: contract}, nil +} + +// bindBlockSigner binds a generic wrapper to an already deployed contract. +func bindBlockSigner(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(BlockSignerABI)) + 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 (_BlockSigner *BlockSignerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _BlockSigner.Contract.BlockSignerCaller.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 (_BlockSigner *BlockSignerRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _BlockSigner.Contract.BlockSignerTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_BlockSigner *BlockSignerRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _BlockSigner.Contract.BlockSignerTransactor.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 (_BlockSigner *BlockSignerCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _BlockSigner.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 (_BlockSigner *BlockSignerTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _BlockSigner.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_BlockSigner *BlockSignerTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _BlockSigner.Contract.contract.Transact(opts, method, params...) +} + +// GetSigners is a free data retrieval call binding the contract method 0xdfceceae. +// +// Solidity: function getSigners(_blockNumber uint256) constant returns(address[]) +func (_BlockSigner *BlockSignerCaller) GetSigners(opts *bind.CallOpts, _blockNumber *big.Int) ([]common.Address, error) { + var ( + ret0 = new([]common.Address) + ) + out := ret0 + err := _BlockSigner.contract.Call(opts, out, "getSigners", _blockNumber) + return *ret0, err +} + +// GetSigners is a free data retrieval call binding the contract method 0xdfceceae. +// +// Solidity: function getSigners(_blockNumber uint256) constant returns(address[]) +func (_BlockSigner *BlockSignerSession) GetSigners(_blockNumber *big.Int) ([]common.Address, error) { + return _BlockSigner.Contract.GetSigners(&_BlockSigner.CallOpts, _blockNumber) +} + +// GetSigners is a free data retrieval call binding the contract method 0xdfceceae. +// +// Solidity: function getSigners(_blockNumber uint256) constant returns(address[]) +func (_BlockSigner *BlockSignerCallerSession) GetSigners(_blockNumber *big.Int) ([]common.Address, error) { + return _BlockSigner.Contract.GetSigners(&_BlockSigner.CallOpts, _blockNumber) +} + +// Sign is a paid mutator transaction binding the contract method 0x2fb1b25f. +// +// Solidity: function sign(_blockNumber uint256) returns() +func (_BlockSigner *BlockSignerTransactor) Sign(opts *bind.TransactOpts, _blockNumber *big.Int) (*types.Transaction, error) { + return _BlockSigner.contract.Transact(opts, "sign", _blockNumber) +} + +// Sign is a paid mutator transaction binding the contract method 0x2fb1b25f. +// +// Solidity: function sign(_blockNumber uint256) returns() +func (_BlockSigner *BlockSignerSession) Sign(_blockNumber *big.Int) (*types.Transaction, error) { + return _BlockSigner.Contract.Sign(&_BlockSigner.TransactOpts, _blockNumber) +} + +// Sign is a paid mutator transaction binding the contract method 0x2fb1b25f. +// +// Solidity: function sign(_blockNumber uint256) returns() +func (_BlockSigner *BlockSignerTransactorSession) Sign(_blockNumber *big.Int) (*types.Transaction, error) { + return _BlockSigner.Contract.Sign(&_BlockSigner.TransactOpts, _blockNumber) +} + +// BlockSignerSignIterator is returned from FilterSign and is used to iterate over the raw logs and unpacked data for Sign events raised by the BlockSigner contract. +type BlockSignerSignIterator struct { + Event *BlockSignerSign // 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 + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// 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 *BlockSignerSignIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(BlockSignerSign) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(BlockSignerSign) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *BlockSignerSignIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *BlockSignerSignIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// BlockSignerSign represents a Sign event raised by the BlockSigner contract. +type BlockSignerSign struct { + Signer common.Address + BlockNumber *big.Int + Raw types.Log // Blockchain specific contextual infos +} + +// FilterSign is a free log retrieval operation binding the contract event 0x9a10b6124411386407c4a174729b856d293832181c352e98b5cb316b96cd3059. +// +// Solidity: event Sign(_signer address, blockNumber uint256) +func (_BlockSigner *BlockSignerFilterer) FilterSign(opts *bind.FilterOpts) (*BlockSignerSignIterator, error) { + + logs, sub, err := _BlockSigner.contract.FilterLogs(opts, "Sign") + if err != nil { + return nil, err + } + return &BlockSignerSignIterator{contract: _BlockSigner.contract, event: "Sign", logs: logs, sub: sub}, nil +} + +// WatchSign is a free log subscription operation binding the contract event 0x9a10b6124411386407c4a174729b856d293832181c352e98b5cb316b96cd3059. +// +// Solidity: event Sign(_signer address, blockNumber uint256) +func (_BlockSigner *BlockSignerFilterer) WatchSign(opts *bind.WatchOpts, sink chan<- *BlockSignerSign) (event.Subscription, error) { + + logs, sub, err := _BlockSigner.contract.WatchLogs(opts, "Sign") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(BlockSignerSign) + if err := _BlockSigner.contract.UnpackLog(event, "Sign", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// SafeMathABI is the input ABI used to generate the binding from. +const SafeMathABI = "[]" + +// SafeMathBin is the compiled bytecode used for deploying new contracts. +const SafeMathBin = `0x604c602c600b82828239805160001a60731460008114601c57601e565bfe5b5030600052607381538281f30073000000000000000000000000000000000000000030146060604052600080fd00a165627a7a72305820b9407d48ebc7efee5c9f08b3b3a957df2939281f5913225e8c1291f069b900490029` + +// DeploySafeMath deploys a new Ethereum contract, binding an instance of SafeMath to it. +func DeploySafeMath(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *SafeMath, error) { + parsed, err := abi.JSON(strings.NewReader(SafeMathABI)) + if err != nil { + return common.Address{}, nil, nil, err + } + address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(SafeMathBin), backend) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, tx, &SafeMath{SafeMathCaller: SafeMathCaller{contract: contract}, SafeMathTransactor: SafeMathTransactor{contract: contract}, SafeMathFilterer: SafeMathFilterer{contract: contract}}, nil +} + +// SafeMath is an auto generated Go binding around an Ethereum contract. +type SafeMath struct { + SafeMathCaller // Read-only binding to the contract + SafeMathTransactor // Write-only binding to the contract + SafeMathFilterer // Log filterer for contract events +} + +// SafeMathCaller is an auto generated read-only Go binding around an Ethereum contract. +type SafeMathCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// SafeMathTransactor is an auto generated write-only Go binding around an Ethereum contract. +type SafeMathTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// SafeMathFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type SafeMathFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// SafeMathSession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type SafeMathSession struct { + Contract *SafeMath // 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 +} + +// SafeMathCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type SafeMathCallerSession struct { + Contract *SafeMathCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// SafeMathTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type SafeMathTransactorSession struct { + Contract *SafeMathTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// SafeMathRaw is an auto generated low-level Go binding around an Ethereum contract. +type SafeMathRaw struct { + Contract *SafeMath // Generic contract binding to access the raw methods on +} + +// SafeMathCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type SafeMathCallerRaw struct { + Contract *SafeMathCaller // Generic read-only contract binding to access the raw methods on +} + +// SafeMathTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type SafeMathTransactorRaw struct { + Contract *SafeMathTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewSafeMath creates a new instance of SafeMath, bound to a specific deployed contract. +func NewSafeMath(address common.Address, backend bind.ContractBackend) (*SafeMath, error) { + contract, err := bindSafeMath(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &SafeMath{SafeMathCaller: SafeMathCaller{contract: contract}, SafeMathTransactor: SafeMathTransactor{contract: contract}, SafeMathFilterer: SafeMathFilterer{contract: contract}}, nil +} + +// NewSafeMathCaller creates a new read-only instance of SafeMath, bound to a specific deployed contract. +func NewSafeMathCaller(address common.Address, caller bind.ContractCaller) (*SafeMathCaller, error) { + contract, err := bindSafeMath(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &SafeMathCaller{contract: contract}, nil +} + +// NewSafeMathTransactor creates a new write-only instance of SafeMath, bound to a specific deployed contract. +func NewSafeMathTransactor(address common.Address, transactor bind.ContractTransactor) (*SafeMathTransactor, error) { + contract, err := bindSafeMath(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &SafeMathTransactor{contract: contract}, nil +} + +// NewSafeMathFilterer creates a new log filterer instance of SafeMath, bound to a specific deployed contract. +func NewSafeMathFilterer(address common.Address, filterer bind.ContractFilterer) (*SafeMathFilterer, error) { + contract, err := bindSafeMath(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &SafeMathFilterer{contract: contract}, nil +} + +// bindSafeMath binds a generic wrapper to an already deployed contract. +func bindSafeMath(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(SafeMathABI)) + 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 (_SafeMath *SafeMathRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _SafeMath.Contract.SafeMathCaller.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 (_SafeMath *SafeMathRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _SafeMath.Contract.SafeMathTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_SafeMath *SafeMathRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _SafeMath.Contract.SafeMathTransactor.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 (_SafeMath *SafeMathCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _SafeMath.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 (_SafeMath *SafeMathTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _SafeMath.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _SafeMath.Contract.contract.Transact(opts, method, params...) +} diff --git a/contracts/blocksigner/contract/libs/SafeMath.sol b/contracts/blocksigner/contract/libs/SafeMath.sol new file mode 100644 index 0000000000..9c9a2bd22f --- /dev/null +++ b/contracts/blocksigner/contract/libs/SafeMath.sol @@ -0,0 +1,47 @@ +pragma solidity ^0.4.21; + +/** + * @title SafeMath + * @dev Math operations with safety checks that throw on error + */ +library SafeMath { + + /** + * @dev Multiplies two numbers, throws on overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + uint256 c = a * b; + assert(c / a == b); + return c; + } + + /** + * @dev Integer division of two numbers, truncating the quotient. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + // assert(b > 0); // Solidity automatically throws when dividing by 0 + // uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + return a / b; + } + + /** + * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + /** + * @dev Adds two numbers, throws on overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + assert(c >= a); + return c; + } +} From 7ad8b48b39efcffd6c717ab3e350775d317d7c1e Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Thu, 14 Jun 2018 03:45:15 +0000 Subject: [PATCH 15/15] osx now support cask --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 388f8a5df0..861fb6cbb9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,6 @@ matrix: script: - unset -f cd - brew update - - brew install caskroom/cask/brew-cask - brew cask install osxfuse - go run build/ci.go install - go run build/ci.go test -coverage