add option genesis generator for POSV

This commit is contained in:
parmmarrushabh 2018-10-27 17:52:28 +05:30
parent 5ec2a20aa4
commit 9765dea721
11 changed files with 211 additions and 149 deletions

View file

@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
"math/rand"
"time"
@ -29,6 +28,16 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"context"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
blockSignerContract "github.com/ethereum/go-ethereum/contracts/blocksigner"
randomizeContract "github.com/ethereum/go-ethereum/contracts/randomize"
validatorContract "github.com/ethereum/go-ethereum/contracts/validator"
"github.com/ethereum/go-ethereum/crypto"
)
// makeGenesis creates a new genesis struct based on some user input.
@ -52,6 +61,7 @@ func (w *wizard) makeGenesis() {
fmt.Println("Which consensus engine to use? (default = clique)")
fmt.Println(" 1. Ethash - proof-of-work")
fmt.Println(" 2. Clique - proof-of-authority")
fmt.Println(" 3. Xdpos - proof-of-stake-voting")
choice := w.read()
switch {
@ -111,7 +121,126 @@ func (w *wizard) makeGenesis() {
fmt.Println()
fmt.Println("How many blocks before checkpoint need to prepare new set of masternodes? (default = 50)")
genesis.Config.Clique.Gap = uint64(w.readDefaultInt(50))
case choice == "3":
genesis.Difficulty = big.NewInt(1)
genesis.Config.Clique = &params.CliqueConfig{
Period: 15,
Epoch: 30000,
Reward: 0,
}
fmt.Println()
fmt.Println("How many seconds should blocks take? (default = 2)")
genesis.Config.Clique.Period = uint64(w.readDefaultInt(2))
fmt.Println()
fmt.Println("How many Ethers should be rewarded to masternode? (default = 10)")
genesis.Config.Clique.Reward = uint64(w.readDefaultInt(10))
fmt.Println()
fmt.Println("Who own the first masternodes? (mandatory)")
owner := *w.readAddress()
// We also need the initial list of signers
fmt.Println()
fmt.Println("Which accounts are allowed to seal (signers)? (mandatory at least one)")
var signers []common.Address
for {
if address := w.readAddress(); address != nil {
signers = append(signers, *address)
continue
}
if len(signers) > 0 {
break
}
}
// Sort the signers and embed into the extra-data section
for i := 0; i < len(signers); i++ {
for j := i + 1; j < len(signers); j++ {
if bytes.Compare(signers[i][:], signers[j][:]) > 0 {
signers[i], signers[j] = signers[j], signers[i]
}
}
}
validatorCap := new(big.Int)
validatorCap.SetString("50000000000000000000000", 10)
var validatorCaps []*big.Int
genesis.ExtraData = make([]byte, 32+len(signers)*common.AddressLength+65)
for i, signer := range signers {
validatorCaps = append(validatorCaps, validatorCap)
copy(genesis.ExtraData[32+i*common.AddressLength:], signer[:])
}
fmt.Println()
fmt.Println("How many blocks per epoch? (default = 990)")
epochNumber := w.readDefaultInt(990)
genesis.Config.Clique.RewardCheckpoint = uint64(epochNumber)
fmt.Println()
fmt.Println("How many blocks before checkpoint need to prepare new set of masternodes? (default = 50)")
genesis.Config.Clique.Gap = uint64(w.readDefaultInt(50))
// Validator Smart Contract Code
pKey, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
addr := crypto.PubkeyToAddress(pKey.PublicKey)
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
transactOpts := bind.NewKeyedTransactor(pKey)
validatorAddress, _, err := validatorContract.DeployValidator(transactOpts, contractBackend, signers, validatorCaps, owner)
if err != nil {
fmt.Println("Can't deploy root registry")
}
contractBackend.Commit()
d := time.Now().Add(1000 * time.Millisecond)
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil)
storage := make(map[common.Hash]common.Hash)
f := func(key, val common.Hash) bool {
storage[key] = val
return true
}
contractBackend.ForEachStorageAt(ctx, validatorAddress, nil, f)
genesis.Alloc[common.HexToAddress(common.MasternodeVotingSMC)] = core.GenesisAccount{
Balance: validatorCap.Mul(validatorCap, big.NewInt(int64(len(validatorCaps)))),
Code: code,
Storage: storage,
}
// Block Signers Smart Contract
blockSignerAddress, _, err := blockSignerContract.DeployBlockSigner(transactOpts, contractBackend, big.NewInt(int64(epochNumber)))
if err != nil {
fmt.Println("Can't deploy root registry")
}
contractBackend.Commit()
code, _ = contractBackend.CodeAt(ctx, blockSignerAddress, nil)
storage = make(map[common.Hash]common.Hash)
contractBackend.ForEachStorageAt(ctx, blockSignerAddress, nil, f)
genesis.Alloc[common.HexToAddress(common.BlockSigners)] = core.GenesisAccount{
Balance: big.NewInt(0),
Code: code,
Storage: storage,
}
// Randomize Smart Contract Code
randomizeAddress, _, err := randomizeContract.DeployRandomize(transactOpts, contractBackend, big.NewInt(99))
if err != nil {
fmt.Println("Can't deploy root registry")
}
contractBackend.Commit()
code, _ = contractBackend.CodeAt(ctx, randomizeAddress, nil)
storage = make(map[common.Hash]common.Hash)
contractBackend.ForEachStorageAt(ctx, randomizeAddress, nil, f)
genesis.Alloc[common.HexToAddress(common.RandomizeSMC)] = core.GenesisAccount{
Balance: big.NewInt(0),
Code: code,
Storage: storage,
}
default:
log.Crit("Invalid consensus engine choice", "choice", choice)
}
@ -129,7 +258,7 @@ func (w *wizard) makeGenesis() {
break
}
// Add a batch of precompile balances to avoid them getting deleted
for i := int64(0); i < 256; i++ {
for i := int64(0); i < 2; i++ {
genesis.Alloc[common.BigToAddress(big.NewInt(i))] = core.GenesisAccount{Balance: big.NewInt(1)}
}
// Query the user for some custom extras

View file

@ -32,6 +32,7 @@ const (
AddressLength = 20
BlockSigners = "0x0000000000000000000000000000000000000089"
MasternodeVotingSMC = "0x0000000000000000000000000000000000000088"
RandomizeSMC = "0x0000000000000000000000000000000000000090"
)
var (

View file

@ -27,8 +27,8 @@ func NewBlockSigner(transactOpts *bind.TransactOpts, contractAddr common.Address
}, nil
}
func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *BlockSigner, error) {
blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, big.NewInt(99))
func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, epochNumber *big.Int) (common.Address, *BlockSigner, error) {
blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, epochNumber)
if err != nil {
return blockSignerAddr, nil, err
}

