mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
Merge pull request #145 from thanhson1085/master
prepare contract, genesis
This commit is contained in:
commit
94d7507b35
4 changed files with 14 additions and 8 deletions
|
|
@ -217,7 +217,7 @@ func (w *wizard) makeGenesis() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Randomize Smart Contract Code
|
// Randomize Smart Contract Code
|
||||||
randomizeAddress, _, err := randomizeContract.DeployRandomize(transactOpts, contractBackend, big.NewInt(99))
|
randomizeAddress, _, err := randomizeContract.DeployRandomize(transactOpts, contractBackend, big.NewInt(90))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Can't deploy root registry")
|
fmt.Println("Can't deploy root registry")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ contract TomoValidator {
|
||||||
mapping(address => address[]) voters;
|
mapping(address => address[]) voters;
|
||||||
address[] public candidates;
|
address[] public candidates;
|
||||||
|
|
||||||
uint256 public candidateCount = 3;
|
uint256 public candidateCount = 0;
|
||||||
uint256 public minCandidateCap;
|
uint256 public minCandidateCap;
|
||||||
uint256 public maxValidatorNumber;
|
uint256 public maxValidatorNumber;
|
||||||
uint256 public candidateWithdrawDelay;
|
uint256 public candidateWithdrawDelay;
|
||||||
|
|
@ -90,6 +90,7 @@ contract TomoValidator {
|
||||||
maxValidatorNumber = _maxValidatorNumber;
|
maxValidatorNumber = _maxValidatorNumber;
|
||||||
candidateWithdrawDelay = _candidateWithdrawDelay;
|
candidateWithdrawDelay = _candidateWithdrawDelay;
|
||||||
voterWithdrawDelay = _voterWithdrawDelay;
|
voterWithdrawDelay = _voterWithdrawDelay;
|
||||||
|
candidateCount = candidateCount.add(_candidates.length);
|
||||||
|
|
||||||
for (uint256 i = 0; i < _candidates.length; i++) {
|
for (uint256 i = 0; i < _candidates.length; i++) {
|
||||||
candidates.push(_candidates[i]);
|
candidates.push(_candidates[i]);
|
||||||
|
|
@ -104,14 +105,15 @@ contract TomoValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
function propose(address _candidate) external payable onlyValidCandidateCap onlyNotCandidate(_candidate) {
|
function propose(address _candidate) external payable onlyValidCandidateCap onlyNotCandidate(_candidate) {
|
||||||
|
uint256 cap = validatorsState[_candidate].cap.add(msg.value);
|
||||||
candidates.push(_candidate);
|
candidates.push(_candidate);
|
||||||
validatorsState[_candidate] = ValidatorState({
|
validatorsState[_candidate] = ValidatorState({
|
||||||
owner: msg.sender,
|
owner: msg.sender,
|
||||||
isCandidate: true,
|
isCandidate: true,
|
||||||
cap: msg.value
|
cap: cap
|
||||||
});
|
});
|
||||||
validatorsState[_candidate].voters[msg.sender] = msg.value;
|
validatorsState[_candidate].voters[msg.sender] = msg.value;
|
||||||
candidateCount = candidateCount + 1;
|
candidateCount = candidateCount.add(1);
|
||||||
voters[_candidate].push(msg.sender);
|
voters[_candidate].push(msg.sender);
|
||||||
emit Propose(msg.sender, _candidate, msg.value);
|
emit Propose(msg.sender, _candidate, msg.value);
|
||||||
}
|
}
|
||||||
|
|
@ -171,7 +173,7 @@ contract TomoValidator {
|
||||||
|
|
||||||
function resign(address _candidate) public onlyOwner(_candidate) onlyCandidate(_candidate) {
|
function resign(address _candidate) public onlyOwner(_candidate) onlyCandidate(_candidate) {
|
||||||
validatorsState[_candidate].isCandidate = false;
|
validatorsState[_candidate].isCandidate = false;
|
||||||
candidateCount = candidateCount - 1;
|
candidateCount = candidateCount.sub(1);
|
||||||
for (uint256 i = 0; i < candidates.length; i++) {
|
for (uint256 i = 0; i < candidates.length; i++) {
|
||||||
if (candidates[i] == _candidate) {
|
if (candidates[i] == _candidate) {
|
||||||
delete candidates[i];
|
delete candidates[i];
|
||||||
|
|
@ -181,7 +183,7 @@ contract TomoValidator {
|
||||||
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;
|
||||||
// refunding after retiring X blocks
|
// refunding after resigning X blocks
|
||||||
uint256 withdrawBlockNumber = candidateWithdrawDelay.add(block.number);
|
uint256 withdrawBlockNumber = candidateWithdrawDelay.add(block.number);
|
||||||
withdrawsState[msg.sender].caps[withdrawBlockNumber] = withdrawsState[msg.sender].caps[withdrawBlockNumber].add(cap);
|
withdrawsState[msg.sender].caps[withdrawBlockNumber] = withdrawsState[msg.sender].caps[withdrawBlockNumber].add(cap);
|
||||||
withdrawsState[msg.sender].blockNumbers.push(withdrawBlockNumber);
|
withdrawsState[msg.sender].blockNumbers.push(withdrawBlockNumber);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -45,7 +45,11 @@ func NewValidator(transactOpts *bind.TransactOpts, contractAddr common.Address,
|
||||||
func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, validatorAddress []common.Address, caps []*big.Int, ownerAddress common.Address) (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 := new(big.Int)
|
||||||
minDeposit.SetString("50000000000000000000000", 10)
|
minDeposit.SetString("50000000000000000000000", 10)
|
||||||
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, big.NewInt(99), big.NewInt(100), big.NewInt(100))
|
// Deposit 50K TOMO
|
||||||
|
// 150 masternodes
|
||||||
|
// Candidate Delay Withdraw 30 days = 1296000 blocks
|
||||||
|
// Voter Delay Withdraw 2 days = 8640 blocks
|
||||||
|
validatorAddr, _, _, err := contract.DeployTomoValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, big.NewInt(150), big.NewInt(8640), big.NewInt(1296000))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return validatorAddr, nil, err
|
return validatorAddr, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue