/// expiring_market.sol // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . pragma solidity ^0.4.18; import "ds-auth/auth.sol"; import "./simple_market.sol"; // Simple Market with a market lifetime. When the close_time has been reached, // offers can only be cancelled (offer and buy will throw). contract ExpiringMarket is DSAuth, SimpleMarket { uint64 public close_time; bool public stopped; // after close_time has been reached, no new offers are allowed modifier can_offer { require(!isClosed()); _; } // after close, no new buys are allowed modifier can_buy(uint id) { require(isActive(id)); require(!isClosed()); _; } // after close, anyone can cancel an offer modifier can_cancel(uint id) { require(isActive(id)); require((msg.sender == getOwner(id)) || isClosed()); _; } function ExpiringMarket(uint64 _close_time) public { close_time = _close_time; } function isClosed() public constant returns (bool closed) { return stopped || getTime() > close_time; } function getTime() public constant returns (uint64) { return uint64(now); } function stop() public auth { stopped = true; } }