Skip to content

Instantly share code, notes, and snippets.

@seresistvanandras
Last active February 16, 2019 15:06
Show Gist options
  • Save seresistvanandras/e65eb438652c846dff1338c48f4ce7ed to your computer and use it in GitHub Desktop.
Save seresistvanandras/e65eb438652c846dff1338c48f4ce7ed to your computer and use it in GitHub Desktop.
Open Blockchain Workshop Series 1st edition

Important addresses, links for the 1st Open Blockchain Workshop

Get some (testnet) ether here

István's account on Ropsten and the corresponding address: 0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b

Use this Blockchain explorer: https://ropsten.etherscan.io

helloOBWS contract address: 0xD568eC979E970f104d429D7fEdc7aa78bD5Df8f6

pragma solidity ^0.4.24; pragma experimental ABIEncoderV2;

contract helloOBW { string public readME = "Hello Open Blockchain Workshop 2019.02.16";

event Message(string greeting, string message);
function hello(string _name) public {
    emit Message("Hi! how you doing?", _name);
}

}

István's rock paper scissors contract address: 0x34117bc3a7a453768039a085bb5dac6a51c3a397 RockPaperScissors code:

pragma solidity ^0.4.24; pragma experimental ABIEncoderV2;

//0 is rock //1 is paper //2 is scissors contract rockPaperScissors { address public player1; address public player2; uint256 choicePlayer1; uint256 choicePlayer2; bool alreadyCalled = false;

mapping(address => bool) tookHerMove;

constructor() public payable {
    require(msg.value == 0.01 ether);
    player1 = msg.sender;
}

function addPlayer2() public payable {
    require(!alreadyCalled);
    require(msg.value == 0.01 ether);
    player2= msg.sender;
    alreadyCalled = true;
}

function makeChoice(uint256 _choice) public {
    require(msg.sender == player1 || msg.sender == player2);
    require(_choice==0 ||_choice == 1||_choice==2);
    if(msg.sender==player1) {
        require(!tookHerMove[player1]);
        choicePlayer1 = _choice;
        tookHerMove[player1] = true;
    } else {
        require(!tookHerMove[player2]);
        choicePlayer2 == _choice;
        tookHerMove[player2] = true;
    }
    
}

event Draw(string message);
function withdrawPrize() public {
    require(tookHerMove[player1]&&tookHerMove[player2]);
    require(msg.sender==player1|| msg.sender == player2);
    uint256 winner = (3 + choicePlayer1 - choicePlayer2) % 3;
    if(winner==0) {
        emit Draw("It was draw");
    }
    if(winner == 1) {
        player1.transfer(this.balance);
    } else {
        player2.transfer(this.balance);
    }
    tookHerMove[player1] = false;
    tookHerMove[player2] = false;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment