alexscheitlin / lottery-dapp

MIT License
3 stars 3 forks source link

[SC] Refund Caller of EndGame Method #4

Closed alexscheitlin closed 5 years ago

alexscheitlin commented 5 years ago

There needs to be an external account (not a SC) initiating a method call. This caller pays the consumed amount of gas and should be refunded when calling the endGame method.

access consumed amount of gas before the gas is refunded estimate gas usage for remaining statement executions

simibac commented 5 years ago

This might be really difficult to achieve since we cannot exactly calculate the cost of the endGame function (as described here).

One possible solution is to deduct a fixed amount from the jackpot (let's say 0.1 eth). The caller of endGame can in a later step claim the transaction costs from these 0.1 eth and the rest of that amount would go in the next jackpot. However, another problem is that solidity cannot access the blockchain data and thus, it cannot retrieve the actual amount which the caller has spent. This could be estimated with the gasleft function.

Or have you found a better solution? Or should we just ignore it? We could also just reward the caller of the endGame function with 0.1 ether. Then people are incentivized to draw the lottery and start a new one.

alexscheitlin commented 5 years ago

I see. I like the idea of "just" paying back 0.1 eth before paying out the winners. We should make sure, that if there were no tickets purchased, that the 0.1 eth won't be refunded (because there is no eth if the previous jackpot was fully payed out). We should also deduct this amount from the getJackpot method.