Revoke confirmation.

Revoke confirmation.

//sol Wallet
// Multi-sig, daily-limited account proxy/wallet.
// @authors:
// Gav Wood <g@ethdev.com>
// inheritable "property" contract that enables methods to be protected by requiring the acquiescence of either a
// single, or, crucially, each of a number of, designated owners.
// usage:
// use modifiers onlyowner (just own owned) or onlymanyowners(hash), whereby the same hash must be provided by
// some number (specified in constructor) of the set of owners (specified in the constructor, modifiable) before the
// interior is executed.
contract multiowned {
    // struct for the status of a pending operation.
    struct PendingState {
        uint yetNeeded;
        uint ownersDone;
        uint index;
    }
    // this contract only has five types of events: it can accept a confirmation, in which case
    // we record owner and operation (hash) alongside it.
    event Confirmation(address owner, bytes32 operation);
    // some others are in the case of an owner changing.
    event OwnerChanged(address oldOwner, address newOwner);
    event OwnerAdded(address newOwner);
    event OwnerRemoved(address oldOwner);
    // the last one is emitted if the required signatures change
    event RequirementChanged(uint newRequirement);
    // constructor is given number of sigs required to do protected "onlymanyowners" transactions
    // as well as the selection of addresses capable of confirming them.
    function multiowned() {
        m_required = 1;
        m_numOwners = 1;
        m_owners[m_numOwners] = uint(msg.sender);
        m_ownerIndex[uint(msg.sender)] = m_numOwners;
    }
    // simple single-sig function modifier.
    modifier onlyowner {
        if (isOwner(msg.sender))
            _
    }
    // multi-sig function modifier: the operation must have an intrinsic hash in order
    // that later attempts can be realised as the same underlying operation and
    // thus count as confirmations.
    modifier onlymanyowners(bytes32 _operation) {
        if (confirmed(_operation))
            _
    }
    // Revokes a prior confirmation of the given operation
    function revoke(bytes32 _operation) external {
        uint ownerIndex = m_ownerIndex[msg.sender];
        // make sure they're an owner
        if (ownerIndex == 0) return;
        uint ownerIndexBit = 2**ownerIndex;
        var pending = m_pending[_operation];
        if (pending.ownersDone & ownerIndexBit > 0) {
            pending.yetNeeded++;
            pending.ownersDone -= ownerIndexBit;
        }
    }
    function confirmed(bytes32 _operation) internal returns (bool) {
        // determine what index the present sender is:
        uint ownerIndex = m_ownerIndex[uint(msg.sender)];
        // make sure they're an owner
        if (ownerIndex == 0) return;

        var pending = m_pending[_operation];
        // if we're not yet working on this operation, switch over and reset the confirmation status.
        if (pending.yetNeeded == 0) {
            // reset count of confirmations needed.
            pending.yetNeeded = m_required;
            // reset which owners have confirmed (none) - set our bitmap to 0.
            pending.ownersDone = 0;
            pending.index = m_pendingIndex.length++;
            m_pendingIndex[pending.index] = _operation;
        }
        // determine the bit to set for this owner.
        uint ownerIndexBit = 2**ownerIndex;
        // make sure we (the message sender) haven't confirmed this operation previously.
        if (pending.ownersDone & ownerIndexBit == 0) {
            Confirmation(msg.sender, _operation);
            // ok - check if count is enough to go ahead.
            if (pending.yetNeeded <= 1) {
                // enough confirmations: reset and run interior.
                delete m_pendingIndex[m_pending[_operation].index];
                delete m_pending[_operation];
                return true;
            }
            else
            {
                // not enough: record that this owner in particular confirmed.
                pending.yetNeeded--;
                pending.ownersDone |= ownerIndexBit;
            }
        }
    }
    // Replaces an owner `_from` with another `_to`.
    function changeOwner(address _from, address _to) onlymanyowners(sha3(msg.data)) external {
        if (isOwner(_to)) return;
        uint ownerIndex = m_ownerIndex[uint(_from)];
        if (ownerIndex == 0) return;

        clearPending();
        m_owners[ownerIndex] = uint(_to);
        m_ownerIndex[uint(_from)] = 0;
        m_ownerIndex[uint(_to)] = ownerIndex;
        OwnerChanged(_from, _to);
    }
    function addOwner(address _owner) onlymanyowners(sha3(msg.data)) external {
        if (isOwner(_owner)) return;

        clearPending();
        if (m_numOwners >= c_maxOwners)
            reorganizeOwners();
        if (m_numOwners >= c_maxOwners)
            return;
        m_numOwners++;
        m_owners[m_numOwners] = uint(_owner);
        m_ownerIndex[uint(_owner)] = m_numOwners;
        OwnerAdded(_owner);
    }
    function removeOwner(address _owner) onlymanyowners(sha3(msg.data)) external {
        uint ownerIndex = m_ownerIndex[uint(_owner)];
        if (ownerIndex == 0) return;
        if (m_required > m_numOwners - 1) return;

        m_owners[ownerIndex] = 0;
        m_ownerIndex[uint(_owner)] = 0;
        clearPending();
        reorganizeOwners(); //make sure m_numOwner is equal to the number of owners and always points to the optimal free slot
        OwnerRemoved(_owner);
    }
    function reorganizeOwners() private returns (bool) {
        uint free = 1;
        while (free < m_numOwners)
        {
            while (free < m_numOwners && m_owners[free] != 0) free++;
            while (m_numOwners > 1 && m_owners[m_numOwners] == 0) m_numOwners--;
            if (free < m_numOwners && m_owners[m_numOwners] != 0 && m_owners[free] == 0)
            {
                m_owners[free] = m_owners[m_numOwners];
                m_ownerIndex[m_owners[free]] = free;
                m_owners[m_numOwners] = 0;
            }
        }
    }
    function clearPending() private {
        uint length = m_pendingIndex.length;
        for (uint i = 0; i < length; ++i)
            if (m_pendingIndex[i] != 0)
                delete m_pending[m_pendingIndex[i]];
        delete m_pendingIndex;
    }
    function changeRequirement(uint _newRequired) onlymanyowners(sha3(msg.data)) external {
        if (_newRequired < m_numOwners) return;
        m_required = _newRequired;
        clearPending();
        RequirementChanged(_newRequired);
    }
    function isOwner(address _addr) returns (bool) {
        return m_ownerIndex[uint(_addr)] > 0;
    }

    // the number of owners that must confirm the same operation before it is run.
    uint m_required;
    // pointer used to find a free slot in m_owners
    uint m_numOwners;
    // list of owners
    uint[256] m_owners;
    uint constant c_maxOwners = 250;
    // index on the list of owners to allow reverse lookup
    mapping(uint => uint) m_ownerIndex;
    // the ongoing operations.
    mapping(bytes32 => PendingState) m_pending;
    bytes32[] m_pendingIndex;
}

// inheritable "property" contract that enables methods to be protected by placing a linear limit (specifiable)
// on a particular resource per calendar day. is multiowned to allow the limit to be altered. resource that method
// uses is specified in the modifier.
contract daylimit is multiowned {
    // constructor - just records the present day's index.
    function daylimit() {
        m_lastDay = today();
    }
    // (re)sets the daily limit. needs many of the owners to confirm. doesn't alter the amount already spent today.
    function setDailyLimit(uint _newLimit) onlymanyowners(sha3(msg.data)) external {
        m_dailyLimit = _newLimit;
    }
    // (re)sets the daily limit. needs many of the owners to confirm. doesn't alter the amount already spent today.
    function resetSpentToday() onlymanyowners(sha3(msg.data)) external {
        m_spentToday = 0;
    }
    // checks to see if there is at least `_value` left from the daily limit today. if there is, subtracts it and
    // returns true. otherwise just returns false.
    function underLimit(uint _value) internal onlyowner returns (bool) {
        // reset the spend limit if we're on a different day to last time.
        if (today() > m_lastDay) {
            m_spentToday = 0;
            m_lastDay = today();
        }
        // check to see if there's enough left - if so, subtract and return true.
        if (m_spentToday + _value >= m_spentToday && m_spentToday + _value <= m_dailyLimit) {
            m_spentToday += _value;
            return true;
        }
        return false;
    }
    // simple modifier for daily limit.
    modifier limitedDaily(uint _value) {
        if (underLimit(_value))
            _
    }
    // determines today's index.
    function today() private constant returns (uint) { return now / 1 days; }
    uint m_spentToday;
    uint m_dailyLimit;
    uint m_lastDay;
}
// interface contract for multisig proxy contracts; see below for docs.
contract multisig {
    event Deposit(address from, uint value);
    event SingleTransact(address owner, uint value, address to, bytes data);
    event MultiTransact(address owner, bytes32 operation, uint value, address to, bytes data);
    event ConfirmationNeeded(bytes32 operation, address initiator, uint value, address to, bytes data);
    function changeOwner(address _from, address _to) external;
    function execute(address _to, uint _value, bytes _data) external returns (bytes32);
    function confirm(bytes32 _h) returns (bool);
}
// usage:
// bytes32 h = Wallet(w).from(oneOwner).transact(to, value, data);
// Wallet(w).from(anotherOwner).confirm(h);
contract Wallet is multisig, multiowned, daylimit {
    // Transaction structure to remember details of transaction lest it need be saved for a later call.
    struct Transaction {
        address to;
        uint value;
        bytes data;
    }
    /*
    // logged events:
    // Funds has arrived into the wallet (record how much).
    event Deposit(address from, uint value);
    // Single transaction going out of the wallet (record who signed for it, how much, and to whom it's going).
    event SingleTransact(address owner, uint value, address to, bytes data);
    // Multi-sig transaction going out of the wallet (record who signed for it last, the operation hash, how much, and to whom it's going).
    event MultiTransact(address owner, bytes32 operation, uint value, address to, bytes data);*/
    // constructor - just pass on the owner arra to the multiowned.
    event Created();
    function Wallet() {
        Created();
    }
    // kills the contract sending everything to `_to`.
    function kill(address _to) onlymanyowners(sha3(msg.data)) external {
        suicide(_to);
    }
    // gets called when no other function matches
    function() {
        // just being sent some cash?
        if (msg.value > 0)
            Deposit(msg.sender, msg.value);
    }
    // Outside-visible transact entry point. Executes transacion immediately if below daily spend limit.
    // If not, goes into multisig process. We provide a hash on return to allow the sender to provide
    // shortcuts for the other confirmations (allowing them to avoid replicating the _to, _value
    // and _data arguments). They still get the option of using them if they want, anyways.
    function execute(address _to, uint _value, bytes _data) external returns (bytes32 _r) {
        // first, take the opportunity to check that we're under the daily limit.
        if (underLimit(_value)) {
            SingleTransact(msg.sender, _value, _to, _data);
            // yes - just execute the call.
            _to.call.value(_value)(_data);
            return 0;
        }
        // determine our operation hash.
        _r = sha3(msg.data);
        if (!confirm(_r) && m_txs[_r].to == 0) {
            m_txs[_r].to = _to;
            m_txs[_r].value = _value;
            m_txs[_r].data = _data;
            ConfirmationNeeded(_r, msg.sender, _value, _to, _data);
        }
    }
    // confirm a transaction through just the hash. we use the previous transactions map, m_txs, in order
    // to determine the body of the transaction from the hash provided.
    function confirm(bytes32 _h) onlymanyowners(_h) returns (bool) {
        if (m_txs[_h].to != 0) {
            m_txs[_h].to.call.value(m_txs[_h].value)(m_txs[_h].data);
            MultiTransact(msg.sender, _h, m_txs[_h].value, m_txs[_h].to, m_txs[_h].data);
            delete m_txs[_h];
            return true;
        }
    }
    // // internally confirm transaction with all of the info. returns true iff confirmed good and executed.
    // function confirmVerbose(bytes32 _h, address _to, uint _value, bytes _data) private onlymanyowners(_h) returns (bool) {
    //     _to.call.value(_value)(_data);
    //     MultiTransact("out", msg.sender, _h, _value, _to);
    //     return true;
    // }
    // pending transactions we have at present.
    mapping (bytes32 => Transaction) m_txs;
}

//sol Wallet
// Multi-sig, daily-limited account proxy/wallet.
// @authors:
// Gav Wood <g@ethdev.com>
// inheritable "property" contract that enables methods to be protected by requiring the acquiescence of either a
// single, or, crucially, each of a number of, designated owners.
// usage:
// use modifiers onlyowner (just own owned) or onlymanyowners(hash), whereby the same hash must be provided by
// some number (specified in constructor) of the set of owners (specified in the constructor, modifiable) before the
// interior is executed.
contract multiowned {
    // struct for the status of a pending operation.
    struct PendingState {
        uint yetNeeded;
        uint ownersDone;
        uint index;
    }
    // this contract only has five types of events: it can accept a confirmation, in which case
    // we record owner and operation (hash) alongside it.
    event Confirmation(address owner, bytes32 operation);
    // some others are in the case of an owner changing.
    event OwnerChanged(address oldOwner, address newOwner);
    event OwnerAdded(address newOwner);
    event OwnerRemoved(address oldOwner);
    // the last one is emitted if the required signatures change
    event RequirementChanged(uint newRequirement);
    // constructor is given number of sigs required to do protected "onlymanyowners" transactions
    // as well as the selection of addresses capable of confirming them.
    function multiowned() {
        m_required = 1;
        m_numOwners = 1;
        m_owners[m_numOwners] = uint(msg.sender);
        m_ownerIndex[uint(msg.sender)] = m_numOwners;
    }
    // simple single-sig function modifier.
    modifier onlyowner {
        if (isOwner(msg.sender))
            _
    }
    // multi-sig function modifier: the operation must have an intrinsic hash in order
    // that later attempts can be realised as the same underlying operation and
    // thus count as confirmations.
    modifier onlymanyowners(bytes32 _operation) {
        if (confirmed(_operation))
            _
    }
    function confirmed(bytes32 _operation) internal returns (bool) {
        // determine what index the present sender is:
        uint ownerIndex = m_ownerIndex[uint(msg.sender)];
        // make sure they're an owner
        if (ownerIndex == 0) return;

        var pending = m_pending[_operation];
        // if we're not yet working on this operation, switch over and reset the confirmation status.
        if (pending.yetNeeded == 0) {
            // reset count of confirmations needed.
            pending.yetNeeded = m_required;
            // reset which owners have confirmed (none) - set our bitmap to 0.
            pending.ownersDone = 0;
            pending.index = m_pendingIndex.length++;
            m_pendingIndex[pending.index] = _operation;
        }
        // determine the bit to set for this owner.
        uint ownerIndexBit = 2**ownerIndex;
        // make sure we (the message sender) haven't confirmed this operation previously.
        if (pending.ownersDone & ownerIndexBit == 0) {
            Confirmation(msg.sender, _operation);
            // ok - check if count is enough to go ahead.
            if (pending.yetNeeded <= 1) {
                // enough confirmations: reset and run interior.
                delete m_pendingIndex[m_pending[_operation].index];
                delete m_pending[_operation];
                return true;
            }
            else
            {
                // not enough: record that this owner in particular confirmed.
                pending.yetNeeded--;
                pending.ownersDone |= ownerIndexBit;
            }
        }
    }
    // Replaces an owner `_from` with another `_to`.
    function changeOwner(address _from, address _to) onlymanyowners(sha3(msg.data)) external {
        if (isOwner(_to)) return;
        uint ownerIndex = m_ownerIndex[uint(_from)];
        if (ownerIndex == 0) return;

        clearPending();
        m_owners[ownerIndex] = uint(_to);
        m_ownerIndex[uint(_from)] = 0;
        m_ownerIndex[uint(_to)] = ownerIndex;
        OwnerChanged(_from, _to);
    }
    function addOwner(address _owner) onlymanyowners(sha3(msg.data)) external {
        if (isOwner(_owner)) return;

        clearPending();
        if (m_numOwners >= c_maxOwners)
            reorganizeOwners();
        if (m_numOwners >= c_maxOwners)
            return;
        m_numOwners++;
        m_owners[m_numOwners] = uint(_owner);
        m_ownerIndex[uint(_owner)] = m_numOwners;
        OwnerAdded(_owner);
    }
    function removeOwner(address _owner) onlymanyowners(sha3(msg.data)) external {
        uint ownerIndex = m_ownerIndex[uint(_owner)];
        if (ownerIndex == 0) return;
        if (m_required > m_numOwners - 1) return;

        m_owners[ownerIndex] = 0;
        m_ownerIndex[uint(_owner)] = 0;
        clearPending();
        reorganizeOwners(); //make sure m_numOwner is equal to the number of owners and always points to the optimal free slot
        OwnerRemoved(_owner);
    }
    function reorganizeOwners() private returns (bool) {
        uint free = 1;
        while (free < m_numOwners)
        {
            while (free < m_numOwners && m_owners[free] != 0) free++;
            while (m_numOwners > 1 && m_owners[m_numOwners] == 0) m_numOwners--;
            if (free < m_numOwners && m_owners[m_numOwners] != 0 && m_owners[free] == 0)
            {
                m_owners[free] = m_owners[m_numOwners];
                m_ownerIndex[m_owners[free]] = free;
                m_owners[m_numOwners] = 0;
            }
        }
    }
    function clearPending() private {
        uint length = m_pendingIndex.length;
        for (uint i = 0; i < length; ++i)
            if (m_pendingIndex[i] != 0)
                delete m_pending[m_pendingIndex[i]];
        delete m_pendingIndex;
    }
    function changeRequirement(uint _newRequired) onlymanyowners(sha3(msg.data)) external {
        if (_newRequired < m_numOwners) return;
        m_required = _newRequired;
        clearPending();
        RequirementChanged(_newRequired);
    }
    function isOwner(address _addr) returns (bool) {
        return m_ownerIndex[uint(_addr)] > 0;
    }

    // the number of owners that must confirm the same operation before it is run.
    uint m_required;
    // pointer used to find a free slot in m_owners
    uint m_numOwners;
    // list of owners
    uint[256] m_owners;
    uint constant c_maxOwners = 250;
    // index on the list of owners to allow reverse lookup
    mapping(uint => uint) m_ownerIndex;
    // the ongoing operations.
    mapping(bytes32 => PendingState) m_pending;
    bytes32[] m_pendingIndex;
}

// inheritable "property" contract that enables methods to be protected by placing a linear limit (specifiable)
// on a particular resource per calendar day. is multiowned to allow the limit to be altered. resource that method
// uses is specified in the modifier.
contract daylimit is multiowned {
    // constructor - just records the present day's index.
    function daylimit() {
        m_lastDay = today();
    }
    // (re)sets the daily limit. needs many of the owners to confirm. doesn't alter the amount already spent today.
    function setDailyLimit(uint _newLimit) onlymanyowners(sha3(msg.data)) external {
        m_dailyLimit = _newLimit;
    }
    // (re)sets the daily limit. needs many of the owners to confirm. doesn't alter the amount already spent today.
    function resetSpentToday() onlymanyowners(sha3(msg.data)) external {
        m_spentToday = 0;
    }
    // checks to see if there is at least `_value` left from the daily limit today. if there is, subtracts it and
    // returns true. otherwise just returns false.
    function underLimit(uint _value) internal onlyowner returns (bool) {
        // reset the spend limit if we're on a different day to last time.
        if (today() > m_lastDay) {
            m_spentToday = 0;
            m_lastDay = today();
        }
        // check to see if there's enough left - if so, subtract and return true.
        if (m_spentToday + _value >= m_spentToday && m_spentToday + _value <= m_dailyLimit) {
            m_spentToday += _value;
            return true;
        }
        return false;
    }
    // simple modifier for daily limit.
    modifier limitedDaily(uint _value) {
        if (underLimit(_value))
            _
    }
    // determines today's index.
    function today() private constant returns (uint) { return now / 1 days; }
    uint m_spentToday;
    uint m_dailyLimit;
    uint m_lastDay;
}
// interface contract for multisig proxy contracts; see below for docs.
contract multisig {
    event Deposit(address from, uint value);
    event SingleTransact(address owner, uint value, address to, bytes data);
    event MultiTransact(address owner, bytes32 operation, uint value, address to, bytes data);
    event ConfirmationNeeded(bytes32 operation, address initiator, uint value, address to, bytes data);
    function changeOwner(address _from, address _to) external;
    function execute(address _to, uint _value, bytes _data) external returns (bytes32);
    function confirm(bytes32 _h) returns (bool);
}
// usage:
// bytes32 h = Wallet(w).from(oneOwner).transact(to, value, data);
// Wallet(w).from(anotherOwner).confirm(h);
contract Wallet is multisig, multiowned, daylimit {
    // Transaction structure to remember details of transaction lest it need be saved for a later call.
    struct Transaction {
        address to;
        uint value;
        bytes data;
    }
    /*
    // logged events:
    // Funds has arrived into the wallet (record how much).
    event Deposit(address from, uint value);
    // Single transaction going out of the wallet (record who signed for it, how much, and to whom it's going).
    event SingleTransact(address owner, uint value, address to, bytes data);
    // Multi-sig transaction going out of the wallet (record who signed for it last, the operation hash, how much, and to whom it's going).
    event MultiTransact(address owner, bytes32 operation, uint value, address to, bytes data);*/
    // constructor - just pass on the owner arra to the multiowned.
    event Created();
    function Wallet() {
        Created();
    }
    // kills the contract sending everything to `_to`.
    function kill(address _to) onlymanyowners(sha3(msg.data)) external {
        suicide(_to);
    }
    // gets called when no other function matches
    function() {
        // just being sent some cash?
        if (msg.value > 0)
            Deposit(msg.sender, msg.value);
    }
    // Outside-visible transact entry point. Executes transacion immediately if below daily spend limit.
    // If not, goes into multisig process. We provide a hash on return to allow the sender to provide
    // shortcuts for the other confirmations (allowing them to avoid replicating the _to, _value
    // and _data arguments). They still get the option of using them if they want, anyways.
    function execute(address _to, uint _value, bytes _data) external returns (bytes32 _r) {
        // first, take the opportunity to check that we're under the daily limit.
        if (underLimit(_value)) {
            SingleTransact(msg.sender, _value, _to, _data);
            // yes - just execute the call.
            _to.call.value(_value)(_data);
            return 0;
        }
        // determine our operation hash.
        _r = sha3(msg.data);
        if (!confirm(_r) && m_txs[_r].to == 0) {
            m_txs[_r].to = _to;
            m_txs[_r].value = _value;
            m_txs[_r].data = _data;
            ConfirmationNeeded(_r, msg.sender, _value, _to, _data);
        }
    }
    // confirm a transaction through just the hash. we use the previous transactions map, m_txs, in order
    // to determine the body of the transaction from the hash provided.
    function confirm(bytes32 _h) onlymanyowners(_h) returns (bool) {
        if (m_txs[_h].to != 0) {
            m_txs[_h].to.call.value(m_txs[_h].value)(m_txs[_h].data);
            MultiTransact(msg.sender, _h, m_txs[_h].value, m_txs[_h].to, m_txs[_h].data);
            delete m_txs[_h];
            return true;
        }
    }
    // // internally confirm transaction with all of the info. returns true iff confirmed good and executed.
    // function confirmVerbose(bytes32 _h, address _to, uint _value, bytes _data) private onlymanyowners(_h) returns (bool) {
    //     _to.call.value(_value)(_data);
    //     MultiTransact("out", msg.sender, _h, _value, _to);
    //     return true;
    // }
    // pending transactions we have at present.
    mapping (bytes32 => Transaction) m_txs;
}


add events

add events

pragma solidity 0.4.11;

import 'tokens/StandardToken.sol';

/**
* Depot is an ERC20 Token that enables users to effectively sell space
* Each token represents a cubic foot, which a provider has the ability to determine
*   the price of its space
* Once an agreement has concluded the token will be destroyed and Provider can register space once more
* --Hackathon coding, so dont judge me--
**/
contract Depot is StandardToken {
    string public name = 'Depot';
    uint8 public decimals = 0;
    string public symbol= 'Dpt';
    string public version = 'H0.1';

    // Vehicle and warehouses are essentially the same
    // But vehicles enables a change of locations
    Warehouse[] public listOfWarehouses;
    Warehouse[] public listOfVehicles;

    struct Warehouse {
        uint spaceAvailable;
        uint totalSpace;
        uint pricePerCubicFootPerHour;
        address owner;
        bytes32 beginningCity;
        bytes32 endingCity;
        uint beginDate;
        uint endDate;
    }

    event Agreement(address indexed requestor, address indexed seller, uint amount);
    /**
    *   Constructs a new Depot
    **/
    function Depot() {
    }

    /**
    *   Adds a warehouse to the registry
    **/
    function addWarehouse(uint256 _cubicFeet, uint pricePerCubicFootPerHour, bytes32 startingPosition) {
        totalSupply += _cubicFeet;
        listOfWarehouses.push(Warehouse(_cubicFeet, _cubicFeet, pricePerCubicFootPerHour, msg.sender, startingPosition, startingPosition, 0, 0));
    }

    /**
    *   Adds a vehicle to the registry
    **/
    function addVehicle(uint256 _cubicFeet, uint pricePerCubicFootPerHour, bytes32 startingPosition, bytes32 endingPosition, uint beginDate, uint endDate) {
        totalSupply += _cubicFeet;
        listOfVehicles.push(Warehouse(_cubicFeet, _cubicFeet, pricePerCubicFootPerHour, msg.sender, startingPosition, endingPosition, beginDate, endDate));
    }

    /**
    *   purchaseWarehouseSpace enables requestor purchases warehouse space
    **/
    function purchaseWarehouseSpace(address addr, uint cubicFeet, uint amountOfHours) payable {
        Warehouse storage warehouse = getWarehouseByAddress(addr);
        //Would probably import SafeMath module to multiply but MEH
        uint price = cubicFeet * amountOfHours * warehouse.pricePerCubicFootPerHour;
        if(msg.value != price) throw;
        if(warehouse.spaceAvailable < cubicFeet) throw;
        warehouse.spaceAvailable -= cubicFeet;
        Agreement(msg.sender, addr, price);
        totalSupply -= cubicFeet;
    }

    /**
    *   purchaseVehicleSpace enables requestor purchases vehicle space
    **/
    function purchaseVehicleSpace(address addr, uint cubicFeet, uint amountOfHours) payable {
        Warehouse storage warehouse = getVehicleByAddress(addr);
        //Would probably import SafeMath module to multiply but MEH
        uint price = cubicFeet * amountOfHours * warehouse.pricePerCubicFootPerHour;
        if(msg.value != price) throw;
        if(warehouse.spaceAvailable < cubicFeet) throw;
        warehouse.spaceAvailable -= cubicFeet;
        Agreement(msg.sender, addr, price);
        totalSupply -= cubicFeet;
    }

    /** GETTER METHODS **/

    /**
    *   warehouses grabs all of the available warehoues
    **/
    function warehouses() constant returns (uint[], uint[], uint[], address[], bytes32[], bytes32[]) {
        uint[] memory _spaceAvailable = new uint[](listOfWarehouses.length);
        uint[] memory _totalSpace = new uint[](listOfWarehouses.length);
        uint[] memory _pricePerCubicFootPerHour = new uint[](listOfWarehouses.length);
        bytes32[] memory _beginningCity = new bytes32[](listOfWarehouses.length);
        bytes32[] memory _endingCity = new bytes32[](listOfWarehouses.length);
        address[] memory _owner = new address[](listOfWarehouses.length);

        for (var i = 0; i < listOfWarehouses.length; i++) {
            _spaceAvailable[i] = listOfWarehouses[i].spaceAvailable;
            _totalSpace[i] = listOfWarehouses[i].totalSpace;
            _pricePerCubicFootPerHour[i] = listOfWarehouses[i].pricePerCubicFootPerHour;
            _owner[i] = listOfWarehouses[i].owner;
            _beginningCity[i] = listOfWarehouses[i].beginningCity;
            _endingCity[i] = listOfWarehouses[i].endingCity;
        }
        return (_spaceAvailable, _totalSpace, _pricePerCubicFootPerHour, _owner, _beginningCity, _endingCity);
    }

    /**
    *   vehicleDates grabs the date for vehicles,
    *   unable to put this in get vehicles method due to stack too deep error
    **/
    function vehicleDates() constant returns (uint[], uint[]) {
        uint[] memory _beginDate = new uint[](listOfVehicles.length);
        uint[] memory _endDate = new uint[](listOfVehicles.length);

        for (var i = 0; i < listOfVehicles.length; i++) {
          _beginDate[i] = listOfVehicles[i].beginDate;
          _endDate[i] = listOfVehicles[i].endDate;
        }
        return (_beginDate, _endDate);
    }

    /**
    * vehicles grabs all of the available vehicles
    **/
    function vehicles() constant returns (uint[], uint[], uint[], address[], bytes32[], bytes32[]) {
        uint[] memory _spaceAvailable = new uint[](listOfVehicles.length);
        uint[] memory _totalSpace = new uint[](listOfVehicles.length);
        uint[] memory _pricePerCubicFootPerHour = new uint[](listOfVehicles.length);
        bytes32[] memory _beginningCity = new bytes32[](listOfVehicles.length);
        bytes32[] memory _endingCity = new bytes32[](listOfVehicles.length);
        address[] memory _owner = new address[](listOfVehicles.length);

        for (var i = 0; i < listOfVehicles.length; i++) {
            _spaceAvailable[i] = listOfVehicles[i].spaceAvailable;
            _totalSpace[i] = listOfVehicles[i].totalSpace;
            _pricePerCubicFootPerHour[i] = listOfVehicles[i].pricePerCubicFootPerHour;
            _owner[i] = listOfVehicles[i].owner;
            _beginningCity[i] = listOfVehicles[i].beginningCity;
            _endingCity[i] = listOfVehicles[i].endingCity;
        }
        return (_spaceAvailable, _totalSpace, _pricePerCubicFootPerHour, _owner, _beginningCity, _endingCity);
    }

    /**
    * vehiclesByCity grabs vehicles from the starting city
    **/
    function vehiclesByCity(bytes32 city) constant returns (uint[], uint[], uint[], address[], bytes32[], bytes32[]) {
        uint count;
        for (var j = 0; j < listOfVehicles.length; j++) {
            if(listOfVehicles[j].beginningCity == city) count++;
        }

        uint[] memory _spaceAvailable = new uint[](count);
        uint[] memory _totalSpace = new uint[](count);
        uint[] memory _pricePerCubicFootPerHour = new uint[](count);
        bytes32[] memory _beginningCity = new bytes32[](count);
        bytes32[] memory _endingCity = new bytes32[](count);
        address[] memory _owner = new address[](count);
        count = 0;
        for (var i = 0; i < listOfVehicles.length; i++) {
            if(listOfVehicles[i].beginningCity == city) {
                _spaceAvailable[count] = listOfVehicles[i].spaceAvailable;
                _totalSpace[count] = listOfVehicles[i].totalSpace;
                _pricePerCubicFootPerHour[count] = listOfVehicles[i].pricePerCubicFootPerHour;
                _owner[count] = listOfVehicles[i].owner;
                _beginningCity[count] = listOfVehicles[i].beginningCity;
                _endingCity[count] = listOfVehicles[i].endingCity;
                count++;
            }
        }
        return (_spaceAvailable, _totalSpace, _pricePerCubicFootPerHour, _owner, _beginningCity, _endingCity);
    }

    function vehicleDatesByCity(bytes32 city) constant returns (uint[], uint[]) {
        uint count;
        for (var j = 0; j < listOfVehicles.length; j++) {
            if(listOfVehicles[j].beginningCity == city) count++;
        }

        uint[] memory _beginDate = new uint[](count);
        uint[] memory _endDate= new uint[](count);
        count = 0;
        for (var i = 0; i < listOfVehicles.length; i++) {
            if(listOfVehicles[i].beginningCity == city) {
                _beginDate[count] = listOfVehicles[i].beginDate;
                _endDate[count] = listOfVehicles[i].endDate;
                count++;
            }
        }
        return (_beginDate, _endDate);
    }

    /** INTERNAL METHODS **/

    function getVehicleByAddress(address addr) internal returns (Warehouse storage) {
        for (var i = 0; i < listOfVehicles.length; i++) {
            if(listOfVehicles[i].owner == addr) return listOfVehicles[i];
        }
        throw;
    }

    function getWarehouseByAddress(address addr) internal returns (Warehouse storage) {
        for (var i = 0; i < listOfWarehouses.length; i++) {
            if(listOfWarehouses[i].owner == addr) return listOfWarehouses[i];
        }
        throw;
    }

    /** Do not accept ether **/
    function () payable {
        throw;
    }
}

pragma solidity 0.4.11;

import 'tokens/StandardToken.sol';

