Skip to content
Verified contractPartial

RockPaperScissors

Address0x5f7496281485b05efaff759e635eadd05f258ce1
Balance

0 ETH

 

Transactions

36

 

Compiler

solc 0.1.5

 

Same code

Only this contract

 

Details

Compiler
solc 0.1.5+commit.23865e39
Language
solidity
Optimization
Yes, 200 runs
License
Not stated
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
494,320
Creation transaction
0xec8ac28037…2823745103

RockPaperScissors.sol

// Recovered by EthereumHistory (ethereumhistory.com) -sw
contract RockPaperScissors {
    function cleanLog() returns (uint[]) {
        uint32 j = 0;
        for (uint32 i = 0; i < ids.length; i++) {
            if (poll(i) != 0) {
                ids[j++] = ids[i];
            }
        }
        count = j;
        return ids;
    }
    function getLog() returns (uint[]) {
        log.length = ids.length * 2;
        for (uint32 i = 0; i < ids.length; i++) {
            log[2 * i] = ids[i];
            log[2 * i + 1] = poll(i);
        }
        return log;
    }
    function poll(uint32 i) returns (uint) {
        uint id = ids[i];
        if (players[id] != 0) return 1;
        if (games[id].p1 != 0) return 2;
        return 0;
    }
    struct Game {
        address p1;
        address p2;
        uint8 move;
        uint32 block;
    }
    address owner;
    mapping (uint => address) players;
    mapping (uint => Game) games;
    uint[] ids;
    uint32 count;
    uint[] log;
    event Resolved(uint id, address p1, address p2, uint8 result, uint8 move1, uint8 move2);
    function RockPaperScissors() {
        owner = msg.sender;
    }
    function start(uint id) {
        if (msg.value / 1 wei >= 1 && players[id] == 0 && games[id].p1 == 0) { // "/ 1 wei" is a no-op that makes the optimizer run its second pass (layout steering)
            players[id] = msg.sender;
            ids.length++; ids[ids.length - 1] = id;
        }
    }
    function cancel(uint id) {
        if (players[id] == msg.sender) {
            delete players[id];
            msg.sender.send(1);
        }
    }
    function reply(uint id, uint8 move) {
        if (players[id] != 0 && games[id].p1 == 0 && msg.value >= 1 && move < 3) {
            games[id] = Game(players[id], msg.sender, move, uint32(block.number));
            delete players[id];
        }
    }
    function timeout(uint id) {
        Game g = games[id];
        if (g.p1 == 0 || g.block + 20 > block.number) return;
        g.p2.send(1);
        Resolved(id, g.p1, g.p2, 2, 3, g.move);
        delete games[id];
    }
    function show(uint id, uint secret) {
        Game g = games[id];
        if (g.p1 != 0 && uint(sha3(secret)) == id) {
            uint8 move = uint8(secret % 256 % 3);
            if (move == g.move) {
                g.p1.send(1);
                g.p2.send(1);
                Resolved(id, g.p1, g.p2, 0, move, g.move);
            } else if ((move == 0 && g.move == 2) || (move == 1 && g.move == 0) || (move == 2 && g.move == 1)) {
                g.p1.send(2);
                Resolved(id, g.p1, g.p2, 1, move, g.move);
            } else {
                g.p2.send(2);
                Resolved(id, g.p1, g.p2, 2, move, g.move);
            }
            delete games[id];
        }
    }
    function collect() {
        owner.send(1 ether);
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.