solidity/test/compilationTests/gnosis/Tokens/EtherToken.sol

48 lines
1.2 KiB
Solidity
Raw Normal View History

2018-10-24 12:52:11 +00:00
pragma solidity >=0.0;
2017-07-12 13:46:33 +00:00
import "../Tokens/StandardToken.sol";
/// @title Token contract - Token exchanging Ether 1:1
/// @author Stefan George - <stefan@gnosis.pm>
contract EtherToken is StandardToken {
using Math for *;
/*
* Events
*/
event Deposit(address indexed sender, uint value);
event Withdrawal(address indexed receiver, uint value);
/*
* Constants
*/
string public constant name = "Ether Token";
string public constant symbol = "ETH";
uint8 public constant decimals = 18;
/*
* Public functions
*/
/// @dev Buys tokens with Ether, exchanging them 1:1
function deposit()
public
payable
{
balances[msg.sender] = balances[msg.sender].add(msg.value);
totalTokens = totalTokens.add(msg.value);
2018-06-27 08:35:38 +00:00
emit Deposit(msg.sender, msg.value);
2017-07-12 13:46:33 +00:00
}
/// @dev Sells tokens in exchange for Ether, exchanging them 1:1
/// @param value Number of tokens to sell
function withdraw(uint value)
public
{
// Balance covers value
balances[msg.sender] = balances[msg.sender].sub(value);
totalTokens = totalTokens.sub(value);
msg.sender.transfer(value);
2018-06-27 08:35:38 +00:00
emit Withdrawal(msg.sender, value);
2017-07-12 13:46:33 +00:00
}
}