Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function endCoinFlip(bytes32 _stack, bytes32 _counterStack, bytes32 _reveal)
- public
- returns (bool) {
- require(stacks[_stack].owner==msg.sender);
- require(stackCounter[_counterStack]==_stack);
- require(counterOfStack[_stack]==_counterStack);
- require(mode[_stack]==2);
- require(uint32(block.number)>commitBlock[_stack]);
- if(keccak256(_reveal)!=commit[_stack]){
- mode[_stack]=1;
- CoinFlipFail(_stack);
- return false;
- }else{
- mode[_stack]=3;
- round[_stack]=1;
- bytes32 pseudoRandomHash = keccak256(_reveal,block.blockhash(commitBlock[_stack]));
- if(uint256(pseudoRandomHash)%2==0){
- lastBlock[_stack]=uint32(block.number);
- lastActor[_stack]=stacks[_counterStack].owner;
- CoinFlipSuccess(_stack,stacks[_stack].owner,true);
- }else{
- lastBlock[_stack]=uint32(block.number);
- lastActor[_stack]=stacks[_stack].owner;
- CoinFlipSuccess(_stack,stacks[_counterStack].owner,false);
- }
- return true;
- }
- }
- event CoinFlipSuccess(bytes32 indexed stack,address whosTurn,bool heads);
- event CoinFlipFail(bytes32 stack);
Add Comment
Please, Sign In to add comment