diff --git a/MyAdvancedToken.sol b/MyAdvancedToken.sol index f8af15d..bea9d20 100644 --- a/MyAdvancedToken.sol +++ b/MyAdvancedToken.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.16; +pragma solidity ^0.4.20; import "./owned.sol"; @@ -19,7 +19,7 @@ contract MyAdvancedToken is owned, TokenERC20 { event FrozenFunds(address target, bool frozen); /* Initializes contract with initial supply tokens to the creator of the contract */ - function MyAdvancedToken( + constructor ( uint256 initialSupply, string tokenName, string tokenSymbol @@ -34,7 +34,7 @@ contract MyAdvancedToken is owned, TokenERC20 { require(!frozenAccount[_to]); // Check if recipient is frozen balanceOf[_from] -= _value; // Subtract from the sender balanceOf[_to] += _value; // Add the same to the recipient - Transfer(_from, _to, _value); + emit Transfer(_from, _to, _value); } /// @notice Create `mintedAmount` tokens and send it to `target` @@ -43,8 +43,8 @@ contract MyAdvancedToken is owned, TokenERC20 { function mintToken(address target, uint256 mintedAmount) onlyOwner public { balanceOf[target] += mintedAmount; totalSupply += mintedAmount; - Transfer(0, this, mintedAmount); - Transfer(this, target, mintedAmount); + emit Transfer(0, this, mintedAmount); + emit Transfer(this, target, mintedAmount); } /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens @@ -52,7 +52,7 @@ contract MyAdvancedToken is owned, TokenERC20 { /// @param freeze either to freeze it or not function freezeAccount(address target, bool freeze) onlyOwner public { frozenAccount[target] = freeze; - FrozenFunds(target, freeze); + emit FrozenFunds(target, freeze); } /// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth diff --git a/TokenERC20.sol b/TokenERC20.sol index 1d57c12..e5f698d 100644 --- a/TokenERC20.sol +++ b/TokenERC20.sol @@ -1,6 +1,6 @@ -pragma solidity ^0.4.16; +pragma solidity ^0.4.20; -interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; } +interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; } contract TokenERC20 { string public name; @@ -22,7 +22,7 @@ contract TokenERC20 { /** * 初始化构造 */ - function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { + constructor(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // 供应的份额,份额跟最小的代币单位有关,份额 = 币数 * 10 ** decimals。 balanceOf[msg.sender] = totalSupply; // 创建者拥有所有的代币 name = tokenName; // 代币名称 @@ -46,7 +46,7 @@ contract TokenERC20 { balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; - Transfer(_from, _to, _value); + emit Transfer(_from, _to, _value); // 用assert来检查代码逻辑。 assert(balanceOf[_from] + balanceOf[_to] == previousBalances); @@ -114,7 +114,7 @@ contract TokenERC20 { require(balanceOf[msg.sender] >= _value); // Check if the sender has enough balanceOf[msg.sender] -= _value; // Subtract from the sender totalSupply -= _value; // Updates totalSupply - Burn(msg.sender, _value); + emit Burn(msg.sender, _value); return true; } @@ -132,7 +132,7 @@ contract TokenERC20 { balanceOf[_from] -= _value; // Subtract from the targeted balance allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance totalSupply -= _value; // Update totalSupply - Burn(_from, _value); + emit Burn(_from, _value); return true; } } diff --git a/owned.sol b/owned.sol index 3f270bf..6976a3b 100644 --- a/owned.sol +++ b/owned.sol @@ -3,7 +3,7 @@ pragma solidity ^0.4.16; contract owned { address public owner; - function owned() public { + constructor() public { owner = msg.sender; }