github.com/XinFinOrg/xdcchain@v1.1.0/contracts/validator/validator.go (about) 1 // Copyright (c) 2018 XDCchain 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Lesser General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Lesser General Public License for more details. 12 // 13 // You should have received a copy of the GNU Lesser General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package validator 17 18 import ( 19 "math/big" 20 21 "github.com/ethereum/go-ethereum/accounts/abi/bind" 22 "github.com/ethereum/go-ethereum/common" 23 "github.com/ethereum/go-ethereum/contracts/validator/contract" 24 ) 25 26 type Validator struct { 27 *contract.XDCValidatorSession 28 contractBackend bind.ContractBackend 29 } 30 31 func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*Validator, error) { 32 validator, err := contract.NewXDCValidator(contractAddr, contractBackend) 33 if err != nil { 34 return nil, err 35 } 36 37 return &Validator{ 38 &contract.XDCValidatorSession{ 39 Contract: validator, 40 TransactOpts: *transactOpts, 41 }, 42 contractBackend, 43 }, nil 44 } 45 46 func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, validatorAddress []common.Address, caps []*big.Int, ownerAddress common.Address) (common.Address, *Validator, error) { 47 minDeposit := new(big.Int) 48 minDeposit.SetString("10000000000000000000000000", 10) 49 minVoterCap := new(big.Int) 50 minVoterCap.SetString("25000000000000000000000", 10) 51 // Deposit 50K XDC 52 // Min Voter Cap 10 XDC 53 // 150 masternodes 54 // Candidate Delay Withdraw 30 days = 1296000 blocks 55 // Voter Delay Withdraw 10 days = 432000 blocks 56 validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, minVoterCap, big.NewInt(18), big.NewInt(1296000), big.NewInt(432000)) 57 if err != nil { 58 return validatorAddr, nil, err 59 } 60 61 validator, err := NewValidator(transactOpts, validatorAddr, contractBackend) 62 if err != nil { 63 return validatorAddr, nil, err 64 } 65 66 return validatorAddr, validator, nil 67 }