/**
* Depot is an ERC20 Token that enables users to effectively sell space
* Each token represents a cubic foot, which a provider has the ability to determine
*   the price of its space
* Once an agreement has concluded the token will be destroyed and Provider can register space once more
* --Hackathon coding, so dont judge me--
**/
contract Depot is StandardToken {
    string public name = 'Depot';
    uint8 public decimals = 0;
    string public symbol= 'Dpt';
    string public version = 'H0.1';

    // Vehicle and warehouses are essentially the same
    // But vehicles enables a change of locations
    Warehouse[] public listOfWarehouses;
    Warehouse[] public listOfVehicles;

    struct Warehouse {
        uint spaceAvailable;
        uint totalSpace;
        uint pricePerCubicFootPerHour;
        address owner;
        bytes32 beginningCity;
        bytes32 endingCity;
        uint beginDate;
        uint endDate;
    }

    event Agreement(address indexed requestor, address indexed seller, uint amount);
    /**
    *   Constructs a new Depot
    **/
    function Depot() {
    }

    /**
    *   Adds a warehouse to the registry
    **/
    function addWarehouse(uint256 _cubicFeet, uint pricePerCubicFootPerHour, bytes32 startingPosition) {
        totalSupply += _cubicFeet;
        listOfWarehouses.push(Warehouse(_cubicFeet, _cubicFeet, pricePerCubicFootPerHour, msg.sender, startingPosition, startingPosition, 0, 0));
    }

    /**
    *   Adds a vehicle to the registry
    **/
    function addVehicle(uint256 _cubicFeet, uint pricePerCubicFootPerHour, bytes32 startingPosition, bytes32 endingPosition, uint beginDate, uint endDate) {
        totalSupply += _cubicFeet;
        listOfVehicles.push(Warehouse(_cubicFeet, _cubicFeet, pricePerCubicFootPerHour, msg.sender, startingPosition, endingPosition, beginDate, endDate));
    }

    /**
    *   purchaseWarehouseSpace enables requestor purchases warehouse space
    **/
    function purchaseWarehouseSpace(address addr, uint cubicFeet, uint amountOfHours) payable {
        Warehouse storage warehouse = getWarehouseByAddress(addr);
        //Would probably import SafeMath module to multiply but MEH
        uint price = cubicFeet * amountOfHours * warehouse.pricePerCubicFootPerHour;
        if(msg.value != price) throw;
        if(warehouse.spaceAvailable < cubicFeet) throw;
        warehouse.spaceAvailable -= cubicFeet;
        Agreement(msg.sender, addr, price);
        totalSupply -= cubicFeet;
    }

    /**
    *   purchaseVehicleSpace enables requestor purchases vehicle space
    **/
    function purchaseVehicleSpace(address addr, uint cubicFeet, uint amountOfHours) payable {
        Warehouse storage warehouse = getVehicleByAddress(addr);
        //Would probably import SafeMath module to multiply but MEH
        uint price = cubicFeet * amountOfHours * warehouse.pricePerCubicFootPerHour;
        if(msg.value != price) throw;
        if(warehouse.spaceAvailable < cubicFeet) throw;
        warehouse.spaceAvailable -= cubicFeet;
        totalSupply -= cubicFeet;
    }

    /** GETTER METHODS **/

    /**
    *   warehouses grabs all of the available warehoues
    **/
    function warehouses() constant returns (uint[], uint[], uint[], address[], bytes32[], bytes32[]) {
        uint[] memory _spaceAvailable = new uint[](listOfWarehouses.length);
        uint[] memory _totalSpace = new uint[](listOfWarehouses.length);
        uint[] memory _pricePerCubicFootPerHour = new uint[](listOfWarehouses.length);
        bytes32[] memory _beginningCity = new bytes32[](listOfWarehouses.length);
        bytes32[] memory _endingCity = new bytes32[](listOfWarehouses.length);
        address[] memory _owner = new address[](listOfWarehouses.length);

        for (var i = 0; i < listOfWarehouses.length; i++) {
            _spaceAvailable[i] = listOfWarehouses[i].spaceAvailable;
            _totalSpace[i] = listOfWarehouses[i].totalSpace;
            _pricePerCubicFootPerHour[i] = listOfWarehouses[i].pricePerCubicFootPerHour;
            _owner[i] = listOfWarehouses[i].owner;
            _beginningCity[i] = listOfWarehouses[i].beginningCity;
            _endingCity[i] = listOfWarehouses[i].endingCity;
        }
        return (_spaceAvailable, _totalSpace, _pricePerCubicFootPerHour, _owner, _beginningCity, _endingCity);
    }

    /**
    *   vehicleDates grabs the date for vehicles,
    *   unable to put this in get vehicles method due to stack too deep error
    **/
    function vehicleDates() constant returns (uint[], uint[]) {
        uint[] memory _beginDate = new uint[](listOfVehicles.length);
        uint[] memory _endDate = new uint[](listOfVehicles.length);

        for (var i = 0; i < listOfVehicles.length; i++) {
          _beginDate[i] = listOfVehicles[i].beginDate;
          _endDate[i] = listOfVehicles[i].endDate;
        }
        return (_beginDate, _endDate);
    }

    /**
    * vehicles grabs all of the available vehicles
    **/
    function vehicles() constant returns (uint[], uint[], uint[], address[], bytes32[], bytes32[]) {
        uint[] memory _spaceAvailable = new uint[](listOfVehicles.length);
        uint[] memory _totalSpace = new uint[](listOfVehicles.length);
        uint[] memory _pricePerCubicFootPerHour = new uint[](listOfVehicles.length);
        bytes32[] memory _beginningCity = new bytes32[](listOfVehicles.length);
        bytes32[] memory _endingCity = new bytes32[](listOfVehicles.length);
        address[] memory _owner = new address[](listOfVehicles.length);

        for (var i = 0; i < listOfVehicles.length; i++) {
            _spaceAvailable[i] = listOfVehicles[i].spaceAvailable;
            _totalSpace[i] = listOfVehicles[i].totalSpace;
            _pricePerCubicFootPerHour[i] = listOfVehicles[i].pricePerCubicFootPerHour;
            _owner[i] = listOfVehicles[i].owner;
            _beginningCity[i] = listOfVehicles[i].beginningCity;
            _endingCity[i] = listOfVehicles[i].endingCity;
        }
        return (_spaceAvailable, _totalSpace, _pricePerCubicFootPerHour, _owner, _beginningCity, _endingCity);
    }

    /**
    * vehiclesByCity grabs vehicles from the starting city
    **/
    function vehiclesByCity(bytes32 city) constant returns (uint[], uint[], uint[], address[], bytes32[], bytes32[]) {
        uint count;
        for (var j = 0; j < listOfVehicles.length; j++) {
            if(listOfVehicles[j].beginningCity == city) count++;
        }

        uint[] memory _spaceAvailable = new uint[](count);
        uint[] memory _totalSpace = new uint[](count);
        uint[] memory _pricePerCubicFootPerHour = new uint[](count);
        bytes32[] memory _beginningCity = new bytes32[](count);
        bytes32[] memory _endingCity = new bytes32[](count);
        address[] memory _owner = new address[](count);
        count = 0;
        for (var i = 0; i < listOfVehicles.length; i++) {
            if(listOfVehicles[i].beginningCity == city) {
                _spaceAvailable[count] = listOfVehicles[i].spaceAvailable;
                _totalSpace[count] = listOfVehicles[i].totalSpace;
                _pricePerCubicFootPerHour[count] = listOfVehicles[i].pricePerCubicFootPerHour;
                _owner[count] = listOfVehicles[i].owner;
                _beginningCity[count] = listOfVehicles[i].beginningCity;
                _endingCity[count] = listOfVehicles[i].endingCity;
                count++;
            }
        }
        return (_spaceAvailable, _totalSpace, _pricePerCubicFootPerHour, _owner, _beginningCity, _endingCity);
    }

    function vehicleDatesByCity(bytes32 city) constant returns (uint[], uint[]) {
        uint count;
        for (var j = 0; j < listOfVehicles.length; j++) {
            if(listOfVehicles[j].beginningCity == city) count++;
        }

        uint[] memory _beginDate = new uint[](count);
        uint[] memory _endDate= new uint[](count);
        count = 0;
        for (var i = 0; i < listOfVehicles.length; i++) {
            if(listOfVehicles[i].beginningCity == city) {
                _beginDate[count] = listOfVehicles[i].beginDate;
                _endDate[count] = listOfVehicles[i].endDate;
                count++;
            }
        }
        return (_beginDate, _endDate);
    }

    /** INTERNAL METHODS **/

    function getVehicleByAddress(address addr) internal returns (Warehouse storage) {
        for (var i = 0; i < listOfVehicles.length; i++) {
            if(listOfVehicles[i].owner == addr) return listOfVehicles[i];
        }
        throw;
    }

    function getWarehouseByAddress(address addr) internal returns (Warehouse storage) {
        for (var i = 0; i < listOfWarehouses.length; i++) {
            if(listOfWarehouses[i].owner == addr) return listOfWarehouses[i];
        }
        throw;
    }

    /** Do not accept ether **/
    function () payable {
        throw;
    }
}


Simplify judge contract

Simplify judge contract

pragma solidity ^0.4.8;

contract Judge {
  function resolveDispute(uint _input1, uint _input2, uint _result, uint8 _operation) returns (bool check) {
    uint check_result;

    if (operation == 0) {
      check_result = _input1 + _input2;
      if (check_result == _result) check = true;
    }
    else if (operation == 1) {
      check_result = _input1 - _input2;
      if (check_result == _result) check = true;
    }
    else if (operation== 2) {
      check_result = _input1 * _input2;
      if (check_result == _result) check = true;
    }
    return check;
  }
}

pragma solidity ^0.4.8;

contract Judge {
  struct Request {
    uint input1;
    uint input2;
    uint result;
    uint8 operation;
  }

  mapping(bytes32 => Request) requestMapping;

  address[] public verifiers;

  function createRequest(bytes32 _identifier, uint _input1, uint _input2, uint _result, uint8 _operation) payable {
    Request memory _request;
    _request.input1 = _input1;
    _request.input2 = _input2;
    _request.result = _result;
    _request.operation = _operation;

    requestMapping[_identifier] = _request;
  }

  function resolveDispute(bytes32 _identifier) returns (bool check) {
    uint input1 = requestMapping[_identifier].input1;
    uint input2 = requestMapping[_identifier].input2;
    uint result = requestMapping[_identifier].result;
    uint8 operation = requestMapping[_identifier].operation;
    uint check_result;

    if (operation == 0) {
      check_result = input1 + input2;
      if (check_result == result) check = true;
    }
    else if (operation == 1) {
      check_result = input1 - input2;
      if (check_result == result) check = true;
    }
    else if (operation== 2) {
      check_result = input1 * input2;
      if (check_result == result) check = true;
    }
    return check;
  }
}


Improved Upgradable contract;

Improved Upgradable contract;

pragma solidity ^0.4.15;

import "./Owned.sol";

/**
 * The contract can be deprecated and the owner can set - only once - another address to advertise
 * clients of the existence of another more recent contract.
 */
contract Upgradable is Owned {

    string  public VERSION;
    bool    public deprecated;
    string  public newVersion;
    address public newAddress;
    uint    public timestamp;

    function Upgradable(string _version)  {
        VERSION = _version;
    }

    function setDeprecated(string _newVersion, address _newAddress) external onlyOwner returns (bool success) {
        require(!deprecated && !Upgradable(_newAddress).deprecated());
        address _currentAddress = this;
        require(_newAddress != _currentAddress);
        deprecated = true;
        newVersion = _newVersion;
        newAddress = _newAddress;
        timestamp = block.timestamp;
        return true;
    }
}

pragma solidity ^0.4.15;

import "./Owned.sol";

/**
 * The contract can be deprecated and the owner can set - only once - another address to advertise
 * to clients the existence of another more recent contract.
 */
contract Upgradable is Owned {

    string  public VERSION;
    bool    public deprecated;
    string  public newVersion;
    address public newAddress;

    function Upgradable(string _version) {
        VERSION = _version;
    }

    function setDeprecated(string _newVersion, address _newAddress) onlyOwner returns (bool success) {
        require(!deprecated);
        deprecated = true;
        newVersion = _newVersion;
        newAddress = _newAddress;
        return true;
    }
}


0.5.0 SafeSend

0.5.0 SafeSend

pragma solidity ^0.5.0;

contract NewSafeSend {
  address payable public recipient;

  constructor(address payable _recipient) public payable {
    recipient = _recipient;
  }

  function deliver() public {
    selfdestruct(recipient);
  }
}

pragma solidity ^0.5.0;

contract SafeSend {
  address payable public recipient;

  constructor(address payable _recipient) public payable {
    recipient = _recipient;
  }

  function deliver() public {
    selfdestruct(recipient);
  }
}


after testing 2 honest parties

after testing 2 honest parties

contract mixer {

    struct anon_registeration{
        address sender;
        uint value;
        bool valid;
    }

    struct public_user{
        uint deposit;
        address addr;
        bool valid;
        uint revealed_deposit;
        anon_registeration[] registrations; // used only if there is violation
    }

    struct mixing_deal{
        uint start_time;
        public_user[] users; // must hold array to iterate them
        mapping (address=>uint) user_to_index_mapping;
        anon_registeration[] registrations;
        mapping (address=>uint) registration_to_index_mapping;

        uint32 min_num_participants;
        uint   registration_deposit_size_in_wei;
        uint   phase_time_in_secs;

        uint   deposit_sum;
        uint   registration_sum;
        bool   violated;
    }

    mixing_deal[] deals;

    enum deal_state{
        invalid,

        initial_deposit,
        anonymous_registration,
        anonymous_withdraw,

        anonymous_revealing,
        public_withdraw_not_enough_parties,
        public_withdraw_violation
    }

    modifier non_payable {
        if (msg.value > 0 )
            throw;
        _
    }
    function mixer(){
        deals.length = 0;
    }

    function not_after_phase(mixing_deal deal, uint phase) constant private returns(bool){
        return deal.start_time + deal.phase_time_in_secs * phase >= now;
    }

    function get_deal_state(uint deal_id) constant returns(deal_state){
        if( deals.length <= deal_id ) return deal_state.invalid;
        mixing_deal deal = deals[ deal_id ];
        if( not_after_phase(deal, 1) ) return deal_state.initial_deposit;

        if( deal.users.length < deal.min_num_participants ) return deal_state.public_withdraw_not_enough_parties;

        if( not_after_phase(deal, 2) ) return deal_state.anonymous_registration;

        if( deal.violated ){
            if( not_after_phase(deal, 3) ) return deal_state.anonymous_revealing;
            // else - phase 4
            return deal_state.public_withdraw_violation;
        }
        else{
            return deal_state.anonymous_withdraw;
        }
    }

    function create_new_deal(uint32 _min_num_participants,
                             uint   _registration_deposit_size_in_wei,
                             uint32 _phase_time_in_minutes ) non_payable returns (uint) {
        uint deal_id = deals.length;
        deals.length += 1;

        deals[ deal_id ].start_time = now;
        deals[ deal_id ].min_num_participants = _min_num_participants;
        deals[ deal_id ].registration_deposit_size_in_wei = _registration_deposit_size_in_wei;
        deals[ deal_id ].phase_time_in_secs = _phase_time_in_minutes * 1 minutes;

        deals[ deal_id ].deposit_sum = 0;
        deals[ deal_id ].registration_sum = 0;
        deals[ deal_id ].violated = false;

        return deal_id;
    }

    function make_initial_deposit( uint deal_id ){
        if( get_deal_state( deal_id ) != deal_state.initial_deposit ) throw;

        mixing_deal deal = deals[ deal_id ];
        uint user_index = deal.users.length;
        deal.users.length += 1;

        deal.users[ user_index ].deposit = msg.value;
        deal.users[ user_index ].addr = msg.sender;
        deal.users[ user_index ].revealed_deposit = 0;
        deal.users[ user_index ].valid = true;

        deal.user_to_index_mapping[ msg.sender ] = user_index;

        deal.deposit_sum += msg.value;
    }

    function make_anonymous_registration( uint deal_id, uint amount_in_wei ){
        if( get_deal_state( deal_id ) != deal_state.anonymous_registration ) throw;
        if( amount_in_wei > 1024 * 1024 * 1024 ether ) throw; // prevent possible overflows

        mixing_deal deal = deals[ deal_id ];

        if( msg.value != deal.registration_deposit_size_in_wei ) throw;

        uint reg_id = deal.registrations.length;
        deal.registrations.length += 1;

        deal.registrations[ reg_id ].sender = msg.sender;
        deal.registrations[ reg_id ].value = amount_in_wei;
        deal.registrations[ reg_id ].valid = true;

        deal.registration_to_index_mapping[ msg.sender ] = reg_id;

        deals[ deal_id ].registration_sum += amount_in_wei;

        if( deals[ deal_id ].registration_sum > deal.deposit_sum ) deals[ deal_id ].violated = true;
    }

    function make_anonymous_withdraw(uint deal_id) non_payable{
        if( get_deal_state( deal_id ) != deal_state.anonymous_withdraw ) throw;
        uint reg_index = deals[ deal_id ].registration_to_index_mapping[ msg.sender ];
        anon_registeration reg = deals[ deal_id ].registrations[ reg_index ];
        if( ! reg.valid ) throw;

        // invalidate for next time
        reg.valid = false;

        uint value = reg.value + deals[ deal_id ].registration_deposit_size_in_wei;

        if( ! reg.sender.send( value ) ) throw;
    }

    function reveal_registration( uint deal_id, address public_address ) non_payable{
        if( get_deal_state( deal_id ) != deal_state.anonymous_revealing ) throw;

        mixing_deal deal = deals[ deal_id ];

        // get registration
        uint reg_index = deal.registration_to_index_mapping[ msg.sender ];
        anon_registeration reg = deal.registrations[ reg_index ];
        if( ! reg.valid ) throw;

        // get user
        uint user_index = deal.user_to_index_mapping[ public_address ];
        public_user user = deal.users[ user_index ];
        if( ! user.valid ) throw;

        // assume no overflows
        if( user.deposit >= user.revealed_deposit + reg.value ){
            user.registrations.length += 1;
            user.registrations[ user.registrations.length - 1 ] = reg;
            user.revealed_deposit += reg.value;
            return;
        }

        // else - replace with maximal value deposit
        uint max_index = 0;
        uint max_value = user.registrations[ 0 ].value;
        for ( uint index = 1; index < user.registrations.length; index += 1 ){
            if( user.registrations[ index ].value > max_value ){
                max_index = index;
                max_value = user.registrations[ index ].value;
            }
        }
        if( max_value > reg.value ) return; // ignore this registration
        // else - replace max with new reg
        user.registrations[ max_index ] = reg;
        user.revealed_deposit = user.revealed_deposit + reg.value - max_value;
    }

    function public_withdraw( uint deal_id ) non_payable{
        if( ( get_deal_state( deal_id ) != deal_state.public_withdraw_not_enough_parties ) &&
            ( get_deal_state( deal_id ) != deal_state.public_withdraw_violation ) ) throw;

        mixing_deal deal = deals[ deal_id ];
        uint user_index = deal.user_to_index_mapping[ msg.sender ];
        public_user user = deal.users[ user_index ];
        if( ! user.valid ) throw;

        uint value = user.deposit;

        if( get_deal_state( deal_id ) == deal_state.public_withdraw_violation ){
            value += user.registrations.length * deal.registration_deposit_size_in_wei;
        }

        user.valid = false;

        if( ! user.addr.send( value ) ) throw;
    }

}

