Contract Overview
Balance:
0 Ether
EtherValue:
$0.00
More Info
My Name Tag:
Not Available, login to update
[ Download CSV Export ]
Latest 4 internal transactions
Parent Txn Hash | Block | From | To | Value | |||
---|---|---|---|---|---|---|---|
0x0b551d8bbecaa1f9a900b8ef6e7bbe868b3536db6afad11d18780cf0e20f4de5 | 3424356 | 1971 days 1 hr ago | 0x1d77340d3819007bbfd7fdd37c22bd3b5c311350 | 0xa69c7e93f7b073cdae328a57eff059b130e75fd4 | 0.002 Ether | ||
0x0b551d8bbecaa1f9a900b8ef6e7bbe868b3536db6afad11d18780cf0e20f4de5 | 3424356 | 1971 days 1 hr ago | 0x1d77340d3819007bbfd7fdd37c22bd3b5c311350 | 0x04528fb91840ce4bcfc7390919a455d530da8ecb | 0.198 Ether | ||
0x4b01e5a55f1763d1a1725b491e7e5dfd4566b90f006b730a88920d21d2b87e10 | 2743468 | 2083 days 21 hrs ago | 0x1d77340d3819007bbfd7fdd37c22bd3b5c311350 | 0xa69c7e93f7b073cdae328a57eff059b130e75fd4 | 0.002 Ether | ||
0x4b01e5a55f1763d1a1725b491e7e5dfd4566b90f006b730a88920d21d2b87e10 | 2743468 | 2083 days 21 hrs ago | 0x1d77340d3819007bbfd7fdd37c22bd3b5c311350 | 0xa69c7e93f7b073cdae328a57eff059b130e75fd4 | 0.198 Ether |
[ Download CSV Export ]
Contract Name:
RockPaperScissors
Compiler Version
v0.3.6+commit.3fc68da
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity)
/** *Submitted for verification at Etherscan.io on 2016-09-30 */ contract RockPaperScissors { /* Brief introduction: the game is about to submit your pick (R/P/S) with fee to the blockchain, join players into pairs and withdraw 2x the fee, or just 1x the fee in case of draw. if there will be no other player in "LimitOfMinutes" minutes you can refund your fee. The whole thing is made by picking a random value called SECRET_RAND, where (SECRET_RAND % 3) gives 0,1 or 2 for Rock,Paper or Scissors, then taking a hash of SECRET_RAND and submitting it as your ticket. At this moment player waits for opponent. If there is no opponent in "LimitOfMinutes", player can refund or wait more. When both players sended their hashes then they have "LimitOfMinutes" minutes to announce their SECRET_RAND. As soon as both players provided their SECRET_RAND the withdraw is possible. If opponent will not announce his SECRET_RAND in LimitOfMinutes then the players bet is treated as a winning one. In any case (win, draw, refund) you should use Withdraw() function to pay out. There is fee of 1% for contract owner, charged while player withdraws. There is no fee for contract owner in case of refund. */ /* JSON Interface: [{"constant":true,"inputs":[],"name":"Announcement","outputs":[{"name":"","type":"string"}],"type":"function"},{"constant":false,"inputs":[{"name":"HASH","type":"bytes32"}],"name":"play","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"MySecretRand","type":"bytes32"}],"name":"announce","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"MyHash","type":"bytes32"}],"name":"IsPayoutReady__InfoFunction","outputs":[{"name":"Info","type":"string"}],"type":"function"},{"constant":true,"inputs":[{"name":"RockPaperOrScissors","type":"uint8"},{"name":"WriteHereSomeUniqeRandomStuff","type":"string"}],"name":"CreateHash","outputs":[{"name":"SendThisHashToStart","type":"bytes32"},{"name":"YourSecretRandKey","type":"bytes32"},{"name":"Info","type":"string"}],"type":"function"},{"constant":true,"inputs":[{"name":"SecretRand","type":"bytes32"}],"name":"WhatWasMyHash","outputs":[{"name":"HASH","type":"bytes32"}],"type":"function"},{"constant":false,"inputs":[{"name":"HASH","type":"bytes32"}],"name":"withdraw","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"LimitOfMinutes","outputs":[{"name":"","type":"uint8"}],"type":"function"},{"constant":true,"inputs":[],"name":"Cost","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"inputs":[],"type":"constructor"}] */ modifier OnlyOwner() { // Modifier if (msg.sender != owner) throw; _ } uint8 public LimitOfMinutes;//number of minutes you have to announce (1)your choice or (2)wait to withdraw funds back if no one else will play uint public Cost; string public Announcement; address owner; uint TimeOfLastPriceChange; mapping(bytes32=>bet_t) bets; uint playerssofar; struct bet_t { bytes32 OpponentHash; address sender; uint timestamp; int8 Pick; bool can_withdraw;//default==false } bytes32 LastHash; function RockPaperScissors() { playerssofar=0; owner=msg.sender; //SetInternalValues(limitofminutes, cost); LimitOfMinutes=255; Cost=100000000000000000;//0.1ETH TimeOfLastPriceChange = now - 255*60; } function SetInternalValues(uint8 limitofminutes, uint cost) OnlyOwner { LimitOfMinutes=limitofminutes; if(Cost!=cost) { Cost=cost; TimeOfLastPriceChange=now; } } function OwnerAnnounce(string announcement) OnlyOwner { Announcement=announcement; } function play(bytes32 HASH) { if(now < TimeOfLastPriceChange + LimitOfMinutes*60 || //the game is temprorary off msg.value != Cost || // pay to play //bets[HASH].can_withdraw == true ||//to play twice, give another random seed in CreateHash() f-n bets[HASH].sender != 0 || //throw because someone have already made this bet HASH == 0 //this would be problematic situation ) throw; bets[HASH].sender=msg.sender; bets[HASH].can_withdraw=true; if(playerssofar%2 == 1) { bets[HASH].OpponentHash=LastHash; bets[LastHash].OpponentHash=HASH; } else LastHash=HASH; bets[HASH].timestamp=now; playerssofar++; } function announce(bytes32 MySecretRand) { if(msg.value != 0 || bets[sha3(MySecretRand)].can_withdraw==false) throw; //if you try to announce non existing bet (do not waste your gas) bets[sha3(MySecretRand)].Pick= int8( uint(MySecretRand)%3 + 1 ); //there is no check of msg.sender. If your secret rand was guessed by someone else it is no longer secret //remember to give good 'random' seed as input of CreateHash f-n. bets[sha3(MySecretRand)].timestamp=now; } function withdraw(bytes32 HASH) { //3 ways to payout: //1: both sides announced their picks and you have won OR draw happend //2: no one else played - you can payout after LimitOfMinutes (100% refund) //3: you have announced your pick but opponent not (you have won) //note that both of you has "LimitOfMinutes" minutes to announce the SecretRand numbers after 2nd player played if(msg.value != 0 || bets[HASH].can_withdraw == false) throw; if(bets[HASH].OpponentHash!=0 && //case 1 bets[bets[HASH].OpponentHash].Pick != 0 && //check if opponent announced bets[HASH].Pick != 0 //check if player announced //it is impossible for val .Pick to be !=0 without broadcasting SecretRand ) { int8 tmp = bets[HASH].Pick - bets[bets[HASH].OpponentHash].Pick; if(tmp==0)//draw? { bets[HASH].can_withdraw=false; if(!bets[HASH].sender.send(Cost*99/100)) //return ETH throw; else if(!owner.send(Cost/100)) throw; } else if(tmp == 1 || tmp == -2)//you have won { bets[HASH].can_withdraw=false; bets[bets[HASH].OpponentHash].can_withdraw=false; if(!bets[HASH].sender.send(2*Cost*99/100)) //refund throw; else if(!owner.send(2*Cost/100)) throw; } else throw; } else if(bets[HASH].OpponentHash==0 && //case 2 now > bets[HASH].timestamp + LimitOfMinutes*60) { bets[HASH].can_withdraw=false; if(!bets[HASH].sender.send(Cost)) //refund throw; //if we are here that means we should repair playerssofar --playerssofar; } else if(bets[HASH].OpponentHash!=0 && bets[bets[HASH].OpponentHash].Pick == 0 && //opponent did not announced bets[HASH].Pick != 0 //check if player announced )//case 3 { //now lets make sure that opponent had enough time to announce if(//now > (time of last interaction from player or opponent) now > bets[HASH].timestamp + LimitOfMinutes*60 && now > bets[bets[HASH].OpponentHash].timestamp + LimitOfMinutes*60 )//then refund is possible { bets[HASH].can_withdraw=false; bets[bets[HASH].OpponentHash].can_withdraw=false; if(!bets[HASH].sender.send(2*Cost*99/100)) throw; else if(!owner.send(2*Cost/100)) throw; } else throw;//you still need to wait some more time } else throw; //throw in any other case //here program flow jumps //and program ends } function IsPayoutReady__InfoFunction(bytes32 MyHash) constant returns (string Info) { // "write your hash" // "you can send this hash and double your ETH!" // "wait for opponent [Xmin left]" // "you can announce your SecretRand" // "wait for opponent SecretRand" // "ready to withdraw - you have won!" // "you have lost, try again" if(MyHash == 0) return "write your hash"; if(bets[MyHash].sender == 0) return "you can send this hash and double your ETH!"; if(bets[MyHash].sender != 0 && bets[MyHash].can_withdraw==false) return "this bet is burned"; if(bets[MyHash].OpponentHash==0 && now < bets[MyHash].timestamp + LimitOfMinutes*60) return "wait for other player"; if(bets[MyHash].OpponentHash==0) return "no one played, use withdraw() for refund"; //from now there is opponent bool timeforaction = (now < bets[MyHash].timestamp + LimitOfMinutes*60) || (now < bets[bets[MyHash].OpponentHash].timestamp + LimitOfMinutes*60 ); if(bets[MyHash].Pick == 0 && timeforaction ) return "you can announce your SecretRand"; if(bets[MyHash].Pick == 0) return "you have failed to announce your SecretRand but still you can try before opponent withdraws"; if(bets[bets[MyHash].OpponentHash].Pick == 0 && timeforaction ) return "wait for opponent SecretRand"; bool win=false; bool draw=false; int8 tmp = bets[MyHash].Pick - bets[bets[MyHash].OpponentHash].Pick; if(tmp==0)//draw? draw=true; else if(tmp == 1 || tmp == -2)//you have won win=true; if(bets[bets[MyHash].OpponentHash].Pick == 0 || win ) return "you have won! now you can withdraw your ETH"; if(draw) return "Draw happend! withdraw back your funds"; return "you have lost, try again"; } function WhatWasMyHash(bytes32 SecretRand) constant returns (bytes32 HASH) { return sha3(SecretRand); } function CreateHash(uint8 RockPaperOrScissors, string WriteHereSomeUniqeRandomStuff) constant returns (bytes32 SendThisHashToStart, bytes32 YourSecretRandKey, string Info) { uint SecretRand; SecretRand=3*( uint(sha3(WriteHereSomeUniqeRandomStuff))/3 ) + (RockPaperOrScissors-1)%3; //SecretRand%3 == //0 - Rock //1 - Paper //2 - Scissors if(RockPaperOrScissors==0) return(0,0, "enter 1 for Rock, 2 for Paper, 3 for Scissors"); return (sha3(bytes32(SecretRand)),bytes32(SecretRand), bets[sha3(bytes32(SecretRand))].sender != 0 ? "someone have already used this random string - try another one" : SecretRand%3==0 ? "Rock" : SecretRand%3==1 ? "Paper" : "Scissors"); } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"constant":false,"inputs":[{"name":"limitofminutes","type":"uint8"},{"name":"cost","type":"uint256"}],"name":"SetInternalValues","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"Announcement","outputs":[{"name":"","type":"string"}],"type":"function"},{"constant":true,"inputs":[],"name":"LimitOfMinutes","outputs":[{"name":"","type":"uint8"}],"type":"function"},{"constant":false,"inputs":[{"name":"MySecretRand","type":"bytes32"}],"name":"announce","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"MyHash","type":"bytes32"}],"name":"IsPayoutReady__InfoFunction","outputs":[{"name":"Info","type":"string"}],"type":"function"},{"constant":true,"inputs":[{"name":"SecretRand","type":"bytes32"}],"name":"WhatWasMyHash","outputs":[{"name":"HASH","type":"bytes32"}],"type":"function"},{"constant":false,"inputs":[{"name":"HASH","type":"bytes32"}],"name":"withdraw","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"HASH","type":"bytes32"}],"name":"play","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"announcement","type":"string"}],"name":"OwnerAnnounce","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"RockPaperOrScissors","type":"uint8"},{"name":"WriteHereSomeUniqeRandomStuff","type":"string"}],"name":"CreateHash","outputs":[{"name":"SendThisHashToStart","type":"bytes32"},{"name":"YourSecretRandKey","type":"bytes32"},{"name":"Info","type":"string"}],"type":"function"},{"constant":true,"inputs":[],"name":"Cost","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"inputs":[],"type":"constructor"}]
Contract Creation Code
60606040526000600681905560038054600160a060020a03191633179055805460ff191660ff17905567016345785d8a0000600155613bc31942016004556112488061004b6000396000f36060604052361561008d5760e060020a600035046318f303a1811461008f578063538d1267146100b357806354cbffc41461010e5780636056969b1461011a5780636534b4e214610167578063856f3080146101c35780638e19899e146101ea578063c7a1865b14610224578063e2894a8a14610284578063e9794dc1146102e4578063f63c533c1461040c575b005b61008d60043560243560035433600160a060020a0390811691161461051e57610002565b6040805160028054602060018216156101000260001901909116829004601f8101829004820284018201909452838352610415939083018282801561056c5780601f106105415761010080835404028352916020019161056c565b61048360005460ff1681565b61008d60043534600014158061015d57506040805182815281519081900360209081019091206000908152600590915290812060030154610100900460ff161515145b1561057457610002565b61041560043560408051602081019091526000808252808080858114156106175760408051808201909152600f81527f777269746520796f7572206861736800000000000000000000000000000000006020820152945061060e565b60408051600435815290519081900360200190205b60408051918252519081900360200190f35b61008d600435600034600014158061021a575081815260056020526040812060030154610100900460ff16151581145b15610b4e57610002565b61008d600435600054600454603c60ff928316029091160142108061024b57506001543414155b8061026f5750600081815260056020526040812060010154600160a060020a031614155b8061027a5750600081145b15610f5d57610002565b6040805160206004803580820135601f810184900484028501840190955284845261008d94919360249390929184019190819084018382808284375094965050505050505060035433600160a060020a0390811691161461103357610002565b60408051602060046024803582810135601f810185900485028601850190965285855261049a9583359593946044949392909201918190840183828082843750949650505050505050600060006020604051908101604052806000815260200150600060036001870360ff160660ff16600386604051808280519060200190808383829060006004602084601f0104600302600f01f1509050019150506040518091039020600190040460030201905080508560ff166000141561113f5760408051606081018252602d81527f656e746572203120666f7220526f636b2c203220666f722050617065722c203360208201527f20666f722053636973736f72730000000000000000000000000000000000000091810191909152600094508493509150611137565b6101d860015481565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156104755780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6040805160ff929092168252519081900360200190f35b604051808460001916815260200183600019168152602001806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f16801561050e5780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b6000805460ff191683179055600154811461053d576001819055426004555b5050565b820191906000526020600020905b81548152906001019060200180831161054f57829003601f168201915b505050505081565b6040805182815281519081900360209081018220600090815260058083528482206003908101805460ff191660f860020a928906600101830292909204919091179055948352835192839003820190922082529290925290204260029190910155565b60408051808201909152601881527f796f752068617665206c6f73742c2074727920616761696e0000000000000000602082015294505b50505050919050565b600086815260056020526040812060010154600160a060020a0316141561069b5760408051606081018252602b81527f796f752063616e2073656e642074686973206861736820616e6420646f75626c60208201527f6520796f7572204554482100000000000000000000000000000000000000000091810191909152945061060e565b600086815260056020526040812060010154600160a060020a0316148015906106d657506040600090812060030154610100900460ff161515145b156107165760408051808201909152601281527f7468697320626574206973206275726e656400000000000000000000000000006020820152945061060e565b60008681526005602052604081205414801561074757506040600090812060020154905460ff908116603c02160142105b156107875760408051808201909152601581527f7761697420666f72206f7468657220706c6179657200000000000000000000006020820152945061060e565b60008681526005602052604081205414156107ff5760408051606081018252602881527f6e6f206f6e6520706c617965642c20757365207769746864726177282920666f60208201527f7220726566756e6400000000000000000000000000000000000000000000000091810191909152945061060e565b600080548782526005602052604090912060020154603c60ff92831602909116014210806108895750600060009054906101000a900460ff16603c0260ff1660056000506000600560005060008a60001916815260200190815260200160002060005060000160005054600019168152602001908152602001600020600050600201600050540142105b60008781526005602052604081206003015491955090810b810b1480156108ad5750835b156108ed576040805180820190915260208082527f796f752063616e20616e6e6f756e636520796f75722053656372657452616e6490820152945061060e565b600086815260056020526040812060030154810b810b14156109925760408051608081018252605b81527f796f752068617665206661696c656420746f20616e6e6f756e636520796f757260208201527f2053656372657452616e6420627574207374696c6c20796f752063616e207472918101919091527f79206265666f7265206f70706f6e656e742077697468647261777300000000006060820152945061060e565b600086815260056020526040808220548252812060030154810b810b1480156109b85750835b156109f85760408051808201909152601c81527f7761697420666f72206f70706f6e656e742053656372657452616e64000000006020820152945061060e565b505050600083815260056020526040808220805483529082206003908101548684529101548291820b90820b0380820b821415610a385760019150610a58565b8060000b60011480610a4e57508060000b600119145b15610a5857600192505b600086815260056020526040808220548252812060030154810b810b1480610a7d5750825b15610ae55760408051606081018252602b81527f796f75206861766520776f6e21206e6f7720796f752063616e2077697468647260208201527f617720796f75722045544800000000000000000000000000000000000000000091810191909152945061060e565b81156105d75760408051606081018252602681527f447261772068617070656e6421207769746864726177206261636b20796f757260208201527f2066756e6473000000000000000000000000000000000000000000000000000091810191909152945061060e565b60008281526005602052604081205414801590610b7e57506040600081812054815290812060030154810b810b14155b8015610b9e5750600082815260056020526040812060030154810b810b14155b15610c7c57506000818152600560205260408082208054835290822060039081015484845291015490820b90820b039081810b1415610cff576000600560005060008460001916815260200190815260200160002060005060030160016101000a81548160ff02191690830217905550600560005060008360001916815260200190815260200160002060005060010160009054906101000a9004600160a060020a0316600160a060020a03166000606460016000505460630204604051809050600060405180830381858888f193505050501515610d8357610002565b600082815260056020526040812054148015610cad57506040600090812060020154905460ff908116603c02160142115b15610dfe5760008281526005602052604080822060038101805461ff001916905560019081015490549151600160a060020a039190911692919082818181858883f193505050501515610f4e57610002565b8060000b60011480610d1557508060000b600119145b15610dbe576000828152600560205260408082206003818101805461ff00199081169091558254855283852090910180549091169055848352905160018054920154600160a060020a03169291606460c6909102049082818181858883f193505050501515610dc357610002565b604051600354600154600160a060020a039190911691600091606490049082818181858883f193505050501515610db957610002565b61053d565b610002565b604051600354600154600160a060020a0391909116916000916064600291909102049082818181858883f193505050501515610db957610002565b60008281526005602052604081205414801590610e2d57506040600081812054815290812060030154810b810b145b8015610e4d5750600082815260056020526040812060030154810b810b14155b15610dbe57600080548382526005602052604090912060020154603c60ff928316029091160142118015610d155750600060009054906101000a900460ff16603c0260ff16600560005060006005600050600086600019168152602001908152602001600020600050600001600050546000191681526020019081526020016000206000506002016000505401421115610dbe576000828152600560205260408082206003818101805461ff0019908116909155825485528385209091018054909116905584835290516001918201549154600160a060020a03929092169291606460c6909102049082818181858883f193505050501515610dc357610002565b6006805460001901905561053d565b60008181526005602052604090206001818101805473ffffffffffffffffffffffffffffffffffffffff191633179055600391909101805461ff00191661010017905560065460029006141561100c57600760005054600560005060008360001916815260200190815260200160002060005060000160005081905550806005600050600060076000505460001916815260200190815260200160002060005060000160005081905550611012565b60078190555b60009081526005602052604090204260029190910155600680546001019055565b8060026000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061109a57805160ff19168380011785555b506110ca9291505b808211156110cf5760008155600101611086565b8280016001018555821561107e579182015b8281111561107e5782518260005055916020019190600101906110ac565b505050565b5090565b60408051606081018252603e81527f736f6d656f6e65206861766520616c726561647920757365642074686973207260208201527f616e646f6d20737472696e67202d2074727920616e6f74686572206f6e650000918101919091525b9350935093505b509250925092565b60408051828152815190819003602090810182208483528351928390038201909220600090815260059091529182206001015490918391600160a060020a031614156110d357600383066000146111d4576003830660011461120e5760408051808201909152600881527f53636973736f72730000000000000000000000000000000000000000000000006020820152611243565b60408051808201909152600481527f526f636b0000000000000000000000000000000000000000000000000000000060208201525b611130565b60408051808201909152600581527f506170657200000000000000000000000000000000000000000000000000000060208201525b61120956
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.