View file

@ -23,7 +23,7 @@ func TestBlockSigner(t *testing.T) {
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
transactOpts := bind.NewKeyedTransactor(key)
blockSignerAddress, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend)
blockSignerAddress, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend, big.NewInt(99))
if err != nil {
t.Fatalf("can't deploy root registry: %v", err)
}

View file

@ -1,4 +1,4 @@
// Code generated - DO NOT EDIT.
// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package contract
@ -19,7 +19,7 @@ import (
const BlockSignerABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"sign\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"getSigners\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"epochNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_epochNumber\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_signer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"Sign\",\"type\":\"event\"}]"
// BlockSignerBin is the compiled bytecode used for deploying new contracts.
const BlockSignerBin = `0x608060405234801561001057600080fd5b506040516020806102c58339810160405251600255610291806100346000396000f3006080604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663e341eaa4811461005b578063e7ec6aef14610078578063f4145a83146100e0575b600080fd5b34801561006757600080fd5b50610076600435602435610107565b005b34801561008457600080fd5b506100906004356101d2565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156100cc5781810151838201526020016100b4565b505050509050019250505060405180910390f35b3480156100ec57600080fd5b506100f5610249565b60408051918252519081900360200190f35b4382111561011457600080fd5b6002805461012a9184910263ffffffff61024f16565b43111561013657600080fd5b6000828152600160208181526040808420805480850182559085528285200185905584845283825280842080549384018155845292819020909101805473ffffffffffffffffffffffffffffffffffffffff191633908117909155825190815290810184905280820183905290517f62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f549181900360600190a15050565b6000818152602081815260409182902080548351818402810184019094528084526060939283018282801561023d57602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610212575b50505050509050919050565b60025481565b60008282018381101561025e57fe5b93925050505600a165627a7a72305820b035faa3fa77d5019e1705483157467de16d51fe08a7194c30e2586e42ca7ccb0029`
const BlockSignerBin = `0x6060604052341561000f57600080fd5b604051602080610386833981016040528080516002555050610350806100366000396000f3006060604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663e341eaa4811461005b578063e7ec6aef14610076578063f4145a83146100df575b600080fd5b341561006657600080fd5b610074600435602435610104565b005b341561008157600080fd5b61008c600435610227565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cb5780820151838201526020016100b3565b505050509050019250505060405180910390f35b34156100ea57600080fd5b6100f26102ac565b60405190815260200160405180910390f35b438290101561011257600080fd5b600280546101289184910263ffffffff6102b216565b43111561013457600080fd5b600082815260016020819052604090912080549091810161015583826102c8565b5060009182526020808320919091018390558282528190526040902080546001810161018183826102c8565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19163373ffffffffffffffffffffffffffffffffffffffff8116919091179091557f62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f5490838360405173ffffffffffffffffffffffffffffffffffffffff909316835260208301919091526040808301919091526060909101905180910390a15050565b61022f6102f1565b600082815260208181526040918290208054909290918281020190519081016040528092919081815260200182805480156102a057602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610275575b50505050509050919050565b60025481565b6000828201838110156102c157fe5b9392505050565b8154818355818115116102ec576000838152602090206102ec918101908301610303565b505050565b60206040519081016040526000815290565b61032191905b8082111561031d5760008155600101610309565b5090565b905600a165627a7a72305820a8ceddaea8e4ae00991e2ae81c8c88e160dd8770f255523282c24c2df4c30ec70029`
// DeployBlockSigner deploys a new Ethereum contract, binding an instance of BlockSigner to it.
func DeployBlockSigner(auth *bind.TransactOpts, backend bind.ContractBackend, _epochNumber *big.Int) (common.Address, *types.Transaction, *BlockSigner, error) {
@ -532,4 +532,4 @@ func (_SafeMath *SafeMathTransactorRaw) Transfer(opts *bind.TransactOpts) (*type
// 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...)
}
}

View file

@ -4,57 +4,28 @@ import "./libs/SafeMath.sol";
contract XDCRandomize {
using SafeMath for uint256;
uint256 public epochNumber;
uint256 public blockTimeSecret;
uint256 public blockTimeOpening;
uint256 public randomNumber;
mapping (address=>bytes32[]) randomSecret;
mapping (address=>bytes32[]) randomOpening;
mapping (address=>bytes32) randomOpening;
function XDCRandomize (uint256 _epochNumber, uint256 _blockTimeSecret, uint256 _blockTimeOpening) public {
epochNumber = _epochNumber;
blockTimeOpening = _blockTimeOpening;
blockTimeSecret = _blockTimeSecret;
function XDCRandomize (uint256 _randomNumber) public {
randomNumber = _randomNumber;
}
function setSecret(bytes32[] _secret) public {
require(_secret.length == epochNumber);
uint256 _blockNum = block.number;
uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber));
require(_epoch <= blockTimeSecret);
randomSecret[msg.sender] = _secret;
}
function setOpening(bytes32[] _opening) public {
require(_opening.length == epochNumber);
uint256 _blockNum = block.number;
uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber));
require(_epoch > blockTimeSecret && _epoch <= blockTimeOpening);
function setOpening(bytes32 _opening) public {
randomOpening[msg.sender] = _opening;
}
function getSecret(address _validator) public view returns(bytes32[]) {
uint256 _blockNum = block.number;
uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber));
require(_epoch > blockTimeSecret);
return randomSecret[_validator];
}
function getOpening(address _validator) public view returns(bytes32[]) {
uint256 _blockNum = block.number;
uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber));
require(_epoch > blockTimeOpening);
function getOpening(address _validator) public view returns(bytes32) {
return randomOpening[_validator];
}
}

View file

@ -175,18 +175,18 @@ func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method
}
// XDCRandomizeABI is the input ABI used to generate the binding from.
const XDCRandomizeABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_opening\",\"type\":\"bytes32[]\"}],\"name\":\"setOpening\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"blockTimeSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_secret\",\"type\":\"bytes32[]\"}],\"name\":\"setSecret\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"blockTimeOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"epochNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_epochNumber\",\"type\":\"uint256\"},{\"name\":\"_blockTimeSecret\",\"type\":\"uint256\"},{\"name\":\"_blockTimeOpening\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]"
const XDCRandomizeABI = "[{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_secret\",\"type\":\"bytes32[]\"}],\"name\":\"setSecret\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"randomNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_opening\",\"type\":\"bytes32\"}],\"name\":\"setOpening\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_randomNumber\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]"
// XDCRandomizeBin is the compiled bytecode used for deploying new contracts.
const XDCRandomizeBin = `0x6060604052341561000f57600080fd5b6040516060806105d48339810160405280805191906020018051919060200180516000948555600255505060015561058790819061004d90396000f3006060604052600436106100825763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632141c7d98114610087578063257b03e9146100d8578063284180fc146100fd57806334d386001461016f57806337a52ecc146101be578063d442d6cc146101d1578063f4145a83146101f0575b600080fd5b341561009257600080fd5b6100d6600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061020395505050505050565b005b34156100e357600080fd5b6100eb61029b565b60405190815260200160405180910390f35b341561010857600080fd5b61011c600160a060020a03600435166102a1565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561015b578082015183820152602001610143565b505050509050019250505060405180910390f35b341561017a57600080fd5b6100d6600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061035795505050505050565b34156101c957600080fd5b6100eb6103c2565b34156101dc57600080fd5b61011c600160a060020a03600435166103c8565b34156101fb57600080fd5b6100eb61047c565b60008060005483511461021557600080fd5b60005443925061024c9061023f90610233858263ffffffff61048216565b9063ffffffff61049716565b839063ffffffff6104cd16565b90506001548111801561026157506002548111155b151561026c57600080fd5b600160a060020a03331660009081526004602052604090208380516102959291602001906104df565b50505050565b60015481565b6102a961052c565b600080544391906102c89061023f90610233858263ffffffff61048216565b60015490915081116102d957600080fd5b6003600085600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561034957602002820191906000526020600020905b81548152600190910190602001808311610334575b505050505092505050919050565b60008060005483511461036957600080fd5b6000544392506103879061023f90610233858263ffffffff61048216565b60015490915081111561039957600080fd5b600160a060020a03331660009081526003602052604090208380516102959291602001906104df565b60025481565b6103d061052c565b600080544391906103ef9061023f90610233858263ffffffff61048216565b600254909150811161040057600080fd5b6004600085600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561034957602002820191906000526020600020908154815260019091019060200180831161033457505050505092505050919050565b60005481565b6000818381151561048f57fe5b049392505050565b6000808315156104aa57600091506104c6565b508282028284828115156104ba57fe5b04146104c257fe5b8091505b5092915050565b6000828211156104d957fe5b50900390565b82805482825590600052602060002090810192821561051c579160200282015b8281111561051c57825182556020909201916001909101906104ff565b5061052892915061053e565b5090565b60206040519081016040526000815290565b61055891905b808211156105285760008155600101610544565b905600a165627a7a7230582031eb1183e55e5d47012ab3437f7e50e5d73edca48c1e66da1b1b45d7fa0d566b0029`
const XDCRandomizeBin = `0x6060604052341561000f57600080fd5b604051602080610359833981016040528080516000555050610323806100366000396000f30060606040526004361061006c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663284180fc811461007157806334d38600146100e3578063ccbac9f514610134578063d442d6cc14610159578063e11f5ba214610178575b600080fd5b341561007c57600080fd5b610090600160a060020a036004351661018e565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cf5780820151838201526020016100b7565b505050509050019250505060405180910390f35b34156100ee57600080fd5b610132600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061021295505050505050565b005b341561013f57600080fd5b61014761023f565b60405190815260200160405180910390f35b341561016457600080fd5b610147600160a060020a0360043516610245565b341561018357600080fd5b610132600435610260565b61019661027b565b6001600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561020657602002820191906000526020600020905b815481526001909101906020018083116101f1575b50505050509050919050565b600160a060020a033316600090815260016020526040902081805161023b92916020019061028d565b5050565b60005481565b600160a060020a031660009081526002602052604090205490565b600160a060020a033316600090815260026020526040902055565b60206040519081016040526000815290565b8280548282559060005260206000209081019282156102ca579160200282015b828111156102ca57825182556020909201916001909101906102ad565b506102d69291506102da565b5090565b6102f491905b808211156102d657600081556001016102e0565b905600a165627a7a7230582043a345787b9942e3361515ce1a0a4dbaab0ed6ce42c6ca0344119134351d9ffe0029`
// DeployXDCRandomize deploys a new Ethereum contract, binding an instance of XDCRandomize to it.
func DeployXDCRandomize(auth *bind.TransactOpts, backend bind.ContractBackend, _epochNumber *big.Int, _blockTimeSecret *big.Int, _blockTimeOpening *big.Int) (common.Address, *types.Transaction, *XDCRandomize, error) {
func DeployXDCRandomize(auth *bind.TransactOpts, backend bind.ContractBackend, _randomNumber *big.Int) (common.Address, *types.Transaction, *XDCRandomize, error) {
parsed, err := abi.JSON(strings.NewReader(XDCRandomizeABI))
if err != nil {
return common.Address{}, nil, nil, err
}
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(XDCRandomizeBin), backend, _epochNumber, _blockTimeSecret, _blockTimeOpening)
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(XDCRandomizeBin), backend, _randomNumber)
if err != nil {
return common.Address{}, nil, nil, err
}
@ -335,90 +335,12 @@ func (_XDCRandomize *XDCRandomizeTransactorRaw) Transact(opts *bind.TransactOpts
return _XDCRandomize.Contract.contract.Transact(opts, method, params...)
}
// BlockTimeOpening is a free data retrieval call binding the contract method 0x37a52ecc.
//
// Solidity: function blockTimeOpening() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeCaller) BlockTimeOpening(opts *bind.CallOpts) (*big.Int, error) {
var (
ret0 = new(*big.Int)
)
out := ret0
err := _XDCRandomize.contract.Call(opts, out, "blockTimeOpening")
return *ret0, err
}
// BlockTimeOpening is a free data retrieval call binding the contract method 0x37a52ecc.
//
// Solidity: function blockTimeOpening() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeSession) BlockTimeOpening() (*big.Int, error) {
return _XDCRandomize.Contract.BlockTimeOpening(&_XDCRandomize.CallOpts)
}
// BlockTimeOpening is a free data retrieval call binding the contract method 0x37a52ecc.
//
// Solidity: function blockTimeOpening() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeCallerSession) BlockTimeOpening() (*big.Int, error) {
return _XDCRandomize.Contract.BlockTimeOpening(&_XDCRandomize.CallOpts)
}
// BlockTimeSecret is a free data retrieval call binding the contract method 0x257b03e9.
//
// Solidity: function blockTimeSecret() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeCaller) BlockTimeSecret(opts *bind.CallOpts) (*big.Int, error) {
var (
ret0 = new(*big.Int)
)
out := ret0
err := _XDCRandomize.contract.Call(opts, out, "blockTimeSecret")
return *ret0, err
}
// BlockTimeSecret is a free data retrieval call binding the contract method 0x257b03e9.
//
// Solidity: function blockTimeSecret() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeSession) BlockTimeSecret() (*big.Int, error) {
return _XDCRandomize.Contract.BlockTimeSecret(&_XDCRandomize.CallOpts)
}
// BlockTimeSecret is a free data retrieval call binding the contract method 0x257b03e9.
//
// Solidity: function blockTimeSecret() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeCallerSession) BlockTimeSecret() (*big.Int, error) {
return _XDCRandomize.Contract.BlockTimeSecret(&_XDCRandomize.CallOpts)
}
// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83.
//
// Solidity: function epochNumber() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeCaller) EpochNumber(opts *bind.CallOpts) (*big.Int, error) {
var (
ret0 = new(*big.Int)
)
out := ret0
err := _XDCRandomize.contract.Call(opts, out, "epochNumber")
return *ret0, err
}
// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83.
//
// Solidity: function epochNumber() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeSession) EpochNumber() (*big.Int, error) {
return _XDCRandomize.Contract.EpochNumber(&_XDCRandomize.CallOpts)
}
// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83.
//
// Solidity: function epochNumber() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeCallerSession) EpochNumber() (*big.Int, error) {
return _XDCRandomize.Contract.EpochNumber(&_XDCRandomize.CallOpts)
}
// GetOpening is a free data retrieval call binding the contract method 0xd442d6cc.
//
// Solidity: function getOpening(_validator address) constant returns(bytes32[])
func (_XDCRandomize *XDCRandomizeCaller) GetOpening(opts *bind.CallOpts, _validator common.Address) ([][32]byte, error) {
// Solidity: function getOpening(_validator address) constant returns(bytes32)
func (_XDCRandomize *XDCRandomizeCaller) GetOpening(opts *bind.CallOpts, _validator common.Address) ([32]byte, error) {
var (
ret0 = new([][32]byte)
ret0 = new([32]byte)
)
out := ret0
err := _XDCRandomize.contract.Call(opts, out, "getOpening", _validator)
@ -427,15 +349,15 @@ func (_XDCRandomize *XDCRandomizeCaller) GetOpening(opts *bind.CallOpts, _valida
// GetOpening is a free data retrieval call binding the contract method 0xd442d6cc.
//
// Solidity: function getOpening(_validator address) constant returns(bytes32[])
func (_XDCRandomize *XDCRandomizeSession) GetOpening(_validator common.Address) ([][32]byte, error) {
// Solidity: function getOpening(_validator address) constant returns(bytes32)
func (_XDCRandomize *XDCRandomizeSession) GetOpening(_validator common.Address) ([32]byte, error) {
return _XDCRandomize.Contract.GetOpening(&_XDCRandomize.CallOpts, _validator)
}
// GetOpening is a free data retrieval call binding the contract method 0xd442d6cc.
//
// Solidity: function getOpening(_validator address) constant returns(bytes32[])
func (_XDCRandomize *XDCRandomizeCallerSession) GetOpening(_validator common.Address) ([][32]byte, error) {
// Solidity: function getOpening(_validator address) constant returns(bytes32)
func (_XDCRandomize *XDCRandomizeCallerSession) GetOpening(_validator common.Address) ([32]byte, error) {
return _XDCRandomize.Contract.GetOpening(&_XDCRandomize.CallOpts, _validator)
}
@ -465,24 +387,50 @@ func (_XDCRandomize *XDCRandomizeCallerSession) GetSecret(_validator common.Addr
return _XDCRandomize.Contract.GetSecret(&_XDCRandomize.CallOpts, _validator)
}
// SetOpening is a paid mutator transaction binding the contract method 0x2141c7d9.
// RandomNumber is a free data retrieval call binding the contract method 0xccbac9f5.
//
// Solidity: function setOpening(_opening bytes32[]) returns()
func (_XDCRandomize *XDCRandomizeTransactor) SetOpening(opts *bind.TransactOpts, _opening [][32]byte) (*types.Transaction, error) {
// Solidity: function randomNumber() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeCaller) RandomNumber(opts *bind.CallOpts) (*big.Int, error) {
var (
ret0 = new(*big.Int)
)
out := ret0
err := _XDCRandomize.contract.Call(opts, out, "randomNumber")
return *ret0, err
}
// RandomNumber is a free data retrieval call binding the contract method 0xccbac9f5.
//
// Solidity: function randomNumber() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeSession) RandomNumber() (*big.Int, error) {
return _XDCRandomize.Contract.RandomNumber(&_XDCRandomize.CallOpts)
}
// RandomNumber is a free data retrieval call binding the contract method 0xccbac9f5.
//
// Solidity: function randomNumber() constant returns(uint256)
func (_XDCRandomize *XDCRandomizeCallerSession) RandomNumber() (*big.Int, error) {
return _XDCRandomize.Contract.RandomNumber(&_XDCRandomize.CallOpts)
}
// SetOpening is a paid mutator transaction binding the contract method 0xe11f5ba2.
//
// Solidity: function setOpening(_opening bytes32) returns()
func (_XDCRandomize *XDCRandomizeTransactor) SetOpening(opts *bind.TransactOpts, _opening [32]byte) (*types.Transaction, error) {
return _XDCRandomize.contract.Transact(opts, "setOpening", _opening)
}
// SetOpening is a paid mutator transaction binding the contract method 0x2141c7d9.
// SetOpening is a paid mutator transaction binding the contract method 0xe11f5ba2.
//
// Solidity: function setOpening(_opening bytes32[]) returns()
func (_XDCRandomize *XDCRandomizeSession) SetOpening(_opening [][32]byte) (*types.Transaction, error) {
// Solidity: function setOpening(_opening bytes32) returns()
func (_XDCRandomize *XDCRandomizeSession) SetOpening(_opening [32]byte) (*types.Transaction, error) {
return _XDCRandomize.Contract.SetOpening(&_XDCRandomize.TransactOpts, _opening)
}
// SetOpening is a paid mutator transaction binding the contract method 0x2141c7d9.
// SetOpening is a paid mutator transaction binding the contract method 0xe11f5ba2.
//
// Solidity: function setOpening(_opening bytes32[]) returns()
func (_XDCRandomize *XDCRandomizeTransactorSession) SetOpening(_opening [][32]byte) (*types.Transaction, error) {
// Solidity: function setOpening(_opening bytes32) returns()
func (_XDCRandomize *XDCRandomizeTransactorSession) SetOpening(_opening [32]byte) (*types.Transaction, error) {
return _XDCRandomize.Contract.SetOpening(&_XDCRandomize.TransactOpts, _opening)
}

View file

@ -27,8 +27,8 @@ func NewRandomize(transactOpts *bind.TransactOpts, contractAddr common.Address,
}, nil
}
func DeployRandomize(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *Randomize, error) {
randomizeAddr, _, _, err := contract.DeployXDCRandomize(transactOpts, contractBackend, big.NewInt(2), big.NewInt(0), big.NewInt(1))
func DeployRandomize(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, randomNumber *big.Int) (common.Address, *Randomize, error) {
randomizeAddr, _, _, err := contract.DeployXDCRandomize(transactOpts, contractBackend, randomNumber)
if err != nil {
return randomizeAddr, nil, err
}

View file

@ -23,7 +23,7 @@ func TestRandomize(t *testing.T) {
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
transactOpts := bind.NewKeyedTransactor(key)
randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend)
randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend, big.NewInt(2))
t.Log("contract address", randomizeAddress.String())
if err != nil {
t.Fatalf("can't deploy root registry: %v", err)

View file

@ -1,3 +1,18 @@
// Copyright (c) 2018 Xinfin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package contracts
import (

View file

@ -27,12 +27,10 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address,
}, nil
}
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *Validator, error) {
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)
fmt.Println("--->", common.BigToHash(minDeposit).Hex())
validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, minDeposit, big.NewInt(99), big.NewInt(100), big.NewInt(100))
validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, big.NewInt(99), big.NewInt(100), big.NewInt(100))
if err != nil {
return validatorAddr, nil, err
}