Merge pull request #49 from federicobond/ownable-stoppable
Make Stoppable a subclass of Ownable
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
pragma solidity ^0.4.0;
|
pragma solidity ^0.4.0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ownable
|
* Ownable
|
||||||
* Base contract with an owner
|
* Base contract with an owner
|
||||||
|
|||||||
@ -1,28 +1,22 @@
|
|||||||
pragma solidity ^0.4.0;
|
pragma solidity ^0.4.0;
|
||||||
|
|
||||||
|
import "./Ownable.sol";
|
||||||
/*
|
/*
|
||||||
* Stoppable
|
* Stoppable
|
||||||
* Abstract contract that allows children to implement an
|
* Abstract contract that allows children to implement an
|
||||||
* emergency stop mechanism.
|
* emergency stop mechanism.
|
||||||
*/
|
*/
|
||||||
contract Stoppable {
|
contract Stoppable is Ownable {
|
||||||
address public curator;
|
|
||||||
bool public stopped;
|
bool public stopped;
|
||||||
|
|
||||||
modifier stopInEmergency { if (!stopped) _; }
|
modifier stopInEmergency { if (!stopped) _; }
|
||||||
modifier onlyInEmergency { if (stopped) _; }
|
modifier onlyInEmergency { if (stopped) _; }
|
||||||
|
|
||||||
function Stoppable(address _curator) {
|
function emergencyStop() external onlyOwner {
|
||||||
if (_curator == 0) throw;
|
|
||||||
curator = _curator;
|
|
||||||
}
|
|
||||||
|
|
||||||
function emergencyStop() external {
|
|
||||||
if (msg.sender != curator) throw;
|
|
||||||
stopped = true;
|
stopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function release() external onlyInEmergency {
|
function release() external onlyOwner onlyInEmergency {
|
||||||
if (msg.sender != curator) throw;
|
|
||||||
stopped = false;
|
stopped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,10 +7,6 @@ contract StoppableBid is Stoppable, PullPayment {
|
|||||||
address public highestBidder;
|
address public highestBidder;
|
||||||
uint public highestBid;
|
uint public highestBid;
|
||||||
|
|
||||||
function StoppableBid(address _curator)
|
|
||||||
Stoppable(_curator)
|
|
||||||
PullPayment() {}
|
|
||||||
|
|
||||||
function bid() external stopInEmergency {
|
function bid() external stopInEmergency {
|
||||||
if (msg.value <= highestBid) throw;
|
if (msg.value <= highestBid) throw;
|
||||||
|
|
||||||
@ -22,7 +18,7 @@ contract StoppableBid is Stoppable, PullPayment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function withdraw() onlyInEmergency {
|
function withdraw() onlyInEmergency {
|
||||||
suicide(curator);
|
suicide(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,11 +2,11 @@ pragma solidity ^0.4.0;
|
|||||||
import '../Stoppable.sol';
|
import '../Stoppable.sol';
|
||||||
|
|
||||||
// mock class using Stoppable
|
// mock class using Stoppable
|
||||||
contract StoppableMock is Stoppable(msg.sender) {
|
contract StoppableMock is Stoppable {
|
||||||
bool public drasticMeasureTaken;
|
bool public drasticMeasureTaken;
|
||||||
uint public count;
|
uint public count;
|
||||||
|
|
||||||
function StoppableMock() Stoppable(msg.sender){
|
function StoppableMock() {
|
||||||
drasticMeasureTaken = false;
|
drasticMeasureTaken = false;
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ contract('Stoppable', function(accounts) {
|
|||||||
|
|
||||||
it("can perform normal process in non-emergency", function(done) {
|
it("can perform normal process in non-emergency", function(done) {
|
||||||
var stoppable;
|
var stoppable;
|
||||||
return StoppableMock.new(accounts[0])
|
return StoppableMock.new()
|
||||||
.then(function(_stoppable) {
|
.then(function(_stoppable) {
|
||||||
stoppable = _stoppable;
|
stoppable = _stoppable;
|
||||||
return stoppable.count();
|
return stoppable.count();
|
||||||
@ -24,7 +24,7 @@ contract('Stoppable', function(accounts) {
|
|||||||
|
|
||||||
it("can not perform normal process in emergency", function(done) {
|
it("can not perform normal process in emergency", function(done) {
|
||||||
var stoppable;
|
var stoppable;
|
||||||
return StoppableMock.new(accounts[0])
|
return StoppableMock.new()
|
||||||
.then(function(_stoppable) {
|
.then(function(_stoppable) {
|
||||||
stoppable = _stoppable;
|
stoppable = _stoppable;
|
||||||
return stoppable.emergencyStop();
|
return stoppable.emergencyStop();
|
||||||
@ -50,7 +50,7 @@ contract('Stoppable', function(accounts) {
|
|||||||
|
|
||||||
it("can not take drastic measure in non-emergency", function(done) {
|
it("can not take drastic measure in non-emergency", function(done) {
|
||||||
var stoppable;
|
var stoppable;
|
||||||
return StoppableMock.new(accounts[0])
|
return StoppableMock.new()
|
||||||
.then(function(_stoppable) {
|
.then(function(_stoppable) {
|
||||||
stoppable = _stoppable;
|
stoppable = _stoppable;
|
||||||
return stoppable.drasticMeasure();
|
return stoppable.drasticMeasure();
|
||||||
@ -66,7 +66,7 @@ contract('Stoppable', function(accounts) {
|
|||||||
|
|
||||||
it("can take a drastic measure in an emergency", function(done) {
|
it("can take a drastic measure in an emergency", function(done) {
|
||||||
var stoppable;
|
var stoppable;
|
||||||
return StoppableMock.new(accounts[0])
|
return StoppableMock.new()
|
||||||
.then(function(_stoppable) {
|
.then(function(_stoppable) {
|
||||||
stoppable = _stoppable;
|
stoppable = _stoppable;
|
||||||
return stoppable.emergencyStop();
|
return stoppable.emergencyStop();
|
||||||
@ -85,7 +85,7 @@ contract('Stoppable', function(accounts) {
|
|||||||
|
|
||||||
it("should resume allowing normal process after emergency is over", function(done) {
|
it("should resume allowing normal process after emergency is over", function(done) {
|
||||||
var stoppable;
|
var stoppable;
|
||||||
return StoppableMock.new(accounts[0])
|
return StoppableMock.new()
|
||||||
.then(function(_stoppable) {
|
.then(function(_stoppable) {
|
||||||
stoppable = _stoppable;
|
stoppable = _stoppable;
|
||||||
return stoppable.emergencyStop();
|
return stoppable.emergencyStop();
|
||||||
|
|||||||
Reference in New Issue
Block a user