Commit 18581f13 by Peter Murray Committed by Francisco Giordano

converted if() throw convention to require()/assert()/revert()

parent f3867f84
......@@ -19,9 +19,7 @@ contract Bounty is PullPayment, Destructible {
* @dev Fallback function allowing the contract to recieve funds, if they haven't already been claimed.
*/
function() payable {
if (claimed) {
throw;
}
require(!claimed);
}
/**
......@@ -48,13 +46,9 @@ contract Bounty is PullPayment, Destructible {
*/
function claim(Target target) {
address researcher = researchers[target];
if (researcher == 0) {
throw;
}
require(researcher != 0);
// Check Target contract invariants
if (target.checkInvariant()) {
throw;
}
require(!target.checkInvariant());
asyncSend(researcher, this.balance);
claimed = true;
}
......
......@@ -67,9 +67,7 @@ contract DayLimit {
* @dev Simple modifier for daily limit.
*/
modifier limitedDaily(uint256 _value) {
if (!underLimit(_value)) {
throw;
}
require(underLimit(_value));
_;
}
}
......@@ -23,9 +23,7 @@ contract LimitBalance {
* @dev Checks if limit was reached. Case true, it throws.
*/
modifier limitedPayable() {
if (this.balance > limit) {
throw;
}
require(this.balance <= limit);
_;
}
......
......@@ -61,7 +61,7 @@ contract MultisigWallet is Multisig, Shareable, DayLimit {
SingleTransact(msg.sender, _value, _to, _data);
// yes - just execute the call.
if (!_to.call.value(_value)(_data)) {
throw;
revert();
}
return 0;
}
......@@ -82,9 +82,7 @@ contract MultisigWallet is Multisig, Shareable, DayLimit {
*/
function confirm(bytes32 _h) onlymanyowners(_h) returns (bool) {
if (txs[_h].to != 0) {
if (!txs[_h].to.call.value(txs[_h].value)(txs[_h].data)) {
throw;
}
assert(txs[_h].to.call.value(txs[_h].value)(txs[_h].data));
MultiTransact(msg.sender, _h, txs[_h].value, txs[_h].to, txs[_h].data);
delete txs[_h];
return true;
......
......@@ -22,13 +22,10 @@ contract ReentrancyGuard {
* wrapper marked as `nonReentrant`.
*/
modifier nonReentrant() {
if(rentrancy_lock == false) {
require(!rentrancy_lock);
rentrancy_lock = true;
_;
rentrancy_lock = false;
} else {
throw;
}
}
}
......@@ -19,7 +19,7 @@ contract Pausable is Ownable {
* @dev modifier to allow actions only when the contract IS paused
*/
modifier whenNotPaused() {
if (paused) throw;
require(!paused);
_;
}
......@@ -27,7 +27,7 @@ contract Pausable is Ownable {
* @dev modifier to allow actions only when the contract IS NOT paused
*/
modifier whenPaused {
if (!paused) throw;
require(paused);
_;
}
......
......@@ -16,9 +16,7 @@ contract Claimable is Ownable {
* @dev Modifier throws if called by any account other than the pendingOwner.
*/
modifier onlyPendingOwner() {
if (msg.sender != pendingOwner) {
throw;
}
require(msg.sender == pendingOwner);
_;
}
......
......@@ -21,8 +21,7 @@ contract DelayedClaimable is Claimable {
* @param _end The latest time ownership can be claimed.
*/
function setLimits(uint256 _start, uint256 _end) onlyOwner {
if (_start > _end)
throw;
require(_start <= _end);
end = _end;
start = _start;
}
......@@ -33,8 +32,7 @@ contract DelayedClaimable is Claimable {
* the specified start and end time.
*/
function claimOwnership() onlyPendingOwner {
if ((block.number > end) || (block.number < start))
throw;
require((block.number <= end) && (block.number >= start));
owner = pendingOwner;
pendingOwner = 0x0;
end = 0;
......
......@@ -22,9 +22,7 @@ contract HasNoEther is Ownable {
* we could use assembly to access msg.value.
*/
function HasNoEther() payable {
if(msg.value > 0) {
throw;
}
require(msg.value == 0);
}
/**
......@@ -37,8 +35,6 @@ contract HasNoEther is Ownable {
* @dev Transfer all Ether held by the contract to the owner.
*/
function reclaimEther() external onlyOwner {
if(!owner.send(this.balance)) {
throw;
}
assert(owner.send(this.balance));
}
}
......@@ -19,7 +19,7 @@ contract HasNoTokens is Ownable {
* @param data_ Bytes The data passed from the caller.
*/
function tokenFallback(address from_, uint256 value_, bytes data_) external {
throw;
revert();
}
/**
......
......@@ -23,9 +23,7 @@ contract Ownable {
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
if (msg.sender != owner) {
throw;
}
require(msg.sender == owner);
_;
}
......
......@@ -36,9 +36,7 @@ contract Shareable {
// simple single-sig function modifier.
modifier onlyOwner {
if (!isOwner(msg.sender)) {
throw;
}
require(isOwner(msg.sender));
_;
}
......@@ -67,9 +65,7 @@ contract Shareable {
ownerIndex[_owners[i]] = 2 + i;
}
required = _required;
if (required > owners.length) {
throw;
}
require(required <= owners.length);
}
/**
......@@ -138,9 +134,7 @@ contract Shareable {
// determine what index the present sender is:
uint256 index = ownerIndex[msg.sender];
// make sure they're an owner
if (index == 0) {
throw;
}
require(index != 0);
var pending = pendings[_operation];
// if we're not yet working on this operation, switch over and reset the confirmation status.
......
......@@ -32,19 +32,12 @@ contract PullPayment {
address payee = msg.sender;
uint256 payment = payments[payee];
if (payment == 0) {
throw;
}
if (this.balance < payment) {
throw;
}
require(payment != 0);
require(this.balance >= payment);
totalPayments = totalPayments.sub(payment);
payments[payee] = 0;
if (!payee.send(payment)) {
throw;
}
assert(payee.send(payment));
}
}
......@@ -23,7 +23,7 @@ contract LimitedTransferToken is ERC20 {
* @dev Checks whether it can transfer or otherwise throws.
*/
modifier canTransfer(address _sender, uint256 _value) {
if (_value > transferableTokens(_sender, uint64(now))) throw;
require(_value <= transferableTokens(_sender, uint64(now)));
_;
}
......
......@@ -21,7 +21,7 @@ contract MintableToken is StandardToken, Ownable {
modifier canMint() {
if(mintingFinished) throw;
require(!mintingFinished);
_;
}
......
......@@ -27,7 +27,7 @@ contract StandardToken is ERC20, BasicToken {
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// if (_value > _allowance) throw;
// require (_value <= _allowance);
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
......@@ -47,7 +47,7 @@ contract StandardToken is ERC20, BasicToken {
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw;
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
......
......@@ -45,11 +45,9 @@ contract VestedToken is StandardToken, LimitedTransferToken {
) public {
// Check for date inconsistencies that may cause unexpected behavior
if (_cliff < _start || _vesting < _cliff) {
throw;
}
require(_cliff >= _start && _vesting >= _cliff);
if (tokenGrantsCount(_to) > MAX_GRANTS_PER_ADDRESS) throw; // To prevent a user being spammed and have his balance locked (out of gas attack when calculating vesting).
require(tokenGrantsCount(_to) <= MAX_GRANTS_PER_ADDRESS); // To prevent a user being spammed and have his balance locked (out of gas attack when calculating vesting).
uint256 count = grants[_to].push(
TokenGrant(
......@@ -76,13 +74,8 @@ contract VestedToken is StandardToken, LimitedTransferToken {
function revokeTokenGrant(address _holder, uint256 _grantId) public {
TokenGrant grant = grants[_holder][_grantId];
if (!grant.revokable) { // Check if grant was revokable
throw;
}
if (grant.granter != msg.sender) { // Only granter can revoke it
throw;
}
require(grant.revokable);
require(grant.granter == msg.sender); // Only granter can revoke it
address receiver = grant.burnsOnRevoke ? 0xdead : msg.sender;
......
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