Hey @Laurenzius,
Congratulations for your first project.
As you correctly said, you can clean up your code now
Some consideration about the code and how to keep it cleaner:
uint constant GAMBLING_FEE = 50000000000000000;
modifier mincosts(uint cost){
require(msg.value >= cost, "Not enough Ether!");
_;
}
function flip(bool betOnHeads) public payable mincosts(GAMBLING_FEE){
require(GAMBLING_FEE<msg.value,'REQUIRE: flip(): must be more than the gambling fee, which is 0.01 ether');
You have redundant verifications here.
require(GAMBLING_FEE<msg.value
is the same as require(msg.value >= cost, "Not enough Ether!");
As you are sending GAMBLING_FEE
as param to the modifier.
Also consider that GAMBLING_FEE
is global in your contract therefore you do not need to pass it as parameter to the modifier.
uint constant GAMBLING_FEE = 50000000000000000;
modifier mincosts(){
require(msg.value >= GAMBLING_FEE, "Not enough Ether!");
_;
}
function flip(bool betOnHeads) public payable mincosts (){
......
}
This should be enough.
Also your function flip
calls startDraw
where you check require(msg.value >= _bet, "REQUIRED: startDraw(): msg.value >= _bet,");
Because you already verified msg.value
are you sure that require is useful?
There are other things you can improve, feel free to ask me if you need help!
Again congrats for your 1st dapp!
Happy coding,
Dani