-
Notifications
You must be signed in to change notification settings - Fork 0
/
dead_man_switch.sol
50 lines (36 loc) · 1.26 KB
/
dead_man_switch.sol
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
49
50
pragma solidity >=0.5.0 <0.6.0;
contract DIY{
mapping(address=>address) recovToPrimary;
mapping(address=>address) primToRecovery;
mapping(address=>uint) balance;
mapping (address=>uint) alive;
uint aliveCondition=10;
function getBalanceOfContract() public view returns (uint256) {
return address(this).balance;
}
function myBalance() public view returns(uint256){
return balance[msg.sender];
}
function deposit() payable public{
balance[msg.sender]+=msg.value;
}
function setRecovery(address _address) public{
primToRecovery[msg.sender]=_address;
recovToPrimary[_address]=msg.sender;
alive[msg.sender]=block.number;
}
function claimTransfer(address payable _address,uint _amount) internal {
_address.transfer(_amount);
}
function claimAmount() public {
require((block.number-alive[recovToPrimary[msg.sender]])>aliveCondition);
claimTransfer(msg.sender,balance[recovToPrimary[msg.sender]]);
balance[recovToPrimary[msg.sender]]=0;
}
function still_alive() public{
alive[msg.sender]=block.number;
}
function aliveStatus() public view returns(uint){
return alive[msg.sender];
}
}