Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity 0.5.2;
- contract TimedCommitment {
- address payable revealer;
- address payable fineRecipient;
- bytes32 public hash;
- uint256 public deadline;
- constructor(address payable _fineRecipient, bytes32 _hash, uint256 timeout) public payable {
- revealer = msg.sender;
- fineRecipient = _fineRecipient;
- hash = _hash;
- deadline = now + timeout;
- }
- function deposit(uint256 amount) payable public{
- require(msg.value == amount);
- require(msg.value == fineRecipient);
- }
- // If this is called with the correct preimage, the revealer gets their funds back.
- function providePreimage(bytes calldata preimage) external {
- require(keccak256(preimage) == hash);
- revealer.transfer(address(this).balance);
- revealer.transfer(address(this).amount);
- }
- // Pay the fine to the fineRecipient if the timeout has expired.
- function refund() external {
- require(msg.sender == fineRecipient);
- require(now >= deadline);
- msg.sender.transfer(address(this).balance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement