mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
Merge pull request #83 from thanhson1085/master
add option genesis generator for POSV
This commit is contained in:
commit
23f651a2f7
15 changed files with 478 additions and 509 deletions
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/big"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -29,6 +28,16 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"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.
|
// 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("Which consensus engine to use? (default = clique)")
|
||||||
fmt.Println(" 1. Ethash - proof-of-work")
|
fmt.Println(" 1. Ethash - proof-of-work")
|
||||||
fmt.Println(" 2. Clique - proof-of-authority")
|
fmt.Println(" 2. Clique - proof-of-authority")
|
||||||
|
fmt.Println(" 3. Tomo - proof-of-stake-voting")
|
||||||
|
|
||||||
choice := w.read()
|
choice := w.read()
|
||||||
switch {
|
switch {
|
||||||
|
|
@ -112,6 +122,125 @@ func (w *wizard) makeGenesis() {
|
||||||
fmt.Println("How many blocks before checkpoint need to prepare new set of masternodes? (default = 50)")
|
fmt.Println("How many blocks before checkpoint need to prepare new set of masternodes? (default = 50)")
|
||||||
genesis.Config.Clique.Gap = uint64(w.readDefaultInt(50))
|
genesis.Config.Clique.Gap = uint64(w.readDefaultInt(50))
|
||||||
|
|
||||||
|
case choice == "3":
|
||||||
|
genesis.Difficulty = big.NewInt(1)
|
||||||
|
genesis.Config.Clique = ¶ms.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:
|
default:
|
||||||
log.Crit("Invalid consensus engine choice", "choice", choice)
|
log.Crit("Invalid consensus engine choice", "choice", choice)
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +258,7 @@ func (w *wizard) makeGenesis() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Add a batch of precompile balances to avoid them getting deleted
|
// 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)}
|
genesis.Alloc[common.BigToAddress(big.NewInt(i))] = core.GenesisAccount{Balance: big.NewInt(1)}
|
||||||
}
|
}
|
||||||
// Query the user for some custom extras
|
// Query the user for some custom extras
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ const (
|
||||||
AddressLength = 20
|
AddressLength = 20
|
||||||
BlockSigners = "0x0000000000000000000000000000000000000089"
|
BlockSigners = "0x0000000000000000000000000000000000000089"
|
||||||
MasternodeVotingSMC = "0x0000000000000000000000000000000000000088"
|
MasternodeVotingSMC = "0x0000000000000000000000000000000000000088"
|
||||||
|
RandomizeSMC = "0x0000000000000000000000000000000000000090"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ func NewBlockSigner(transactOpts *bind.TransactOpts, contractAddr common.Address
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *BlockSigner, error) {
|
func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, epochNumber *big.Int) (common.Address, *BlockSigner, error) {
|
||||||
blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, big.NewInt(99))
|
blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, epochNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return blockSignerAddr, nil, err
|
return blockSignerAddr, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func TestBlockSigner(t *testing.T) {
|
||||||
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
||||||
transactOpts := bind.NewKeyedTransactor(key)
|
transactOpts := bind.NewKeyedTransactor(key)
|
||||||
|
|
||||||
blockSignerAddress, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend)
|
blockSignerAddress, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend, big.NewInt(99))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't deploy root registry: %v", err)
|
t.Fatalf("can't deploy root registry: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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\"}]"
|
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.
|
// 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.
|
// 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) {
|
func DeployBlockSigner(auth *bind.TransactOpts, backend bind.ContractBackend, _epochNumber *big.Int) (common.Address, *types.Transaction, *BlockSigner, error) {
|
||||||
|
|
|
||||||
|
|
@ -4,57 +4,28 @@ import "./libs/SafeMath.sol";
|
||||||
|
|
||||||
contract TomoRandomize {
|
contract TomoRandomize {
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
uint256 public epochNumber;
|
uint256 public randomNumber;
|
||||||
uint256 public blockTimeSecret;
|
|
||||||
uint256 public blockTimeOpening;
|
|
||||||
|
|
||||||
mapping (address=>bytes32[]) randomSecret;
|
mapping (address=>bytes32[]) randomSecret;
|
||||||
mapping (address=>bytes32[]) randomOpening;
|
mapping (address=>bytes32) randomOpening;
|
||||||
|
|
||||||
function TomoRandomize (uint256 _epochNumber, uint256 _blockTimeSecret, uint256 _blockTimeOpening) public {
|
function TomoRandomize (uint256 _randomNumber) public {
|
||||||
epochNumber = _epochNumber;
|
randomNumber = _randomNumber;
|
||||||
blockTimeOpening = _blockTimeOpening;
|
|
||||||
blockTimeSecret = _blockTimeSecret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSecret(bytes32[] _secret) public {
|
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;
|
randomSecret[msg.sender] = _secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setOpening(bytes32[] _opening) public {
|
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);
|
|
||||||
|
|
||||||
randomOpening[msg.sender] = _opening;
|
randomOpening[msg.sender] = _opening;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSecret(address _validator) public view returns(bytes32[]) {
|
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];
|
return randomSecret[_validator];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOpening(address _validator) public view returns(bytes32[]) {
|
function getOpening(address _validator) public view returns(bytes32) {
|
||||||
uint256 _blockNum = block.number;
|
|
||||||
uint256 _epoch = _blockNum.sub(_blockNum.div(epochNumber).mul(epochNumber));
|
|
||||||
|
|
||||||
require(_epoch > blockTimeOpening);
|
|
||||||
|
|
||||||
return randomOpening[_validator];
|
return randomOpening[_validator];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,18 +175,18 @@ func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method
|
||||||
}
|
}
|
||||||
|
|
||||||
// TomoRandomizeABI is the input ABI used to generate the binding from.
|
// TomoRandomizeABI is the input ABI used to generate the binding from.
|
||||||
const TomoRandomizeABI = "[{\"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 TomoRandomizeABI = "[{\"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\"}]"
|
||||||
|
|
||||||
// TomoRandomizeBin is the compiled bytecode used for deploying new contracts.
|
// TomoRandomizeBin is the compiled bytecode used for deploying new contracts.
|
||||||
const TomoRandomizeBin = `0x6060604052341561000f57600080fd5b6040516060806105d48339810160405280805191906020018051919060200180516000948555600255505060015561058790819061004d90396000f3006060604052600436106100825763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632141c7d98114610087578063257b03e9146100d8578063284180fc146100fd57806334d386001461016f57806337a52ecc146101be578063d442d6cc146101d1578063f4145a83146101f0575b600080fd5b341561009257600080fd5b6100d6600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061020395505050505050565b005b34156100e357600080fd5b6100eb61029b565b60405190815260200160405180910390f35b341561010857600080fd5b61011c600160a060020a03600435166102a1565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561015b578082015183820152602001610143565b505050509050019250505060405180910390f35b341561017a57600080fd5b6100d6600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061035795505050505050565b34156101c957600080fd5b6100eb6103c2565b34156101dc57600080fd5b61011c600160a060020a03600435166103c8565b34156101fb57600080fd5b6100eb61047c565b60008060005483511461021557600080fd5b60005443925061024c9061023f90610233858263ffffffff61048216565b9063ffffffff61049716565b839063ffffffff6104cd16565b90506001548111801561026157506002548111155b151561026c57600080fd5b600160a060020a03331660009081526004602052604090208380516102959291602001906104df565b50505050565b60015481565b6102a961052c565b600080544391906102c89061023f90610233858263ffffffff61048216565b60015490915081116102d957600080fd5b6003600085600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561034957602002820191906000526020600020905b81548152600190910190602001808311610334575b505050505092505050919050565b60008060005483511461036957600080fd5b6000544392506103879061023f90610233858263ffffffff61048216565b60015490915081111561039957600080fd5b600160a060020a03331660009081526003602052604090208380516102959291602001906104df565b60025481565b6103d061052c565b600080544391906103ef9061023f90610233858263ffffffff61048216565b600254909150811161040057600080fd5b6004600085600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561034957602002820191906000526020600020908154815260019091019060200180831161033457505050505092505050919050565b60005481565b6000818381151561048f57fe5b049392505050565b6000808315156104aa57600091506104c6565b508282028284828115156104ba57fe5b04146104c257fe5b8091505b5092915050565b6000828211156104d957fe5b50900390565b82805482825590600052602060002090810192821561051c579160200282015b8281111561051c57825182556020909201916001909101906104ff565b5061052892915061053e565b5090565b60206040519081016040526000815290565b61055891905b808211156105285760008155600101610544565b905600a165627a7a7230582031eb1183e55e5d47012ab3437f7e50e5d73edca48c1e66da1b1b45d7fa0d566b0029`
|
const TomoRandomizeBin = `0x6060604052341561000f57600080fd5b604051602080610359833981016040528080516000555050610323806100366000396000f30060606040526004361061006c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663284180fc811461007157806334d38600146100e3578063ccbac9f514610134578063d442d6cc14610159578063e11f5ba214610178575b600080fd5b341561007c57600080fd5b610090600160a060020a036004351661018e565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cf5780820151838201526020016100b7565b505050509050019250505060405180910390f35b34156100ee57600080fd5b610132600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061021295505050505050565b005b341561013f57600080fd5b61014761023f565b60405190815260200160405180910390f35b341561016457600080fd5b610147600160a060020a0360043516610245565b341561018357600080fd5b610132600435610260565b61019661027b565b6001600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561020657602002820191906000526020600020905b815481526001909101906020018083116101f1575b50505050509050919050565b600160a060020a033316600090815260016020526040902081805161023b92916020019061028d565b5050565b60005481565b600160a060020a031660009081526002602052604090205490565b600160a060020a033316600090815260026020526040902055565b60206040519081016040526000815290565b8280548282559060005260206000209081019282156102ca579160200282015b828111156102ca57825182556020909201916001909101906102ad565b506102d69291506102da565b5090565b6102f491905b808211156102d657600081556001016102e0565b905600a165627a7a7230582043a345787b9942e3361515ce1a0a4dbaab0ed6ce42c6ca0344119134351d9ffe0029`
|
||||||
|
|
||||||
// DeployTomoRandomize deploys a new Ethereum contract, binding an instance of TomoRandomize to it.
|
// DeployTomoRandomize deploys a new Ethereum contract, binding an instance of TomoRandomize to it.
|
||||||
func DeployTomoRandomize(auth *bind.TransactOpts, backend bind.ContractBackend, _epochNumber *big.Int, _blockTimeSecret *big.Int, _blockTimeOpening *big.Int) (common.Address, *types.Transaction, *TomoRandomize, error) {
|
func DeployTomoRandomize(auth *bind.TransactOpts, backend bind.ContractBackend, _randomNumber *big.Int) (common.Address, *types.Transaction, *TomoRandomize, error) {
|
||||||
parsed, err := abi.JSON(strings.NewReader(TomoRandomizeABI))
|
parsed, err := abi.JSON(strings.NewReader(TomoRandomizeABI))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Address{}, nil, nil, err
|
return common.Address{}, nil, nil, err
|
||||||
}
|
}
|
||||||
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TomoRandomizeBin), backend, _epochNumber, _blockTimeSecret, _blockTimeOpening)
|
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TomoRandomizeBin), backend, _randomNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Address{}, nil, nil, err
|
return common.Address{}, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -335,90 +335,12 @@ func (_TomoRandomize *TomoRandomizeTransactorRaw) Transact(opts *bind.TransactOp
|
||||||
return _TomoRandomize.Contract.contract.Transact(opts, method, params...)
|
return _TomoRandomize.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 (_TomoRandomize *TomoRandomizeCaller) BlockTimeOpening(opts *bind.CallOpts) (*big.Int, error) {
|
|
||||||
var (
|
|
||||||
ret0 = new(*big.Int)
|
|
||||||
)
|
|
||||||
out := ret0
|
|
||||||
err := _TomoRandomize.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 (_TomoRandomize *TomoRandomizeSession) BlockTimeOpening() (*big.Int, error) {
|
|
||||||
return _TomoRandomize.Contract.BlockTimeOpening(&_TomoRandomize.CallOpts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockTimeOpening is a free data retrieval call binding the contract method 0x37a52ecc.
|
|
||||||
//
|
|
||||||
// Solidity: function blockTimeOpening() constant returns(uint256)
|
|
||||||
func (_TomoRandomize *TomoRandomizeCallerSession) BlockTimeOpening() (*big.Int, error) {
|
|
||||||
return _TomoRandomize.Contract.BlockTimeOpening(&_TomoRandomize.CallOpts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockTimeSecret is a free data retrieval call binding the contract method 0x257b03e9.
|
|
||||||
//
|
|
||||||
// Solidity: function blockTimeSecret() constant returns(uint256)
|
|
||||||
func (_TomoRandomize *TomoRandomizeCaller) BlockTimeSecret(opts *bind.CallOpts) (*big.Int, error) {
|
|
||||||
var (
|
|
||||||
ret0 = new(*big.Int)
|
|
||||||
)
|
|
||||||
out := ret0
|
|
||||||
err := _TomoRandomize.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 (_TomoRandomize *TomoRandomizeSession) BlockTimeSecret() (*big.Int, error) {
|
|
||||||
return _TomoRandomize.Contract.BlockTimeSecret(&_TomoRandomize.CallOpts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockTimeSecret is a free data retrieval call binding the contract method 0x257b03e9.
|
|
||||||
//
|
|
||||||
// Solidity: function blockTimeSecret() constant returns(uint256)
|
|
||||||
func (_TomoRandomize *TomoRandomizeCallerSession) BlockTimeSecret() (*big.Int, error) {
|
|
||||||
return _TomoRandomize.Contract.BlockTimeSecret(&_TomoRandomize.CallOpts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83.
|
|
||||||
//
|
|
||||||
// Solidity: function epochNumber() constant returns(uint256)
|
|
||||||
func (_TomoRandomize *TomoRandomizeCaller) EpochNumber(opts *bind.CallOpts) (*big.Int, error) {
|
|
||||||
var (
|
|
||||||
ret0 = new(*big.Int)
|
|
||||||
)
|
|
||||||
out := ret0
|
|
||||||
err := _TomoRandomize.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 (_TomoRandomize *TomoRandomizeSession) EpochNumber() (*big.Int, error) {
|
|
||||||
return _TomoRandomize.Contract.EpochNumber(&_TomoRandomize.CallOpts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83.
|
|
||||||
//
|
|
||||||
// Solidity: function epochNumber() constant returns(uint256)
|
|
||||||
func (_TomoRandomize *TomoRandomizeCallerSession) EpochNumber() (*big.Int, error) {
|
|
||||||
return _TomoRandomize.Contract.EpochNumber(&_TomoRandomize.CallOpts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetOpening is a free data retrieval call binding the contract method 0xd442d6cc.
|
// GetOpening is a free data retrieval call binding the contract method 0xd442d6cc.
|
||||||
//
|
//
|
||||||
// Solidity: function getOpening(_validator address) constant returns(bytes32[])
|
// Solidity: function getOpening(_validator address) constant returns(bytes32)
|
||||||
func (_TomoRandomize *TomoRandomizeCaller) GetOpening(opts *bind.CallOpts, _validator common.Address) ([][32]byte, error) {
|
func (_TomoRandomize *TomoRandomizeCaller) GetOpening(opts *bind.CallOpts, _validator common.Address) ([32]byte, error) {
|
||||||
var (
|
var (
|
||||||
ret0 = new([][32]byte)
|
ret0 = new([32]byte)
|
||||||
)
|
)
|
||||||
out := ret0
|
out := ret0
|
||||||
err := _TomoRandomize.contract.Call(opts, out, "getOpening", _validator)
|
err := _TomoRandomize.contract.Call(opts, out, "getOpening", _validator)
|
||||||
|
|
@ -427,15 +349,15 @@ func (_TomoRandomize *TomoRandomizeCaller) GetOpening(opts *bind.CallOpts, _vali
|
||||||
|
|
||||||
// GetOpening is a free data retrieval call binding the contract method 0xd442d6cc.
|
// GetOpening is a free data retrieval call binding the contract method 0xd442d6cc.
|
||||||
//
|
//
|
||||||
// Solidity: function getOpening(_validator address) constant returns(bytes32[])
|
// Solidity: function getOpening(_validator address) constant returns(bytes32)
|
||||||
func (_TomoRandomize *TomoRandomizeSession) GetOpening(_validator common.Address) ([][32]byte, error) {
|
func (_TomoRandomize *TomoRandomizeSession) GetOpening(_validator common.Address) ([32]byte, error) {
|
||||||
return _TomoRandomize.Contract.GetOpening(&_TomoRandomize.CallOpts, _validator)
|
return _TomoRandomize.Contract.GetOpening(&_TomoRandomize.CallOpts, _validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOpening is a free data retrieval call binding the contract method 0xd442d6cc.
|
// GetOpening is a free data retrieval call binding the contract method 0xd442d6cc.
|
||||||
//
|
//
|
||||||
// Solidity: function getOpening(_validator address) constant returns(bytes32[])
|
// Solidity: function getOpening(_validator address) constant returns(bytes32)
|
||||||
func (_TomoRandomize *TomoRandomizeCallerSession) GetOpening(_validator common.Address) ([][32]byte, error) {
|
func (_TomoRandomize *TomoRandomizeCallerSession) GetOpening(_validator common.Address) ([32]byte, error) {
|
||||||
return _TomoRandomize.Contract.GetOpening(&_TomoRandomize.CallOpts, _validator)
|
return _TomoRandomize.Contract.GetOpening(&_TomoRandomize.CallOpts, _validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -465,24 +387,50 @@ func (_TomoRandomize *TomoRandomizeCallerSession) GetSecret(_validator common.Ad
|
||||||
return _TomoRandomize.Contract.GetSecret(&_TomoRandomize.CallOpts, _validator)
|
return _TomoRandomize.Contract.GetSecret(&_TomoRandomize.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()
|
// Solidity: function randomNumber() constant returns(uint256)
|
||||||
func (_TomoRandomize *TomoRandomizeTransactor) SetOpening(opts *bind.TransactOpts, _opening [][32]byte) (*types.Transaction, error) {
|
func (_TomoRandomize *TomoRandomizeCaller) RandomNumber(opts *bind.CallOpts) (*big.Int, error) {
|
||||||
|
var (
|
||||||
|
ret0 = new(*big.Int)
|
||||||
|
)
|
||||||
|
out := ret0
|
||||||
|
err := _TomoRandomize.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 (_TomoRandomize *TomoRandomizeSession) RandomNumber() (*big.Int, error) {
|
||||||
|
return _TomoRandomize.Contract.RandomNumber(&_TomoRandomize.CallOpts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RandomNumber is a free data retrieval call binding the contract method 0xccbac9f5.
|
||||||
|
//
|
||||||
|
// Solidity: function randomNumber() constant returns(uint256)
|
||||||
|
func (_TomoRandomize *TomoRandomizeCallerSession) RandomNumber() (*big.Int, error) {
|
||||||
|
return _TomoRandomize.Contract.RandomNumber(&_TomoRandomize.CallOpts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOpening is a paid mutator transaction binding the contract method 0xe11f5ba2.
|
||||||
|
//
|
||||||
|
// Solidity: function setOpening(_opening bytes32) returns()
|
||||||
|
func (_TomoRandomize *TomoRandomizeTransactor) SetOpening(opts *bind.TransactOpts, _opening [32]byte) (*types.Transaction, error) {
|
||||||
return _TomoRandomize.contract.Transact(opts, "setOpening", _opening)
|
return _TomoRandomize.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()
|
// Solidity: function setOpening(_opening bytes32) returns()
|
||||||
func (_TomoRandomize *TomoRandomizeSession) SetOpening(_opening [][32]byte) (*types.Transaction, error) {
|
func (_TomoRandomize *TomoRandomizeSession) SetOpening(_opening [32]byte) (*types.Transaction, error) {
|
||||||
return _TomoRandomize.Contract.SetOpening(&_TomoRandomize.TransactOpts, _opening)
|
return _TomoRandomize.Contract.SetOpening(&_TomoRandomize.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()
|
// Solidity: function setOpening(_opening bytes32) returns()
|
||||||
func (_TomoRandomize *TomoRandomizeTransactorSession) SetOpening(_opening [][32]byte) (*types.Transaction, error) {
|
func (_TomoRandomize *TomoRandomizeTransactorSession) SetOpening(_opening [32]byte) (*types.Transaction, error) {
|
||||||
return _TomoRandomize.Contract.SetOpening(&_TomoRandomize.TransactOpts, _opening)
|
return _TomoRandomize.Contract.SetOpening(&_TomoRandomize.TransactOpts, _opening)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ func NewRandomize(transactOpts *bind.TransactOpts, contractAddr common.Address,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeployRandomize(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *Randomize, error) {
|
func DeployRandomize(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, randomNumber *big.Int) (common.Address, *Randomize, error) {
|
||||||
randomizeAddr, _, _, err := contract.DeployTomoRandomize(transactOpts, contractBackend, big.NewInt(2), big.NewInt(0), big.NewInt(1))
|
randomizeAddr, _, _, err := contract.DeployTomoRandomize(transactOpts, contractBackend, randomNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return randomizeAddr, nil, err
|
return randomizeAddr, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,14 @@
|
||||||
package randomize
|
package randomize
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
"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/core"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
)
|
)
|
||||||
|
|
@ -35,16 +38,28 @@ func TestRandomize(t *testing.T) {
|
||||||
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
||||||
transactOpts := bind.NewKeyedTransactor(key)
|
transactOpts := bind.NewKeyedTransactor(key)
|
||||||
|
|
||||||
_, randomize, err := DeployRandomize(transactOpts, contractBackend)
|
randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend, big.NewInt(2))
|
||||||
|
t.Log("contract address", randomizeAddress.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't deploy root registry: %v", err)
|
t.Fatalf("can't deploy root registry: %v", err)
|
||||||
}
|
}
|
||||||
contractBackend.Commit()
|
contractBackend.Commit()
|
||||||
|
|
||||||
|
d := time.Now().Add(1000 * time.Millisecond)
|
||||||
|
ctx, cancel := context.WithDeadline(context.Background(), d)
|
||||||
|
defer cancel()
|
||||||
|
code, _ := contractBackend.CodeAt(ctx, randomizeAddress, nil)
|
||||||
|
t.Log("contract code", common.ToHex(code))
|
||||||
|
f := func(key, val common.Hash) bool {
|
||||||
|
t.Log(key.Hex(), val.Hex())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
contractBackend.ForEachStorageAt(ctx, randomizeAddress, nil, f)
|
||||||
|
|
||||||
s, err := randomize.SetSecret(byte0)
|
s, err := randomize.SetSecret(byte0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't get secret: %v", err)
|
t.Fatalf("can't get secret: %v", err)
|
||||||
}
|
}
|
||||||
t.Log("secret", s)
|
t.Log("tx data", s)
|
||||||
contractBackend.Commit()
|
contractBackend.Commit()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -216,12 +216,18 @@ func GetRewardBalancesRate(masterAddr common.Address, totalReward *big.Int, vali
|
||||||
log.Error("Fail to get vote capacity", "error", err)
|
log.Error("Fail to get vote capacity", "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
totalCap.Add(totalCap, voterCap)
|
totalCap.Add(totalCap, voterCap)
|
||||||
voterCaps[voteAddr] = voterCap
|
voterCaps[voteAddr] = voterCap
|
||||||
}
|
}
|
||||||
for addr, voteCap := range voterCaps {
|
for addr, voteCap := range voterCaps {
|
||||||
balances[addr] = new(big.Int).Mul(totalVoterReward, voteCap)
|
rcap := new(big.Int).Mul(totalVoterReward, voteCap)
|
||||||
balances[addr] = new(big.Int).Div(balances[addr], totalCap)
|
rcap = new(big.Int).Div(rcap, totalCap)
|
||||||
|
if balances[addr] != nil {
|
||||||
|
balances[addr].Add(balances[addr], rcap)
|
||||||
|
} else {
|
||||||
|
balances[addr] = rcap
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ func TestSendTxSign(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
transactOpts := bind.NewKeyedTransactor(acc1Key)
|
transactOpts := bind.NewKeyedTransactor(acc1Key)
|
||||||
blockSignerAddr, blockSigner, err := blocksigner.DeployBlockSigner(transactOpts, backend)
|
blockSignerAddr, blockSigner, err := blocksigner.DeployBlockSigner(transactOpts, backend, big.NewInt(99))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't get block signer: %v", err)
|
t.Fatalf("Can't get block signer: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,41 @@
|
||||||
pragma solidity ^0.4.21;
|
pragma solidity ^0.4.21;
|
||||||
|
|
||||||
import "./interfaces/IValidator.sol";
|
|
||||||
import "./libs/SafeMath.sol";
|
import "./libs/SafeMath.sol";
|
||||||
|
|
||||||
contract TomoValidator is IValidator {
|
contract TomoValidator {
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
|
||||||
event Vote(address _voter, address _candidate, uint256 _cap);
|
event Vote(address _voter, address _candidate, uint256 _cap);
|
||||||
event Unvote(address _voter, address _candidate, uint256 _cap);
|
event Unvote(address _voter, address _candidate, uint256 _cap);
|
||||||
event Propose(address _owner, address _candidate, uint256 _cap);
|
event Propose(address _owner, address _candidate, uint256 _cap);
|
||||||
event Resign(address _owner, address _candidate);
|
event Resign(address _owner, address _candidate);
|
||||||
event SetNodeUrl(address _owner, address _candidate, string _nodeUrl);
|
event SetNodeId(address _owner, address _candidate, string _nodeId);
|
||||||
event Withdraw(address _owner, address _candidate, uint256 _cap);
|
event Withdraw(address _owner, uint256 _blockNumber, uint256 _cap);
|
||||||
|
|
||||||
struct ValidatorState {
|
struct ValidatorState {
|
||||||
address owner;
|
address owner;
|
||||||
string nodeUrl;
|
string nodeId;
|
||||||
bool isCandidate;
|
bool isCandidate;
|
||||||
uint256 cap;
|
uint256 cap;
|
||||||
uint256 withdrawBlockNumber;
|
|
||||||
mapping(address => uint256) voters;
|
mapping(address => uint256) voters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct WithdrawState {
|
||||||
|
mapping(uint256 => uint256) caps;
|
||||||
|
uint256[] blockNumbers;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapping(address => WithdrawState) withdrawsState;
|
||||||
|
|
||||||
mapping(address => ValidatorState) validatorsState;
|
mapping(address => ValidatorState) validatorsState;
|
||||||
mapping(address => address[]) voters;
|
mapping(address => address[]) voters;
|
||||||
address[] public candidates = [
|
address[] public candidates;
|
||||||
0xf99805B536609cC03AcBB2604dFaC11E9E54a448,
|
|
||||||
0x31b249fE6F267aa2396Eb2DC36E9c79351d97Ec5,
|
uint256 public candidateCount = 3;
|
||||||
0xfC5571921c6d3672e13B58EA23DEA534f2b35fA0
|
|
||||||
];
|
|
||||||
uint256 candidateCount = 3;
|
|
||||||
uint256 public minCandidateCap;
|
uint256 public minCandidateCap;
|
||||||
uint256 public maxValidatorNumber;
|
uint256 public maxValidatorNumber;
|
||||||
uint256 public candidateWithdrawDelay; // blocks
|
uint256 public candidateWithdrawDelay;
|
||||||
|
uint256 public voterWithdrawDelay;
|
||||||
|
|
||||||
modifier onlyValidCandidateCap {
|
modifier onlyValidCandidateCap {
|
||||||
// anyone can deposit X TOMO to become a candidate
|
// anyone can deposit X TOMO to become a candidate
|
||||||
|
|
@ -50,12 +53,6 @@ contract TomoValidator is IValidator {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifier onlyAlreadyResigned(address _candidate) {
|
|
||||||
require(validatorsState[_candidate].withdrawBlockNumber > 0);
|
|
||||||
require(block.number >= validatorsState[_candidate].withdrawBlockNumber);
|
|
||||||
_;
|
|
||||||
}
|
|
||||||
|
|
||||||
modifier onlyValidCandidate (address _candidate) {
|
modifier onlyValidCandidate (address _candidate) {
|
||||||
require(validatorsState[_candidate].isCandidate);
|
require(validatorsState[_candidate].isCandidate);
|
||||||
_;
|
_;
|
||||||
|
|
@ -71,37 +68,52 @@ contract TomoValidator is IValidator {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modifier onlyValidWithdraw (uint256 _blockNumber, uint _index) {
|
||||||
|
require(_blockNumber > 0);
|
||||||
|
require(block.number >= _blockNumber);
|
||||||
|
require(withdrawsState[msg.sender].caps[_blockNumber] > 0);
|
||||||
|
require(withdrawsState[msg.sender].blockNumbers[_index] == _blockNumber);
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
function TomoValidator (
|
function TomoValidator (
|
||||||
|
address[] _candidates,
|
||||||
|
uint256[] _caps,
|
||||||
|
address _firstOwner,
|
||||||
uint256 _minCandidateCap,
|
uint256 _minCandidateCap,
|
||||||
uint256 _maxValidatorNumber,
|
uint256 _maxValidatorNumber,
|
||||||
uint256 _candidateWithdrawDelay
|
uint256 _candidateWithdrawDelay,
|
||||||
|
uint256 _voterWithdrawDelay
|
||||||
) public {
|
) public {
|
||||||
minCandidateCap = _minCandidateCap;
|
minCandidateCap = _minCandidateCap;
|
||||||
maxValidatorNumber = _maxValidatorNumber;
|
maxValidatorNumber = _maxValidatorNumber;
|
||||||
candidateWithdrawDelay = _candidateWithdrawDelay;
|
candidateWithdrawDelay = _candidateWithdrawDelay;
|
||||||
|
voterWithdrawDelay = _voterWithdrawDelay;
|
||||||
|
|
||||||
for (uint256 i = 0; i < candidates.length; i++) {
|
for (uint256 i = 0; i < _candidates.length; i++) {
|
||||||
validatorsState[candidates[i]] = ValidatorState({
|
candidates.push(_candidates[i]);
|
||||||
owner: 0x487d62d33467c4842c5e54Eb370837E4E88BBA0F,
|
validatorsState[_candidates[i]] = ValidatorState({
|
||||||
nodeUrl: '',
|
owner: _firstOwner,
|
||||||
|
nodeId: '',
|
||||||
isCandidate: true,
|
isCandidate: true,
|
||||||
withdrawBlockNumber: 0,
|
cap: _caps[i]
|
||||||
cap: minCandidateCap
|
|
||||||
});
|
});
|
||||||
|
voters[_candidates[i]].push(_firstOwner);
|
||||||
|
validatorsState[candidates[i]].voters[_firstOwner] = minCandidateCap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function propose(address _candidate, string _nodeUrl) external payable onlyValidCandidateCap onlyNotCandidate(_candidate) {
|
function propose(address _candidate, string _nodeId) external payable onlyValidCandidateCap onlyNotCandidate(_candidate) {
|
||||||
candidates.push(_candidate);
|
candidates.push(_candidate);
|
||||||
validatorsState[_candidate] = ValidatorState({
|
validatorsState[_candidate] = ValidatorState({
|
||||||
owner: msg.sender,
|
owner: msg.sender,
|
||||||
nodeUrl: _nodeUrl,
|
nodeId: _nodeId,
|
||||||
isCandidate: true,
|
isCandidate: true,
|
||||||
withdrawBlockNumber: 0,
|
|
||||||
cap: msg.value
|
cap: msg.value
|
||||||
});
|
});
|
||||||
validatorsState[_candidate].voters[msg.sender] = msg.value;
|
validatorsState[_candidate].voters[msg.sender] = msg.value;
|
||||||
candidateCount = candidateCount + 1;
|
candidateCount = candidateCount + 1;
|
||||||
|
voters[_candidate].push(_candidate);
|
||||||
emit Propose(msg.sender, _candidate, msg.value);
|
emit Propose(msg.sender, _candidate, msg.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,18 +134,14 @@ contract TomoValidator is IValidator {
|
||||||
return validatorsState[_candidate].cap;
|
return validatorsState[_candidate].cap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCandidateNodeUrl(address _candidate) public view returns(string) {
|
function getCandidateNodeId(address _candidate) public view returns(string) {
|
||||||
return validatorsState[_candidate].nodeUrl;
|
return validatorsState[_candidate].nodeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCandidateOwner(address _candidate) public view returns(address) {
|
function getCandidateOwner(address _candidate) public view returns(address) {
|
||||||
return validatorsState[_candidate].owner;
|
return validatorsState[_candidate].owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCandidateWithdrawBlockNumber(address _candidate) public view returns(uint256) {
|
|
||||||
return validatorsState[_candidate].withdrawBlockNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getVoterCap(address _candidate, address _voter) public view returns(uint256) {
|
function getVoterCap(address _candidate, address _voter) public view returns(uint256) {
|
||||||
return validatorsState[_candidate].voters[_voter];
|
return validatorsState[_candidate].voters[_voter];
|
||||||
}
|
}
|
||||||
|
|
@ -146,17 +154,25 @@ contract TomoValidator is IValidator {
|
||||||
return validatorsState[_candidate].isCandidate;
|
return validatorsState[_candidate].isCandidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getWithdrawBlockNumbers() public view returns(uint256[]) {
|
||||||
|
return withdrawsState[msg.sender].blockNumbers;
|
||||||
|
}
|
||||||
|
|
||||||
function unvote(address _candidate, uint256 _cap) public onlyValidVote(_candidate, _cap) {
|
function unvote(address _candidate, uint256 _cap) public onlyValidVote(_candidate, _cap) {
|
||||||
validatorsState[_candidate].cap = validatorsState[_candidate].cap.sub(_cap);
|
validatorsState[_candidate].cap = validatorsState[_candidate].cap.sub(_cap);
|
||||||
validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].sub(_cap);
|
validatorsState[_candidate].voters[msg.sender] = validatorsState[_candidate].voters[msg.sender].sub(_cap);
|
||||||
// refunding to user after unvoting
|
|
||||||
msg.sender.transfer(_cap);
|
// refund after delay X blocks
|
||||||
|
uint256 withdrawBlockNumber = voterWithdrawDelay.add(block.number);
|
||||||
|
withdrawsState[msg.sender].caps[withdrawBlockNumber] = withdrawsState[msg.sender].caps[withdrawBlockNumber].add(_cap);
|
||||||
|
withdrawsState[msg.sender].blockNumbers.push(withdrawBlockNumber);
|
||||||
|
|
||||||
emit Unvote(msg.sender, _candidate, _cap);
|
emit Unvote(msg.sender, _candidate, _cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setNodeUrl(address _candidate, string _nodeUrl) public onlyOwner(_candidate) {
|
function setNodeId(address _candidate, string _nodeId) public onlyOwner(_candidate) {
|
||||||
validatorsState[_candidate].nodeUrl = _nodeUrl;
|
validatorsState[_candidate].nodeId = _nodeId;
|
||||||
emit SetNodeUrl(msg.sender, _candidate, _nodeUrl);
|
emit SetNodeId(msg.sender, _candidate, _nodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resign(address _candidate) public onlyOwner(_candidate) onlyCandidate(_candidate) {
|
function resign(address _candidate) public onlyOwner(_candidate) onlyCandidate(_candidate) {
|
||||||
|
|
@ -168,17 +184,21 @@ contract TomoValidator is IValidator {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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 onlyOwner(_candidate) onlyNotCandidate(_candidate) onlyAlreadyResigned(_candidate) {
|
|
||||||
uint256 cap = validatorsState[_candidate].voters[msg.sender];
|
uint256 cap = validatorsState[_candidate].voters[msg.sender];
|
||||||
validatorsState[_candidate].cap = validatorsState[_candidate].cap.sub(cap);
|
validatorsState[_candidate].cap = validatorsState[_candidate].cap.sub(cap);
|
||||||
validatorsState[_candidate].voters[msg.sender] = 0;
|
validatorsState[_candidate].voters[msg.sender] = 0;
|
||||||
validatorsState[_candidate].withdrawBlockNumber = 0;
|
// refunding after retiring X blocks
|
||||||
|
uint256 withdrawBlockNumber = candidateWithdrawDelay.add(block.number);
|
||||||
|
withdrawsState[msg.sender].caps[withdrawBlockNumber] = withdrawsState[msg.sender].caps[withdrawBlockNumber].add(cap);
|
||||||
|
withdrawsState[msg.sender].blockNumbers.push(withdrawBlockNumber);
|
||||||
|
emit Resign(msg.sender, _candidate);
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdraw(uint256 _blockNumber, uint _index) public onlyValidWithdraw(_blockNumber, _index) {
|
||||||
|
uint256 cap = withdrawsState[msg.sender].caps[_blockNumber];
|
||||||
|
delete withdrawsState[msg.sender].caps[_blockNumber];
|
||||||
|
delete withdrawsState[msg.sender].blockNumbers[_index];
|
||||||
msg.sender.transfer(cap);
|
msg.sender.transfer(cap);
|
||||||
emit Withdraw(msg.sender, _candidate, cap);
|
emit Withdraw(msg.sender, _blockNumber, cap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -42,8 +42,10 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address,
|
||||||
}, nil
|
}, 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) {
|
||||||
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100))
|
minDeposit := new(big.Int)
|
||||||
|
minDeposit.SetString("50000000000000000000000", 10)
|
||||||
|
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, big.NewInt(99), big.NewInt(100), big.NewInt(100))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return validatorAddr, nil, err
|
return validatorAddr, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,19 @@
|
||||||
package validator
|
package validator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/contracts"
|
"github.com/ethereum/go-ethereum/contracts"
|
||||||
"github.com/ethereum/go-ethereum/contracts/validator/contract"
|
"github.com/ethereum/go-ethereum/contracts/validator/contract"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -46,12 +48,25 @@ func TestValidator(t *testing.T) {
|
||||||
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
||||||
transactOpts := bind.NewKeyedTransactor(key)
|
transactOpts := bind.NewKeyedTransactor(key)
|
||||||
|
|
||||||
_, validator, err := DeployValidator(transactOpts, contractBackend)
|
validatorCap := new(big.Int)
|
||||||
|
validatorCap.SetString("50000000000000000000000", 10)
|
||||||
|
validatorAddress, validator, err := DeployValidator(transactOpts, contractBackend, []common.Address{addr}, []*big.Int{validatorCap}, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't deploy root registry: %v", err)
|
t.Fatalf("can't deploy root registry: %v", err)
|
||||||
}
|
}
|
||||||
contractBackend.Commit()
|
contractBackend.Commit()
|
||||||
|
|
||||||
|
d := time.Now().Add(1000 * time.Millisecond)
|
||||||
|
ctx, cancel := context.WithDeadline(context.Background(), d)
|
||||||
|
defer cancel()
|
||||||
|
code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil)
|
||||||
|
t.Log("contract code", common.ToHex(code))
|
||||||
|
f := func(key, val common.Hash) bool {
|
||||||
|
t.Log(key.Hex(), val.Hex())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
contractBackend.ForEachStorageAt(ctx, validatorAddress, nil, f)
|
||||||
|
|
||||||
candidates, err := validator.GetCandidates()
|
candidates, err := validator.GetCandidates()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't get candidates: %v", err)
|
t.Fatalf("can't get candidates: %v", err)
|
||||||
|
|
@ -76,7 +91,20 @@ func TestRewardBalance(t *testing.T) {
|
||||||
accounts := []*bind.TransactOpts{acc1Opts, acc2Opts}
|
accounts := []*bind.TransactOpts{acc1Opts, acc2Opts}
|
||||||
transactOpts := bind.NewKeyedTransactor(acc1Key)
|
transactOpts := bind.NewKeyedTransactor(acc1Key)
|
||||||
|
|
||||||
validatorAddr, _, baseValidator, err := contract.DeployTomoValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100))
|
// validatorAddr, _, baseValidator, err := contract.DeployTomoValidator(transactOpts, contractBackend, big.NewInt(50000), big.NewInt(99), big.NewInt(100), big.NewInt(100))
|
||||||
|
validatorCap := new(big.Int)
|
||||||
|
validatorCap.SetString("50000000000000000000000", 10)
|
||||||
|
validatorAddr, _, baseValidator, err := contract.DeployTomoValidator(
|
||||||
|
transactOpts,
|
||||||
|
contractBackend,
|
||||||
|
[]common.Address{addr},
|
||||||
|
[]*big.Int{validatorCap},
|
||||||
|
addr,
|
||||||
|
big.NewInt(50000),
|
||||||
|
big.NewInt(99),
|
||||||
|
big.NewInt(100),
|
||||||
|
big.NewInt(100),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't deploy root registry: %v", err)
|
t.Fatalf("can't deploy root registry: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +152,7 @@ func TestRewardBalance(t *testing.T) {
|
||||||
afterReward = new(big.Int).Add(afterReward, value)
|
afterReward = new(big.Int).Add(afterReward, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if totalReward.Int64()+1 < afterReward.Int64() || totalReward.Int64()-1 > afterReward.Int64() {
|
if totalReward.Int64()+5 < afterReward.Int64() || totalReward.Int64()-5 > afterReward.Int64() {
|
||||||
callOpts := new(bind.CallOpts)
|
callOpts := new(bind.CallOpts)
|
||||||
voters, err := baseValidator.GetVoters(callOpts, acc3Addr)
|
voters, err := baseValidator.GetVoters(callOpts, acc3Addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue