mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1594 from ethereum/fixStdToken
Make standard token compileable.
This commit is contained in:
commit
f9af2de0b4
@ -33,6 +33,10 @@ REPO_ROOT="$(dirname "$0")"/..
|
|||||||
echo "Running commandline tests..."
|
echo "Running commandline tests..."
|
||||||
"$REPO_ROOT/test/cmdlineTests.sh"
|
"$REPO_ROOT/test/cmdlineTests.sh"
|
||||||
|
|
||||||
|
echo "Checking that StandardToken.sol, owned.sol and mortal.sol produce bytecode..."
|
||||||
|
output=$("$REPO_ROOT"/build/solc/solc --bin "$REPO_ROOT"/std/*.sol 2>/dev/null | grep "ffff" | wc -l)
|
||||||
|
test "$output" = "3"
|
||||||
|
|
||||||
# This conditional is only needed because we don't have a working Homebrew
|
# This conditional is only needed because we don't have a working Homebrew
|
||||||
# install for `eth` at the time of writing, so we unzip the ZIP file locally
|
# install for `eth` at the time of writing, so we unzip the ZIP file locally
|
||||||
# instead. This will go away soon.
|
# instead. This will go away soon.
|
||||||
|
@ -3,31 +3,43 @@ pragma solidity ^0.4.0;
|
|||||||
import "./Token.sol";
|
import "./Token.sol";
|
||||||
|
|
||||||
contract StandardToken is Token {
|
contract StandardToken is Token {
|
||||||
uint256 public totalSupply;
|
uint256 supply;
|
||||||
mapping (address => uint256) public balanceOf;
|
mapping (address => uint256) balance;
|
||||||
mapping (address =>
|
mapping (address =>
|
||||||
mapping (address => uint256)) public allowance;
|
mapping (address => uint256)) m_allowance;
|
||||||
|
|
||||||
function StandardToken(address _initialOwner, uint256 _supply) {
|
function StandardToken(address _initialOwner, uint256 _supply) {
|
||||||
totalSupply = _supply;
|
supply = _supply;
|
||||||
balanceOf[_initialOwner] = _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) {
|
function transfer(address _to, uint256 _value) returns (bool success) {
|
||||||
if (balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) {
|
return doTransfer(msg.sender, _to, _value);
|
||||||
balanceOf[msg.sender] -= _value;
|
}
|
||||||
balanceOf[_to] += _value;
|
|
||||||
Transfer(msg.sender, _to, _value);
|
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
||||||
|
if (m_allowance[_from][msg.sender] >= _value) {
|
||||||
|
if (doTransfer(_from, _to, _value)) {
|
||||||
|
m_allowance[_from][msg.sender] -= _value;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
function doTransfer(address _from, address _to, uint _value) internal returns (bool success) {
|
||||||
if (allowance[_from][msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) {
|
if (balance[_from] >= _value && balance[_to] + _value >= balance[_to]) {
|
||||||
allowance[_from][msg.sender] -= _value;
|
balance[_from] -= _value;
|
||||||
balanceOf[_to] += _value;
|
balance[_to] += _value;
|
||||||
Transfer(_from, _to, _value);
|
Transfer(_from, _to, _value);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -36,8 +48,12 @@ contract StandardToken is Token {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function approve(address _spender, uint256 _value) returns (bool success) {
|
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);
|
Approval(msg.sender, _spender, _value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
|
||||||
|
return m_allowance[_owner][_spender];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user