Last updated
Last updated
Remember, we built an endpoint that allow players to make a bet, but it's result should be computed in another transaction.
We said earlier that the bounty endpoint, not built yet, will compute all waiting bets results in a row. We'll write the bounty endpoint in the next part of this tutorial, now we'll focus on writing the function to generate result for a single bet.
Here is the function's signature, again inside the FlipContract
class :
The key point is the private
keyword. makeFlip
is NOT an endpoint but an internal function we'll use in the future bounty endpoint.
bountyAddress
is the address of the bounty caller endpoint. It is needed to send the incentive.
Making a function private
ensure no one will be able to call it, forget it is a big security issue.
Here is the full function :
Nothing special in this function.
RandomnessSource
is a class containing statics methods allowing you to generate random numbers. Remember that these numbers are predictables knowing current block random seed and transaction infos (sender, hash, ...).
The contract is almost finished, last thing we need to do is the bounty endpoint.
Flips are initialised, time to make them