-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample10.sol
More file actions
31 lines (24 loc) · 823 Bytes
/
example10.sol
File metadata and controls
31 lines (24 loc) · 823 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
pragma solidity ^0.4.21;
contract Reentrancy {
mapping(address => uint) public balances;
uint private totalSupply;
constructor(uint initialSupply) public payable {
totalSupply = initialSupply;
balances[msg.sender] = initialSupply;
}
function() public payable {}
function transfer(address _to, uint _value) public returns(bool) {
if (balances[msg.sender] < _value) return false;
balances[msg.sender] -= _value;
balances[_to] += _value;
return true;
}
function withdraw() public {
if(msg.sender.call.value(balances[msg.sender])()) {
balances[msg.sender] = 0;
}
}
function getBalance() public constant returns(uint) {
return address(this).balance;
}
}