Skip to content

Commit

Permalink
Make token constructible.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Jan 20, 2017
1 parent 61a15bb commit c6207e2
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions std/StandardToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ pragma solidity ^0.4.0;
import "./Token.sol";

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

function StandardToken(address _initialOwner, uint256 _supply) {
totalSupply = _supply;
balanceOf[_initialOwner] = _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 (balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) {
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
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 {
Expand All @@ -25,9 +33,9 @@ contract StandardToken is Token {
}

function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (allowance[_from][msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) {
allowance[_from][msg.sender] -= _value;
balanceOf[_to] += _value;
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 {
Expand All @@ -36,8 +44,12 @@ contract StandardToken is Token {
}

function approve(address _spender, uint256 _value) returns (bool success) {
allowance[msg.sender][_spender] = _value;
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];
}
}

0 comments on commit c6207e2

Please sign in to comment.