github.com/halybang/go-ethereum@v1.0.5-0.20180325041310-3b262bc1367c/contracts/demo/StandardToken.sol (about) 1 /* 2 You should inherit from StandardToken or, for a token like you would want to 3 deploy in something like Mist, see HumanStandardToken.sol. 4 (This implements ONLY the standard functions and NOTHING else. 5 If you deploy this, you won't have anything useful.) 6 7 Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20 8 */ 9 10 pragma solidity ^0.4.11; 11 12 contract ERC20Protocol { 13 /* This is a slight change to the ERC20 base standard. 14 function totalSupply() constant returns (uint supply); 15 is replaced with: 16 uint public totalSupply; 17 This automatically creates a getter function for the totalSupply. 18 This is moved to the base contract since public getter functions are not 19 currently recognised as an implementation of the matching abstract 20 function by the compiler. 21 */ 22 /// total amount of tokens 23 uint public totalSupply; 24 25 /// @param _owner The address from which the balance will be retrieved 26 /// @return The balance 27 function balanceOf(address _owner) public constant returns (uint balance); 28 29 /// @notice send `_value` token to `_to` from `msg.sender` 30 /// @param _to The address of the recipient 31 /// @param _value The amount of token to be transferred 32 /// @return Whether the transfer was successful or not 33 function transfer(address _to, uint _value) public returns (bool success); 34 35 /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` 36 /// @param _from The address of the sender 37 /// @param _to The address of the recipient 38 /// @param _value The amount of token to be transferred 39 /// @return Whether the transfer was successful or not 40 function transferFrom(address _from, address _to, uint _value) public returns (bool success); 41 42 /// @notice send `_value` token to `_to` from `msg.sender` 43 /// @param _to The address of the recipient 44 /// @param _toKey the ota pubkey 45 /// @param _value The amount of token to be transferred 46 /// @return Whether the transfer was successful or not 47 function otatransfer(address _to, bytes _toKey, uint256 _value) public returns (string); 48 49 /// @param _owner The address from which the ota balance will be retrieved 50 /// @return The balance 51 function otabalanceOf(address _owner) public constant returns (uint256 balance); 52 53 /// @notice `msg.sender` approves `_spender` to spend `_value` tokens 54 /// @param _spender The address of the account able to transfer the tokens 55 /// @param _value The amount of tokens to be approved for transfer 56 /// @return Whether the approval was successful or not 57 function approve(address _spender, uint _value) public returns (bool success); 58 59 /// @param _owner The address of the account owning tokens 60 /// @param _spender The address of the account able to transfer the tokens 61 /// @return Amount of remaining tokens allowed to spent 62 function allowance(address _owner, address _spender) public constant returns (uint remaining); 63 64 event Transfer(address indexed _from, address indexed _to, uint _value); 65 event Approval(address indexed _owner, address indexed _spender, uint _value); 66 } 67 68 /** 69 * Math operations with safety checks 70 */ 71 library SafeMath { 72 function mul(uint a, uint b) internal pure returns (uint) { 73 uint c = a * b; 74 assert(a == 0 || c / a == b); 75 return c; 76 } 77 78 function div(uint a, uint b) internal pure returns (uint) { 79 assert(b > 0); 80 uint c = a / b; 81 assert(a == b * c + a % b); 82 return c; 83 } 84 85 function sub(uint a, uint b) internal pure returns (uint) { 86 assert(b <= a); 87 return a - b; 88 } 89 90 function add(uint a, uint b) internal pure returns (uint) { 91 uint c = a + b; 92 assert(c >= a); 93 return c; 94 } 95 96 function max64(uint64 a, uint64 b) internal pure returns (uint64) { 97 return a >= b ? a : b; 98 } 99 100 function min64(uint64 a, uint64 b) internal pure returns (uint64) { 101 return a < b ? a : b; 102 } 103 104 function max256(uint256 a, uint256 b) internal pure returns (uint256) { 105 return a >= b ? a : b; 106 } 107 108 function min256(uint256 a, uint256 b) internal pure returns (uint256) { 109 return a < b ? a : b; 110 } 111 } 112 113 contract StandardToken is ERC20Protocol { 114 115 using SafeMath for uint; 116 string public constant name = "WanToken-Beta"; 117 string public constant symbol = "WTB"; 118 uint public constant decimals = 18; 119 120 function transfer(address _to, uint _value) public returns (bool success) { 121 122 if (balances[msg.sender] >= _value) { 123 balances[msg.sender] -= _value; 124 balances[_to] += _value; 125 Transfer(msg.sender, _to, _value); 126 return true; 127 } else { return false; } 128 } 129 130 function transferFrom(address _from, address _to, uint _value) public returns (bool success) { 131 132 if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value) { 133 balances[_to] += _value; 134 balances[_from] -= _value; 135 allowed[_from][msg.sender] -= _value; 136 Transfer(_from, _to, _value); 137 return true; 138 } else { return false; } 139 } 140 141 function balanceOf(address _owner) public constant returns (uint balance) { 142 return balances[_owner]; 143 } 144 145 function approve(address _spender, uint _value) public returns (bool success) { 146 147 assert((_value == 0) || (allowed[msg.sender][_spender] == 0)); 148 149 allowed[msg.sender][_spender] = _value; 150 Approval(msg.sender, _spender, _value); 151 return true; 152 } 153 154 function allowance(address _owner, address _spender) public constant returns (uint remaining) { 155 return allowed[_owner][_spender]; 156 } 157 158 function () public payable { 159 buyWanCoin(msg.sender); 160 } 161 162 function buyWanCoin(address receipient) public payable returns (bool) { 163 require(receipient != 0x0); 164 require(msg.value >= 0.1 ether); 165 166 balances[receipient] = balances[receipient].add(msg.value*10); 167 168 wanport.transfer(msg.value); 169 170 return true; 171 } 172 173 address public wanport = 0x2CC79FA3B80c5b9b02051fACD02478EA88a78E2c; 174 175 mapping (address => uint) balances; 176 mapping (address => mapping (address => uint)) allowed; 177 178 // privacy balance, bytes for public key 179 mapping (address => uint256) public privacyBalance; 180 mapping (address => bytes) public otaKey; 181 182 //this only for initialize, only for test to mint token to one wan address 183 function initPrivacyAsset(address initialBase, bytes baseKeyBytes, uint256 value) public { 184 privacyBalance[initialBase] = value; 185 otaKey[initialBase] = baseKeyBytes; 186 } 187 188 // return string just for debug 189 function otatransfer(address _to, bytes _toKey, uint256 _value) public returns (string) { 190 if(privacyBalance[msg.sender] < _value) return "sender token too low"; 191 192 privacyBalance[msg.sender] -= _value; 193 privacyBalance[_to] += _value; 194 otaKey[_to] = _toKey; 195 return "success"; 196 } 197 198 function otabalanceOf(address _owner) public view returns (uint256 balance) { 199 return privacyBalance[_owner]; 200 } 201 202 } 203 204 1000000000000000000