dirty

dirty

import "libraries/GroveLib.sol";

library CallLib {
        /*
         *  Address: 0x2746bcf29bffafcc7906752f639819171d18ce2b
         */
        struct Call {
                address contract_address;
                bytes4 abi_signature;
                bytes call_data;
                uint anchor_gas_price;
                uint suggested_gas;

                address bidder;
                uint bid_amount;
                uint bidder_deposit;
        }

        // The number of blocks that each caller in the pool has to complete their
        // call.
        uint constant CALL_WINDOW_SIZE = 16;

        address constant creator = 0xd3cda913deb6f67967b99d67acdfa1712c293601;

        function extract_call_data(Call storage call, bytes data) public {
            call.call_data.length = data.length - 4;
            if (data.length > 4) {
                    for (uint i = 0; i < call.call_data.length; i++) {
                            call.call_data[i] = data[i + 4];
                    }
            }
        }

        function send_safe(address to_address, uint value) public returns (uint) {
                if (value > address(this).balance) {
                        value = address(this).balance;
                }
                if (value > 0) {
                        AccountingLib.sendRobust(to_address, value);
                        return value;
                }
                return 0;
        }

        function get_gas_scalar(uint base_gas_price, uint gas_price) constant returns (uint) {
                /*
                 *  Return a number between 0 - 200 to scale the fee based on
                 *  the gas price set for the calling transaction as compared
                 *  to the gas price of the scheduling transaction.
                 *
                 *  - number approaches zero as the transaction gas price goes
                 *  above the gas price recorded when the call was scheduled.
                 *
                 *  - the number approaches 200 as the transaction gas price
                 *  drops under the price recorded when the call was scheduled.
                 *
                 *  This encourages lower gas costs as the lower the gas price
                 *  for the executing transaction, the higher the payout to the
                 *  caller.
                 */
                if (gas_price > base_gas_price) {
                        return 100 * base_gas_price / gas_price;
                }
                else {
                        return 200 - 100 * base_gas_price / (2 * base_gas_price - gas_price);
                }
        }

        event CallExecuted(address indexed executor, uint gas_cost, uint payment, uint fee, bool success);

        event _CallAborted(address executor, bytes32 reason);
        function CallAborted(address executor, bytes32 reason) public {
            _CallAborted(executor, reason);
        }

        function execute(Call storage call, uint start_gas, address executor, uint base_payment, uint base_fee, uint overhead, uint extraGas) public {
            FutureCall _call = FutureCall(this);

            // If the pre-execution checks do not pass, exit early.
            if (!_call.before_execute(executor)) {
                return;
            }

            // Make the call
            bool success = call.contract_address.call.gas(msg.gas - overhead)(call.abi_signature, call.call_data);

            // Compute the scalar (0 - 200) for the fee.
            uint gas_scalar = get_gas_scalar(call.anchor_gas_price, tx.gasprice);

            uint payment = base_payment * gas_scalar / 100;
            uint fee = base_fee * gas_scalar / 100;

            // Log how much gas this call used.  EXTRA_CALL_GAS is a fixed
            // amount that represents the gas usage of the commands that
            // happen after this line.
            uint gas_cost = tx.gasprice * (start_gas - msg.gas + extraGas);

            // Now we need to pay the executor as well as keep fee.
            payment = send_safe(executor, payment + gas_cost);
            fee = send_safe(creator, fee);

            // Log execution
            CallExecuted(executor, gas_cost, payment, fee, success);
        }

        event Cancelled(address indexed cancelled_by);

        function cancel(address sender) public {
                Cancelled(sender);
                // TODO: remove suicide.
                suicide(sender);
        }

        /*
         *  Bid API
         *  - Gas costs for this transaction are not covered so it
         *    must be up to the call executors to ensure that their actions
         *    remain profitable.  Any form of bidding war is likely to eat into
         *    profits.
         */
        event Claimed(address executor, uint bid_amount);

        // The duration (in blocks) during which the maximum bid will slowly rise
        // towards the base_payment amount.
        uint constant BID_GROWTH_WINDOW = 240;

        // The duration (in blocks) after the BID_WINDOW that bidding will
        // remain open.
        uint constant MAXIMUM_BID_WINDOW = 15;

        // The duration (in blocks) before the call's target block during which
        // all actions are frozen.  This includes bidding, cancellation,
        // registering call data.
        uint constant BEFORE_CALL_FREEZE_WINDOW = 10;

        /*
         *  The maximum allowed bid slowly rises across a window of blocks
         *  BID_GROWTH_WINDOW prior to the call.  No bidder is allowed to bid
         *  above this value.  This is intended to prevent bidding wars in that
         *  each caller should know how much they are willing to execute a call
         *  for.
         */
        function get_bid_amount_for_block(uint block_number) constant returns (uint) {
            var _call = FutureBlockCall(this);

            uint last_block = _call.target_block() - BEFORE_CALL_FREEZE_WINDOW;

            // bid window has closed
            if (block_number > last_block) return _call.base_payment();

            uint first_block = last_block - MAXIMUM_BID_WINDOW - BID_GROWTH_WINDOW;

            // bid window has not begun
            if (block_number < first_block) return 0;

            // in the maximum bid window.
            if (block_number > last_block - MAXIMUM_BID_WINDOW) return _call.base_payment();

            uint x = block_number - first_block;

            return 100 * x / BID_GROWTH_WINDOW;
        }

        function claim(Call storage self, address executor, uint deposit_amount, uint base_payment) public returns (bool) {
                // Already claimed
                if (self.bidder != 0x0) return false;

                // Insufficient Deposit
                if (deposit_amount < 2 * base_payment) return false;

                self.bid_amount = get_maximum_bid_for_block(block.number);
                self.bidder = executor;
                self.bidder_deposit = deposit_amount;

                // Log the bid.
                Claimed(executor, self.bid_amount);
        }

        function check_execution_authorization(Call storage self, address executor, uint block_number) returns (bool) {
                /*
                 *  Check whether the given `executor` is authorized.
                 */
                var call = FutureCall(this);

                uint target_block = call.target_block();

                // Invalid, not in call window.
                if (block_number < target_block || block_number > target_block + call.grace_period()) throw;

                // Within the reserved call window so if there is a bidder, the
                // executor must be the biddor.
                if (block_number - target_block < CALL_WINDOW_SIZE) {
                    return (self.bidder == 0x0 || self.bidder == executor);
                }

                // Must be in the free-for-all period.
                return true;
        }
}

contract FutureCall {
        address public scheduler_address;

        uint public base_payment;
        uint public base_fee;

        // TODO: These *should* live on FutureBlockCall but I haven't figured
        // the modularity part out quite yet.  For now I'm going to muddle
        // these two concepts together for the sake of progress and pay this
        // debt down later.
        uint public target_block;
        uint8 public grace_period;

        CallLib.Call call;

        /*
         *  Data accessor functions.
         */
        function contract_address() constant returns (address) {
                return call.contract_address;
        }

        function abi_signature() constant returns (bytes4) {
                return call.abi_signature;
        }

        function call_data() constant returns (bytes) {
                return call.call_data;
        }

        function anchor_gas_price() constant returns (uint) {
                return call.anchor_gas_price;
        }

        function suggested_gas() constant returns (uint) {
                return call.suggested_gas;
        }

        function () {
                // Fallback to allow sending funds to this contract.
                // Also allows call data registration.
                if (msg.sender == scheduler_address && msg.data.length > 0) {
                        if (call.call_data.length != 0) {
                            throw;
                        }
                        call.call_data = msg.data;
                }
        }

        modifier onlyscheduler { if (msg.sender == scheduler_address) _ }

        // The author (Piper Merriam) address.
        address constant creator = 0xd3cda913deb6f67967b99d67acdfa1712c293601;

        function register_data() public onlyscheduler {
                if (call.call_data.length > 0) {
                        // cannot write over call data
                        throw;
                }
                CallLib.extract_call_data(call, msg.data);
        }

        function bid(uint bidAmount) public returns (bool) {
                bool success = CallLib.bid(call, msg.sender, bidAmount, msg.value, base_payment);
                if (!success) {
                        if (!AccountingLib.sendRobust(msg.sender, msg.value)) throw;
                }
                return success;
        }

        function check_execution_authorization(address executor, uint block_number) constant returns (bool) {
                return CallLib.check_execution_authorization(call, executor, block_number);
        }

        // API for inherited contracts
        function before_execute(address executor) public returns (bool);
        function after_execute(address executor) internal;
        function get_overhead() constant returns (uint);
        function get_extra_gas() constant returns (uint);

        function send_safe(address to_address, uint value) internal {
                CallLib.send_safe(to_address, value);
        }

        function execute() public {
            uint start_gas = msg.gas;

            // Check that the call should be executed now.
            if (!before_execute(msg.sender)) return;

            // Execute the call
            CallLib.execute(call, start_gas, msg.sender, base_payment, base_fee, get_overhead(), get_extra_gas());

            // Any logic that needs to occur after the call has executed should
            // go in after_execute
            after_execute(msg.sender);
        }
}

contract FutureBlockCall is FutureCall {
        // TODO: This it the *appropriate* place for these to live, but for
        // unfortunate reasons, they are present on the FutureCall contract
        // class.
        //uint public target_block;
        //uint8 public grace_period;

        function FutureBlockCall(address _scheduler_address, uint _target_block, uint8 _grace_period, address _contract_address, bytes4 _abi_signature, uint _suggested_gas, uint _base_payment, uint _base_fee) {
                // TODO: split this constructor across this contract and the
                // parent contract FutureCall
                scheduler_address = _scheduler_address;

                target_block = _target_block;
                grace_period = _grace_period;

                base_payment = _base_payment;
                base_fee = _base_fee;

                call.suggested_gas = _suggested_gas;
                call.anchor_gas_price = tx.gasprice;
                call.contract_address = _contract_address;
                call.abi_signature = _abi_signature;
        }

        function before_execute(address executor) public returns (bool) {
            if (block.number < target_block || block.number > target_block + grace_period) {
                // Not being called within call window.
                CallLib.CallAborted(executor, "NOT_IN_CALL_WINDOW");
                return false;
            }

            // If they are not authorized to execute the call at this time,
            // exit early.
            if (!CallLib.check_execution_authorization(executor, block.number)) {
                CallLib.CallAborted(executor, "NOT_AUTHORIZED");
                return;
            }

            return true;
        }

        function after_execute(address executor) internal {
            // TODO: Remove suicide
            suicide(scheduler_address);
        }

        function get_overhead() constant returns (uint) {
                // TODO real numbers
                return 46000;
        }

        function get_extra_gas() constant returns (uint) {
                // TODO real numbers
                return 17000;
        }

        uint constant BEFORE_CALL_FREEZE_WINDOW = 10;

        function cancel() public {
                if ((block.number < target_block - BEFORE_CALL_FREEZE_WINDOW && msg.sender == scheduler_address) || block.number > target_block + grace_period) {
                        CallLib.cancel(scheduler_address);
                }
        }
}

import "libraries/GroveLib.sol";

library CallLib {
        /*
         *  Address: 0x2746bcf29bffafcc7906752f639819171d18ce2b
         */
        struct Call {
                address contractAddress;
                bytes4 abiSignature;
                bytes callData;
                uint anchorGasPrice;
                uint suggestedGas;

                address bidder;
                uint bid_amount;
                uint bidder_deposit;
        }

        // The number of blocks that each caller in the pool has to complete their
        // call.
        uint constant CALL_WINDOW_SIZE = 16;

        address constant creator = 0xd3cda913deb6f67967b99d67acdfa1712c293601;

        function extractCallData(Call storage call, bytes data) public {
            call.callData.length = data.length - 4;
            if (data.length > 4) {
                    for (uint i = 0; i < call.callData.length; i++) {
                            call.callData[i] = data[i + 4];
                    }
            }
        }

        function sendSafe(address toAddress, uint value) public returns (uint) {
                if (value > address(this).balance) {
                        value = address(this).balance;
                }
                if (value > 0) {
                        AccountingLib.sendRobust(toAddress, value);
                        return value;
                }
                return 0;
        }

        function get_gas_scalar(uint baseGasPrice, uint gasPrice) constant returns (uint) {
                /*
                 *  Return a number between 0 - 200 to scale the fee based on
                 *  the gas price set for the calling transaction as compared
                 *  to the gas price of the scheduling transaction.
                 *
                 *  - number approaches zero as the transaction gas price goes
                 *  above the gas price recorded when the call was scheduled.
                 *
                 *  - the number approaches 200 as the transaction gas price
                 *  drops under the price recorded when the call was scheduled.
                 *
                 *  This encourages lower gas costs as the lower the gas price
                 *  for the executing transaction, the higher the payout to the
                 *  caller.
                 */
                if (gasPrice > baseGasPrice) {
                        return 100 * baseGasPrice / gasPrice;
                }
                else {
                        return 200 - 100 * baseGasPrice / (2 * baseGasPrice - gasPrice);
                }
        }

        event CallExecuted(address indexed executor, uint gasCost, uint payment, uint fee, bool success);

        event _CallAborted(address executor, bytes32 reason);
        function CallAborted(address executor, bytes32 reason) public {
            _CallAborted(executor, reason);
        }

        function execute(Call storage call, uint startGas, address executor, uint basePayment, uint baseFee, uint overhead, uint extraGas) public {
            FutureCall _call = FutureCall(this);

            if (!_call.checkExecutionAuthorization(executor, block.number)) {
                return;
            }

            if (!_call.before_execute(executor)) {
                return;
            }

            // Make the call
            bool success = call.contractAddress.call.gas(msg.gas - overhead)(call.abiSignature, call.callData);

            // Compute the scalar (0 - 200) for the fee.
            uint gas_scalar = get_gas_scalar(call.anchorGasPrice, tx.gasprice);

            uint payment = basePayment * gas_scalar / 100;
            uint fee = baseFee * gas_scalar / 100;

            // Log how much gas this call used.  EXTRA_CALL_GAS is a fixed
            // amount that represents the gas usage of the commands that
            // happen after this line.
            uint gasCost = tx.gasprice * (startGas - msg.gas + extraGas);

            // Now we need to pay the executor as well as keep fee.
            payment = sendSafe(executor, payment + gasCost);
            fee = sendSafe(creator, fee);

            // Log execution
            CallExecuted(executor, gasCost, payment, fee, success);
        }

        event Cancelled(address indexed cancelledBy);

        function cancel(address sender) public {
                Cancelled(sender);
                // TODO: remove suicide.
                suicide(sender);
        }

        /*
         *  Bid API
         *  - Gas costs for this transaction are not covered so it
         *    must be up to the call executors to ensure that their actions
         *    remain profitable.  Any form of bidding war is likely to eat into
         *    profits.
         */
        event Bid(address executor, uint bidAmount);

        // The duration (in blocks) during which the maximum bid will slowly rise
        // towards the base_payment amount.
        uint constant BID_GROWTH_WINDOW = 240;

        // The duration (in blocks) after the BID_WINDOW that bidding will
        // remain open.
        uint constant MAXIMUM_BID_WINDOW = 15;

        // The duration (in blocks) before the call's target block during which
        // all actions are frozen.  This includes bidding, cancellation,
        // registering call data.
        uint constant BEFORE_CALL_FREEZE_WINDOW = 10;

        /*
         *  The maximum allowed bid slowly rises across a window of blocks
         *  BID_GROWTH_WINDOW prior to the call.  No bidder is allowed to bid
         *  above this value.  This is intended to prevent bidding wars in that
         *  each caller should know how much they are willing to execute a call
         *  for.
         */
        function get_bid_amount_for_block(uint block_number) constant returns (uint) {
            var _call = FutureBlockCall(this);

            uint last_block = _call.target_block() - BEFORE_CALL_FREEZE_WINDOW;

            // bid window has closed
            if (block_number > last_block) return _call.basePayment();

            uint first_block = last_block - MAXIMUM_BID_WINDOW - BID_GROWTH_WINDOW;

            // bid window has not begun
            if (block_number < first_block) return 0;

            // in the maximum bid window.
            if (block_number > last_block - MAXIMUM_BID_WINDOW) return _call.basePayment();

            uint x = block_number - first_block;

            return 100 * x / BID_GROWTH_WINDOW;
        }

        function claim(Call storage self, address executor, uint deposit_amount, uint base_payment) public returns (bool) {
                // Already claimed
                if (self.bidder != 0x0) return false;

                // Insufficient Deposit
                if (deposit_amount < 2 * base_payment) return false;

                self.bid_amount = get_maximum_bid_for_block(block.number);
                self.bidder = executor;
                self.bidder_deposit = deposit_amount;

                // Log the bid.
                Bid(executor, self.bid_amount);
        }

        function check_execution_authorization(Call storage self, address executor, uint block_number) returns (bool) {
                /*
                 *  Check whether the given `executor` is authorized.
                 */
                var call = FutureCall(this);

                uint target_block = call.target_block();

                // Call window hasn't started
                if (block_number < target_block) return false;

                if (block_number - target_block < CALL_WINDOW_SIZE) {
                    return (self.bidder == 0x0 || self.bidder == executor);
                }

                if (block_number > target_block + call.grace_period()) return false;

                return true;
        }
}

contract FutureCall {
        address public scheduler_address;

        uint public basePayment;
        uint public baseFee;

        // TODO: These *should* live on FutureBlockCall but I haven't figured
        // the modularity part out quite yet.  For now I'm going to muddle
        // these two concepts together for the sake of progress and pay this
        // debt down later.
        uint public target_block;
        uint8 public grace_period;

        CallLib.Call call;

        /*
         *  Data accessor functions.
         */
        function contractAddress() constant returns (address) {
                return call.contractAddress;
        }

        function abiSignature() constant returns (bytes4) {
                return call.abiSignature;
        }

        function callData() constant returns (bytes) {
                return call.callData;
        }

        function anchorGasPrice() constant returns (uint) {
                return call.anchorGasPrice;
        }

        function suggestedGas() constant returns (uint) {
                return call.suggestedGas;
        }

        function () {
                // Fallback to allow sending funds to this contract.
                // Also allows call data registration.
                if (msg.sender == scheduler_address && msg.data.length > 0) {
                        if (call.callData.length != 0) {
                            throw;
                        }
                        call.callData = msg.data;
                }
        }

        modifier onlyscheduler { if (msg.sender == scheduler_address) _ }

        // The author (Piper Merriam) address.
        address constant creator = 0xd3cda913deb6f67967b99d67acdfa1712c293601;

        function registerData() public onlyscheduler {
                if (call.callData.length > 0) {
                        // cannot write over call data
                        throw;
                }
                CallLib.extractCallData(call, msg.data);
        }

        function bid(uint bidAmount) public returns (bool) {
                bool success = CallLib.bid(call, msg.sender, bidAmount, msg.value, basePayment);
                if (!success) {
                        if (!AccountingLib.sendRobust(msg.sender, msg.value)) throw;
                }
                return success;
        }

        function checkBid() constant returns (uint) {
                return checkBid(msg.sender);
        }

        function checkBid(address bidder) constant returns (uint) {
                return CallLib.checkBid(call, bidder);
        }

        function checkExecutionAuthorization(address executor, uint blockNumber) constant returns (bool) {
                return CallLib.checkExecutionAuthorization(call, executor, blockNumber);
        }

        // API for inherited contracts
        function before_execute(address executor) public returns (bool);
        function after_execute(address executor) internal;
        function get_overhead() constant returns (uint);
        function get_extra_gas() constant returns (uint);

        function sendSafe(address toAddress, uint value) internal {
                CallLib.sendSafe(toAddress, value);
        }

        function execute() public {
            uint startGas = msg.gas;

            // Check that the call should be executed now.
            if (!before_execute(msg.sender)) return;

            // Execute the call
            CallLib.execute(call, startGas, msg.sender, basePayment, baseFee, get_overhead(), get_extra_gas());

            // Any logic that needs to occur after the call has executed should
            // go in after_execute
            after_execute(msg.sender);
        }
}

