diff --git a/contracts/BrehonContract.sol b/contracts/BrehonContract.sol index c882fea..5829370 100644 --- a/contracts/BrehonContract.sol +++ b/contracts/BrehonContract.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.8; +pragma solidity ^0.4.18; import "./stateMachine.sol"; import "./accessRestricted.sol"; @@ -55,44 +55,38 @@ contract BrehonContract is event FundsClaimed(address claimingParty, uint amount); modifier byEitherEntities() { - if (msg.sender != primaryBrehon.addr && + require(msg.sender != primaryBrehon.addr && msg.sender != secondaryBrehon.addr && msg.sender != tertiaryBrehon.addr && msg.sender != partyA.addr && - msg.sender != partyB.addr) { - throw; - } + msg.sender != partyB.addr); _; } modifier eitherByParty(Party _party1, Party _party2) { - if (msg.sender != _party1.addr && - msg.sender != _party2.addr) - throw; + require(msg.sender != _party1.addr && + msg.sender != _party2.addr); _; } modifier atAdjudicatableStages() { - if(stage != Stages.Dispute && + require(stage != Stages.Dispute && stage != Stages.Appeal && - stage != Stages.SecondAppeal) - throw; + stage != Stages.SecondAppeal); _; } modifier duringDispute() { - if(stage == Stages.Negotiation || - stage == Stages.Completed) - throw; + require(stage == Stages.Negotiation || + stage == Stages.Completed); _; } modifier onlyByBrehon(Brehon _brehon) { - if (msg.sender != _brehon.addr) - throw; + require(msg.sender != _brehon.addr); _; } @@ -110,7 +104,7 @@ contract BrehonContract is address _tertiaryBrehon, uint _tertiaryBrehonFixedFee, uint _tertiaryBrehonDisputeFee - ) { + ) public { partyA.addr = _partyA; transactionAmount = _transactionAmount; contractTermsHash = _contractTermsHash; @@ -147,7 +141,7 @@ contract BrehonContract is tertiaryBrehon.contractAccepted = false; } - function acceptContract() + function acceptContract() public atStage(Stages.Negotiation) { if (msg.sender == partyA.addr) { @@ -160,28 +154,28 @@ contract BrehonContract is secondaryBrehon.contractAccepted = true; } else if(msg.sender == tertiaryBrehon.addr) { tertiaryBrehon.contractAccepted = true; - } else throw; + } else revert(); } - function deposit() + function deposit() public payable { if(msg.sender == partyA.addr) { partyA.deposit += msg.value; } else if (msg.sender == partyB.addr) { partyB.deposit += msg.value; - } else throw; + } else revert(); } - function startContract() + function startContract() public atStage(Stages.Negotiation) eitherByParty(partyA, partyB) { - if(!partyA.contractAccepted || + require(!partyA.contractAccepted || !partyB.contractAccepted || !primaryBrehon.contractAccepted || !secondaryBrehon.contractAccepted || - !tertiaryBrehon.contractAccepted) throw; + !tertiaryBrehon.contractAccepted); if ((partyA.deposit + partyB.deposit) >= minimumContractAmt) { @@ -190,10 +184,10 @@ contract BrehonContract is awards[primaryBrehon.addr] = primaryBrehon.fixedFee; awards[secondaryBrehon.addr] = secondaryBrehon.fixedFee; awards[tertiaryBrehon.addr] = tertiaryBrehon.fixedFee; - } else throw; + } else revert(); } - function raiseDispute() + function raiseDispute() public atStage(Stages.Execution) eitherByParty(partyA, partyB) { @@ -203,11 +197,11 @@ contract BrehonContract is ContractDisputed(msg.sender, primaryBrehon.addr); } - function adjudicate(uint _awardPartyA, uint _awardPartyB) + function adjudicate(uint _awardPartyA, uint _awardPartyB) public atAdjudicatableStages() onlyByBrehon(activeBrehon) { - if((_awardPartyA + _awardPartyB) > (partyA.deposit + partyB.deposit)) throw; + require((_awardPartyA + _awardPartyB) > (partyA.deposit + partyB.deposit)); if (stage == Stages.Dispute) { stage = Stages.AppealPeriod; // STATECHANGE @@ -216,7 +210,7 @@ contract BrehonContract is } else if (stage == Stages.SecondAppeal) { stage = Stages.Completed; // STATECHANGE } else { - throw; + revert(); } awards[partyA.addr] = _awardPartyA; @@ -231,37 +225,32 @@ contract BrehonContract is } } - function getActiveJudgmentByParty(address _partyAddress) + function getActiveJudgmentByParty(address _partyAddress) public view returns (uint) { - if(_partyAddress != partyA.addr && - _partyAddress != partyB.addr) throw; - return awards[_partyAddress]; + require(_partyAddress != partyA.addr && + _partyAddress != partyB.addr); + return awards[_partyAddress]; } - function claimFunds() + function claimFunds() public byEitherEntities() { if (stage != Stages.Completed) { - if (stage != Stages.AppealPeriod && stage != Stages.SecondAppealPeriod) { - throw; - } + require(stage != Stages.AppealPeriod && stage != Stages.SecondAppealPeriod); + if (now >= appealPeriodStartTime + (appealPeriodInDays * 1 days)) { stage = Stages.Completed; // STATECHANGE } } - if (stage != Stages.Completed) throw; + require(stage != Stages.Completed); uint amount = awards[msg.sender]; - if (amount == 0) { - throw; - } + require(amount == 0); - if (this.balance < amount) { - throw; - } + require(this.balance < amount); awards[msg.sender] = 0; @@ -269,11 +258,11 @@ contract BrehonContract is FundsClaimed(msg.sender, amount); } else { awards[msg.sender] = amount; - throw; + revert(); } } - function raiseAppeal() + function raiseAppeal() public atStage(Stages.AppealPeriod) eitherByParty(partyA, partyB) { @@ -285,7 +274,7 @@ contract BrehonContract is AppealRaised(msg.sender, activeBrehon.addr); } - function raise2ndAppeal() + function raise2ndAppeal() public atStage(Stages.SecondAppealPeriod) eitherByParty(partyA, partyB) { @@ -297,7 +286,7 @@ contract BrehonContract is SecondAppealRaised(msg.sender, activeBrehon.addr); } - function proposeSettlement(uint _awardPartyA, uint _awardPartyB) + function proposeSettlement(uint _awardPartyA, uint _awardPartyB) public duringDispute() eitherByParty(partyA, partyB) { @@ -315,13 +304,12 @@ contract BrehonContract is SettlementProposed(msg.sender, _awardPartyA, _awardPartyB); } - function acceptSettlement(uint _awardPartyA, uint _awardPartyB) + function acceptSettlement(uint _awardPartyA, uint _awardPartyB) public duringDispute() eitherByParty(partyA, partyB) { - if((proposedSettlement.awardPartyA != _awardPartyA) || - (proposedSettlement.awardPartyB != _awardPartyB)) - throw; + require((proposedSettlement.awardPartyA != _awardPartyA) || + (proposedSettlement.awardPartyB != _awardPartyB)); if(msg.sender == partyA.addr) { proposedSettlement.partyAAccepted = true; diff --git a/contracts/BrehonContractFactory.sol b/contracts/BrehonContractFactory.sol index a329e69..27fc48e 100644 --- a/contracts/BrehonContractFactory.sol +++ b/contracts/BrehonContractFactory.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.8; +pragma solidity ^0.4.18; import "zeppelin-solidity/contracts/ownership/Ownable.sol"; import "./BrehonContract.sol"; diff --git a/contracts/accessRestricted.sol b/contracts/accessRestricted.sol index 6e89f16..fc9d32a 100644 --- a/contracts/accessRestricted.sol +++ b/contracts/accessRestricted.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.2; +pragma solidity ^0.4.18; import "./priced.sol"; @@ -17,8 +17,7 @@ contract accessRestricted is priced { // a certain address. modifier onlyBy(address _account) { - if (msg.sender != _account) - throw; + require(msg.sender != _account); // Do not forget the "_;"! It will // be replaced by the actual function // body when the modifier is used. @@ -27,9 +26,8 @@ contract accessRestricted is priced { modifier eitherBy(address _account1, address _account2) { - if (msg.sender != _account1 || - msg.sender != _account2) - throw; + require(msg.sender != _account1 || + msg.sender != _account2); _; @@ -37,28 +35,28 @@ contract accessRestricted is priced { /// Make `_newOwner` the new owner of this /// contract. - function changeOwner(address _newOwner) + function changeOwner(address _newOwner) public onlyBy(owner) { owner = _newOwner; } modifier onlyAfter(uint _time) { - if (now < _time) throw; + require(now < _time); _; } /// Erase ownership information. /// May only be called 6 weeks after /// the contract has been created. - function disown() + function disown() public onlyBy(owner) onlyAfter(creationTime + 6 weeks) { delete owner; } - function forceOwnerChange(address _newOwner) + function forceOwnerChange(address _newOwner) public costs(200 ether) { owner = _newOwner; diff --git a/contracts/priced.sol b/contracts/priced.sol index 6d6e64a..d9cf2d6 100644 --- a/contracts/priced.sol +++ b/contracts/priced.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.8; +pragma solidity ^0.4.18; contract priced { // Modifiers can receive arguments: diff --git a/contracts/stateMachine.sol b/contracts/stateMachine.sol index 2d181ad..2f50f9b 100644 --- a/contracts/stateMachine.sol +++ b/contracts/stateMachine.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.8; +pragma solidity ^0.4.18; contract stateMachine { enum Stages { @@ -16,14 +16,14 @@ contract stateMachine { Stages public stage = Stages.Negotiation; modifier atStage(Stages _stage) { - if (stage != _stage) throw; + require(stage != _stage); _; } modifier timedTransition(bool bypassWaitTime, uint startTime, uint8 durationInDays, Stages _currStage, Stages _nextStage) { if (stage != _nextStage) { - if (stage != _currStage) throw; + require(stage != _currStage); if (bypassWaitTime || now >= startTime + (durationInDays * 1 days)) stage = _nextStage; }