I'm making a simple lottery game where there are hourly, daily and weekly prizes. My contract has functions to pick winners for each of these game types. Each game types will have different number of entries and I need to generate a random number based on the number of entries to pick the winner.
e.g.
function chooseHourly() public {
address HourlyWinner = pickWinner(hourlyParticipants);
..
}
function chooseDaily() public {
address dailyWinner = pickWinner(dailyParticipants);
...
}
function chooseWeekly() public {
address weeklyWinner = pickWinner(weeklyParticipants);
...
}
function __callback(
bytes32 _queryId,
string memory _result,
bytes memory _proof
)
public
{
require(msg.sender == provable_cbAddress());
if (
provable_randomDS_proofVerify__returnCode(
_queryId,
_result,
_proof
) != 0
) {
revert("Proof verification failed.");
} else {
randomNumber = uint256(keccak256(abi.encodePacked(_result)));
emit generatedRandomNumber(randomNumber);
}
}
function pickWinner(Entry[] memory entries) internal returns(address) {
uint256 QUERY_EXECUTION_DELAY = 0;
uint256 GAS_FOR_CALLBACK = 200000;
provable_newRandomDSQuery(
QUERY_EXECUTION_DELAY,
entries.length,
GAS_FOR_CALLBACK
);
//Need to return a winner somehow. If I pick winner here, it would probably use the previously generated number, not the one just requested.
}
However I would need to wait for the callback function to select the winning address in pickWinner and the callback function has no knowledge of which game it will be. I'm not sure of the best way to structure this. I don't really want to create separate contracts for each game type, but is it possible to have more than one different oracle call per contract or is there another way to go about this?
the callback function has no knowledge of which game it will be
- what exactly prevents you from passing that little piece of information to the callback function?