-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeadman.sol
37 lines (29 loc) · 950 Bytes
/
deadman.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
contract DeadmansSwitch {
address public owner;
address public destination;
uint public last;
event SwitchTriggered(address indexed sender, uint balanceTransferred);
modifier onlyOwner() {
require(msg.sender == owner, "Not the owner");
_;
}
constructor(address _destination) {
owner = msg.sender;
destination = _destination;
last = block.number;
}
function stillAlive() external onlyOwner {
last = block.number;
}
function checkStatus() external {
require(block.number - last <= 10, "Switch triggered");
uint balanceToSend = address(this).balance;
require(balanceToSend > 0, "No balance to transfer");
payable(destination).transfer(balanceToSend);
emit SwitchTriggered(msg.sender, balanceToSend);
}
receive() external payable {
}
}