Skip to content

Commit 2d0c67a

Browse files
committed
Update DAO to use revert() and not throw
1 parent c0d5ee7 commit 2d0c67a

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

test/DAO/DAO.sol

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
353353

354354
// Modifier that allows only shareholders to vote and create new proposals
355355
modifier onlyTokenholders {
356-
if (balanceOf(msg.sender) == 0) throw;
356+
if (balanceOf(msg.sender) == 0) revert();
357357
_;
358358
}
359359

@@ -381,9 +381,9 @@ contract DAO is DAOInterface, Token, TokenCreation {
381381
rewardAccount = new ManagedAccount(address(this), false);
382382
DAOrewardAccount = new ManagedAccount(address(this), false);
383383
if (address(rewardAccount) == 0)
384-
throw;
384+
revert();
385385
if (address(DAOrewardAccount) == 0)
386-
throw;
386+
revert();
387387
lastTimeMinQuorumMet = now;
388388
minQuorumDivisor = 5; // sets the minimal quorum to 20%
389389
proposals.length = 1; // avoids a proposal with ID 0 because it is used
@@ -421,30 +421,30 @@ contract DAO is DAOInterface, Token, TokenCreation {
421421
|| _recipient == curator
422422
|| msg.value > 0
423423
|| _debatingPeriod < minSplitDebatePeriod)) {
424-
throw;
424+
revert();
425425
} else if (
426426
!_newCurator
427427
&& (!isRecipientAllowed(_recipient) || (_debatingPeriod < minProposalDebatePeriod))
428428
) {
429-
throw;
429+
revert();
430430
}
431431

432432
if (_debatingPeriod > 8 weeks)
433-
throw;
433+
revert();
434434

435435
if (!isFueled
436436
|| now < closingTime
437437
|| (msg.value < proposalDeposit && !_newCurator)) {
438438

439-
throw;
439+
revert();
440440
}
441441

442442
if (now + _debatingPeriod < now) // prevents overflow
443-
throw;
443+
revert();
444444

445445
// to prevent a 51% attacker to convert the ether into deposit
446446
if (msg.sender == address(this))
447-
throw;
447+
revert();
448448

449449
// to prevent curator from halving quorum before first proposal
450450
if (proposals.length == 1) // initial length is 1 (see constructor)
@@ -498,7 +498,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
498498
|| p.votedNo[msg.sender]
499499
|| now >= p.votingDeadline) {
500500

501-
throw;
501+
revert();
502502
}
503503

504504
if (_supportsProposal) {
@@ -545,7 +545,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
545545
// Does the transaction code match the proposal?
546546
|| p.proposalHash != sha3(p.recipient, p.amount, _transactionData)) {
547547

548-
throw;
548+
revert();
549549
}
550550

551551
// If the curator removed the recipient from the whitelist, close the proposal
@@ -574,7 +574,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
574574

575575
if (quorum >= minQuorum(p.amount)) {
576576
if (!p.creator.send(p.proposalDeposit))
577-
throw;
577+
revert();
578578

579579
lastTimeMinQuorumMet = now;
580580
// set the minQuorum to 20% again, in the case it has been reached
@@ -591,7 +591,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
591591
p.proposalPassed = true;
592592

593593
if (!p.recipient.call.value(p.amount)(_transactionData))
594-
throw;
594+
revert();
595595

596596
_success = true;
597597

@@ -642,7 +642,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
642642
// Did you already vote on another proposal?
643643
|| (blocked[msg.sender] != _proposalID && blocked[msg.sender] != 0) ) {
644644

645-
throw;
645+
revert();
646646
}
647647

