Open Zeppelins mintable token has the method mint(address _to, uint256 _amount) ... returns (bool)
to create new tokens.
I'd like to introduce a supply limit and am unsure how to validate the input correctly. Should I use require(), throw, or is it preferred to return a boolean as the caller might expect?
What are the consequences of these options?
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
// TODO: validate amount is not too big.
// Validate with require():
// require((totalSupply + _amount) <= SUPPLY_LIMIT);
// Or validate with if:
// if ((totalSupply + _amount) > SUPPLY_LIMIT) return false;
// Or throw?
// if ((totalSupply + _amount) > SUPPLY_LIMIT) throw;
totalSupply = totalSupply.add(_amount);
if (totalSupply == SUPPLY_LIMIT) mintingFinished = true;
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(0x0, _to, _amount);
assert(totalSupply <= SUPPLY_LIMIT);
return true;
}
The calling contract looks like this:
contract Crowdsale {
// ...
function buyTokens(address beneficiary) public payable {
require(beneficiary != 0x0);
require(validPurchase());
// ...
token.mint(beneficiary, tokens); // return value not used
// ...
}
}