I want to switch function according to "result" value.
Here is my solidity code.
function rockPaperScissors(uint _userHand) public affordPay() payable { uint randHand = random(); uint result = rpsResult(_userHand, randHand); address toAccount = 0x*************************; if (result == 1) { // LOSE toAccount.transfer(msg.value / 2); msg.sender.transfer(msg.value / 2); } else if (result == 2) { // WIN toAccount.transfer(msg.value); } else { // DRAW msg.sender.transfer(msg.value); } return result; }
In fact, I want to send half amount of msg.value in case "result" is 1, send full amount of msg.value in case "result" is 2, and send nothing in case other "result".
Additionaly, I want to send back remaining eth to msg.sender.
I use msg.sender.transfer(msg.value);
when send back, but I read the docs, which says revert() will not consume any gas.
Is this means it is suitable to use revert()
when you want to send back all eth you send to the contract ?
I'm a newbie in solidity develpment, so if there are any other good solutions, please teach me.
Thanks in advance!