From 4599fbf2482688eddf3d5c8621c076d2d7e748ae Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Tue, 1 Nov 2016 23:34:57 -0300 Subject: [PATCH] Make Stoppable a subclass of Ownable. Fixes #47 --- contracts/Ownable.sol | 1 + contracts/Stoppable.sol | 16 +++++----------- contracts/examples/StoppableBid.sol | 6 +----- contracts/test-helpers/StoppableMock.sol | 4 ++-- test/Stoppable.js | 10 +++++----- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/contracts/Ownable.sol b/contracts/Ownable.sol index ab8e9583d..8ec50c945 100644 --- a/contracts/Ownable.sol +++ b/contracts/Ownable.sol @@ -1,4 +1,5 @@ pragma solidity ^0.4.0; + /* * Ownable * Base contract with an owner diff --git a/contracts/Stoppable.sol b/contracts/Stoppable.sol index 99ad5ad3b..d008e7b3f 100644 --- a/contracts/Stoppable.sol +++ b/contracts/Stoppable.sol @@ -1,28 +1,22 @@ pragma solidity ^0.4.0; + +import "./Ownable.sol"; /* * Stoppable * Abstract contract that allows children to implement an * emergency stop mechanism. */ -contract Stoppable { - address public curator; +contract Stoppable is Ownable { bool public stopped; modifier stopInEmergency { if (!stopped) _; } modifier onlyInEmergency { if (stopped) _; } - function Stoppable(address _curator) { - if (_curator == 0) throw; - curator = _curator; - } - - function emergencyStop() external { - if (msg.sender != curator) throw; + function emergencyStop() external onlyOwner { stopped = true; } - function release() external onlyInEmergency { - if (msg.sender != curator) throw; + function release() external onlyOwner onlyInEmergency { stopped = false; } diff --git a/contracts/examples/StoppableBid.sol b/contracts/examples/StoppableBid.sol index 364c186f8..08f278e5e 100644 --- a/contracts/examples/StoppableBid.sol +++ b/contracts/examples/StoppableBid.sol @@ -7,10 +7,6 @@ contract StoppableBid is Stoppable, PullPayment { address public highestBidder; uint public highestBid; - function StoppableBid(address _curator) - Stoppable(_curator) - PullPayment() {} - function bid() external stopInEmergency { if (msg.value <= highestBid) throw; @@ -22,7 +18,7 @@ contract StoppableBid is Stoppable, PullPayment { } function withdraw() onlyInEmergency { - suicide(curator); + suicide(owner); } } diff --git a/contracts/test-helpers/StoppableMock.sol b/contracts/test-helpers/StoppableMock.sol index dcb9834f5..e7b1e74a1 100644 --- a/contracts/test-helpers/StoppableMock.sol +++ b/contracts/test-helpers/StoppableMock.sol @@ -2,11 +2,11 @@ pragma solidity ^0.4.0; import '../Stoppable.sol'; // mock class using Stoppable -contract StoppableMock is Stoppable(msg.sender) { +contract StoppableMock is Stoppable { bool public drasticMeasureTaken; uint public count; - function StoppableMock() Stoppable(msg.sender){ + function StoppableMock() { drasticMeasureTaken = false; count = 0; } diff --git a/test/Stoppable.js b/test/Stoppable.js index f4ecc0e34..3fa4f3ad2 100644 --- a/test/Stoppable.js +++ b/test/Stoppable.js @@ -2,7 +2,7 @@ contract('Stoppable', function(accounts) { it("can perform normal process in non-emergency", function(done) { var stoppable; - return StoppableMock.new(accounts[0]) + return StoppableMock.new() .then(function(_stoppable) { stoppable = _stoppable; return stoppable.count(); @@ -24,7 +24,7 @@ contract('Stoppable', function(accounts) { it("can not perform normal process in emergency", function(done) { var stoppable; - return StoppableMock.new(accounts[0]) + return StoppableMock.new() .then(function(_stoppable) { stoppable = _stoppable; return stoppable.emergencyStop(); @@ -50,7 +50,7 @@ contract('Stoppable', function(accounts) { it("can not take drastic measure in non-emergency", function(done) { var stoppable; - return StoppableMock.new(accounts[0]) + return StoppableMock.new() .then(function(_stoppable) { stoppable = _stoppable; return stoppable.drasticMeasure(); @@ -66,7 +66,7 @@ contract('Stoppable', function(accounts) { it("can take a drastic measure in an emergency", function(done) { var stoppable; - return StoppableMock.new(accounts[0]) + return StoppableMock.new() .then(function(_stoppable) { stoppable = _stoppable; return stoppable.emergencyStop(); @@ -85,7 +85,7 @@ contract('Stoppable', function(accounts) { it("should resume allowing normal process after emergency is over", function(done) { var stoppable; - return StoppableMock.new(accounts[0]) + return StoppableMock.new() .then(function(_stoppable) { stoppable = _stoppable; return stoppable.emergencyStop();