I want to use rewardsAmount variable to calculate my rewards:
uint rewardsAmount = 0; // Only here i can withdraw rewards function withdrawRewards() onlyOwner external { require(rewardsAmount != 0); owner.transfer(rewardsAmount); rewardsAmount = 0; } // If the contract doesn't have users funds, then i can destroy it function kill() onlyOwner external { require(address(this).balance - rewardsAmount == 0); selfdestruct(owner); } function someFunction() public { // some code rewardsAmount += 100; }
If someone sends to the contract address some ether, I can never kill the contract, right? So how can I prevent ether from being sent to my contract?