Commit ecd6c57f by Nicolás Venturo

Added internal check methods.

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