forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ESToken.sol
77 lines (62 loc) · 2.08 KB
/
ESToken.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pragma solidity ^0.4.18;
import '../storage/EternalStorage.sol';
import '../math/SafeMath.sol';
/**
* @title Eternal Storage token
* @dev version of Basic Token using Eternal Storage
*/
contract ESToken {
using SafeMath for uint256;
EternalStorage public s;
function ESToken() {
s = new EternalStorage();
s.setAddress(keccak256('owner'), msg.sender);
}
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
uint256 senderBalance = s.getUint(keccak256('balance', msg.sender));
require(_value <= senderBalance);
uint256 receiverBalance = s.getUint(keccak256('balance', _to));
s.setUint(keccak256('balance', msg.sender), senderBalance.sub(_value));
s.setUint(keccak256('balance', _to), receiverBalance.add(_value));
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev mint tokens, only calleed by the owner
* @param _to The address to receive the tokens.
* @param _value The amount to be minted.
*/
function mint(address _to, uint256 _value) {
address _owner = s.getAddress(keccak256('owner'));
require(_owner == msg.sender);
s.setUint(keccak256('balance', _to), _value);
s.setUint(keccak256('totalSupply'), _value);
}
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return s.getUint(keccak256('totalSupply'));
}
/**
* @dev owner address
*/
function owner() public view returns (address) {
return s.getAddress(keccak256('owner'));
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return s.getUint(keccak256('balance', _owner));
}
}