summaryrefslogtreecommitdiffstats
path: root/contracts/Recovery.sol
blob: cf708eb28ed1d6dafa7976019021a0dee8fd5438 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

contract Recovery is Ownable {
    uint256 public depositValue;

    mapping(uint256 => address[]) public votes;
    mapping(uint256 => mapping(address => bool)) public voted;
    mapping(address => uint256) public withdrawable;

    event VotedForRecovery(uint256 indexed height, address voter);
    event Withdrawn(address indexed owner, uint256 amount);

    function setDeposit(uint256 DepositValue) public onlyOwner {
        depositValue = DepositValue;
    }

    function refund(uint256 height, uint256 value) public onlyOwner {
        for (uint i = 0; i < votes[height].length; i++) {
            withdrawable[votes[height][i]] += value;
        }
    }

    function withdraw() public {
        require(withdrawable[msg.sender] > 0);

        uint256 amount = withdrawable[msg.sender];
        withdrawable[msg.sender] = 0;
        msg.sender.transfer(amount);

        emit Withdrawn(msg.sender, amount);
    }

    function voteForSkipBlock(uint256 height) public payable {
        require(msg.value >= depositValue);
        require(!voted[height][msg.sender]);

        votes[height].push(msg.sender);
        voted[height][msg.sender] = true;

        emit VotedForRecovery(height, msg.sender);
    }

    function numVotes(uint256 height) public returns (uint256) {
        return votes[height].length;
    }
}