-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample14.sol
More file actions
32 lines (26 loc) · 859 Bytes
/
example14.sol
File metadata and controls
32 lines (26 loc) · 859 Bytes
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
pragma solidity ^0.4.18;
// pragma solidity >=0.4.21 <0.7.0;
contract Reentrance {
event Test(address addr, uint value, uint amount);
// using SafeMath for uint256;
mapping(address => uint) public balances;
function donate(address _to) public payable {
// balances[_to] = balances[_to].add(msg.value);
balances[_to] = balances[_to] + msg.value;
}
function balanceOf(address _who) public view returns (uint balance) {
return balances[_who];
}
function withdraw(uint _amount) public {
emit Test(msg.sender, balances[msg.sender], _amount);
if(balances[msg.sender] >= _amount) {
if(msg.sender.call.value(_amount)()) {
_amount;
} else {
revert("COULD NOT SEND VALUE!");
}
balances[msg.sender] -= _amount;
}
}
function() public payable {}
}