contract mixer {

    struct anon_registeration{
        address sender;
        uint value;
        bool valid;
    }

    struct public_user{
        uint deposit;
        address addr;
        bool valid;
        uint revealed_deposit;
        anon_registeration[] registrations; // used only if there is violation
    }

    struct mixing_deal{
        uint start_time;
        public_user[] users; // must hold array to iterate them
        mapping (address=>uint) user_to_index_mapping;
        anon_registeration[] registrations;
        mapping (address=>uint) registration_to_index_mapping;

        uint32 min_num_participants;
        uint   registration_deposit_size_in_wei;
        uint   phase_time_in_secs;

        uint   deposit_sum;
        uint   registration_sum;
        bool   violated;
    }

    mixing_deal[] deals;

    enum deal_state{
        invalid,

        initial_deposit,
        anonymous_registration,
        anonymous_withdraw,

        anonymous_revealing,
        public_withdraw_not_enough_parties,
        public_withdraw_violation
    }

    modifier non_payable {
        if (msg.value > 0 )
            throw;
        _
    }
    function mixer(){
        deals.length = 0;
    }

    function not_after_phase(mixing_deal deal, uint phase) constant private returns(bool){
        return deal.start_time + deal.phase_time_in_secs * phase >= now;
    }

    function get_deal_state(uint deal_id) constant returns(deal_state){
        if( deals.length >= deal_id ) return deal_state.invalid;
        mixing_deal deal = deals[ deal_id ];
        if( not_after_phase(deal, 1) ) return deal_state.initial_deposit;

        if( deal.users.length < deal.min_num_participants ) return deal_state.public_withdraw_not_enough_parties;

        if( not_after_phase(deal, 2) ) return deal_state.anonymous_registration;

        if( deal.violated ){
            if( not_after_phase(deal, 3) ) return deal_state.anonymous_revealing;
            // else - phase 4
            return deal_state.public_withdraw_violation;
        }
        else{
            return deal_state.anonymous_withdraw;
        }
    }

    function create_new_deal(uint32 _min_num_participants,
                             uint   _registration_deposit_size_in_wei,
                             uint32 _phase_time_in_hours ) non_payable returns (uint) {
        uint deal_id = deals.length;
        deals.length += 1;

        deals[ deal_id ].start_time = now;
        deals[ deal_id ].min_num_participants = _min_num_participants;
        deals[ deal_id ].registration_deposit_size_in_wei = _registration_deposit_size_in_wei;
        deals[ deal_id ].phase_time_in_secs = _phase_time_in_hours * 1 hours;

        deals[ deal_id ].deposit_sum = 0;
        deals[ deal_id ].registration_sum = 0;
        deals[ deal_id ].violated = false;

        return deal_id;
    }

    function make_initial_deposit( uint deal_id ){
        if( get_deal_state( deal_id ) != deal_state.initial_deposit ) throw;

        mixing_deal deal = deals[ deal_id ];
        uint user_index = deal.users.length;
        deal.users.length += 1;

        deal.users[ user_index ].deposit = msg.value;
        deal.users[ user_index ].addr = msg.sender;
        deal.users[ user_index ].revealed_deposit = 0;
        deal.users[ user_index ].valid = true;

        deal.user_to_index_mapping[ msg.sender ] = user_index;

        deal.deposit_sum += msg.value;
    }

    function make_anonymous_registration( uint deal_id, uint amount_in_wei ){
        if( get_deal_state( deal_id ) != deal_state.anonymous_registration ) throw;
        if( amount_in_wei > 1024 * 1024 * 1024 ether ) throw; // prevent possible overflows

        mixing_deal deal = deals[ deal_id ];

        if( msg.value != deal.registration_deposit_size_in_wei ) throw;

        uint reg_id = deal.registrations.length;
        deal.registrations.length += 1;

        deal.registrations[ reg_id ].sender = msg.sender;
        deal.registrations[ reg_id ].value = amount_in_wei;
        deal.registrations[ reg_id ].valid = true;

        deal.registration_to_index_mapping[ msg.sender ] = reg_id;

        deals[ deal_id ].registration_sum += amount_in_wei;

        if( deals[ deal_id ].registration_sum > deal.deposit_sum ) deals[ deal_id ].violated = true;
    }

    function make_anonymous_withdraw(uint deal_id) non_payable{
        if( get_deal_state( deal_id ) != deal_state.anonymous_withdraw ) throw;
        uint reg_index = deals[ deal_id ].registration_to_index_mapping[ msg.sender ];
        anon_registeration reg = deals[ deal_id ].registrations[ reg_index ];
        if( ! reg.valid ) throw;

        // invalidate for next time
        reg.valid = false;

        uint value = reg.value + deals[ deal_id ].deposit_sum;

        if( ! reg.sender.send( value ) ) throw;
    }

    function reveal_registration( uint deal_id, address public_address ) non_payable{
        if( get_deal_state( deal_id ) != deal_state.anonymous_revealing ) throw;

        mixing_deal deal = deals[ deal_id ];

        // get registration
        uint reg_index = deal.registration_to_index_mapping[ msg.sender ];
        anon_registeration reg = deal.registrations[ reg_index ];
        if( ! reg.valid ) throw;

        // get user
        uint user_index = deal.user_to_index_mapping[ public_address ];
        public_user user = deal.users[ user_index ];
        if( ! user.valid ) throw;

        // assume no overflows
        if( user.deposit >= user.revealed_deposit + reg.value ){
            user.registrations.length += 1;
            user.registrations[ user.registrations.length - 1 ] = reg;
            user.revealed_deposit += reg.value;
            return;
        }

        // else - replace with maximal value deposit
        uint max_index = 0;
        uint max_value = user.registrations[ 0 ].value;
        for ( uint index = 1; index < user.registrations.length; index += 1 ){
            if( user.registrations[ index ].value > max_value ){
                max_index = index;
                max_value = user.registrations[ index ].value;
            }
        }
        if( max_value > reg.value ) return; // ignore this registration
        // else - replace max with new reg
        user.registrations[ max_index ] = reg;
        user.revealed_deposit = user.revealed_deposit + reg.value - max_value;
    }

    function public_withdraw( uint deal_id ) non_payable{
        if( ( get_deal_state( deal_id ) != deal_state.public_withdraw_not_enough_parties ) &&
            ( get_deal_state( deal_id ) != deal_state.public_withdraw_violation ) ) throw;

        mixing_deal deal = deals[ deal_id ];
        uint user_index = deal.user_to_index_mapping[ msg.sender ];
        public_user user = deal.users[ user_index ];
        if( ! user.valid ) throw;

        uint value = user.deposit;

        if( get_deal_state( deal_id ) == deal_state.public_withdraw_violation ){
            value += user.registrations.length * deal.registration_deposit_size_in_wei;
        }

        user.valid = false;

        if( ! user.addr.send( value ) ) throw;
    }

}


Remove duplicate declaration

Remove duplicate declaration

IterableMappingNcc is so far only used inside channelManagerContract.sol -
since it needs ChannelManagerContract I assume it is best kept in the same
file. If this opposes best practices, we have to deal with a circular
dependency...

/// Iteratable data structure of the type [bytes32 k, NettingContract v]
library IterableMappingNcc
{
    // Might have to define the NettingContract type here for insertion
    struct itmap {
        mapping(bytes32 => IndexValue) data;
        KeyFlag[] keys;
        uint size;
    }
    struct IndexValue { uint keyIndex; NettingContract value; }
    struct KeyFlag { bytes32 key; bool deleted; }

    function insert(itmap storage self, bytes32 key, NettingContract value) returns (bool replaced) {
        uint keyIndex = self.data[key].keyIndex;
        self.data[key].value = value;
        if (keyIndex > 0)
            return true;
        else {
            keyIndex = self.keys.length++;
            self.data[key].keyIndex = keyIndex + 1;
            self.keys[keyIndex].key = key;
            self.size++;
            return false;
        }
    }

    function remove(itmap storage self, bytes32 key) returns (bool success){
        uint keyIndex = self.data[key].keyIndex;
        if (keyIndex == 0)
          return false;
        delete self.data[key];
        self.keys[keyIndex - 1].deleted = true;
        self.size --;
    }

    function contains(itmap storage self, bytes32 key) returns (bool) {
        return self.data[key].keyIndex > 0;
    }

    function atIndex(itmap storage self, bytes32 key) returns (uint index) {
        return self.data[key].keyIndex;
    }

    function iterate_start(itmap storage self) returns (uint keyIndex){
        return iterate_next(self, uint(-1));
    }

    function iterate_valid(itmap storage self, uint keyIndex) returns (bool){
        return keyIndex < self.keys.length;
    }

    function iterate_next(itmap storage self, uint keyIndex) returns (uint r_keyIndex){
        keyIndex++;
        while (keyIndex < self.keys.length && self.keys[keyIndex].deleted)
            keyIndex++;
        return keyIndex;
    }

    function iterate_get(itmap storage self, uint keyIndex) returns (bytes32 key, NettingContract value){
        key = self.keys[keyIndex].key;
        value = self.data[key].value;
    }
}


Fix compiler warnings. Issue #367

Fix compiler warnings. Issue #367

pragma solidity ^0.4.11;

import "./CanReclaimToken.sol";

/**
 * @title Contracts that should not own Tokens
 * @author Remco Bloemen <remco@2π.com>
 * @dev This blocks incoming ERC23 tokens to prevent accidental loss of tokens.
 * Should tokens (any ERC20Basic compatible) end up in the contract, it allows the
 * owner to reclaim the tokens.
 */
contract HasNoTokens is CanReclaimToken {

 /**
  * @dev Reject all ERC23 compatible tokens
  * param from_ address The address that is transferring the tokens
  * param value_ uint256 the amount of the specified token
  * param data_ Bytes The data passed from the caller.
  */
  function tokenFallback(address /*from_*/, uint256 /*value_*/, bytes /*data_*/) external {
    revert();
  }

}

pragma solidity ^0.4.11;

import "./CanReclaimToken.sol";

/**
 * @title Contracts that should not own Tokens
 * @author Remco Bloemen <remco@2π.com>
 * @dev This blocks incoming ERC23 tokens to prevent accidental loss of tokens.
 * Should tokens (any ERC20Basic compatible) end up in the contract, it allows the
 * owner to reclaim the tokens.
 */
contract HasNoTokens is CanReclaimToken {

 /**
  * @dev Reject all ERC23 compatible tokens
  * param from_ address The address that is transferring the tokens
  * param value_ uint256 the amount of the specified token
  * param data_ Bytes The data passed from the caller.
  */
  function tokenFallback(address from_, uint256 value_, bytes data_) external {
    // revert();
    if(true || from_ == 0 || value_ == 0 || data_.length == 0 ) revert(); // Temporary fix for solidity compiler warning
  }

}


check that 1 block has passed for startAssesment

pragma solidity ^0.4.0;

import "userRegistry.sol";
import "assessment.sol";
import "user.sol";
import "math.sol";
import "conceptRegistry.sol";

