mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 13:44:31 +00:00
51 lines
No EOL
1.6 KiB
Go
51 lines
No EOL
1.6 KiB
Go
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"
|
|
"math/big"
|
|
)
|
|
|
|
type Validator struct {
|
|
*contract.XDCValidatorSession
|
|
contractBackend bind.ContractBackend
|
|
}
|
|
|
|
func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*Validator, error) {
|
|
validator, err := contract.NewXDCValidator(contractAddr, contractBackend)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Validator{
|
|
&contract.XDCValidatorSession{
|
|
Contract: validator,
|
|
TransactOpts: *transactOpts,
|
|
},
|
|
contractBackend,
|
|
}, nil
|
|
}
|
|
|
|
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, validatorAddress []common.Address, caps []*big.Int, ownerAddress common.Address) (common.Address, *Validator, error) {
|
|
minDeposit := new(big.Int)
|
|
minDeposit.SetString("50000000000000000000000", 10)
|
|
minVoterCap := new(big.Int)
|
|
minVoterCap.SetString("10000000000000000000", 10)
|
|
// Deposit 50K XDC
|
|
// Min Voter Cap 10 XDC
|
|
// 150 masternodes
|
|
// Candidate Delay Withdraw 30 days = 1296000 blocks
|
|
// Voter Delay Withdraw 2 days = 86400 blocks
|
|
validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, minVoterCap, big.NewInt(150), big.NewInt(1296000), big.NewInt(86400))
|
|
if err != nil {
|
|
return validatorAddr, nil, err
|
|
}
|
|
|
|
validator, err := NewValidator(transactOpts, validatorAddr, contractBackend)
|
|
if err != nil {
|
|
return validatorAddr, nil, err
|
|
}
|
|
|
|
return validatorAddr, validator, nil
|
|
} |