Created
September 6, 2019 00:40
-
-
Save bertolo1988/bc16d1b30bb056d53bf895fa492cffa1 to your computer and use it in GitHub Desktop.
The bet function using ProvableAPI 0.5.
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 bet(uint stake, uint spinUnder)external notOwner returns (uint spinUnderInput, uint stakeInput, uint prize, uint payout, uint previousBalance){ | |
require(stake >= minBet && maxBet >= stake , 'stake is outside allowed limits'); | |
require(spinUnder >= MIN_ROLL_UNDER && spinUnder <= MAX_ROLL_UNDER, 'spinUnder must be between or equal to 11 and 91'); | |
require(balances[msg.sender] >= stake, 'insufficient balance to cover stake'); | |
(payout, prize) = getPrizeAndPayout(stake, spinUnder); | |
require(balances[owner] >= (prize.sub(stake)), 'insufficient contract balance to cover the prize'); | |
previousBalance = balances[msg.sender]; | |
subtractAmountFromUser(stake); | |
uint QUERY_EXECUTION_DELAY = 0; | |
uint GAS_FOR_CALLBACK = 200000; | |
bytes32 queryId = provable_newRandomDSQuery( | |
QUERY_EXECUTION_DELAY, | |
NUM_RANDOM_BYTES_REQUESTED, | |
GAS_FOR_CALLBACK | |
); | |
ongoingBets[queryId] = Bet(spinUnder, stake, prize, payout, msg.sender); | |
emit logBetStarted(msg.sender, spinUnder, stake, prize, payout, previousBalance); | |
return (spinUnder, stake, prize, payout, previousBalance); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment