Guest User

Untitled

a guest
Mar 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. function endCoinFlip(bytes32 _stack, bytes32 _counterStack, bytes32 _reveal)
  2. public
  3. returns (bool) {
  4. require(stacks[_stack].owner==msg.sender);
  5. require(stackCounter[_counterStack]==_stack);
  6. require(counterOfStack[_stack]==_counterStack);
  7. require(mode[_stack]==2);
  8. require(uint32(block.number)>commitBlock[_stack]);
  9.  
  10. if(keccak256(_reveal)!=commit[_stack]){
  11. mode[_stack]=1;
  12. CoinFlipFail(_stack);
  13. return false;
  14. }else{
  15. mode[_stack]=3;
  16. round[_stack]=1;
  17. bytes32 pseudoRandomHash = keccak256(_reveal,block.blockhash(commitBlock[_stack]));
  18. if(uint256(pseudoRandomHash)%2==0){
  19. lastBlock[_stack]=uint32(block.number);
  20. lastActor[_stack]=stacks[_counterStack].owner;
  21. CoinFlipSuccess(_stack,stacks[_stack].owner,true);
  22. }else{
  23. lastBlock[_stack]=uint32(block.number);
  24. lastActor[_stack]=stacks[_stack].owner;
  25. CoinFlipSuccess(_stack,stacks[_counterStack].owner,false);
  26. }
  27. return true;
  28. }
  29. }
  30.  
  31. event CoinFlipSuccess(bytes32 indexed stack,address whosTurn,bool heads);
  32. event CoinFlipFail(bytes32 stack);
Add Comment
Please, Sign In to add comment