Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. pragma solidity 0.5.2;
  2.  
  3. contract TimedCommitment {
  4. address payable revealer;
  5. address payable fineRecipient;
  6. bytes32 public hash;
  7. uint256 public deadline;
  8.  
  9. constructor(address payable _fineRecipient, bytes32 _hash, uint256 timeout) public payable {
  10. revealer = msg.sender;
  11. fineRecipient = _fineRecipient;
  12. hash = _hash;
  13. deadline = now + timeout;
  14. }
  15.  
  16. function deposit(uint256 amount) payable public{
  17. require(msg.value == amount);
  18. require(msg.value == fineRecipient);
  19.  
  20. }
  21.  
  22. // If this is called with the correct preimage, the revealer gets their funds back.
  23. function providePreimage(bytes calldata preimage) external {
  24. require(keccak256(preimage) == hash);
  25. revealer.transfer(address(this).balance);
  26. revealer.transfer(address(this).amount);
  27. }
  28.  
  29. // Pay the fine to the fineRecipient if the timeout has expired.
  30. function refund() external {
  31. require(msg.sender == fineRecipient);
  32. require(now >= deadline);
  33.  
  34. msg.sender.transfer(address(this).balance);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement