I have a function which looks more or less like this:
function exchange(uint256 amount, bool specialCase) external returns (uint256) {
let retVal;
if (specialCase) {
register(amount);
retVal = 0;
}
else if (amount > address(this).balance) {
register(amount - address(this).balance);
retVal = address(this).balance;
}
else {
register(0);
retVal = amount;
}
require(authorized(msg.sender));
msg.sender.transfer(retVal);
return retVal;
}
As you can see, in some cases, it will execute msg.sender.transfer(0)
.
Of course, I can avoid this by placing msg.sender.transfer(retVal)
only where retVal > 0
.
But I think that my code looks "cleaner" this way, and I would like to keep it as is.
So I would like to know if there is any gas cost in executing msg.sender.transfer(0)
.
Thank you!!!