forked from miladmostavi/gnosis-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStandardToken.sol
94 lines (86 loc) · 2.92 KB
/
StandardToken.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
pragma solidity ^0.4.0;
import "Tokens/AbstractToken.sol";
/// @title Standard token contract - Standard token interface implementation.
contract StandardToken is Token {
/*
* Data structures
*/
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
/*
* Read and write functions
*/
/// @dev Transfers sender's tokens to a given address. Returns success.
/// @param _to Address of token receiver.
/// @param _value Number of tokens to transfer.
/// @return success Returns success of function call.
function transfer(address _to, uint256 _value)
public
returns (bool success)
{
if (balances[msg.sender] < _value) {
// Balance too low
throw;
}
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success.
/// @param _from Address from where tokens are withdrawn.
/// @param _to Address to where tokens are sent.
/// @param _value Number of tokens to transfer.
/// @return success Returns success of function call.
function transferFrom(address _from, address _to, uint256 _value)
public
returns (bool success)
{
if (balances[_from] < _value || allowed[_from][msg.sender] < _value) {
// Balance or allowance too low
throw;
}
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
}
/// @dev Sets approved amount of tokens for spender. Returns success.
/// @param _spender Address of allowed account.
/// @param _value Number of approved tokens.
/// @return success Returns success of function call.
function approve(address _spender, uint256 _value)
public
returns (bool success)
{
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/*
* Read functions
*/
/// @dev Returns number of allowed tokens for given address.
/// @param _owner Address of token owner.
/// @param _spender Address of token spender.
/// @return remaining Returns remaining allowance for spender.
function allowance(address _owner, address _spender)
constant
public
returns (uint256 remaining)
{
return allowed[_owner][_spender];
}
/// @dev Returns number of tokens owned by given address.
/// @param _owner Address of token owner.
/// @return balance Returns balance of owner.
function balanceOf(address _owner)
constant
public
returns (uint256 balance)
{
return balances[_owner];
}
}