/*
@type: contract
@name: Concept
@purpose: To store concept data and create and store information about assessments of this concept
*/
contract Concept
{
  address[] public parents; //The concepts that this concept is child to (ie: Calculus is child to Math)
  address[] public children; //The concepts that this concept is parent to (ie: Math is parent to Calculus)
  address userRegistry; //The address of the userRegistry contract
  address conceptRegistry; //The address of the conceptRegistry contract
  uint public maxWeight; //The current highest weight for this assessment
  address[] public owners; //Those who have earned the concept
  address math = 0x90B66E80448eb60938FAed4A738dE0D5b630B2Fd;
  address mew;
  mapping (address => int) public currentScores; //The most recent score of a user
  mapping (address => uint) public assessmentSizes; //The most recent size of an assessment taken by a user
  mapping (address => bool) public assessmentExists; //All existing assessments
  mapping (address => uint) public weights; //The weighting used by the assessor selection algorhitm for each owner

  /*
  @type: modifier
  @name: onlyUserRegistry
  @purpose: to only allow the UserRegistry contract to call a function to which this modifier is applied
  */
  modifier onlyUserRegistry()
  {
    if(msg.sender != userRegistry) //checks if msg.sender has the same address as userRegistry
    {
      throw; //throws the function call if not
    }
    _;
  }

  /*
  @type: modifier
  @name: onlyConceptRegistry
  @purpose: to only allow the ConceptRegistry contract to call a function to which this modifier is applied
  */
  modifier onlyConceptRegistry()
  {
    if(msg.sender != conceptRegistry) //checks if msg.sender has the same address as conceptRegistry
    {
      throw; //throws the function call if not
    }
    _;
  }

  modifier isAssessmentOrConcept()
  {
    if(!(assessmentExists[msg.sender] || ConceptRegistry(conceptRegistry).conceptExists(msg.sender)))
    {
      throw;
    }
    _;
  }

  /*
  @type: modifier
  @name: onlyThis
  @purpose: to only allow the this contract to call a function to which this modifier is applied
  */
  modifier onlyThis()
  {
    if(msg.sender != address(this)) //Checks if msg.sender is this contract
    {
      throw; //Throws out the function call if it isn't
    }
    _;
  }

  /*
  @type: event
  @name: CompletedAssessment
  @purpose: To build a database of completed assessments
  */
  event CompletedAssessment
  ( address _assessee, //The address of the user who took the assessment
    int _score, //The score of the assessee
    address _assessment); //The address of the assessment

  /*
  @type: constructor function
  @purpose: To initialize the Concept contract
  @param: string conceptName = the name of the conceptName
  @param: address[] parents = the addresses of the concept's parents
  @param: address userRegistryAddress = the address of the UserRegistry contract
  @param: address conceptRegistry = the address of the ConceptRegistry that spawned this user
  @returns: nothing
  */
  function Concept(address[] _parents, address _userRegistry, address _conceptRegistry)
  {
    parents = _parents; //sets the  parents array
    userRegistry = _userRegistry; //sets the userRegistry address
    conceptRegistry = _conceptRegistry; //sets the conceptRegistry address
  }

  /*
  @type: function
  @purpose: To get the number of owners of this concept
  @returns: The number of users that own this concept in the form of an uint
  */
  function getOwnerLength() constant returns(uint)
  {
    return owners.length;
  }

  /*
  @type: function
  @purpose: To get the number of parents for this concept
  @returns: The number of parents for this concept in the form of an uint
  */
  function getParentsLength() constant returns(uint)
  {
    return parents.length;
  }

  /*
  @type: function
  @purpose: To get the number of children of this concept
  @returns: The number of children of this concept in the form of an uint
  */
  function getChildrenLength() constant returns(uint)
  {
    return children.length;
  }

  /*
  @type: function
  @purpose: To set the first user for this concept
  @param: address firstUser = the address of the first user to own the concept
  @returns: nothing
  */
  function addUser(address user) onlyUserRegistry()
  {
    if(mew == address(0x0))
    {
      owners.push(user); //If there aren't then firstUser is made to be an owner of this concept
    }
  }

  /*
  @type: function
  @purpose: To add a parent to the concept
  @param: address parentAddress = the address of the new parent concept
  @returns: nothing
  */
  function addParent(address _parent) onlyConceptRegistry()
  {
    parents.push(_parent);
  }

  /*
  @type: function
  @purpose: To add a child to the concept
  @param: address childAddress = the address of the new child concept
  @returns: nothing
  */
  function addChild(address _child) onlyConceptRegistry()
  {
    children.push(_child);
  }

  function getAssessors(uint num, uint seed, address assessment) isAssessmentOrConcept()
  {
    uint numberOfAssessorsCalled = 0;
    for(uint i = 0; i < owners.length; i++)
    {
      address randomUser = owners[Math(math).getRandom(seed + i, owners.length-1)]; //gets a random owner of the concept
      if(User(randomUser).availability() && weights[randomUser] > now % maxWeight) //Checks if the randomly drawn is available and then puts it through a random check that it has a higher chance of passing if it has had a higher score and a larger assessment
      {
        if(Assessment(assessment).addAssessorToPool(randomUser))
        {
          numberOfAssessorsCalled++;
        }
      }
      if(numberOfAssessorsCalled > owners.length/10)
      {
        break;
      }
    }
    if(num > numberOfAssessorsCalled)
    {
      for(uint k = 0; k < parents.length; k++)
      {
        Concept(parents[k]).getAssessors((num - numberOfAssessorsCalled)/parents.length + 1, seed + now % k, assessment);
      }
    }
  }

  /*
  @type: function
  @purpose: To make a new assessment
  @param: uint time = the time that assessors will have to assess in this assessment
  @param: uint size = the size of the assessment
  @returns: nothing
  */
  function makeAssessment(uint cost, uint size) returns(bool)
  {
    if(size >= 5 && UserRegistry(userRegistry).balances(msg.sender) >= cost*size) //Checks if the assessment has a size of at least 5
    {
      Assessment newAssessment = new Assessment(msg.sender, userRegistry, conceptRegistry, size, cost); //Makes a new assessment with the given parameters
      assessmentExists[address(newAssessment)] = true; //Sets the assessment's existance to true
      setBalance(msg.sender, UserRegistry(userRegistry).balances(msg.sender) - cost*size);
      User(msg.sender).notification(address(this), 19); //You have been charged for your assessment
      return true;
    }
    else
    {
      return false;
    }
  }

  /*
  @type: function
  @purpose: To start the assessment process
  @param: address assessment = the address of the assessment
  @returns: nothing
  */
  function startAssessment(address assessment)
  {
    if((block.number - Assessment(assessment).startTime()) <= 10 &&
       (block.number - Assessment(assessment).startTime()) >= 1) //Checks if this function is being called 4 to 6 blocks after the block in which the assessment was created
    {
      Assessment(assessment).setAssessorPool(block.number); //Calls the function to set the assessor pool
    }
    else
    {
      Assessment(assessment).cancelAssessment(); //If this function is called too early or too late the assessment is cancelled
    }
  }

  /*
  @type: function
  @purpose: To finish the assessment process
  @param: int score = the assessee's score
  @param: address assessee = the address of the assessee
  @param: address assessment = the address of the assessment
  @returns: nothing
  */
  function finishAssessment(int score, address assessee, address assessment)
  {
    if(msg.sender == assessment) //Checks to make sure this function is being callled by the assessment
    {
      if(score > 0)
      {
        owners.push(assessee); //Makes the assessee an owner of this concept
        uint weight = Assessment(assessment).size()*uint(score);
        addOwner(assessee, weight);
        User(assessee).setConceptPassed(true);
      }
      User(assessee).mapHistory(assessment); //Maps the assessee to the assessment in the user master as part of the assessee's history
      currentScores[assessee] = score; //Maps the assessee to their score
      assessmentSizes[assessee] = Assessment(assessment).size(); //Maps the assessee to the assessment size
      CompletedAssessment(assessee, score, assessment); //Makes an event with this assessment's data
    }
  }

  /*
  @type: function
  @purpose: To add an owner to a concept and recursively add an owner to parent concept, halving the added weight with each generation and chinging the macWeight for a concept if neccisairy
  @param: bool pass = whether or not the assessee passed the assessment
  @param: address assessee = the address of the assessee
  @param: uint weight = the weight for the owner
  @returns: nothing
  */
  function addOwner(address assessee, uint weight)
  {
    owners.push(assessee); //adds the owner to the array
    weights[assessee] += weight; //adds the weight to the current value in mapping
    if(weight > maxWeight) //checks if the weight is greater than the currant maxWeight
    {
      maxWeight = weight; //if so changes the maxWeight value
    }
    for(uint i = 0; i < parents.length; i++)
    {
      Concept(parents[i]).addOwner(assessee, weight/2); //recursively adds owner to all parent concepts but with half the weight
    }
  }

  /*
  @type: function
  @purpose: To pay/charge a user for an assessment
  @param: address user = the user to pay/charge
  @param: int amount = the user's new token balance
  */
  function setBalance(address user, uint amount)
  {
    if(assessmentExists[msg.sender] || msg.sender == address(this)) //Checks if msg.sender is an existing assessment
    {
      UserRegistry(userRegistry).setBalance(user, amount); //Changes the user's token balance
    }
  }

  /*
  @type: function
  @purpose: to remove this contract
  @param: address receiver = the address of the wallet that will receive of the ether
  @returns: nothing
  */
  function remove(address reciever) onlyThis()
  {
    suicide(reciever);
  }
}

pragma solidity ^0.4.0;

import "userRegistry.sol";
import "assessment.sol";
import "user.sol";
import "math.sol";
import "conceptRegistry.sol";

