-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodee
32 lines (26 loc) · 765 Bytes
/
codee
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract DeadmansSwitch {
address public owner;
address public presetAddress;
uint256 public lastAliveBlock;
modifier onlyOwner() {
require(msg.sender == owner, "Not the contract owner");
_;
}
constructor(address _presetAddress) {
owner = msg.sender;
presetAddress = _presetAddress;
lastAliveBlock = block.number;
}
function still_alive() external onlyOwner {
lastAliveBlock = block.number;
}
function checkAlive() external {
require(block.number - lastAliveBlock <= 10, "Owner not alive");
_selfDestruct();
}
function _selfDestruct() internal {
selfdestruct(presetAddress);
}
}