forked from miladmostavi/gnosis-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EtherToken.sol
53 lines (48 loc) · 1.39 KB
/
EtherToken.sol
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
pragma solidity ^0.4.0;
import "Tokens/StandardTokenWithOverflowProtection.sol";
/// @title Token contract - Token exchanging Ether 1:1.
/// @author Stefan George - <stefan.george@consensys.net>
contract EtherToken is StandardTokenWithOverflowProtection {
/*
* Constants
*/
// Token meta data
string constant public name = "Ether Token";
string constant public symbol = "ETH";
uint8 constant public decimals = 18;
/*
* Read and write functions
*/
/// @dev Buys tokens with Ether, exchanging them 1:1.
function deposit()
external
payable
{
if ( !safeToAdd(balances[msg.sender], msg.value)
|| !safeToAdd(totalSupply, msg.value))
{
// Overflow operation
throw;
}
balances[msg.sender] += msg.value;
totalSupply += msg.value;
}
/// @dev Sells tokens in exchange for Ether, exchanging them 1:1.
/// @param amount Number of tokens to sell.
function withdraw(uint amount)
external
{
if ( !safeToSubtract(balances[msg.sender], amount)
|| !safeToSubtract(totalSupply, amount))
{
// Overflow operation
throw;
}
balances[msg.sender] -= amount;
totalSupply -= amount;
if (!msg.sender.send(amount)) {
// Sending failed
throw;
}
}
}