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] 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) +}