contract FutureBlockCall is FutureCall {
        // TODO: This it the *appropriate* place for these to live, but for
        // unfortunate reasons, they are present on the FutureCall contract
        // class.
        //uint public target_block;
        //uint8 public grace_period;

        function FutureBlockCall(address _scheduler_address, uint _target_block, uint8 _grace_period, address _contractAddress, bytes4 _abiSignature, uint _suggestedGas, uint _basePayment, uint _baseFee) {
                // TODO: split this constructor across this contract and the
                // parent contract FutureCall
                scheduler_address = _scheduler_address;

                target_block = _target_block;
                grace_period = _grace_period;

                basePayment = _basePayment;
                baseFee = _baseFee;

                call.suggestedGas = _suggestedGas;
                call.anchorGasPrice = tx.gasprice;
                call.contractAddress = _contractAddress;
                call.abiSignature = _abiSignature;
        }

        function before_execute(address executor) public returns (bool) {
                // TODO: check if executor is designated to call during this window.
                if (block.number < target_block || block.number > target_block + grace_period) {
                        // Not being called within call window.
                        CallLib.CallAborted(executor, "NOT_IN_CALL_WINDOW");
                        return false;
                }

                return true;
        }

        function after_execute(address executor) internal {
            // TODO: Remove suicide
            suicide(scheduler_address);
        }

        function get_overhead() constant returns (uint) {
                // TODO real numbers
                return 46000;
        }

        function get_extra_gas() constant returns (uint) {
                // TODO real numbers
                return 17000;
        }

        uint constant BEFORE_CALL_FREEZE_WINDOW = 10;

        function cancel() public {
                if ((block.number < target_block - BEFORE_CALL_FREEZE_WINDOW && msg.sender == scheduler_address) || block.number > target_block + grace_period) {
                        CallLib.cancel(scheduler_address);
                }
        }
}


Specified parameters and ECDSA signature

*/
pragma solidity ^0.4.8;

import "./Proxy.sol";
import "./base/Token.sol";
import "./base/SafeMath.sol";
// Error Codes
    uint8 constant ERROR_FILL_EXPIRED = 0;           // Order has already expired
    uint8 constant ERROR_FILL_NO_VALUE = 1;          // Order has already been fully filled or cancelled
    uint8 constant ERROR_FILL_TRUNCATION = 2;        // Rounding error too large
    uint8 constant ERROR_FILL_BALANCE_ALLOWANCE = 3; // Insufficient balance or allowance for token transfer
    uint8 constant ERROR_CANCEL_EXPIRED = 4;         // Order has already expired
    uint8 constant ERROR_CANCEL_NO_VALUE = 5;        // Order has already been fully filled or cancelled

    address public ZRX;
    address public PROXY;

    // Mappings of orderHash => amounts of valueT filled or cancelled.
    mapping (bytes32 => uint) public filled;
    mapping (bytes32 => uint) public cancelled;

    event LogFill(
        address indexed maker,
        address taker,
        address indexed feeRecipient,
        address tokenM,
        address tokenT,
        uint filledValueM,
        uint filledValueT,
        uint feeMPaid,
        uint feeTPaid,
        bytes32 indexed tokens,
        bytes32 orderHash
    );

    event LogCancel(
        address indexed maker,
        address indexed feeRecipient,
        address tokenM,
        address tokenT,
        uint cancelledValueM,
        uint cancelledValueT,
        bytes32 indexed tokens,
        bytes32 orderHash
    );

    event LogError(uint8 indexed errorId, bytes32 indexed orderHash);

    struct Order {
        address maker;
        address taker;
        address tokenM;
        address tokenT;
        address feeRecipient;
        uint valueM;
        uint valueT;
        uint feeM;
        uint feeT;
        uint expiration;
        bytes32 orderHash;
    }

    function Exchange(address _zrx, address _proxy) {
        ZRX = _zrx;
        PROXY = _proxy;
    }

    /*
    * Core exchange functions
    */

    /// @dev Fills the input order.
    /// @param orderAddresses Array of order's maker, taker, tokenM, tokenT, and feeRecipient.
    /// @param orderValues Array of order's valueM, valueT, feeM, feeT, expiration, and salt.
    /// @param fillValueT Desired amount of tokenT to fill.
    /// @param shouldCheckTransfer Test if transfer will fail before attempting.
    /// @param v ECDSA signature parameter v.
    /// @param r CDSA signature parameters r.
    /// @param s CDSA signature parameters s.
    /// @return Total amount of tokenM filled in trade.
    function fill(
          address[5] orderAddresses,
          uint[6] orderValues,
          uint fillValueT,
          bool shouldCheckTransfer,
          uint8 v,
          bytes32 r,
          bytes32 s)
          returns (uint filledValueT)
    {
        Order memory order = Order({
            maker: orderAddresses[0],
            taker: orderAddresses[1],
            tokenM: orderAddresses[2],
            tokenT: orderAddresses[3],
            feeRecipient: orderAddresses[4],
            valueM: orderValues[0],
            valueT: orderValues[1],
            feeM: orderValues[2],
            feeT: orderValues[3],
            expiration: orderValues[4],
            orderHash: getOrderHash(orderAddresses, orderValues)
        });

        assert(order.taker == address(0) || order.taker == msg.sender);

        if (block.timestamp >= order.expiration) {
            LogError(ERROR_FILL_EXPIRED, order.orderHash);
            return 0;
        }

        uint remainingValueT = safeSub(order.valueT, getUnavailableValueT(order.orderHash));
        filledValueT = min(fillValueT, remainingValueT);
        if (filledValueT == 0) {
            LogError(ERROR_FILL_NO_VALUE, order.orderHash);
            return 0;
        }

        if (isRoundingError(order.valueT, filledValueT, order.valueM)) {
            LogError(ERROR_FILL_TRUNCATION, order.orderHash);
            return 0;
        }

        if (shouldCheckTransfer && !isTransferable(order, filledValueT)) {
            LogError(ERROR_FILL_BALANCE_ALLOWANCE, order.orderHash);
            return 0;
        }

        assert(isValidSignature(
            order.maker,
            order.orderHash,
            v,
            r,
            s
        ));

        uint filledValueM = getPartialValue(order.valueT, filledValueT, order.valueM);
        uint feeMPaid;
        uint feeTPaid;
        filled[order.orderHash] = safeAdd(filled[order.orderHash], filledValueT);
        assert(transferViaProxy(
            order.tokenM,
            order.maker,
            msg.sender,
            filledValueM
        ));
        assert(transferViaProxy(
            order.tokenT,
            msg.sender,
            order.maker,
            filledValueT
        ));
        if (order.feeRecipient != address(0)) {
            if (order.feeM > 0) {
                feeMPaid = getPartialValue(order.valueT, filledValueT, order.feeM);
                assert(transferViaProxy(
                    ZRX,
                    order.maker,
                    order.feeRecipient,
                    feeMPaid
                ));
            }
            if (order.feeT > 0) {
                feeTPaid = getPartialValue(order.valueT, filledValueT, order.feeT);
                assert(transferViaProxy(
                    ZRX,
                    msg.sender,
                    order.feeRecipient,
                    feeTPaid
                ));
            }
        }

        LogFill(
            order.maker,
            msg.sender,
            order.feeRecipient,
            order.tokenM,
            order.tokenT,
            filledValueM,
            filledValueT,
            feeMPaid,
            feeTPaid,
            sha3(order.tokenM, order.tokenT),
            order.orderHash
        );
        return filledValueT;
    }

    /// @dev Cancels the input order.
    /// @param orderAddresses Array of order's maker, taker, tokenM, tokenT, and feeRecipient.
    /// @param orderValues Array of order's valueM, valueT, feeM, feeT, expiration, and salt.
    /// @param cancelValueT Desired amount of tokenT to cancel in order.
    /// @return Amount of tokenM cancelled.
    function cancel(
        address[5] orderAddresses,
        uint[6] orderValues,
        uint cancelValueT)
        returns (uint cancelledValueT)
    {
        Order memory order = Order({
            maker: orderAddresses[0],
            taker: orderAddresses[1],
            tokenM: orderAddresses[2],
            tokenT: orderAddresses[3],
            feeRecipient: orderAddresses[4],
            valueM: orderValues[0],
            valueT: orderValues[1],
            feeM: orderValues[2],
            feeT: orderValues[3],
            expiration: orderValues[4],
            orderHash: getOrderHash(orderAddresses, orderValues)
        });

        assert(order.maker == msg.sender);

        if (block.timestamp >= order.expiration) {
            LogError(ERROR_CANCEL_EXPIRED, order.orderHash);
            return 0;
        }

        uint remainingValueT = safeSub(order.valueT, getUnavailableValueT(order.orderHash));
        cancelledValueT = min(cancelValueT, remainingValueT);
        if (cancelledValueT == 0) {
            LogError(ERROR_CANCEL_NO_VALUE, order.orderHash);
            return 0;
        }

        cancelled[order.orderHash] = safeAdd(cancelled[order.orderHash], cancelledValueT);

        LogCancel(
            order.maker,
            order.feeRecipient,
            order.tokenM,
            order.tokenT,
            getPartialValue(order.valueT, cancelledValueT, order.valueM),
            cancelledValueT,
            sha3(order.tokenM, order.tokenT),
            order.orderHash
        );
        return cancelledValueT;
    }

    /*
    * Wrapper functions
    */

    /// @dev Fills an order with specified parameters and ECDSA signature, throws if specified amount not filled entirely.
    /// @param orderAddresses Array of order's maker, taker, tokenM, tokenT, and feeRecipient.
    /// @param orderValues Array of order's valueM, valueT, feeM, feeT, expiration, and salt.
    /// @param fillValueT Desired amount of tokenT to fill.
    /// @param v ECDSA signature parameter v.
    /// @param r CDSA signature parameters r.
    /// @param s CDSA signature parameters s.
    /// @return Success of entire fillValueT being filled.
    function fillOrKill(
        address[5] orderAddresses,
        uint[6] orderValues,
        uint fillValueT,
        uint8 v,
        bytes32 r,
        bytes32 s)
        returns (bool success)
    {
        assert(fill(
            orderAddresses,
            orderValues,
            fillValueT,
            false,
            v,
            r,
            s
        ) == fillValueT);
        return true;
    }

    /// @dev Synchronously executes multiple fill orders in a single transaction.
    /// @param orderAddresses Array of address arrays containing individual order addresses.
    /// @param orderValues Array of uint arrays containing individual order values.
    /// @param fillValuesT Array of desired amounts of tokenT to fill in orders.
    /// @param shouldCheckTransfer Test if transfers will fail before attempting.
    /// @param v Array ECDSA signature v parameters.
    /// @param r Array of ECDSA signature r parameters.
    /// @param s Array of ECDSA signature s parameters.
    /// @return True if no fills throw.
    function batchFill(
        address[5][] orderAddresses,
        uint[6][] orderValues,
        uint[] fillValuesT,
        bool shouldCheckTransfer,
        uint8[] v,
        bytes32[] r,
        bytes32[] s)
        returns (bool success)
    {
        for (uint i = 0; i < orderAddresses.length; i++) {
            fill(
                orderAddresses[i],
                orderValues[i],
                fillValuesT[i],
                shouldCheckTransfer,
                v[i],
                r[i],
                s[i]
            );
        }
        return true;
    }

    /// @dev Synchronously executes multiple fillOrKill orders in a single transaction.
    /// @param orderAddresses Array of address arrays containing individual order addresses.
    /// @param orderValues Array of uint arrays containing individual order values.
    /// @param fillValuesT Array of desired amounts of tokenT to fill in orders.
    /// @param v Array ECDSA signature v parameters.
    /// @param r Array of ECDSA signature r parameters.
    /// @param s Array of ECDSA signature s parameters.
    /// @return Success of all orders being filled with respective fillValueT.
    function batchFillOrKill(
      address[5][] orderAddresses,
      uint[6][] orderValues,
      uint[] fillValuesT,
      uint8[] v,
      bytes32[] r,
      bytes32[] s)
        returns (bool success)
    {
        for (uint i = 0; i < orderAddresses.length; i++) {
            assert(fillOrKill(
                orderAddresses[i],
                orderValues[i],
                fillValuesT[i],
                v[i],
                r[i],
                s[i]
            ));
        }
        return true;
    }

    /// @dev Synchronously executes multiple fill orders in a single transaction until total fillValueT filled.
    /// @param orderAddresses Array of address arrays containing individual order addresses.
    /// @param orderValues Array of uint arrays containing individual order values.
    /// @param fillValueT Desired total amount of tokenT to fill in orders.
    /// @param shouldCheckTransfer Test if transfers will fail before attempting.
    /// @param v Array ECDSA signature v parameters.
    /// @param r Array of ECDSA signature r parameters.
    /// @param s Array of ECDSA signature s parameters.
    /// @return Total amount of fillValueT filled in orders.
    function fillUpTo(
        address[5][] orderAddresses,
        uint[6][] orderValues,
        uint fillValueT,
        bool shouldCheckTransfer,
        uint8[] v,
        bytes32[] r,
        bytes32[] s)
        returns (uint filledValueT)
    {
        filledValueT = 0;
        for (uint i = 0; i < orderAddresses.length; i++) {
            assert(orderAddresses[i][3] == orderAddresses[0][3]); // tokenT must be the same for each order
            filledValueT = safeAdd(filledValueT, fill(
                orderAddresses[i],
                orderValues[i],
                safeSub(fillValueT, filledValueT),
                shouldCheckTransfer,
                v[i],
                r[i],
                s[i]
            ));
            if (filledValueT == fillValueT) break;
        }
        return filledValueT;
    }

    /// @dev Synchronously cancels multiple orders in a single transaction.
    /// @param orderAddresses Array of address arrays containing individual order addresses.
    /// @param orderValues Array of uint arrays containing individual order values.
    /// @param cancelValuesT Array of desired amounts of tokenT to cancel in orders.
    /// @return Success if no cancels throw.
    function batchCancel(
        address[5][] orderAddresses,
        uint[6][] orderValues,
        uint[] cancelValuesT)
        returns (bool success)
    {
        for (uint i = 0; i < orderAddresses.length; i++) {
            cancel(
                orderAddresses[i],
                orderValues[i],
                cancelValuesT[i]
            );
        }
        return true;
    }

    /*
    * Constant public functions
    */

    /// @dev Calculates Keccak-256 hash of order with specified parameters.
    /// @param orderAddresses Array of order's maker, taker, tokenM, tokenT, and feeRecipient.
    /// @param orderValues Array of order's valueM, valueT, feeM, feeT, expiration, and salt.
    /// @return Keccak-256 hash of order.
    function getOrderHash(address[5] orderAddresses, uint[6] orderValues)
        constant
        returns (bytes32 orderHash)
    {
        return sha3(
            this,
            orderAddresses[0], // maker
            orderAddresses[1], // taker
            orderAddresses[2], // tokenM
            orderAddresses[3], // tokenT
            orderAddresses[4], // feeRecipient
            orderValues[0],    // valueM
            orderValues[1],    // valueT
            orderValues[2],    // feeM
            orderValues[3],    // feeT
            orderValues[4],    // expiration
            orderValues[5]     // salt
        );
    }

    /// @dev Verifies that an order signature is valid.
    /// @param signer address of signer.
    /// @param hash Signed Keccak-256 hash.
    /// @param v ECDSA signature parameter v.
    /// @param r ECDSA signature parameters r.
    /// @param s ECDSA signature parameters s.
    /// @return Validity of order signature.
    function isValidSignature(
        address signer,
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s)
        constant
        returns (bool isValid)
    {
        return signer == ecrecover(
            sha3("\x19chainxSigned Message:\n32", hash),
            v,
            r,
            s
        );
    }

    /// @dev Calculates minimum of two values.
    /// @param a First value.
    /// @param b Second value.
    /// @return Minimum of values.
    function min(uint a, uint b)
        constant
        returns (uint min)
    {
        if (a < b) return a;
        return b;
    }

    /// @dev Checks if rounding error > 0.1%.
    /// @param denominator Denominator
    /// @param numerator Numerator
    /// @param target Value to multiply with numerator/denominator.
    /// @return Rounding error is present
    function isRoundingError(uint denominator, uint numerator, uint target)
        constant
        returns (bool isError)
    {
        return (target < 10**3 && mulmod(target, numerator, denominator) != 0);
    }

    /// @dev Calculates partial value given a fillValue and a corresponding total value.
    /// @param value Amount of token specified in order.
    /// @param fillValue Amount of token to be filled.
    /// @param target Value to calculate partial.
    /// @return Partial value of target.
    function getPartialValue(uint value, uint fillValue, uint target)
        constant
        returns (uint partialValue)
    {
        return safeDiv(safeMul(fillValue, target), value);
    }

    /// @dev Calculates the sum of values already filled and cancelled for a given order.
    /// @param orderHash The Keccak-256 hash of the given order.
    /// @return Sum of values already filled and cancelled.
    function getUnavailableValueT(bytes32 orderHash)
        constant
        returns (uint unavailableValueT)
    {
        return safeAdd(filled[orderHash], cancelled[orderHash]);
    }

    /*
    * Internal functions
    */

    /// @dev Transfers a token using Proxy transferFrom function.
    /// @param token Address of token to transferFrom.
    /// @param from Address transfering token.
    /// @param to Address receiving token.
    /// @param value Amount of token to transfer.
    /// @return Success of token transfer.
    function transferViaProxy(
        address token,
        address from,
        address to,
        uint value)
        internal
        returns (bool success)
    {
        return Proxy(PROXY).transferFrom(token, from, to, value);
    }

    /// @dev Checks if any order transfers will fail.
    /// @param order Order struct of params that will be checked.
    /// @param fillValueT Desired amount of tokenT to fill.
    /// @return Predicted result of transfers.
    function isTransferable(Order order, uint fillValueT)
        internal
        constant
        returns (bool isTransferable)
    {
        address taker = msg.sender;
        uint fillValueM = getPartialValue(order.valueT, fillValueT, order.valueM);
        if (   getBalance(order.tokenM, order.maker) < fillValueM
            || getAllowance(order.tokenM, order.maker) < fillValueM
            || getBalance(order.tokenT, taker) < fillValueT
            || getAllowance(order.tokenT, taker) < fillValueT
        ) return false;
        if (order.feeRecipient != address(0)) {
            uint feeValueM = getPartialValue(order.valueT, fillValueT, order.feeM);
            uint feeValueT = getPartialValue(order.valueT, fillValueT, order.feeT);
            if (   getBalance(ZRX, order.maker) < feeValueM
                || getAllowance(ZRX, order.maker) < feeValueM
                || getBalance(ZRX, taker) < feeValueT
                || getAllowance(ZRX, taker) < feeValueT
            ) return false;
        }
        return true;
    }

    /// @dev Get token balance of an address.
    /// @param token Address of token.
    /// @param owner Address of owner.
    /// @return Token balance of owner.
    function getBalance(address token, address owner)
        internal
        constant
        returns (uint balance)
    {
        return Token(token).balanceOf(owner);
    }

    /// @dev Get allowance of token given to Proxy by an address.
    /// @param token Address of token.
    /// @param owner Address of owner.
    /// @return Allowance of token given to Proxy by owner.
    function getAllowance(address token, address owner)
        internal
        constant
        returns (uint allowance)
    {
        return Token(token).allowance(owner, PROXY);
    }
}

error: pathspec 'Contracts/chainx.sol' did not match any file(s) known to git


Insurance Token added (stub)

Insurance Token added (stub)

pragma solidity ^0.4.8;

import "./ERC20.sol";

contract InsuranceToken is ERC20 {
	string public constant symbol = "INS";
	string public constant name = "Insurance Token";
	uint8 public constant decimals = 18;
	uint256 _totalSupply = 1000000;
	// Owner of this contract
	address public owner;
	// Balances for each account
	mapping(address => uint256) balances;
	// Owner of account approves the transfer of an amount to another account
	mapping(address => mapping (address => uint256)) allowed;
	// Functions with this modifier can only be executed by the owner
	modifier onlyOwner() {
		if (msg.sender != owner) {
			throw;
		}
		_;
	}
	// Constructor
	function InsuranceToken() {
		owner = msg.sender;
		balances[owner] = _totalSupply;
	}
	function totalSupply() constant returns (uint256 totalSupply) {
		totalSupply = _totalSupply;
	}
	// What is the balance of a particular account?
	function balanceOf(address _owner) constant returns (uint256 balance) {
		return balances[_owner];
	}
	// Transfer the balance from owner's account to another account
	function transfer(address _to, uint256 _amount) returns (bool success) {
		if (balances[msg.sender] >= _amount
		&& _amount > 0
		&& balances[_to] + _amount > balances[_to]) {
			balances[msg.sender] -= _amount;
			balances[_to] += _amount;
			Transfer(msg.sender, _to, _amount);
			return true;
		} else {
			return false;
		}
	}
	// Send _value amount of tokens from address _from to address _to
	// The transferFrom method is used for a withdraw workflow, allowing contracts to send
	// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
	// fees in sub-currencies; the command should fail unless the _from account has
	// deliberately authorized the sender of the message via some mechanism; we propose
	// these standardized APIs for approval:
	function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) {
		if (balances[_from] >= _amount
		&& allowed[_from][msg.sender] >= _amount
		&& _amount > 0
		&& balances[_to] + _amount > balances[_to]) {
			balances[_from] -= _amount;
			allowed[_from][msg.sender] -= _amount;
			balances[_to] += _amount;
			Transfer(_from, _to, _amount);
			return true;
		} else {
			return false;
		}
	}

	// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
	// If this function is called again it overwrites the current allowance with _value.
	function approve(address _spender, uint256 _amount) returns (bool success) {
		allowed[msg.sender][_spender] = _amount;
		Approval(msg.sender, _spender, _amount);
		return true;
	}

	function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
		return allowed[_owner][_spender];
	}
}

error: pathspec 'truffle/contracts/InsuranceToken.sol' did not match any file(s) known to git


Make token constructible.

Make token constructible.

pragma solidity ^0.4.0;

import "./Token.sol";

contract StandardToken is Token {
	uint256 supply;
	mapping (address => uint256) balance;
	mapping (address =>
		mapping (address => uint256)) m_allowance;

	function StandardToken(address _initialOwner, uint256 _supply) {
		supply = _supply;
		balance[_initialOwner] = _supply;
	}

	function balanceOf(address _account) constant returns (uint) {
		return balance[_account];
	}

	function totalSupply() constant returns (uint) {
		return supply;
	}

	function transfer(address _to, uint256 _value) returns (bool success) {
		if (balance[msg.sender] >= _value && balance[_to] + _value >= balance[_to]) {
			balance[msg.sender] -= _value;
			balance[_to] += _value;
			Transfer(msg.sender, _to, _value);
			return true;
		} else {
			return false;
		}
	}

	function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
		if (m_allowance[_from][msg.sender] >= _value && balance[_to] + _value >= balance[_to]) {
			m_allowance[_from][msg.sender] -= _value;
			balance[_to] += _value;
			Transfer(_from, _to, _value);
			return true;
		} else {
			return false;
		}
	}

	function approve(address _spender, uint256 _value) returns (bool success) {
		m_allowance[msg.sender][_spender] = _value;
		Approval(msg.sender, _spender, _value);
		return true;
	}

	function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
		return m_allowance[_owner][_spender];
	}
}

pragma solidity ^0.4.0;

import "./Token.sol";

contract StandardToken is Token {
	uint256 public totalSupply;
	mapping (address => uint256) public balanceOf;
	mapping (address =>
		mapping (address => uint256)) public allowance;

	function StandardToken(address _initialOwner, uint256 _supply) {
		totalSupply = _supply;
		balanceOf[_initialOwner] = _supply;
	}

	function transfer(address _to, uint256 _value) returns (bool success) {
		if (balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) {
			balanceOf[msg.sender] -= _value;
			balanceOf[_to] += _value;
			Transfer(msg.sender, _to, _value);
			return true;
		} else {
			return false;
		}
	}

	function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
		if (allowance[_from][msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) {
			allowance[_from][msg.sender] -= _value;
			balanceOf[_to] += _value;
			Transfer(_from, _to, _value);
			return true;
		} else {
			return false;
		}
	}

	function approve(address _spender, uint256 _value) returns (bool success) {
		allowance[msg.sender][_spender] = _value;
		Approval(msg.sender, _spender, _value);
		return true;
	}
}


add previousOwner field to OwnershipTransferred event

pragma solidity ^0.4.11;

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
 */
contract Ownable {
  address public owner;

  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

  /**
   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
   * account.
   */
  function Ownable() {
    owner = msg.sender;
  }

  /**
   * @dev Throws if called by any account other than the owner.
   */
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }

  /**
   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) onlyOwner {
    require(newOwner != address(0));
    owner = newOwner;
    OwnershipTransferred(newOwner);
  }

}

pragma solidity ^0.4.11;

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
 */
