-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoveLetterToWhoever.sol
More file actions
41 lines (31 loc) · 1.01 KB
/
LoveLetterToWhoever.sol
File metadata and controls
41 lines (31 loc) · 1.01 KB
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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
contract LoveLetterToWhoever {
bytes32 private hash;
string private message;
address payable private owner;
address payable private _deployer;
uint256 private pin;
constructor(address payable _deployer) public {
owner = _deployer;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can perform this action.");
_;
}
function setPin(uint256 _pin) public onlyOwner {
pin = _pin;
}
function setMessage(string memory _message) public onlyOwner {
message = _message;
hash = keccak256(abi.encodePacked(message));
}
function revealMessage(uint256 _pin) public view returns (string memory) {
require(_pin == pin, "Incorrect PIN.");
return message;
}
function emergencyWithdraw() public onlyOwner payable {
require(address(this).balance > 0, "No funds to withdraw.");
owner.transfer(address(this).balance);
}
}