Advertisement
Guest User

Step3

a guest
Apr 24th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. pragma solidity ^0.4.2;
  2.  
  3. contract hash {
  4. function computeHash(string _str1, string _str2) public returns bytes32{
  5. return keccak256(_str1, _str2);
  6. }
  7. }
  8.  
  9. contract RPS is hash {
  10.  
  11. address public player1;
  12. address public player2;
  13.  
  14. bytes32 public commitment;
  15.  
  16. //player1.balance>10 and player1.transfer(10)
  17.  
  18. uint public stakes;
  19.  
  20. uint private _players;
  21.  
  22. mapping (address => uint) public balances;
  23.  
  24. function RPS() public payable{
  25. player1 = msg.sender;
  26. _players = 1;
  27. }
  28.  
  29. function p1_commit(bytes32 _commitment) public payable {
  30. require(
  31. msg.sender == player1,
  32. "Only Player1/ creator can commit the stakes."
  33. );
  34.  
  35. require(
  36. msg.value > 0 ether,
  37. "Stakes have to be greater than 0 ethers."
  38. );
  39.  
  40. stakes = msg.value;
  41. commitment = _commitment;
  42. }
  43.  
  44. function is_valid_play(string _play) returns bool{
  45. bytes32 hash_play = hash.computeHash(_play,"1")
  46. if( hash_play == hash.computeHash("Rock","1")){
  47. return true;
  48. }
  49. if( hash_play == hash.computeHash("Paper","1")){
  50. return true;
  51. }
  52. if( hash_play == hash.computeHash("Scissors","1")){
  53. return true;
  54. }
  55.  
  56. return false;
  57. }
  58.  
  59. function p2_join(string _play) external payable {
  60. //Should I use require here or not. Check later on piazza.
  61. require(
  62. _players < 2,
  63. "There are already two players."
  64. );
  65.  
  66.  
  67.  
  68. }
  69.  
  70.  
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement