aboutsummaryrefslogtreecommitdiffstats
path: root/std/StandardToken.sol
blob: f59e04ac78a6e5591fbb6306383b46047d737303 (plain) (blame)
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
pragma solidity ^0.4.0;

import "./Token.sol";

contract StandardToken is Token {
    uint256 supply;
    mapping (address => uint256) balance;
    mapping (address =>
        mapping (address => uint256)) m_allowance;

    function StandardToken(address _initialOwner, uint256 _supply) {
        supply = _supply;
        balance[_initialOwner] = _supply;
    }

    function balanceOf(address _account) constant returns (uint) {
        return balance[_account];
    }

    function totalSupply() constant returns (uint) {
        return supply;
    }

    function transfer(address _to, uint256 _value) returns (bool success) {
        if (balance[msg.sender] >= _value && balance[_to] + _value >= balance[_to]) {
            balance[msg.sender] -= _value;
            balance[_to] += _value;
            Transfer(msg.sender, _to, _value);
            return true;
        } else {
            return false;
        }
    }

    function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
        if (m_allowance[_from][msg.sender] >= _value && balance[_to] + _value >= balance[_to]) {
            m_allowance[_from][msg.sender] -= _value;
            balance[_to] += _value;
            Transfer(_from, _to, _value);
            return true;
        } else {
            return false;
        }
    }

    function approve(address _spender, uint256 _value) returns (bool success) {
        m_allowance[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);
        return true;
    }

    function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
        return m_allowance[_owner][_spender];
    }
}