-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample23.sol
More file actions
36 lines (30 loc) · 1.08 KB
/
example23.sol
File metadata and controls
36 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pragma solidity ^0.4.21;
contract MyAugmented {
mapping(address => uint) balances;
mapping(address => bool) winners;
uint gameReward = 50;
modifier registered() {
require(balances[msg.sender] != 0);
_;
}
function withdrawFunds (uint256 _weiToWithdraw) public registered {
require(balances[msg.sender] >= _weiToWithdraw);
(bool success,) = msg.sender.call.value(_weiToWithdraw)("");
require(success);
balances[msg.sender] -= _weiToWithdraw;
}
function safeWithdrawFunds(uint256 amount) public registered {
require(balances[msg.sender] >= amount);
balances[msg.sender] -= amount;
(bool success,) = msg.sender.call.value(amount)("");
require(success);
}
function claimReward() public registered {
bool isWinner = winners[msg.sender];
require(isWinner);
bool hasMoney = balances[msg.sender] > 5;
require(hasMoney);
require(msg.sender.call.value(gameReward)());
winners[msg.sender] = false;
}
}