Created
September 6, 2019 00:47
-
-
Save bertolo1988/f9385d04349e6b3a5f803306d462d8e1 to your computer and use it in GitHub Desktop.
Callback called by Provable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function __callback( bytes32 _queryId, string memory _result, bytes memory _proof ) public { | |
require(msg.sender == provable_cbAddress()); | |
require(ongoingBets[_queryId].sender != address(0x0) , 'query does not exist'); | |
if(provable_randomDS_proofVerify__returnCode( _queryId, _result, _proof) != 0){ | |
revert(); | |
} else { | |
uint ceiling = (MAX_INT_FROM_BYTE ** NUM_RANDOM_BYTES_REQUESTED) - 1; | |
uint randomNumber = uint(keccak256(abi.encodePacked(_result))) % ceiling; | |
uint spin = (randomNumber % 100) + 1; | |
Bet memory bet = ongoingBets[_queryId]; | |
if(spin < bet.spinUnder){ | |
addAmountToUser(bet.sender, bet.prize); | |
} | |
emit logBetSuccess(bet.sender, spin, bet.spinUnder, bet.stake, bet.prize, bet.payout, balances[bet.sender]); | |
delete ongoingBets[_queryId]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment