Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to solidity 0.5.0 #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2,233 changes: 1,242 additions & 991 deletions build/contracts/DappToken.json

Large diffs are not rendered by default.

2,319 changes: 1,442 additions & 877 deletions build/contracts/DappTokenSale.json

Large diffs are not rendered by default.

2,674 changes: 1,272 additions & 1,402 deletions build/contracts/Migrations.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions contracts/DappToken.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pragma solidity ^0.4.2;
pragma solidity ^0.5.0;

contract DappToken {
string public name = "DApp Token";
string public symbol = "DAPP";
string public standard = "DApp Token v1.0";
uint256 public totalSupply;
uint256 public totalSupply = 75000;

event Transfer(
address indexed _from,
Expand All @@ -21,40 +21,40 @@ contract DappToken {
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;

function DappToken (uint256 _initialSupply) public {
constructor (uint256 _initialSupply) public {
balanceOf[msg.sender] = _initialSupply;
totalSupply = _initialSupply;
}

function transfer(address _to, uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value);
require(balanceOf[msg.sender] >= _value, "Insufficient sender balance");

balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;

Transfer(msg.sender, _to, _value);
emit Transfer(msg.sender, _to, _value);

return true;
}

function approve(address _spender, uint256 _value) public returns (bool success) {
allowance[msg.sender][_spender] = _value;

Approval(msg.sender, _spender, _value);
emit Approval(msg.sender, _spender, _value);

return true;
}

function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= balanceOf[_from]);
require(_value <= allowance[_from][msg.sender]);
require(_value <= balanceOf[_from], 'Amount should not exceed balance');
require(_value <= allowance[_from][msg.sender], 'Amount should not exceed allowance');

balanceOf[_from] -= _value;
balanceOf[_to] += _value;

allowance[_from][msg.sender] -= _value;

Transfer(_from, _to, _value);
emit Transfer(_from, _to, _value);

return true;
}
Expand Down
22 changes: 13 additions & 9 deletions contracts/DappTokenSale.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
pragma solidity ^0.4.2;
pragma solidity ^0.5.0;

import "./DappToken.sol";

contract DappTokenSale {
address admin;
address payable admin;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add payable here, then in constructor for admin = msg.send I get this error:
"Type address is not implicitly convertible to expected type address payable."

DappToken public tokenContract;
uint256 public tokenPrice;
uint256 public tokensSold;

event Sell(address _buyer, uint256 _amount);
event EndSale(uint256 _totalAmountSold);

function DappTokenSale(DappToken _tokenContract, uint256 _tokenPrice) public {
constructor(DappToken _tokenContract, uint256 _tokenPrice) public {
admin = msg.sender;
tokenContract = _tokenContract;
tokenPrice = _tokenPrice;
Expand All @@ -21,21 +22,24 @@ contract DappTokenSale {
}

function buyTokens(uint256 _numberOfTokens) public payable {
require(msg.value == multiply(_numberOfTokens, tokenPrice));
require(tokenContract.balanceOf(this) >= _numberOfTokens);
require(tokenContract.transfer(msg.sender, _numberOfTokens));
require(msg.value == multiply(_numberOfTokens, tokenPrice), 'msg.value must equal number of tokens in wei');
require(tokenContract.balanceOf(address(this)) >= _numberOfTokens, 'cannot purchase more tokens than available');
require(tokenContract.transfer(msg.sender, _numberOfTokens), 'Unable to send tokens');
// emit Balance(address(this), _numberOfTokens);

tokensSold += _numberOfTokens;

Sell(msg.sender, _numberOfTokens);
emit Sell(msg.sender, _numberOfTokens);
}

function endSale() public {
require(msg.sender == admin);
require(tokenContract.transfer(admin, tokenContract.balanceOf(this)));

require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));
// require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));
// UPDATE: Let's not destroy the contract here
// Just transfer the balance to the admin
admin.transfer(address(this).balance);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think payable should be added here:
payable(admin).transfer(address(this).balance);


emit EndSale(tokensSold);
}
}
4 changes: 2 additions & 2 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.17;
pragma solidity ^0.5.0;

contract Migrations {
address public owner;
Expand All @@ -8,7 +8,7 @@ contract Migrations {
if (msg.sender == owner) _;
}

function Migrations() public {
constructor() public {
owner = msg.sender;
}

Expand Down
Loading