padomima.sol 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. pragma solidity ^0.4.7;
  2. contract Padomima {
  3. struct Match {
  4. address creator;
  5. address challenger;
  6. uint amount;
  7. bool finished;
  8. }
  9. address owner = msg.sender;
  10. mapping(address => bytes32) PlayerBinding;
  11. mapping(bytes32 => Match) Matches;
  12. function changeOwner(address _newOwner)
  13. {
  14. if(owner == msg.sender)
  15. owner = _newOwner;
  16. }
  17. function Padomima() {}
  18. function createMatch() payable{
  19. if( msg.value < 50000000000000000 ) throw;
  20. if( PlayerBinding[msg.sender] != bytes32(0x0) )throw;
  21. bytes32 hash = keccak256(msg.sender);
  22. PlayerBinding[msg.sender] = hash;
  23. Matches[hash] = Match(msg.sender, address(0x0), msg.value, false);
  24. }
  25. function claimEmptyMatch() {
  26. if( PlayerBinding[msg.sender] == bytes32(0x0) )throw; // Is the caller in a match?
  27. bytes32 hash = PlayerBinding[msg.sender];
  28. if( Matches[hash].creator != msg.sender)throw; // Creator must be the caller
  29. if( Matches[hash].challenger != address(0x0) )throw; // Check if There is an opponent on this match
  30. if(!msg.sender.send(Matches[hash].amount)) // send money
  31. throw;
  32. delete PlayerBinding[msg.sender]; //delete binding
  33. delete Matches[hash]; // delete match
  34. }
  35. function joinMatch(bytes32 hash) payable{
  36. if( msg.value < Matches[hash].amount ) throw;
  37. if( PlayerBinding[msg.sender] != bytes32(0x0) ) throw;
  38. if( Matches[hash].challenger != address(0x0) ) throw;
  39. if( Matches[hash].creator == msg.sender ) throw;
  40. Matches[hash].challenger = msg.sender;
  41. PlayerBinding[msg.sender] = hash;
  42. }
  43. // function getMyMap() constant returns (uint[32]){
  44. // Match m = Matches[PlayerBinding[msg.sender]];
  45. // bytes32 maphash = keccak256(m.creator, m.challenger);
  46. // uint[32] memory map;
  47. // for(uint i=0; i < 32 ; i++){
  48. // map[i] = uint(maphash[i]);
  49. // }
  50. // return map;
  51. // }
  52. function getMyMap() constant returns (bytes32){
  53. Match m = Matches[PlayerBinding[msg.sender]];
  54. bytes32 maphash = keccak256(m.creator, m.challenger);
  55. return maphash;
  56. }
  57. function getMyStake() constant returns (uint){
  58. if(!amInMatch())throw;
  59. return Matches[PlayerBinding[msg.sender]].amount;
  60. }
  61. function getMyMatch() constant returns (bytes32 hash){
  62. if(!amInMatch())throw;
  63. return PlayerBinding[msg.sender];
  64. }
  65. function getMyOpponent() constant returns (address hash){
  66. if(!amInMatch())throw;
  67. Match m = Matches[PlayerBinding[msg.sender]];
  68. if( m.challenger == msg.sender )return m.creator;
  69. return m.challenger;
  70. }
  71. function getMapRotation() constant returns (uint8){
  72. if(!amInMatch())throw;
  73. Match m = Matches[PlayerBinding[msg.sender]];
  74. if( m.challenger == msg.sender )return 1;
  75. return 0;
  76. }
  77. function amInMatch() constant returns (bool){
  78. return PlayerBinding[msg.sender] != bytes32(0x0);
  79. }
  80. function sig_verify(bytes32 hash, bytes sig) constant returns(address) //verifying the signature
  81. {
  82. bytes32 r;
  83. bytes32 s;
  84. uint8 v;
  85. assembly
  86. {
  87. r := mload(add(sig, 32))
  88. s := mload(add(sig, 64))
  89. v := byte(0, mload(add(sig, 96)))
  90. }
  91. if(v<27)
  92. v+=27;
  93. return ecrecover(hash, v, r, s);
  94. }
  95. }
  96. contract Move {
  97. string tyape;
  98. }