Skip to content

Commit

Permalink
Update Version match ^0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xilibi2003 committed Jun 18, 2019
1 parent db6e3cb commit 7dc384e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
12 changes: 7 additions & 5 deletions ERC20Interface.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
pragma solidity >=0.4.22 <0.7.0;

contract ERC20Interface {

string public constant name = "Token Name";
string public constant symbol = "SYM";
uint8 public constant decimals = 18; // 18 is the most common number of decimal places
// 0.0000000000000000001 个代币

function totalSupply() public constant returns (uint);
function totalSupply() external view returns (uint);

function balanceOf(address tokenOwner) public constant returns (uint balance);
function balanceOf(address tokenOwner) external view returns (uint balance);

function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function approve(address spender, uint tokens) public returns (bool success);
function allowance(address tokenOwner, address spender) external view returns (uint remaining);
function approve(address spender, uint tokens) external returns (bool success);

function transfer(address to, uint tokens) public returns (bool success);
function transfer(address to, uint tokens) external returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);


Expand Down
18 changes: 9 additions & 9 deletions MyAdvancedToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.20;
pragma solidity >=0.4.22 <0.7.0;


import "./owned.sol";
Expand All @@ -21,13 +21,13 @@ contract MyAdvancedToken is owned, TokenERC20 {
/* Initializes contract with initial supply tokens to the creator of the contract */
constructor (
uint256 initialSupply,
string tokenName,
string tokenSymbol
string memory tokenName,
string memory tokenSymbol
) TokenERC20(initialSupply, tokenName, tokenSymbol) payable public {}

/* Internal transfer, only can be called by this contract */
function _transfer(address _from, address _to, uint _value) internal {
require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
require (_to != address(0x0)); // Prevent transfer to 0x0 address. Use burn() instead
require (balanceOf[_from] >= _value); // Check if the sender has enough
require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
require(!frozenAccount[_from]); // Check if sender is frozen
Expand All @@ -43,8 +43,8 @@ contract MyAdvancedToken is owned, TokenERC20 {
function mintToken(address target, uint256 mintedAmount) onlyOwner public {
balanceOf[target] += mintedAmount;
totalSupply += mintedAmount;
emit Transfer(0, this, mintedAmount);
emit Transfer(this, target, mintedAmount);
emit Transfer(address(0), address(this), mintedAmount);
emit Transfer(address(this), target, mintedAmount);
}

/// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
Expand All @@ -66,14 +66,14 @@ contract MyAdvancedToken is owned, TokenERC20 {
/// @notice Buy tokens from contract by sending ether
function buy() payable public {
uint amount = msg.value / buyPrice; // calculates the amount
_transfer(this, msg.sender, amount); // makes the transfers
_transfer(address(this), msg.sender, amount); // makes the transfers
}

/// @notice Sell `amount` tokens to contract
/// @param amount amount of tokens to be sold
function sell(uint256 amount) public {
require(this.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
_transfer(msg.sender, this, amount); // makes the transfers
require(address(this).balance >= amount * sellPrice); // checks if the contract has enough ether to buy
_transfer(msg.sender, address(this), amount); // makes the transfers
msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks
}
}
12 changes: 6 additions & 6 deletions TokenERC20.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.4.20;
pragma solidity >=0.4.22 <0.7.0;

interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; }
interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes calldata _extraData) external; }

contract TokenERC20 {
string public name;
Expand All @@ -22,7 +22,7 @@ contract TokenERC20 {
/**
* 初始化构造
*/
constructor(uint256 initialSupply, string tokenName, string tokenSymbol) public {
constructor(uint256 initialSupply, string memory tokenName, string memory tokenSymbol) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。
balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币
name = tokenName; // 代币名称
Expand All @@ -34,7 +34,7 @@ contract TokenERC20 {
*/
function _transfer(address _from, address _to, uint _value) internal {
// 确保目标地址不为0x0,因为0x0地址代表销毁
require(_to != 0x0);
require(_to != address(0x0));
// 检查发送者余额
require(balanceOf[_from] >= _value);
// 确保转移为正数个
Expand Down Expand Up @@ -97,12 +97,12 @@ contract TokenERC20 {
* @param _value 最大可花费代币数
* @param _extraData 发送给合约的附加数据
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
function approveAndCall(address _spender, uint256 _value, bytes memory _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
spender.receiveApproval(msg.sender, _value, address(this), _extraData);
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion owned.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.16;
pragma solidity >=0.4.22 <0.7.0;

contract owned {
address public owner;
Expand Down

0 comments on commit 7dc384e

Please sign in to comment.