I am making a lottery contract and using Oraclize to select a winning number.
Here is what I have now:
The owner calls a finalize() function, which disallows new entries, and makes a call to Oraclize (using WolframAlpha as data source). The oracle then calls my __callback function with the result, and my contract uses that to find the winner(s), distribute the winnings, and reset the contract to accept entries again. This operation involves loops, and takes steps proportional to the number of entries. Since the number of entries is not limited, I believe this operation's gas usage is not bounded.
I have thought about these options:
- Estimating the gas usage somehow, and specifying that in the oraclize call.
- Removing logic from the callback function, and only using it to set the winning number. The owner then has to call a distribute function to do the calculation-heavy steps.
I find both options problematic. It seems to me that oraclize callback functions were intended to be kept simple. However, I would like to avoid the owner having to call the contract twice (this second option also raises the problem of a dishonest owner not calling the distribute function when he sees the winning number).
Is there a common pattern for this type of usage? What is the correct way to go about this?
Thank you in advance.