Skip to content

Instantly share code, notes, and snippets.

@blutarche
Last active July 6, 2022 00:25
Show Gist options
  • Save blutarche/c9f295eea2d54bea154f3b4dc8a5a0c4 to your computer and use it in GitHub Desktop.
Save blutarche/c9f295eea2d54bea154f3b4dc8a5a0c4 to your computer and use it in GitHub Desktop.
contract LoveLetter {
...
function open(uint256 id) external returns (string memory message) {
require(receivers[id] == msg.sender, "Not receiver");
require(!letters[id].opened, "Already opened");
message = letters[id].message;
letters[id].opened = true;
uint256 amount = letters[id].etherAmount;
console.log("[open]", id, amount);
if (amount > 0) {
payable(msg.sender).transfer(amount);
}
emit Opened(senders[id], msg.sender, id, amount);
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment