Commit ecd6c57f by Nicolás Venturo

Added internal check methods.

parent 6fe9b340
......@@ -141,6 +141,10 @@ contract Crowdsale is Initializable {
// Internal interface (extensible)
// -----------------------------------------
function _hasBeenInitialized() internal view returns (bool) {
return ((_rate > 0) && (_wallet != address(0)) && (_token != address(0)));
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
......
......@@ -26,10 +26,8 @@ contract RefundableCrowdsale is Initializable, FinalizableCrowdsale {
* @param goal Funding goal
*/
function initialize(uint256 goal) public initializer {
// Make sure TimedCrowdsale.initialize (which FinalizableCrowdsale depends on) has been
// called before this initializer is executed
require(openingTime() > 0);
require(closingTime() > 0);
// FinalizableCrowdsale depends on TimedCrowdsale
assert(TimedCrowdsale._hasBeenInitialized());
require(goal > 0);
......
......@@ -22,10 +22,7 @@ contract AllowanceCrowdsale is Initializable, Crowdsale {
* @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale
*/
function initialize(address tokenWallet) public initializer {
// Make sure Crowdsale.initialize has been called before this initializer is executed
assert(rate() > 0);
assert(wallet() != address(0));
assert(token() != address(0));
assert(Crowdsale._hasBeenInitialized());
require(tokenWallet != address(0));
_tokenWallet = tokenWallet;
......
......@@ -23,9 +23,7 @@ contract IncreasingPriceCrowdsale is Initializable, TimedCrowdsale {
* @param finalRate Number of tokens a buyer gets per wei at the end of the crowdsale
*/
function initialize(uint256 initialRate, uint256 finalRate) public initializer {
// Make sure TimedCrowdsale.initialize has been called before this initializer is executed
require(openingTime() > 0);
require(closingTime() > 0);
assert(TimedCrowdsale._hasBeenInitialized());
require(finalRate > 0);
require(initialRate >= finalRate);
......
......@@ -19,10 +19,7 @@ contract CappedCrowdsale is Initializable, Crowdsale {
* @param cap Max amount of wei to be contributed
*/
function initialize(uint256 cap) public initializer {
// Make sure Crowdsale.initialize has been called before this initializer is executed
assert(rate() > 0);
assert(wallet() != address(0));
assert(token() != address(0));
assert(Crowdsale._hasBeenInitialized());
require(cap > 0);
_cap = cap;
......
......@@ -17,10 +17,7 @@ contract IndividuallyCappedCrowdsale is Initializable, Crowdsale, CapperRole {
mapping(address => uint256) private _caps;
function initialize(address sender) public initializer {
// Make sure Crowdsale.initialize has been called before this initializer is executed
assert(rate() > 0);
assert(wallet() != address(0));
assert(token() != address(0));
assert(Crowdsale._hasBeenInitialized());
CapperRole.initialize(sender);
}
......
......@@ -29,10 +29,7 @@ contract TimedCrowdsale is Initializable, Crowdsale {
* @param closingTime Crowdsale closing time
*/
function initialize(uint256 openingTime, uint256 closingTime) public initializer {
// Make sure Crowdsale.initialize has been called before this initializer is executed
assert(rate() > 0);
assert(wallet() != address(0));
assert(token() != address(0));
assert(Crowdsale._hasBeenInitialized());
// solium-disable-next-line security/no-block-members
require(openingTime >= block.timestamp);
......@@ -73,6 +70,10 @@ contract TimedCrowdsale is Initializable, Crowdsale {
return block.timestamp > _closingTime;
}
function _hasBeenInitialized() internal view returns (bool) {
return ((_openingTime > 0) && (_closingTime > 0));
}
/**
* @dev Extend parent behavior requiring to be within contributing period
* @param beneficiary Token purchaser
......
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