contract Ownable {
  address public owner;

  event OwnershipTransferred(address indexed newOwner);

  /**
   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
   * account.
   */
  function Ownable() {
    owner = msg.sender;
  }

  /**
   * @dev Throws if called by any account other than the owner.
   */
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }

  /**
   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) onlyOwner {
    require(newOwner != address(0));
    owner = newOwner;
    OwnershipTransferred(newOwner);
  }

}


Fix replay bug

Fix replay bug

import "BulletinBoard.sol";

contract UnanimousConsent {

	enum ConsentState {
		NONE,
		CONSENTED,
		EXECUTED
	}

	mapping (bytes32 =>
			mapping (address => ConsentState)) consentStates;
	address[] participants;
	BulletinBoard public bulletinBoard;

	modifier onlySelf {
		if (msg.sender == address(this)) {
			_
		} else {
			throw;
		}
	}

	function UnanimousConsent(address[] _participants) {
		participants = _participants;
		bulletinBoard = new BulletinBoard(this);
	}

	function eval(
		address[] _calledContracts,
		bytes4[] _methodSignatures,
		uint[] _argumentLengths,
		bytes32[] _arguments
	) {
		if (
			_calledContracts.length != _methodSignatures.length ||
			_calledContracts.length != _argumentLengths.length
		) {
			throw;
		}

		uint i;
		uint j;
		bytes32 hash = sha3(_calledContracts, _methodSignatures, _argumentLengths, _arguments);

		for (i = 0; i < participants.length; i++) {
			if (consentStates[hash][participants[i]] == ConsentState.CONSENTED) {
				consentStates[hash][participants[i]] = ConsentState.EXECUTED;
			} else {
				throw;
			}
		}

		uint argumentsIndex = 0;
		for (i = 0; i < _calledContracts.length; i++) {

			bytes32[] memory arguments = new bytes32[](_argumentLengths[i]);
			for (j = 0; j < _argumentLengths[i]; j++) {
				arguments[j] = _arguments[argumentsIndex++];
			}

			if (!_calledContracts[i].call(_methodSignatures[i], arguments[i])) {
				throw;
			}
		}
	}

	function consent(bytes32 _hash) returns (bool) {
		if (consentStates[_hash][msg.sender] == ConsentState.NONE) {
			consentStates[_hash][msg.sender] = ConsentState.CONSENTED;
			return true;
		} else {
			return false;
		}
	}

	function sendEther(address _recipient, uint _amount) external onlySelf {
		if (!_recipient.send(_amount)) {
			throw;
		}
	}

	function changeParticipants(address[] _participants) external onlySelf {
		participants = _participants;
	}

	function clean(bytes32[] _hashes, address[] _participants) external onlySelf {
		for (uint i = 0; i < _hashes.length; i++) {
			for (uint j = 0; j < _participants.length; j++) {
				delete consentStates[_hashes[i]][_participants[j]];
			}
		}
	}

	function kill(address _recipient) external onlySelf {
		selfdestruct(_recipient);
	}
}

import "BulletinBoard.sol";

contract UnanimousConsent {

	enum ConsentState {
		NONE,
		CONSENTED,
		EXECUTED
	}

	mapping (bytes32 =>
			mapping (address => ConsentState)) consentStates;
	address[] participants;
	BulletinBoard public bulletinBoard;

	modifier onlySelf {
		if (msg.sender == address(this)) {
			_
		} else {
			throw;
		}
	}

	function UnanimousConsent(address[] _participants) {
		participants = _participants;
		bulletinBoard = new BulletinBoard(this);
	}

	function eval(
		address[] _calledContracts,
		bytes4[] _methodSignatures,
		uint[] _argumentLengths,
		bytes32[] _arguments
	) {
		if (
			_calledContracts.length != _methodSignatures.length ||
			_calledContracts.length != _argumentLengths.length
		) {
			throw;
		}

		uint i;
		uint j;
		bytes32 hash = sha3(_calledContracts, _methodSignatures, _argumentLengths, _arguments);

		for (i = 0; i < participants.length; i++) {
			if (consentStates[hash][participants[i]] == ConsentState.CONSENTED) {
				consentStates[hash][participants[i]] = ConsentState.EXECUTED;
			} else {
				throw;
			}
		}

		uint argumentsIndex = 0;
		for (i = 0; i < _calledContracts.length; i++) {

			bytes32[] memory arguments = new bytes32[](_argumentLengths[i]);
			for (j = 0; j < _argumentLengths[i]; j++) {
				arguments[j] = _arguments[argumentsIndex++];
			}

			if (!_calledContracts[i].call(_methodSignatures[i], arguments[i])) {
				throw;
			}
		}
	}

	function consent(bytes32 _hash) {
		consentStates[_hash][msg.sender] = ConsentState.CONSENTED;
	}

	function sendEther(address _recipient, uint _amount) external onlySelf {
		if (!_recipient.send(_amount)) {
			throw;
		}
	}

	function changeParticipants(address[] _participants) external onlySelf {
		participants = _participants;
	}

	function clean(bytes32[] _hashes, address[] _participants) external onlySelf {
		for (uint i = 0; i < _hashes.length; i++) {
			for (uint j = 0; j < _participants.length; j++) {
				delete consentStates[_hashes[i]][_participants[j]];
			}
		}
	}

	function kill(address _recipient) external onlySelf {
		selfdestruct(_recipient);
	}
}


Make INFTFuseWrapper an interface instead of an abstract contract

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

uint96 constant CANNOT_UNWRAP = 1;
uint96 constant CANNOT_BURN_FUSES = 2;
uint96 constant CANNOT_TRANSFER = 4;
uint96 constant CANNOT_SET_RESOLVER = 8;
uint96 constant CANNOT_SET_TTL = 16;
uint96 constant CANNOT_CREATE_SUBDOMAIN = 32;
uint96 constant CANNOT_REPLACE_SUBDOMAIN = 64;
uint96 constant CAN_DO_EVERYTHING = 0;

interface INFTFuseWrapper is IERC1155 {
    event Wrap(
        bytes32 indexed parentNode,
        string indexed label,
        address owner,
        uint96 fuses
    );

    event WrapETH2LD(bytes32 indexed labelhash, address owner, uint96 fuses);

    event Unwrap(
        bytes32 indexed parentNode,
        bytes32 indexed labelhash,
        address owner
    );

    event UnwrapETH2LD(
        bytes32 indexed labelhash,
        address registrant,
        address controller
    );

    function wrap(
        bytes32 node,
        string calldata label,
        address wrappedOwner,
        uint96 _fuses
    ) external;

    function wrapETH2LD(
        string calldata label,
        address wrappedOwner,
        uint96 _fuses
    ) external;

    function unwrap(
        bytes32 node,
        bytes32 label,
        address owner
    ) external;

    function setSubnodeRecordAndWrap(
        bytes32 node,
        string calldata label,
        address owner,
        address resolver,
        uint64 ttl,
        uint96 _fuses
    ) external returns (bytes32);

    function setSubnodeOwner(
        bytes32 node,
        bytes32 label,
        address owner
    ) external returns (bytes32);

    function setSubnodeOwnerAndWrap(
        bytes32 node,
        string calldata label,
        address newOwner,
        uint96 _fuses
    ) external returns (bytes32);

    function isOwnerOrApproved(bytes32 node, address addr)
        external

        returns (bool);

    function setResolver(bytes32 node, address resolver) external;

    function setTTL(bytes32 node, uint64 ttl) external;
}

// events for wrapping names, unwrap, setFuses
// Then log the event. parentNode, label (string), fuses, owner

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

uint96 constant CANNOT_UNWRAP = 1;
uint96 constant CANNOT_BURN_FUSES = 2;
uint96 constant CANNOT_TRANSFER = 4;
uint96 constant CANNOT_SET_RESOLVER = 8;
uint96 constant CANNOT_SET_TTL = 16;
uint96 constant CANNOT_CREATE_SUBDOMAIN = 32;
uint96 constant CANNOT_REPLACE_SUBDOMAIN = 64;
uint96 constant CAN_DO_EVERYTHING = 0;

abstract contract INFTFuseWrapper is IERC1155 {
    event Wrap(
        bytes32 indexed parentNode,
        string indexed label,
        address owner,
        uint96 fuses
    );

    event WrapETH2LD(bytes32 indexed labelhash, address owner, uint96 fuses);

    event Unwrap(
        bytes32 indexed parentNode,
        bytes32 indexed labelhash,
        address owner
    );

    event UnwrapETH2LD(
        bytes32 indexed labelhash,
        address registrant,
        address controller
    );

    function wrap(
        bytes32 node,
        string calldata label,
        address wrappedOwner,
        uint96 _fuses
    ) public virtual;

    function wrapETH2LD(
        string calldata label,
        address wrappedOwner,
        uint96 _fuses
    ) public virtual;

    function unwrap(
        bytes32 node,
        bytes32 label,
        address owner
    ) public virtual;

    function setSubnodeRecordAndWrap(
        bytes32 node,
        string calldata label,
        address owner,
        address resolver,
        uint64 ttl,
        uint96 _fuses
    ) public virtual returns (bytes32);

    function setSubnodeOwner(
        bytes32 node,
        bytes32 label,
        address owner
    ) public virtual returns (bytes32);

    function setSubnodeOwnerAndWrap(
        bytes32 node,
        string calldata label,
        address newOwner,
        uint96 _fuses
    ) public virtual returns (bytes32);

    function isOwnerOrApproved(bytes32 node, address addr)
        public
        virtual
        returns (bool);

    function setResolver(bytes32 node, address resolver) public virtual;

    function setTTL(bytes32 node, uint64 ttl) public virtual;
}

// events for wrapping names, unwrap, setFuses
// Then log the event. parentNode, label (string), fuses, owner


More precision to take into account precision needed for pluton amount of crowdfunding

/*
The Pluton Contract implements the standard token functionality (https://github.com/ethereum/EIPs/issues/20) as well as the following OPTIONAL extras intended for use by humans.

Pluton contract extends HumanStandardToken, https://github.com/consensys/tokens

.*/
contract Token {

    /// @return total amount of tokens
    function totalSupply() constant returns (uint256 supply) {}

    /// @param _owner The address from which the balance will be retrieved
    /// @return The balance
    function balanceOf(address _owner) constant returns (uint256 balance) {}

    /// @notice send `_value` token to `_to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return Whether the transfer was successful or not
    function transfer(address _to, uint256 _value) returns (bool success) {}

    /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
    /// @param _from The address of the sender
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return Whether the transfer was successful or not
    function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}

    /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _value The amount of wei to be approved for transfer
    /// @return Whether the approval was successful or not
    function approve(address _spender, uint256 _value) returns (bool success) {}

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return Amount of remaining tokens allowed to spent
    function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}

    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}

contract StandardToken is Token {

    function transfer(address _to, uint256 _value) returns (bool success) {
        //Default assumes totalSupply can't be over max (2^256 - 1).
        //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
        //Replace the if with this one instead.
        //if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
        if (balances[msg.sender] >= _value && _value > 0) {
            balances[msg.sender] -= _value;
            balances[_to] += _value;
            Transfer(msg.sender, _to, _value);
            return true;
        } else { return false; }
    }

    function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
        //same as above. Replace this line with the following if you want to protect against wrapping uints.
        //if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
        if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
            balances[_to] += _value;
            balances[_from] -= _value;
            allowed[_from][msg.sender] -= _value;
            Transfer(_from, _to, _value);
            return true;
        } else { return false; }
    }

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

    function approve(address _spender, uint256 _value) returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);
        return true;
    }

    function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
      return allowed[_owner][_spender];
    }

    mapping (address => uint256) balances;
    mapping (address => mapping (address => uint256)) allowed;
    uint256 public totalSupply;
}

contract HumanStandardToken is StandardToken {

    function () {
        //if ether is sent to this address, send it back.
        throw;
    }

    /* Public variables of the token */

    /*
    NOTE:
    The following variables are OPTIONAL vanities. One does not have to include them.
    They allow one to customise the token contract & in no way influences the core functionality.
    Some wallets/interfaces might not even bother to look at this information.
    */
    string public name;                   //fancy name: eg Simon Bucks
    uint8 public decimals;                //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
    string public symbol;                 //An identifier: eg SBX
    string public version = 'H0.1';       //human 0.1 standard. Just an arbitrary versioning scheme.

    function HumanStandardToken(
        uint256 _initialAmount,
        string _tokenName,
        uint8 _decimalUnits,
        string _tokenSymbol
        ) {
        balances[msg.sender] = _initialAmount;               // Give the creator all initial tokens
        totalSupply = _initialAmount;                        // Update total supply
        name = _tokenName;                                   // Set the name for display purposes
        decimals = _decimalUnits;                            // Amount of decimals for display purposes
        symbol = _tokenSymbol;                               // Set the symbol for display purposes
    }

    /* Approves and then calls the receiving contract */
    function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);

        //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
        //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
        //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
        if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
        return true;
    }
}

// Creates 20,000,000.000000000000000000 Pluton (PLU) Tokens
contract Pluton is HumanStandardToken(20000000000000000000000000, "Pluton", 18, "PLU") {}

/*
The Pluton Contract implements the standard token functionality (https://github.com/ethereum/EIPs/issues/20) as well as the following OPTIONAL extras intended for use by humans.

Pluton contract extends HumanStandardToken, https://github.com/consensys/tokens

.*/
contract Token {

    /// @return total amount of tokens
    function totalSupply() constant returns (uint256 supply) {}

    /// @param _owner The address from which the balance will be retrieved
    /// @return The balance
    function balanceOf(address _owner) constant returns (uint256 balance) {}

    /// @notice send `_value` token to `_to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return Whether the transfer was successful or not
    function transfer(address _to, uint256 _value) returns (bool success) {}

    /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
    /// @param _from The address of the sender
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return Whether the transfer was successful or not
    function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}

    /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _value The amount of wei to be approved for transfer
    /// @return Whether the approval was successful or not
    function approve(address _spender, uint256 _value) returns (bool success) {}

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return Amount of remaining tokens allowed to spent
    function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}

    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}

contract StandardToken is Token {

    function transfer(address _to, uint256 _value) returns (bool success) {
        //Default assumes totalSupply can't be over max (2^256 - 1).
        //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
        //Replace the if with this one instead.
        //if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
        if (balances[msg.sender] >= _value && _value > 0) {
            balances[msg.sender] -= _value;
            balances[_to] += _value;
            Transfer(msg.sender, _to, _value);
            return true;
        } else { return false; }
    }

    function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
        //same as above. Replace this line with the following if you want to protect against wrapping uints.
        //if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
        if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
            balances[_to] += _value;
            balances[_from] -= _value;
            allowed[_from][msg.sender] -= _value;
            Transfer(_from, _to, _value);
            return true;
        } else { return false; }
    }

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

    function approve(address _spender, uint256 _value) returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);
        return true;
    }

    function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
      return allowed[_owner][_spender];
    }

    mapping (address => uint256) balances;
    mapping (address => mapping (address => uint256)) allowed;
    uint256 public totalSupply;
}

contract HumanStandardToken is StandardToken {

    function () {
        //if ether is sent to this address, send it back.
        throw;
    }

    /* Public variables of the token */

    /*
    NOTE:
    The following variables are OPTIONAL vanities. One does not have to include them.
    They allow one to customise the token contract & in no way influences the core functionality.
    Some wallets/interfaces might not even bother to look at this information.
    */
    string public name;                   //fancy name: eg Simon Bucks
    uint8 public decimals;                //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
    string public symbol;                 //An identifier: eg SBX
    string public version = 'H0.1';       //human 0.1 standard. Just an arbitrary versioning scheme.

    function HumanStandardToken(
        uint256 _initialAmount,
        string _tokenName,
        uint8 _decimalUnits,
        string _tokenSymbol
        ) {
        balances[msg.sender] = _initialAmount;               // Give the creator all initial tokens
        totalSupply = _initialAmount;                        // Update total supply
        name = _tokenName;                                   // Set the name for display purposes
        decimals = _decimalUnits;                            // Amount of decimals for display purposes
        symbol = _tokenSymbol;                               // Set the symbol for display purposes
    }

    /* Approves and then calls the receiving contract */
    function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);

        //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
        //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
        //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
        if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
        return true;
    }
}

// Creates 20,000,000.00000000 Pluton (PLU) Tokens
contract Pluton is HumanStandardToken(2000000000000000, "Pluton", 8, "PLU") {}


Update escrow.sol

Update escrow.sol

pragma solidity ^0.4.11;

contract Escrow {

  struct transaction {
    uint amount;
    address sender;
    address receiver;
    uint id;
    uint deadline;
    bool accepted;
    bool senderCanWithdraw;
    bool receiverCanWithdraw;
    bool complete;
  }

  transaction[] public transactions;
  uint numTransactions = 0;
  mapping (address => uint[]) sentTransactions;
  mapping (address => uint[]) recTransactions;

  modifier isReceiver(uint id){
    require(transactions[id].receiver == msg.sender);
    _;
  }

  modifier isSender(uint id){
    require(transactions[id].sender == msg.sender);
    _;
  }

  modifier isNotComplete(uint id){
    require(!transactions[id].complete);
    _;
  }

  function Escrow() {}

  function makeTransaction(address receiver, uint deadline) payable {
    require(msg.value != 0);

    transactions.push(transaction({
      amount: msg.value,
      sender: msg.sender,
      receiver: receiver,
      id: numTransactions,
      deadline: deadline,
      accepted: false,
      senderCanWithdraw: true,
      receiverCanWithdraw: false,
      complete: false
      }));

    sentTransactions[msg.sender].push(numTransactions);
    recTransactions[receiver].push(numTransactions);
    numTransactions++;
  }

  function acceptTransaction(uint id) isReceiver(id) isNotComplete(id) {
    require(!transactions[id].accepted);

    transactions[id].accepted = true;
    transactions[id].senderCanWithdraw = false;
    transactions[id].deadline = now + (transactions[id].deadline * 1 days);
  }

  function receiverWithdrawal(uint id) isReceiver(id) isNotComplete(id) {
    require(transactions[id].receiverCanWithdraw ||
    ((now > transactions[id].deadline) && (transactions[id].accepted)));

    uint amount = transactions[id].amount;
    transactions[id].complete = true;

    msg.sender.transfer(amount);
  }

  function senderWithdrawal(uint id) isSender(id) isNotComplete(id) {
    require(transactions[id].senderCanWithdraw);

    uint amount = transactions[id].amount;
    transactions[id].complete = true;

    msg.sender.transfer(amount);
    }

  function finalizeTransaction(uint id) isSender(id) isNotComplete(id) {
    require(!transactions[id].receiverCanWithdraw);

    transactions[id].receiverCanWithdraw = true;
    transactions[id].senderCanWithdraw = false;
  }

  function refundTransaction(uint id) isReceiver(id) isNotComplete(id) {
    require(transactions[id].accepted);

    transactions[id].receiverCanWithdraw = false;
    transactions[id].senderCanWithdraw = true;
  }

  function disputeTransaction(uint id, uint addedTime) isSender(id) isNotComplete(id) {
    require(now <= transactions[id].deadline && !transactions[id].receiverCanWithdraw);

    transactions[id].deadline += (addedTime * 1 days);
  }

  function getSentTransactionData(uint id) isSender(id) constant returns(uint amount,
                                                                     uint deadline,
                                                                     bool accepted,
                                                                     bool senderWithdrawl) {
    return(
      transactions[id].amount,
      transactions[id].deadline,
      transactions[id].accepted,
      transactions[id].senderCanWithdraw
      );
  }

  function getRecTransactionData(uint id) isReceiver(id) constant returns(uint amount,
                                                                  uint deadline,
                                                                  bool accepted,
                                                                  bool receiverCanWithdraw) {

    bool withdraw = false;
    if (transactions[id].receiverCanWithdraw || now > transactions[id].deadline) {
      withdraw = true;
    }

    return(
      transactions[id].amount,
      transactions[id].deadline,
      transactions[id].accepted,
      withdraw
      );
  }

  function getSentTransactions() constant returns(uint[] ids,
                                                  address[] addresses) {
    uint length = 0;
    for (uint p = 0; p < sentTransactions[msg.sender].length; p++){
      var z = transactions[sentTransactions[msg.sender][p]];
      if (!z.complete) {
        length++;
      }
    }

    uint[] memory returnIds = new uint[](length);
    address[] memory returnAddresses = new address[](length);
    uint num = 0;

    for (uint i = 0; i < sentTransactions[msg.sender].length; i++) {
      var x = transactions[sentTransactions[msg.sender][i]];
      if (!x.complete) {
        returnIds[num] = x.id;
        returnAddresses[num] = x.receiver;
        num++;
      }
    }

    return(returnIds, returnAddresses);
  }

  function getRecTransactions() constant returns(uint[] ids,
                                                  address[] addresses) {
  uint length = 0;
  for (uint p = 0; p < sentTransactions[msg.sender].length; p++) {
    var z = transactions[sentTransactions[msg.sender][p]];
      if (!z.complete) {
        length++;
      }
    }

    uint[] memory returnIds = new uint[](length);
    address[] memory returnAddresses = new address[](length);
    uint num = 0;

    for (uint i = 0; i < recTransactions[msg.sender].length; i++) {
      var x = transactions[recTransactions[msg.sender][i]];
      if (!x.complete) {
      returnIds[num] = x.id;
      returnAddresses[num] = x.receiver;
      num++;
      }
    }

    return(returnIds, returnAddresses);
  }

  function () {
    revert();
  }
}

pragma solidity ^0.4.11;

