Unverified Commit beea818f by Francisco Giordano Committed by GitHub

Merge pull request #638 from LimelabsTech/master

BuyTokens getting the token amount from a function instead of just multiplication. Useful for making Crowdsales with bonus periods
parents 94697726 13b75bd5
...@@ -59,12 +59,16 @@ contract Crowdsale { ...@@ -59,12 +59,16 @@ contract Crowdsale {
return new MintableToken(); return new MintableToken();
} }
// fallback function can be used to buy tokens // fallback function can be used to buy tokens
function () external payable { function () external payable {
buyTokens(msg.sender); buyTokens(msg.sender);
} }
// Override this method to have a way to add business logic to your crowdsale when buying
function getTokenAmount(uint256 weiAmount) internal view returns(uint256) {
return weiAmount.mul(rate);
}
// low level token purchase function // low level token purchase function
function buyTokens(address beneficiary) public payable { function buyTokens(address beneficiary) public payable {
require(beneficiary != address(0)); require(beneficiary != address(0));
...@@ -73,7 +77,7 @@ contract Crowdsale { ...@@ -73,7 +77,7 @@ contract Crowdsale {
uint256 weiAmount = msg.value; uint256 weiAmount = msg.value;
// calculate token amount to be created // calculate token amount to be created
uint256 tokens = weiAmount.mul(rate); uint256 tokens = getTokenAmount(weiAmount);
// update state // update state
weiRaised = weiRaised.add(weiAmount); weiRaised = weiRaised.add(weiAmount);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment