aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-01-31 23:05:27 +0800
committerGitHub <noreply@github.com>2017-01-31 23:05:27 +0800
commitf9af2de0b4ad0399344f5e3b80d6d977fdb4f308 (patch)
tree764a685d8817e1c56ac34877db9d79fe82f7c309
parent547501c02ec5c2ce70caca38d797f5d3d864732a (diff)
parent318fbb2604c69dc6eef438aad37b12b99586b198 (diff)
downloaddexon-solidity-f9af2de0b4ad0399344f5e3b80d6d977fdb4f308.tar.gz
dexon-solidity-f9af2de0b4ad0399344f5e3b80d6d977fdb4f308.tar.zst
dexon-solidity-f9af2de0b4ad0399344f5e3b80d6d977fdb4f308.zip
Merge pull request #1594 from ethereum/fixStdToken
Make standard token compileable.
-rwxr-xr-xscripts/tests.sh4
-rw-r--r--std/StandardToken.sol44
2 files changed, 34 insertions, 14 deletions
diff --git a/scripts/tests.sh b/scripts/tests.sh
index cf18cb26..f2142946 100755
--- a/scripts/tests.sh
+++ b/scripts/tests.sh
@@ -33,6 +33,10 @@ REPO_ROOT="$(dirname "$0")"/..
echo "Running commandline tests..."
"$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
# install for `eth` at the time of writing, so we unzip the ZIP file locally
# instead. This will go away soon.
diff --git a/std/StandardToken.sol b/std/StandardToken.sol
index 4ff1b8f9..4dad8541 100644
--- a/std/StandardToken.sol
+++ b/std/StandardToken.sol
@@ -3,31 +3,43 @@ 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;
- Transfer(msg.sender, _to, _value);
+ return doTransfer(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;
} else {
return false;
}
}
- 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;
+ function doTransfer(address _from, address _to, uint _value) internal returns (bool success) {
+ if (balance[_from] >= _value && balance[_to] + _value >= balance[_to]) {
+ balance[_from] -= _value;
+ balance[_to] += _value;
Transfer(_from, _to, _value);
return true;
} else {
@@ -36,8 +48,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];
+ }
}