Hey @FrankB
I’ve checked your contract.
There seem to be an issue with the function withdrawAll ()
I have deployed your contract HERE.
Please assume the following:
actualContractBalance = 0;
netContractBalance = 0;
transferAmount =0;
1- The user plays the first game and loses (0.5 ether bet).
actualContractBalance = 500000000000000000;
netContractBalance = 500000000000000000;
2- The user plays the second game and wins (0.5 ether bet).
Now your function __callback does the following
if((randomNumber % 2 == 0 && moreOnZero)||(randomNumber % 2 == 1 && !moreOnZero)){
customer[addressOfQueryId[_queryId]].totalGain += 2*lastValue;
netContractBalance -= 2*lastValue;
}
therefore:
actualContractBalance = 1000000000000000000;
netContractBalance = 0;
3- The owner calls the function withdrawAll()
function withdrawAll() public onlyOwner{
transferAmount = netContractBalance;
actualContractBalance -= netContractBalance;
netContractBalance = 0;
msg.sender.transfer(transferAmount);
}
In this case, transferAmount is equal to 0.
WithdrawalAll() does not actually withdraw the funds from the contract.
If you check my link posted above, you will see that I have stuck Balance: 0.992 Ether
while I instead should be able to withdraw all funds from the contract.
Contract balance require()
Consider that the contract should always have a balance in order to pay the user in case of a win. You should make sure that the contract has a balance before allowing the user to play.
Consider what happens if the player does not deposit any ether in your contract and wins the 1st round.
user bets: 0.5 ether
and wins:
contractBalance = 500000000000000000
customer[addressOfCst].totalGain = 1000000000000000000
The contract won’t be able to pay the customer.
Provable API fee
Also notice that the first call to provableApi is free, the other ones have a fee instead (that in your case is paid by the contract).
You are not keeping the fee in consideration. According to ProvableAPI documentation, you can use this function to get the price of the oracle provable_getPrice("random")
Unused param
This parameter is not used:
function __callback (,,bytes memory _proof)
According to provable documentation, you can do the following:
constructor () public {
provable_setProof(proofType_Ledger);
}
Then inside function __callback()
if (
provable_randomDS_proofVerify__returnCode(
_queryId,
_result,
_proof
) != 0
) {
} else { your code..
I have done some tests myself, please try as well. If I misunderstood something or if you need more info I am here to help.
Happy coding,
Dani