-
Notifications
You must be signed in to change notification settings - Fork 389
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
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; | ||
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; | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think payable should be added here: |
||
|
||
emit EndSale(tokensSold); | ||
} | ||
} |
There was a problem hiding this comment.
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."