From a3eb8fb155b2a6355b0d02c4314049e6c32fb9cf Mon Sep 17 00:00:00 2001 From: Fynn Date: Wed, 17 Jan 2018 17:22:15 +0100 Subject: [PATCH] withdraw implemented Former-commit-id: f4ec0e7067ecc9406e7b3ef56659d5924b547c87 [formerly 6720442b533ed1bc406087452e5328363f1f01b9] Former-commit-id: e2108b302ee39b6882c3de60b3ef19449c91e32b --- sharding/contracts/validator_manager.sol | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/sharding/contracts/validator_manager.sol b/sharding/contracts/validator_manager.sol index 50a1e5694..b7517c63d 100644 --- a/sharding/contracts/validator_manager.sol +++ b/sharding/contracts/validator_manager.sol @@ -1,6 +1,12 @@ pragma solidity ^0.4.19; +import "RLP.sol"; + contract VMC { + using RLP for RLP.RLPItem; + using RLP for RLP.Iterator; + using RLP for bytes; + struct Validator { // Amount of wei the validator holds uint deposit; @@ -124,8 +130,18 @@ contract VMC { return index; } - function withdraw(uint _validatorIndex, bytes10 _sig) public returns(bool) { - // TODO + function withdraw(int _validatorIndex, bytes10 _sig) public returns(bool) { + var msgHash = keccak256("withdraw"); + var result = validators[_validatorIndex].validationCodeAddr.call.gas(sigGasLimit)(msgHash, _sig) == true; + if (result) { + validators[_validatorIndex].returnAddr.transfer(validators[_validatorIndex].deposit); + isValcodeDeposited[validators[_validatorIndex].validationCodeAddr] = false; + delete validators[_validatorIndex]; + stackPush(_validatorIndex); + --numValidators; + log1(msgHash, bytes32(_validatorIndex)); + return result; + } } function sample(int _shardId) public constant returns(address) { @@ -175,8 +191,8 @@ contract VMC { return shardList; } - - function addHeader(bytes12 header) public returns(bool) { + + function addHeader(bytes _header) public returns(bool) { // TODO }