contract Escrow {

  struct transaction {
    uint amount;
    address sender;
    address receiver;
    uint id;
    uint deadline;
    bool accepted;
    bool senderCanWithdraw;
    bool receiverCanWithdraw;
    bool complete;
  }

  transaction[] public transactions;
  uint numTransactions = 0;
  mapping (address => uint[]) sentTransactions;
  mapping (address => uint[]) recTransactions;

  modifier isReceiver(uint id){
    require(transactions[id].receiver == msg.sender);
    _;
  }

  modifier isSender(uint id){
    require(transactions[id].sender == msg.sender);
    _;
  }

  modifier isNotComplete(uint id){
    require(!transactions[id].complete);
    _;
  }

  function Escrow() {}

  function makeTransaction(address receiver, uint deadline) payable {
    require(msg.value != 0);

    transactions.push(transaction({
      amount: msg.value,
      sender: msg.sender,
      receiver: receiver,
      id: numTransactions,
      deadline: deadline,
      accepted: false,
      senderCanWithdraw: true,
      receiverCanWithdraw: false,
      complete: false
      }));

    sentTransactions[msg.sender].push(numTransactions);
    recTransactions[receiver].push(numTransactions);
    numTransactions++;
  }

  function acceptTransaction(uint id) isReceiver(id) isNotComplete(id) {
    require(!transactions[id].accepted);

    transactions[id].accepted = true;
    transactions[id].senderCanWithdraw = false;
    transactions[id].deadline = now + (transactions[id].deadline * 1 days);
  }

  function receiverWithdrawal(uint id) isReceiver(id) isNotComplete(id) {
    require(transactions[id].receiverCanWithdraw ||
    ((now > transactions[id].deadline) && (transactions[id].accepted)));

    uint amount = transactions[id].amount;
    transactions[id].complete = true;

    msg.sender.transfer(amount);
  }

  function senderWithdrawal(uint id) isSender(id) isNotComplete(id) {
    require(transactions[id].senderCanWithdraw);

    uint amount = transactions[id].amount;
    transactions[id].complete = true;

    msg.sender.transfer(amount);
    }

  function finalizeTransaction(uint id) isSender(id) isNotComplete(id) {
    require(!transactions[id].receiverCanWithdraw);

    transactions[id].receiverCanWithdraw = true;
    transactions[id].senderCanWithdraw = false;
  }

  function refundTransaction(uint id) isReceiver(id) isNotComplete(id) {
    require(transactions[id].accepted);

    transactions[id].receiverCanWithdraw = false;
    transactions[id].senderCanWithdraw = true;
  }

  function disputeTransaction(uint id, uint addedTime) isSender(id) isNotComplete(id) {
    require(now <= transactions[id].deadline && !transactions[id].receiverCanWithdraw);

    transactions[id].deadline += (addedTime * 1 days);
  }

  function getSentTransactionData(uint id) isSender(id) constant returns(uint amount,
                                                                     uint deadline,
                                                                     bool accepted,
                                                                     bool senderWithdrawl) {
    return(
      transactions[id].amount,
      transactions[id].deadline,
      transactions[id].accepted,
      transactions[id].senderCanWithdraw
      );
  }

  function getRecTransactionData(uint id) isReceiver(id) constant returns(uint amount,
                                                                  uint deadline,
                                                                  bool accepted,
                                                                  bool receiverCanWithdraw) {

    bool withdraw;
    if (transactions[id].receiverCanWithdraw || now > transactions[id].deadline) {
      withdraw = true;
    }
    else {
      withdraw = false;
    }

    return(
      transactions[id].amount,
      transactions[id].deadline,
      transactions[id].accepted,
      withdraw
      );
  }

  function getSentTransactions() constant returns(uint[] ids,
                                                  address[] addresses) {
    uint length = 0;
    for (uint p = 0; p < sentTransactions[msg.sender].length; p++){
      var z = transactions[sentTransactions[msg.sender][p]];
      if (!z.complete) {
        length++;
      }
    }

    uint[] memory returnIds = new uint[](length);
    address[] memory returnAddresses = new address[](length);
    uint num = 0;

    for (uint i = 0; i < sentTransactions[msg.sender].length; i++) {
      var x = transactions[sentTransactions[msg.sender][i]];
      if (!x.complete) {
        returnIds[num] = x.id;
        returnAddresses[num] = x.receiver;
        num++;
      }
    }

    return(returnIds, returnAddresses);
  }

  function getRecTransactions() constant returns(uint[] ids,
                                                  address[] addresses) {
  uint length = 0;
  for (uint p = 0; p < sentTransactions[msg.sender].length; p++) {
    var z = transactions[sentTransactions[msg.sender][p]];
      if (!z.complete) {
        length++;
      }
    }

    uint[] memory returnIds = new uint[](length);
    address[] memory returnAddresses = new address[](length);
    uint num = 0;

    for (uint i = 0; i < recTransactions[msg.sender].length; i++) {
      var x = transactions[recTransactions[msg.sender][i]];
      if (!x.complete) {
      returnIds[num] = x.id;
      returnAddresses[num] = x.receiver;
      num++;
      }
    }

    return(returnIds, returnAddresses);
  }

  function () {
    revert();
  }
}


upd emission limit commitment

upd emission limit commitment

pragma solidity ^0.4.4;
import 'token/TokenEmission.sol';
import 'token/Token.sol';
import './InsuranceHolder.sol';
import './Operated.sol';

contract Commitment is Operated {
    // Operated token
    TokenEmission public tokenEmission;

    // Commitment percent
    uint public percentage;

    // Commitment token address
    Token public token;

    // Address of insurance contract
    InsuranceHolder public insuranceHolder;

    /**
     * @dev Commitment contract constructor
     * @param _operator is an operator if this Commitment
     * @param _token is an associated issuer token
     * @param _holder is an issurance holder address
     */
    function Commitment(address _operator,
                     address _token,
                     address _holder) Operated(_operator) {
        // null check
        if (_operator == 0 || _token == 0 || _holder == 0) throw;

        tokenEmission = TokenEmission(_token);
        insuranceHolder = InsuranceHolder(_holder);
        token = insuranceHolder.token();
    }

    /**
     * @dev Commitment percentage setter
     * @param _percentage is a new hold percent
     */
    function setPercentage(uint _percentage) onlyOperator {
        // Assertion for % value
        if (_percentage > 100) throw;

        percentage = _percentage;
    }

    /**
     * @dev Get balance
     * @return amount of tokens on balance
     */
    function balance() constant returns (uint256)
    { return token.balanceOf(this); }

    /**
     * @dev Get emission limit
     * @return amount of tokens
     */
    function emissionLimit() constant returns (uint256)
    {
        if (percentage == 0) return 0;
        var balance = balance() / (10 ** token.decimals);
        var limit = balance * 100 / percentage;
        return limit * (10 ** tokenEmission.decimals);
    }

    /**
     * @dev Commitment emission
     * @param _value is a emission value
     */
    function emission(uint _value) onlyOwner {
        uint limit = emissionLimit();

        // Limit checking
        if (_value > limit) throw;

        // Emission
        tokenEmission.emission(_value);

        // Hold
        var holdPercentage = _value * 100 / limit;
        var holdValue = balance() * holdPercentage / 100;
        token.approve(insuranceHolder, holdValue);
        if (!insuranceHolder.transfer(holdValue)) throw;
    }

    /**
     * @dev Transfer to issuer
     * @param _value is a transfer value
     */
    function transfer(uint _value) onlyOwner
    { if (!tokenEmission.transfer(tokenEmission.owner(), _value)) throw; }
}

pragma solidity ^0.4.4;
import 'token/TokenEmission.sol';
import 'token/Token.sol';
import './InsuranceHolder.sol';
import './Operated.sol';

contract Commitment is Operated {
    // Operated token
    TokenEmission public tokenEmission;

    // Commitment percent
    uint public percentage;

    // Commitment token address
    Token public token;

    // Address of insurance contract
    InsuranceHolder public insuranceHolder;

    /**
     * @dev Commitment contract constructor
     * @param _operator is an operator if this Commitment
     * @param _token is an associated issuer token
     * @param _holder is an issurance holder address
     */
    function Commitment(address _operator,
                     address _token,
                     address _holder) Operated(_operator) {
        // null check
        if (_operator == 0 || _token == 0 || _holder == 0) throw;

        tokenEmission = TokenEmission(_token);
        insuranceHolder = InsuranceHolder(_holder);
        token = insuranceHolder.token();
    }

    /**
     * @dev Commitment percentage setter
     * @param _percentage is a new hold percent
     */
    function setPercentage(uint _percentage) onlyOperator {
        // Assertion for % value
        if (_percentage > 100) throw;

        percentage = _percentage;
    }

    /**
     * @dev Get balance
     * @return amount of tokens on balance
     */
    function balance() constant returns (uint256)
    { return token.balanceOf(this); }

    /**
     * @dev Get emission limit
     * @return amount of tokens
     */
    function emissionLimit() constant returns (uint256)
    {
        if (percentage == 0) return 0;
        return balance() * 100 / percentage;
    }

    /**
     * @dev Commitment emission
     * @param _value is a emission value
     */
    function emission(uint _value) onlyOwner {
        uint limit = emissionLimit();

        // Limit checking
        if (_value > limit) throw;

        // Emission
        tokenEmission.emission(_value);

        // Hold
        var holdPercentage = _value * 100 / limit;
        var holdValue = balance() * holdPercentage / 100;
        token.approve(insuranceHolder, holdValue);
        if (!insuranceHolder.transfer(holdValue)) throw;
    }

    /**
     * @dev Transfer to issuer
     * @param _value is a transfer value
     */
    function transfer(uint _value) onlyOwner
    { if (!tokenEmission.transfer(tokenEmission.owner(), _value)) throw; }
}


Refactor: remove instance variable 'numberOfQuestions'

pragma solidity ^0.4.18;

contract DQuestions {
    string[] questions;

    function numberOfQuestions() public view returns (uint) {
        return questions.length;
    }

    function add(string question) public {
        questions.push(question);
    }

    function getQuestion(uint index) public view returns (string) {
        return questions[index];
    }
}

pragma solidity ^0.4.18;

contract DQuestions {
    uint public numberOfQuestions;
    string[] questions;

    function add(string question) public {
        questions.push(question);
        numberOfQuestions++;
    }

    function getQuestion(uint index) public view returns (string) {
        return questions[index];
    }
}


Make Context abstract (#2229)

Make Context abstract (#2229)

pragma solidity ^0.6.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

pragma solidity ^0.6.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
contract Context {
    // Empty internal constructor, to prevent people from mistakenly deploying
    // an instance of this contract, which should be used via inheritance.
    constructor () internal { }

    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}