/*
@type: contract
@name: Concept
@purpose: To store concept data and create and store information about assessments of this concept
*/
contract Concept
{
  address[] public parents; //The concepts that this concept is child to (ie: Calculus is child to Math)
  address[] public children; //The concepts that this concept is parent to (ie: Math is parent to Calculus)
  address userRegistry; //The address of the userRegistry contract
  address conceptRegistry; //The address of the conceptRegistry contract
  uint public maxWeight; //The current highest weight for this assessment
  address[] public owners; //Those who have earned the concept
  address math = 0x90B66E80448eb60938FAed4A738dE0D5b630B2Fd;
  address mew;
  mapping (address => int) public currentScores; //The most recent score of a user
  mapping (address => uint) public assessmentSizes; //The most recent size of an assessment taken by a user
  mapping (address => bool) public assessmentExists; //All existing assessments
  mapping (address => uint) public weights; //The weighting used by the assessor selection algorhitm for each owner

  /*
  @type: modifier
  @name: onlyUserRegistry
  @purpose: to only allow the UserRegistry contract to call a function to which this modifier is applied
  */
  modifier onlyUserRegistry()
  {
    if(msg.sender != userRegistry) //checks if msg.sender has the same address as userRegistry
    {
      throw; //throws the function call if not
    }
    _;
  }

  /*
  @type: modifier
  @name: onlyConceptRegistry
  @purpose: to only allow the ConceptRegistry contract to call a function to which this modifier is applied
  */
  modifier onlyConceptRegistry()
  {
    if(msg.sender != conceptRegistry) //checks if msg.sender has the same address as conceptRegistry
    {
      throw; //throws the function call if not
    }
    _;
  }

  modifier isAssessmentOrConcept()
  {
    if(!(assessmentExists[msg.sender] || ConceptRegistry(conceptRegistry).conceptExists(msg.sender)))
    {
      throw;
    }
    _;
  }

  /*
  @type: modifier
  @name: onlyThis
  @purpose: to only allow the this contract to call a function to which this modifier is applied
  */
  modifier onlyThis()
  {
    if(msg.sender != address(this)) //Checks if msg.sender is this contract
    {
      throw; //Throws out the function call if it isn't
    }
    _;
  }

  /*
  @type: event
  @name: CompletedAssessment
  @purpose: To build a database of completed assessments
  */
  event CompletedAssessment
  ( address _assessee, //The address of the user who took the assessment
    int _score, //The score of the assessee
    address _assessment); //The address of the assessment

  /*
  @type: constructor function
  @purpose: To initialize the Concept contract
  @param: string conceptName = the name of the conceptName
  @param: address[] parents = the addresses of the concept's parents
  @param: address userRegistryAddress = the address of the UserRegistry contract
  @param: address conceptRegistry = the address of the ConceptRegistry that spawned this user
  @returns: nothing
  */
  function Concept(address[] _parents, address _userRegistry, address _conceptRegistry)
  {
    parents = _parents; //sets the  parents array
    userRegistry = _userRegistry; //sets the userRegistry address
    conceptRegistry = _conceptRegistry; //sets the conceptRegistry address
  }

  /*
  @type: function
  @purpose: To get the number of owners of this concept
  @returns: The number of users that own this concept in the form of an uint
  */
  function getOwnerLength() constant returns(uint)
  {
    return owners.length;
  }

  /*
  @type: function
  @purpose: To get the number of parents for this concept
  @returns: The number of parents for this concept in the form of an uint
  */
  function getParentsLength() constant returns(uint)
  {
    return parents.length;
  }

  /*
  @type: function
  @purpose: To get the number of children of this concept
  @returns: The number of children of this concept in the form of an uint
  */
  function getChildrenLength() constant returns(uint)
  {
    return children.length;
  }

  /*
  @type: function
  @purpose: To set the first user for this concept
  @param: address firstUser = the address of the first user to own the concept
  @returns: nothing
  */
  function addUser(address user) onlyUserRegistry()
  {
    if(mew == address(0x0))
    {
      owners.push(user); //If there aren't then firstUser is made to be an owner of this concept
    }
  }

  /*
  @type: function
  @purpose: To add a parent to the concept
  @param: address parentAddress = the address of the new parent concept
  @returns: nothing
  */
  function addParent(address _parent) onlyConceptRegistry()
  {
    parents.push(_parent);
  }

  /*
  @type: function
  @purpose: To add a child to the concept
  @param: address childAddress = the address of the new child concept
  @returns: nothing
  */
  function addChild(address _child) onlyConceptRegistry()
  {
    children.push(_child);
  }

  function getAssessors(uint num, uint seed, address assessment) isAssessmentOrConcept()
  {
    uint numberOfAssessorsCalled = 0;
    for(uint i = 0; i < owners.length; i++)
    {
      address randomUser = owners[Math(math).getRandom(seed + i, owners.length-1)]; //gets a random owner of the concept
      if(User(randomUser).availability() && weights[randomUser] > now % maxWeight) //Checks if the randomly drawn is available and then puts it through a random check that it has a higher chance of passing if it has had a higher score and a larger assessment
      {
        if(Assessment(assessment).addAssessorToPool(randomUser))
        {
          numberOfAssessorsCalled++;
        }
      }
      if(numberOfAssessorsCalled > owners.length/10)
      {
        break;
      }
    }
    if(num > numberOfAssessorsCalled)
    {
      for(uint k = 0; k < parents.length; k++)
      {
        Concept(parents[k]).getAssessors((num - numberOfAssessorsCalled)/parents.length + 1, seed + now % k, assessment);
      }
    }
  }

  /*
  @type: function
  @purpose: To make a new assessment
  @param: uint time = the time that assessors will have to assess in this assessment
  @param: uint size = the size of the assessment
  @returns: nothing
  */
  function makeAssessment(uint cost, uint size) returns(bool)
  {
    if(size >= 5 && UserRegistry(userRegistry).balances(msg.sender) >= cost*size) //Checks if the assessment has a size of at least 5
    {
      Assessment newAssessment = new Assessment(msg.sender, userRegistry, conceptRegistry, size, cost); //Makes a new assessment with the given parameters
      assessmentExists[address(newAssessment)] = true; //Sets the assessment's existance to true
      setBalance(msg.sender, UserRegistry(userRegistry).balances(msg.sender) - cost*size);
      User(msg.sender).notification(address(this), 19); //You have been charged for your assessment
      return true;
    }
    else
    {
      return false;
    }
  }

  /*
  @type: function
  @purpose: To start the assessment process
  @param: address assessment = the address of the assessment
  @returns: nothing
  */
  function startAssessment(address assessment)
  {
    if(block.number - Assessment(assessment).startTime() <= 10) //Checks if this function is being called 4 to 6 blocks after the block in which the assessment was created
    {
      Assessment(assessment).setAssessorPool(block.number); //Calls the function to set the assessor pool
    }
    else
    {
      Assessment(assessment).cancelAssessment(); //If this function is called too early or too late the assessment is cancelled
    }
  }

  /*
  @type: function
  @purpose: To finish the assessment process
  @param: int score = the assessee's score
  @param: address assessee = the address of the assessee
  @param: address assessment = the address of the assessment
  @returns: nothing
  */
  function finishAssessment(int score, address assessee, address assessment)
  {
    if(msg.sender == assessment) //Checks to make sure this function is being callled by the assessment
    {
      if(score > 0)
      {
        owners.push(assessee); //Makes the assessee an owner of this concept
        uint weight = Assessment(assessment).size()*uint(score);
        addOwner(assessee, weight);
        User(assessee).setConceptPassed(true);
      }
      User(assessee).mapHistory(assessment); //Maps the assessee to the assessment in the user master as part of the assessee's history
      currentScores[assessee] = score; //Maps the assessee to their score
      assessmentSizes[assessee] = Assessment(assessment).size(); //Maps the assessee to the assessment size
      CompletedAssessment(assessee, score, assessment); //Makes an event with this assessment's data
    }
  }

  /*
  @type: function
  @purpose: To add an owner to a concept and recursively add an owner to parent concept, halving the added weight with each generation and chinging the macWeight for a concept if neccisairy
  @param: bool pass = whether or not the assessee passed the assessment
  @param: address assessee = the address of the assessee
  @param: uint weight = the weight for the owner
  @returns: nothing
  */
  function addOwner(address assessee, uint weight)
  {
    owners.push(assessee); //adds the owner to the array
    weights[assessee] += weight; //adds the weight to the current value in mapping
    if(weight > maxWeight) //checks if the weight is greater than the currant maxWeight
    {
      maxWeight = weight; //if so changes the maxWeight value
    }
    for(uint i = 0; i < parents.length; i++)
    {
      Concept(parents[i]).addOwner(assessee, weight/2); //recursively adds owner to all parent concepts but with half the weight
    }
  }

  /*
  @type: function
  @purpose: To pay/charge a user for an assessment
  @param: address user = the user to pay/charge
  @param: int amount = the user's new token balance
  */
  function setBalance(address user, uint amount)
  {
    if(assessmentExists[msg.sender] || msg.sender == address(this)) //Checks if msg.sender is an existing assessment
    {
      UserRegistry(userRegistry).setBalance(user, amount); //Changes the user's token balance
    }
  }

  /*
  @type: function
  @purpose: to remove this contract
  @param: address receiver = the address of the wallet that will receive of the ether
  @returns: nothing
  */
  function remove(address reciever) onlyThis()
  {
    suicide(reciever);
  }
}


BancorBuyer - removed redundant code

BancorBuyer - removed redundant code

pragma solidity ^0.4.11;
import './TokenHolder.sol';
import './interfaces/ISmartToken.sol';
import './interfaces/IEtherToken.sol';
import './interfaces/ITokenChanger.sol';

/*
    Bancor Changer interface
*/
contract IBancorChanger is ITokenChanger {
    function token() public constant returns (ISmartToken _token) { _token; }
    function getReserveBalance(IERC20Token _reserveToken) public constant returns (uint256 balance);
}

/*
    BancorBuyer v0.2

    The bancor buyer contract is a simple bancor changer wrapper that allows buying smart tokens with ETH

    WARNING: the contract will make the purchase using the current price at transaction mining time
*/
contract BancorBuyer is TokenHolder {
    string public version = '0.2';
    IBancorChanger public tokenChanger; // bancor ETH <-> smart token changer
    IEtherToken public etherToken;      // ether token

    /**
        @dev constructor

        @param _changer     bancor token changer that actually does the purchase
        @param _etherToken  ether token used as a reserve in the token changer
    */
    function BancorBuyer(IBancorChanger _changer, IEtherToken _etherToken)
        validAddress(_changer)
        validAddress(_etherToken)
    {
        tokenChanger = _changer;
        etherToken = _etherToken;

        // ensure that the ether token is used as one of the changer's reserves
        tokenChanger.getReserveBalance(etherToken);
    }

    /**
        @dev buys the smart token with ETH
        note that the purchase will use the price at the time of the purchase

        @return tokens issued in return
    */
    function buy() public payable returns (uint256 amount) {
        return buy(1);
    }

    /**
        @dev buys the smart token with ETH if the return amount meets the minimum requested

        @param _minReturn  if the change results in an amount smaller than the minimum return - it is cancelled, must be nonzero

        @return tokens issued in return
    */
    function buyMin(uint256 _minReturn) public payable returns (uint256 amount) {
        etherToken.deposit.value(msg.value)(); // deposit ETH in the reserve
        assert(etherToken.approve(tokenChanger, 0)); // need to reset the allowance to 0 before setting a new one
        assert(etherToken.approve(tokenChanger, msg.value)); // approve the changer to use the ETH amount for the purchase

        ISmartToken smartToken = tokenChanger.token();
        uint256 returnAmount = tokenChanger.change(etherToken, smartToken, msg.value, _minReturn); // do the actual change
        assert(smartToken.transfer(msg.sender, returnAmount)); // transfer the tokens to the sender
        return returnAmount;
    }

    // fallback
    function() payable {
        buy();
    }
}

pragma solidity ^0.4.11;
import './TokenHolder.sol';
import './interfaces/ISmartToken.sol';
import './interfaces/IEtherToken.sol';
import './interfaces/ITokenChanger.sol';

/*
    Bancor Changer interface
*/
contract IBancorChanger is ITokenChanger {
    function token() public constant returns (ISmartToken _token) { _token; }
    function getReserveBalance(IERC20Token _reserveToken) public constant returns (uint256 balance);
}

/*
    BancorBuyer v0.2

    The bancor buyer contract is a simple bancor changer wrapper that allows buying smart tokens with ETH

    WARNING: the contract will make the purchase using the current price at transaction mining time
*/
contract BancorBuyer is TokenHolder {
    string public version = '0.2';
    IBancorChanger public tokenChanger; // bancor ETH <-> smart token changer
    IEtherToken public etherToken;      // ether token

    /**
        @dev constructor

        @param _changer     bancor token changer that actually does the purchase
        @param _etherToken  ether token used as a reserve in the token changer
    */
    function BancorBuyer(IBancorChanger _changer, IEtherToken _etherToken)
        validAddress(_changer)
        validAddress(_etherToken)
    {
        tokenChanger = _changer;
        etherToken = _etherToken;

        // ensure that the ether token is used as one of the changer's reserves
        tokenChanger.getReserveBalance(etherToken);
    }

    /**
        @dev buys the smart token with ETH
        note that the purchase will use the price at the time of the purchase

        @return tokens issued in return
    */
    function buy() public payable returns (uint256 amount) {
        etherToken.deposit.value(msg.value)(); // deposit ETH in the reserve
        assert(etherToken.approve(tokenChanger, 0)); // need to reset the allowance to 0 before setting a new one
        assert(etherToken.approve(tokenChanger, msg.value)); // approve the changer to use the ETH amount for the purchase

        ISmartToken smartToken = tokenChanger.token();
        uint256 returnAmount = tokenChanger.change(etherToken, smartToken, msg.value, 1); // do the actual change using the current price
        assert(smartToken.transfer(msg.sender, returnAmount)); // transfer the tokens to the sender
        return returnAmount;
    }

    /**
        @dev buys the smart token with ETH if the return amount meets the minimum requested

        @param _minReturn  if the change results in an amount smaller than the minimum return - it is cancelled, must be nonzero

        @return tokens issued in return
    */
    function buyMin(uint256 _minReturn) public payable returns (uint256 amount) {
        etherToken.deposit.value(msg.value)(); // deposit ETH in the reserve
        assert(etherToken.approve(tokenChanger, 0)); // need to reset the allowance to 0 before setting a new one
        assert(etherToken.approve(tokenChanger, msg.value)); // approve the changer to use the ETH amount for the purchase

        ISmartToken smartToken = tokenChanger.token();
        uint256 returnAmount = tokenChanger.change(etherToken, smartToken, msg.value, _minReturn); // do the actual change
        assert(smartToken.transfer(msg.sender, returnAmount)); // transfer the tokens to the sender
        return returnAmount;
    }

    // fallback
    function() payable {
        buy();
    }
}