648648
// If the new DAO doesn't exist yet, create the new DAO and store the
@@ -651,10 +651,10 @@ contract DAO is DAOInterface, Token, TokenCreation {
651651
p.splitData[0].newDAO = createNewDAO(_newCurator);
652652
// Call depth limit reached, etc.
653653
if (address(p.splitData[0].newDAO) == 0)
654-
throw;
654+
revert();
655655
// should never happen
656656
if (this.balance < sumOfProposalDeposits)
657-
throw;
657+
revert();
658658
p.splitData[0].splitBalance = actualBalance();
659659
p.splitData[0].rewardToken = rewardToken[address(this)];
660660
p.splitData[0].totalSupply = totalSupply;
@@ -666,7 +666,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
666666
(balances[msg.sender] * p.splitData[0].splitBalance) /
667667
p.splitData[0].totalSupply;
668668
if (p.splitData[0].newDAO.createTokenProxy.value(fundsToBeMoved)(msg.sender) == false)
669-
throw;
669+
revert();
670670

671671

672672
// Assign reward rights to new DAO
@@ -679,12 +679,12 @@ contract DAO is DAOInterface, Token, TokenCreation {
679679

680680
rewardToken[address(p.splitData[0].newDAO)] += rewardTokenToBeMoved;
681681
if (rewardToken[address(this)] < rewardTokenToBeMoved)
682-
throw;
682+
revert();
683683
rewardToken[address(this)] -= rewardTokenToBeMoved;
684684

685685
DAOpaidOut[address(p.splitData[0].newDAO)] += paidOutToBeMoved;
686686
if (DAOpaidOut[address(this)] < paidOutToBeMoved)
687-
throw;
687+
revert();
688688
DAOpaidOut[address(this)] -= paidOutToBeMoved;
689689

690690
// Burn DAO Tokens
@@ -700,7 +700,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
700700
if (msg.sender != address(this) || !allowedRecipients[_newContract]) return;
701701
// move all ether
702702
if (!_newContract.call.value(address(this).balance)()) {
703-
throw;
703+
revert();
704704
}
705705

706706
//move all reward tokens
@@ -716,7 +716,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
716716

717717
if ((rewardToken[msg.sender] * DAOrewardAccount.accumulatedInput()) /
718718
totalRewardToken < DAOpaidOut[msg.sender])
719-
throw;
719+
revert();
720720

721721
uint reward =
722722
(rewardToken[msg.sender] * DAOrewardAccount.accumulatedInput()) /
@@ -726,11 +726,11 @@ contract DAO is DAOInterface, Token, TokenCreation {
726726

727727
if(_toMembers) {
728728
if (!DAOrewardAccount.payOut(dao.rewardAccount(), reward))
729-
throw;
729+
revert();
730730
}
731731
else {
732732
if (!DAOrewardAccount.payOut(dao, reward))
733-
throw;
733+
revert();
734734
}
735735
DAOpaidOut[msg.sender] += reward;
736736
return true;
@@ -743,15 +743,15 @@ contract DAO is DAOInterface, Token, TokenCreation {
743743

744744
function withdrawRewardFor(address _account) noEther internal returns (bool _success) {
745745
if ((balanceOf(_account) * rewardAccount.accumulatedInput()) / totalSupply < paidOut[_account])
746-
throw;
746+
revert();
747747

748748
uint reward =
749749
(balanceOf(_account) * rewardAccount.accumulatedInput()) / totalSupply - paidOut[_account];
750750

751751
reward = rewardAccount.balance < reward ? rewardAccount.balance : reward;
752752

753753
if (!rewardAccount.payOut(_account, reward))
754-
throw;
754+
revert();
755755
paidOut[_account] += reward;
756756
return true;
757757
}
@@ -767,14 +767,14 @@ contract DAO is DAOInterface, Token, TokenCreation {
767767

768768
return true;
769769
} else {
770-
throw;
770+
revert();
771771
}
772772
}
773773

774774

775775
function transferWithoutReward(address _to, uint256 _value) returns (bool success) {
776776
if (!getMyReward())
777-
throw;
777+
revert();
778778
return transfer(_to, _value);
779779
}
780780

@@ -789,7 +789,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
789789

790790
return true;
791791
} else {
792-
throw;
792+
revert();
793793
}
794794
}
795795

@@ -801,7 +801,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
801801
) returns (bool success) {
802802

803803
if (!withdrawRewardFor(_from))
804-
throw;
804+
revert();
805805
return transferFrom(_from, _to, _value);
806806
}
807807

@@ -814,7 +814,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
814814

815815
uint transferPaidOut = paidOut[_from] * _value / balanceOf(_from);
816816
if (transferPaidOut > paidOut[_from])
817-
throw;
817+
revert();
818818
paidOut[_from] -= transferPaidOut;
819819
paidOut[_to] += transferPaidOut;
820820
return true;
@@ -825,15 +825,15 @@ contract DAO is DAOInterface, Token, TokenCreation {
825825
if (msg.sender != address(this) || _proposalDeposit > (actualBalance() + rewardToken[address(this)])
826826
/ maxDepositDivisor) {
827827

828-
throw;
828+
revert();
829829
}
830830
proposalDeposit = _proposalDeposit;
831831
}
832832

833833

834834
function changeAllowedRecipients(address _recipient, bool _allowed) noEther external returns (bool _success) {
835835
if (msg.sender != curator)
836-
throw;
836+
revert();
837837
allowedRecipients[_recipient] = _allowed;
838838
AllowedRecipientChanged(_recipient, _allowed);
839839
return true;

test/DAO/ManagedAccount.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ contract ManagedAccount is ManagedAccountInterface{
5656

5757
function payOut(address _recipient, uint _amount) returns (bool) {
5858
if (msg.sender != owner || msg.value > 0 || (payOwnerOnly && _recipient != owner))
59-
throw;
59+
revert();
6060
if (_recipient.call.value(_amount)()) {
6161
PayOut(_recipient, _amount);
6262
return true;

test/DAO/Token.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ contract tokenRecipient {
9292
contract Token is TokenInterface {
9393
// Protects users by preventing the execution of method calls that
9494
// inadvertently also transferred ether
95-
modifier noEther() {if (msg.value > 0) throw; _; }
95+
modifier noEther() {if (msg.value > 0) revert(); _; }
9696

9797
function balanceOf(address _owner) constant returns (uint256 balance) {
9898
return balances[_owner];

test/DAO/TokenCreation.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ contract TokenCreation is TokenCreationInterface, Token {
116116
}
117117
return true;
118118
}
119-
throw;
119+
revert();
120120
}
121121

122122
function refund() noEther {

0 commit comments

Comments
 (0)