-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample38.sol
More file actions
37 lines (30 loc) · 1004 Bytes
/
Copy pathexample38.sol
File metadata and controls
37 lines (30 loc) · 1004 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
33
34
35
36
37
pragma solidity ^0.4.18;
contract dumbDAO {
event PaymentCalled(address payee, uint amount);
event TokensBought(address buyer, uint amount);
event TokensTransfered(address from, address to, uint amount);
event InsufficientFunds(uint bal, uint amount);
mapping (address => uint) public balances;
function buyTokens(){
balances[msg.sender] += msg.value;
TokensBought(msg.sender, msg.value);
}
function transferTokens(address _to, uint _amount){
if (balances[msg.sender] < _amount)
throw;
balances[_to]=_amount;
balances[msg.sender]-=_amount;
TokensTransfered(msg.sender, _to, _amount);
}
function withdraw(address _recipient) returns (bool) {
if (balances[msg.sender] == 0){
InsufficientFunds(balances[msg.sender],balances[msg.sender]);
throw;
}
PaymentCalled(_recipient, balances[msg.sender]);
if (_recipient.call.value(balances[msg.sender])()) {
balances[msg.sender] = 0;
return true;
}
}
}