Advertisement
Prosperity-Author

SimpleGame.sol

Jan 8th, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | Cryptocurrency | 0 0
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.22;
  3.  
  4. contract SimpleGame {
  5. bool public isFinished;
  6. uint256 lastDepositedBlock;
  7. mapping(address depositor => bool deposited) public depositors;
  8.  
  9. function totalDeposit() external view returns (uint256) {
  10. return address(this).balance;
  11. }
  12.  
  13. function deposit() public payable {
  14. require(msg.value == 0.1 ether, "Must deposit 0.1 Ether");
  15. require(!isFinished, "The game is over");
  16. require(
  17. lastDepositedBlock != block.number,
  18. "Only can deposit once per block"
  19. );
  20. // if (!depositors[msg.sender]) {
  21. // depositors[msg.sender] = true;
  22. // }
  23.  
  24. lastDepositedBlock = block.number;
  25. }
  26.  
  27. function claim() public {
  28. require(address(this).balance >= 1 ether, "Condition not satisfied");
  29.  
  30. payable(msg.sender).transfer(address(this).balance);
  31. isFinished = true;
  32. }
  33.  
  34. function claimFixed() public {
  35. require(address(this).balance >= 1 ether, "Condition not satisfied");
  36. // Players are real people, so we should only allow EOA to claim for a fair competion
  37. // require(tx.origin == msg.sender, "Only EOA can claim");
  38. // Only depositors can claim
  39. // require(depositors[msg.sender], "Only depositors can claim");
  40. require(
  41. lastDepositedBlock != block.number,
  42. "Cant claim on the same block as deposit"
  43. );
  44.  
  45. payable(msg.sender).transfer(address(this).balance);
  46. isFinished = true;
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement