Skip to content

Instantly share code, notes, and snippets.

@bertolo1988
Created September 6, 2019 00:40
Show Gist options
  • Save bertolo1988/bc16d1b30bb056d53bf895fa492cffa1 to your computer and use it in GitHub Desktop.
Save bertolo1988/bc16d1b30bb056d53bf895fa492cffa1 to your computer and use it in GitHub Desktop.
The bet function using ProvableAPI 0.5.
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