Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.2;
- contract hash {
- function computeHash(string _str1, string _str2) public returns bytes32{
- return keccak256(_str1, _str2);
- }
- }
- contract RPS is hash {
- address public player1;
- address public player2;
- bytes32 public commitment;
- //player1.balance>10 and player1.transfer(10)
- uint public stakes;
- uint private _players;
- mapping (address => uint) public balances;
- function RPS() public payable{
- player1 = msg.sender;
- _players = 1;
- }
- function p1_commit(bytes32 _commitment) public payable {
- require(
- msg.sender == player1,
- "Only Player1/ creator can commit the stakes."
- );
- require(
- msg.value > 0 ether,
- "Stakes have to be greater than 0 ethers."
- );
- stakes = msg.value;
- commitment = _commitment;
- }
- function is_valid_play(string _play) returns bool{
- bytes32 hash_play = hash.computeHash(_play,"1")
- if( hash_play == hash.computeHash("Rock","1")){
- return true;
- }
- if( hash_play == hash.computeHash("Paper","1")){
- return true;
- }
- if( hash_play == hash.computeHash("Scissors","1")){
- return true;
- }
- return false;
- }
- function p2_join(string _play) external payable {
- //Should I use require here or not. Check later on piazza.
- require(
- _players < 2,
- "There are already two players."
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement