fix add invalid version label test

fix add invalid version label test

pragma solidity ^0.4.23;

import "truffle/Assert.sol";
import "../contracts/SwapyExchange.sol";
import "./helpers/ThrowProxy.sol";

contract TestSwapyExchange_versioning {
    SwapyExchange protocol = new SwapyExchange(address(0x281055afc982d96fab65b3a49cac8b878184cb16),"1.0.0",address(0x6f46cf5569aefa1acc1009290c8e043747172d89));
    ThrowProxy throwProxy = new ThrowProxy(address(protocol));
    SwapyExchange throwableProtocol = SwapyExchange(address(throwProxy));

    // Truffle looks for `initialBalance` when it compiles the test suite
    // and funds this test contract with the specified amount on deployment.
    uint public initialBalance = 10 ether;

    function shouldThrow(bool execution) public {
        Assert.isFalse(execution, "Should throw an exception");
    }
    // Testing the addLibrary() function
    function testOnlyProtocolOwnerCanAddLibrary() public {
        address(throwableProtocol).call(abi.encodeWithSignature("addLibrary(bytes8,address)", bytes8("3.0.0"), address(0x8f46cf5569aefa1acc1009290c8e043747172d45)));
        throwProxy.shouldThrow();
    }

    function testProtocolOwnerCanAddLibraryVersion() public {
        address lib3 = address(0x9f46cf5569aefa1acc1009290c8e043747172d45);
        bool result = protocol.addLibrary(bytes8("3.0.0"), lib3);
        bytes8 latestVersion = protocol.latestVersion();
        address latestLib = protocol.getLibrary(latestVersion);
        bool check = (latestVersion == bytes8("3.0.0")) && (latestLib == address(lib3));
        Assert.equal(check, true, "The latest version must be 3.0.0 and the library address of this version must be equal the lastest deployed library");
    }

    function testOwnerCannotAddDuplicatedVersion() public {
        bool result = address(protocol).call(abi.encodeWithSignature("addLibrary(bytes8,address)", bytes8("3.0.0"), address(0x9f46cf5569aefa1acc1009290c8e043747172d45)));
        shouldThrow(result);
    }

    function testOwnerCannotAddInvalidVersion() public {
        bool result = address(protocol).call(abi.encodeWithSignature("addLibrary(bytes8,address)", bytes8(0), address(0x9f46cf5569aefa1acc1009290c8e043747172d45)));
        shouldThrow(result);
    }

    function testOwnerCannotAddInvalidLibrary() public {
        bool result = address(protocol).call(abi.encodeWithSignature("addLibrary(bytes8,address)", bytes8("4.0.0"), address(0)));
        shouldThrow(result);
    }
}

pragma solidity ^0.4.23;

import "truffle/Assert.sol";
import "../contracts/SwapyExchange.sol";
import "./helpers/ThrowProxy.sol";

contract TestSwapyExchange_versioning {
    SwapyExchange protocol = new SwapyExchange(address(0x281055afc982d96fab65b3a49cac8b878184cb16),"1.0.0",address(0x6f46cf5569aefa1acc1009290c8e043747172d89));
    ThrowProxy throwProxy = new ThrowProxy(address(protocol));
    SwapyExchange throwableProtocol = SwapyExchange(address(throwProxy));

    // Truffle looks for `initialBalance` when it compiles the test suite
    // and funds this test contract with the specified amount on deployment.
    uint public initialBalance = 10 ether;

    function shouldThrow(bool execution) public {
        Assert.isFalse(execution, "Should throw an exception");
    }
    // Testing the addLibrary() function
    function testOnlyProtocolOwnerCanAddLibrary() public {
        address(throwableProtocol).call(abi.encodeWithSignature("addLibrary(bytes8,address)", bytes8("3.0.0"), address(0x8f46cf5569aefa1acc1009290c8e043747172d45)));
        throwProxy.shouldThrow();
    }

    function testProtocolOwnerCanAddLibraryVersion() public {
        address lib3 = address(0x9f46cf5569aefa1acc1009290c8e043747172d45);
        bool result = protocol.addLibrary(bytes8("3.0.0"), lib3);
        bytes8 latestVersion = protocol.latestVersion();
        address latestLib = protocol.getLibrary(latestVersion);
        bool check = (latestVersion == bytes8("3.0.0")) && (latestLib == address(lib3));
        Assert.equal(check, true, "The latest version must be 3.0.0 and the library address of this version must be equal the lastest deployed library");
    }

    function testOwnerCannotAddDuplicatedVersion() public {
        bool result = address(protocol).call(abi.encodeWithSignature("addLibrary(bytes8,address)", bytes8("3.0.0"), address(0x9f46cf5569aefa1acc1009290c8e043747172d45)));
        shouldThrow(result);
    }

    function testOwnerCannotAddInvalidVersion() public {
        bool result = address(protocol).call(abi.encodeWithSignature("addLibrary(bytes8,address)", bytes8(0), address(0x9f46cf5569aefa1acc1009290c8e043747172d45)));
        shouldThrow(result);
    }

    function testOwnerCannotAddInvalidLibrary() public {
        bool result = address(protocol).call(abi.encodeWithSignature("addLibrary(bytes8,address)", bytes8("3.0.0"), address(0)));
        shouldThrow(result);
    }
}


fixed comments

fixed comments

pragma solidity ^0.4.8;

// This contract implements a simple store that can interact with
// registered customers. Every customer has its own shopping cart.
// @title Contract Store
// @author Harris Brakmic
contract Store {

    /* Store internals */
    address owner;      // store owner's address
    bytes32 public name; // store name
    uint balance;       // store's balance

    mapping (address => Customer) customers;
    mapping (uint => Product) products;

    /* Store Events */
    event CustomerRegistered(address customer);
    event CustomerRegistrationFailed(address customer);
    event CustomerDeregistered(address customer);
    event CustomerDeregistrationFailed(address customer);

    event ProductRegistered(uint productId);
    event ProductDeregistered(uint productId);
    event ProductRegistrationFailed(uint productId);
    event ProductDeregistrationFaled(uint productId);

    event CartProductInserted(address customer, uint prodId);
    event CartProductInsertionFailed(address customer, uint prodId);
    event CartProductRemoved(address customer, uint prodId);
    event CartCheckoutCompleted(address customer, uint paymentSum);
    event CartCheckoutFailed(address customer, uint paymentSum);

    modifier onlyStoreOwner {
        require(msg.sender == owner);
        _;
    }

    // every customer has an address, name,
    // balance and a shopping cart
    struct Customer {
        address adr;
        bytes name;
        uint balance;
        Cart cart;
    }
    // A shopping cart contains an array of product ids: @products
    // and a sum of product prices: @completeSum
    // The @completeSum gets automatically updated when customer
    // adds or removes products.
    struct Cart {
      uint[] products;
      uint completeSum;
    }
    // Represents a product:
    // Product id: @id
    // Product name: @name
    // Decription: @description
    // Amount of items in a single product: @default_amount
    struct Product {
        uint id;
        bytes32 name;
        bytes32 description;
        uint price;
        uint default_amount;
    }
    // Represents a receipt [NOT IN USE]
    struct Receipt {
        InvoiceLine[] lines;
        address customer_address;
    }
    // Represents a single entry describing a single product [NOT IN USE]
    struct InvoiceLine {
        bytes product_id;
        uint amount;
        uint product_price;
        uint total_price;
    }
    /**
          @dev Default constructor
    */
    function Store() {
        owner = msg.sender;
        name = "retailtest";
    }

    /**
          @dev Changes the address of the store owner

          @param  new_owner Address of the new Store Owner
          @return success

    */
    function changeOwner(address new_owner) onlyStoreOwner
                                                        returns (bool success) {
      if (new_owner != owner) {
        owner = new_owner;
        return true;
      }
      return false;
    }

    /**
          @dev Register a single product

          @param id Product ID
          @param name Product Name
          @param description Product Description
          @param price Product Price
          @param default_amount Default amount of items in a single product

          @return success
    */
    function registerProduct(uint id, bytes32 name, bytes32 description,
                             uint price, uint default_amount)
                                         onlyStoreOwner returns (bool success) {
        var product = Product(id, name, description, price, default_amount);
        if (checkProductValidity(product)) {
            products[id] = product;
            ProductRegistered(id);
            return true;
        }
        ProductRegistrationFailed(id);
        return false;
    }

    /**
          @dev Removes a product from the list

          @param productId Product ID
          @return success
    */
    function deregisterProduct(uint productId) onlyStoreOwner
                                                        returns (bool success) {
      Product product = products[productId];
      if (product.id == productId) {
        delete products[productId];
        ProductDeregistered(productId);
        return true;
      }
      ProductDeregistrationFaled(productId);
      return false;
    }

    /**
          @dev Returns a elements describing a product
          @param id Product ID
          @return (prod_name, prod_desc, prod_price, prod_default_amount)
    */
    function getProduct(uint id) constant returns (bytes32 prod_name,
                                                   bytes32 prod_desc,
                                                   uint prod_price,
                                                   uint prod_default_amount) {
       return (products[id].name,
               products[id].description,
               products[id].price,
               products[id].default_amount);
    }

    /**
          @dev Registers a new customer (only store owners)

          @param _address Customer's address
          @param _name Customer's name
          @param _balance Customer's balance
          @return success
    */
    function registerCustomer(address _address, bytes _name, uint _balance)
                                        onlyStoreOwner returns (bool success) {
      if (_address != owner) {
        customers[_address] = Customer(_address, _name, _balance,
                                                        Cart(new uint[](0), 0));
        CustomerRegistered(_address);
        return true;
      }
      CustomerRegistrationFailed(_address);
      return false;
    }

    /**
        @dev Removes a customer (only store owners)

        @param _address Customer'S address
        @return success
    */
    function deregisterCustomer(address _address) onlyStoreOwner
                                                        returns (bool success) {
      Customer customer = customers[_address];
      if (customer.adr != address(0)) {
        delete customers[_address];
        CustomerDeregistered(_address);
        return true;
      }
      CustomerDeregistrationFailed(_address);
      return false;
    }

    /**
        @dev Inserts a product into the shopping cart.
            This function returns a boolean and the position of the
            inserted product.
            The positional information can later be used to directly reference
            the product within the mapping. Solidity mappings aren't interable.

        @param prodId Product ID
        @return (success, position)
    */
    function insertProductIntoCart(uint prodId) returns (bool success,
                                                         uint position) {
      /*if (msg.sender != owner) {*/
        customers[msg.sender].cart.products.push(prodId);
        customers[msg.sender].cart.completeSum += products[prodId].price;
        CartProductInserted(msg.sender, prodId);
        return (true, customers[msg.sender].cart.products.length - 1);
      /*}*/
      /*CartProductInsertionFailed(msg.sender, prodId);*/
      /*return (false, 0);*/
    }

    /**
        @dev Removes a product entry from the shopping cart

        @param prodPosition Product's position in the internal mapping
    */
    function removeProductFromCart(uint prodPosition) {
      if (msg.sender != owner) {
        uint[] memory new_product_list = new uint[](customers[msg.sender]
                                                    .cart.products.length - 1);
        var customerProds = customers[msg.sender].cart.products;
        for (uint i = 0; i < customerProds.length; i++) {
          if (i != prodPosition) {
            new_product_list[i] = customerProds[i];
          } else {
            customers[msg.sender].cart.completeSum -=
                                               products[customerProds[i]].price;
            CartProductRemoved(msg.sender, customerProds[i]);
          }
        }
        customers[msg.sender].cart.products = new_product_list;
      }
    }

    /**
        @dev Returns a list of product ids and a complete sum.
        The caller address must be a registered customer.

        @return (productIds, completeSum)
    */
    function getCart() constant returns (uint[] productIds, uint completeSum) {
      Customer customer = customers[msg.sender];
      uint len = customer.cart.products.length;
      uint[] memory ids = new uint[](len);
      for (uint i = 0; i < len; i++) {
        ids[i] = products[i].id;
      }
      return (ids, customer.cart.completeSum);
    }

    /**
          @dev Returns customer's balance
    */
    function getBalance() constant returns (uint _balance) {
      return customers[msg.sender].balance;
    }

    /**
        @dev Invokes a checkout process that'll use the current shopping cart to
        transfer balances between the current customer and the store

        @return success
    */
    function checkoutCart() returns (bool success) {
      if (msg.sender != owner) {
        Customer customer = customers[msg.sender];
        uint paymentSum = customer.cart.completeSum;
        if ((customer.balance >= paymentSum) &&
            customer.cart.products.length > 0) {
            customer.balance -= paymentSum;
            customer.cart = Cart(new uint[](0), 0);
            balance += paymentSum;
            CartCheckoutCompleted(msg.sender, paymentSum);
            return true;
        }
      }
      CartCheckoutFailed(msg.sender, paymentSum);
      return false;
    }

    /**
          @dev Changes the name of the store

          @param new_store_name New store name
          @return success
    */
    function renameStoreTo(bytes32 new_store_name) onlyStoreOwner
                                                        returns (bool success) {
        if (new_store_name.length != 0 &&
            new_store_name.length <= 32) {
            name = new_store_name;
            return true;
        }
        return false;
    }

    /**
          @dev Checks product validity

          @param product Product struct
          @return valid
    */
    function checkProductValidity(Product product) private
                                                          returns (bool valid) {
       return (product.price > 0);
    }

    /**
          @dev Payable fallback
    */
    function() payable { }
}

pragma solidity ^0.4.8;

// This contract implements a simple store that can interact with
// registered customers. Every customer has its own shopping cart.
// @title Contract Store
// @author Harris Brakmic
contract Store {

    /* Store internals */
    address owner;      // store owner's address
    bytes32 public name; // store name
    uint balance;       // store's balance

    mapping (address => Customer) customers;
    mapping (uint => Product) products;

    /* Store Events */
    event CustomerRegistered(address customer);
    event CustomerRegistrationFailed(address customer);
    event CustomerDeregistered(address customer);
    event CustomerDeregistrationFailed(address customer);

    event ProductRegistered(uint productId);
    event ProductDeregistered(uint productId);
    event ProductRegistrationFailed(uint productId);
    event ProductDeregistrationFaled(uint productId);

    event CartProductInserted(address customer, uint prodId);
    event CartProductInsertionFailed(address customer, uint prodId);
    event CartProductRemoved(address customer, uint prodId);
    event CartCheckoutCompleted(address customer, uint paymentSum);
    event CartCheckoutFailed(address customer, uint paymentSum);

    modifier onlyStoreOwner {
        require(msg.sender == owner);
        _;
    }

    // every customer has an address, name,
    // balance and a shopping cart
    struct Customer {
        address adr;
        bytes name;
        uint balance;
        Cart cart;
    }
    // A shopping cart contains an array of product ids: @products
    // and a sum of product prices: @completeSum
    // The @completeSum gets automatically updated when customer
    // adds or removes products.
    struct Cart {
      uint[] products;
      uint completeSum;
    }
    // Represents a product:
    // Product id: @id
    // Product name: @name
    // Decription: @description
    // Amount of items in a single product: @default_amount
    struct Product {
        uint id;
        bytes32 name;
        bytes32 description;
        uint price;
        uint default_amount;
    }
    // Represents a receipt [NOT IN USE]
    struct Receipt {
        InvoiceLine[] lines;
        address customer_address;
    }
    // Represents a single entry describing a single product [NOT IN USE]
    struct InvoiceLine {
        bytes product_id;
        uint amount;
        uint product_price;
        uint total_price;
    }
    /**
          @dev Default constructor
    */
    function Store() {
        owner = msg.sender;
        name = "retailtest";
    }

    /**
          @dev Changes the address of the store owner

          @param new_owner
          @return success

    */
    function changeOwner(address new_owner) onlyStoreOwner
                                                        returns (bool success) {
      if (new_owner != owner) {
        owner = new_owner;
        return true;
      }
      return false;
    }

    /**
          @dev Register a single product

          @param id
          @param name
          @param description
          @param price
          @param default_amount

          @return success
    */
    function registerProduct(uint id, bytes32 name, bytes32 description,
                             uint price, uint default_amount)
                                         onlyStoreOwner returns (bool success) {
        var product = Product(id, name, description, price, default_amount);
        if (checkProductValidity(product)) {
            products[id] = product;
            ProductRegistered(id);
            return true;
        }
        ProductRegistrationFailed(id);
        return false;
    }

    /**
          @dev Removes a product from the list

          @param productId
          @return success
    */
    function deregisterProduct(uint productId) onlyStoreOwner
                                                        returns (bool success) {
      Product product = products[productId];
      if (product.id == productId) {
        delete products[productId];
        ProductDeregistered(productId);
        return true;
      }
      ProductDeregistrationFaled(productId);
      return false;
    }

    /**
          @dev Returns a elements describing a product
          @param id
          @return (prod_name, prod_desc, prod_price, prod_default_amount)
    */
    function getProduct(uint id) constant returns (bytes32 prod_name,
                                                   bytes32 prod_desc,
                                                   uint prod_price,
                                                   uint prod_default_amount) {
       return (products[id].name,
               products[id].description,
               products[id].price,
               products[id].default_amount);
    }

    /**
          @dev Registers a new customer (only store owners)

          @param _address
          @param _name
          @param _balance
          @return success
    */
    function registerCustomer(address _address, bytes _name, uint _balance)
                                        onlyStoreOwner returns (bool success) {
      if (_address != owner) {
        customers[_address] = Customer(_address, _name, _balance,
                                                        Cart(new uint[](0), 0));
        CustomerRegistered(_address);
        return true;
      }
      CustomerRegistrationFailed(_address);
      return false;
    }

    /**
        @dev Removes a customer (only store owners)

        @param customerAddress
        @return success
    */
    function deregisterCustomer(address customerAddress) onlyStoreOwner
                                                        returns (bool success) {
      Customer customer = customers[customerAddress];
      if (customer.adr != address(0)) {
        delete customers[customerAddress];
        CustomerDeregistered(customerAddress);
        return true;
      }
      CustomerDeregistrationFailed(customerAddress);
      return false;
    }

    /**
        @dev Inserts a product into the shopping cart.
            This function returns a boolean and the position of the
            inserted product.
            The positional information can later be used to directly reference
            the product within the mapping. Solidity mappings aren't interable.

        @param prodId
        @return (success, position)
    */
    function insertProductIntoCart(uint prodId) returns (bool success,
                                                         uint position) {
      /*if (msg.sender != owner) {*/
        customers[msg.sender].cart.products.push(prodId);
        customers[msg.sender].cart.completeSum += products[prodId].price;
        CartProductInserted(msg.sender, prodId);
        return (true, customers[msg.sender].cart.products.length - 1);
      /*}*/
      /*CartProductInsertionFailed(msg.sender, prodId);*/
      /*return (false, 0);*/
    }

    /**
        @dev Removes a product entry from the shopping cart

        @param prodPosition
    */
    function removeProductFromCart(uint prodPosition) {
      if (msg.sender != owner) {
        uint[] memory new_product_list = new uint[](customers[msg.sender]
                                                    .cart.products.length - 1);
        var customerProds = customers[msg.sender].cart.products;
        for (uint i = 0; i < customerProds.length; i++) {
          if (i != prodPosition) {
            new_product_list[i] = customerProds[i];
          } else {
            customers[msg.sender].cart.completeSum -=
                                               products[customerProds[i]].price;
            CartProductRemoved(msg.sender, customerProds[i]);
          }
        }
        customers[msg.sender].cart.products = new_product_list;
      }
    }

    /**
        @dev Returns a list of product ids and a complete sum.
        The caller address must be a registered customer.

        @return (productIds, completeSum)
    */
    function getCart() constant returns (uint[] productIds, uint completeSum) {
      Customer customer = customers[msg.sender];
      uint len = customer.cart.products.length;
      uint[] memory ids = new uint[](len);
      for (uint i = 0; i < len; i++) {
        ids[i] = products[i].id;
      }
      return (ids, customer.cart.completeSum);
    }

    // Returns customer's balance
    function getBalance() constant returns (uint _balance) {
      return customers[msg.sender].balance;
    }

    /**
        @dev Invokes a checkout process that'll use the current shopping cart to
        transfer balances between the current customer and the store

        @return success
    */
    function checkoutCart() returns (bool success) {
      if (msg.sender != owner) {
        Customer customer = customers[msg.sender];
        uint paymentSum = customer.cart.completeSum;
        if ((customer.balance >= paymentSum) &&
            customer.cart.products.length > 0) {
            customer.balance -= paymentSum;
            customer.cart = Cart(new uint[](0), 0);
            balance += paymentSum;
            CartCheckoutCompleted(msg.sender, paymentSum);
            return true;
        }
      }
      CartCheckoutFailed(msg.sender, paymentSum);
      return false;
    }

    /**
          @dev Changes the name of the store

          @param new_store_name
          @return success
    */
    function renameStoreTo(bytes32 new_store_name) onlyStoreOwner
                                                        returns (bool success) {
        if (new_store_name.length != 0 &&
            new_store_name.length <= 32) {
            name = new_store_name;
            return true;
        }
        return false;
    }

    /**
          @dev Checks product validity

          @param product
          @return valid
    */
    function checkProductValidity(Product product) private
                                                          returns (bool valid) {
       return (product.price > 0);
    }

    /**
          @dev Payable fallback
    */
    function() payable { }
}


increased timeout

increased timeout

pragma solidity ^0.4.16;

import "./DepositsManager.sol";
import "./interactive.sol";
import "./fs.sol";

/*
interface InteractiveI {
    function make(uint task_id, address p, address c, bytes32 s, bytes32 e, uint256 par, uint to) external returns (bytes32);

    function calcStateHash(bytes32[10] roots, uint[4] pointers) external returns (bytes32);
    function checkFileProof(bytes32 state, bytes32[10] roots, uint[4] pointers, bytes32[] proof, uint loc) external returns (bool);
    function checkProof(bytes32 hash, bytes32 root, bytes32[] proof, uint loc) external returns (bool);

    // Check if a task has been rejected
    function isRejected(uint id) external returns (bool);
    // Check if a task is blocked, returns the block when it can be accepted
    function blockedTime(uint id) external returns (uint);
    function getChallenger(bytes32 id) external returns (address);
    function getTask(bytes32 id) external view returns (uint);
    function deleteChallenge(bytes32 id) external;
    function getProver(bytes32 id) external returns (address);
}
*/

interface Callback {
    function solved(uint id, bytes32[] files) external;
    function rejected(uint id) external;
}

/*
interface FilesystemI {
  function getRoot(bytes32 id) external view returns (bytes32);
  function getNameHash(bytes32 id) external view returns (bytes32);
}
*/

contract Tasks is DepositsManager {

    uint constant DEPOSIT = 0.01 ether;
    uint constant TIMEOUT = 100;

    enum CodeType {
        WAST,
        WASM,
        INTERNAL
    }

    enum Storage {
        IPFS,
        BLOCKCHAIN
    }

    event Posted(address giver, bytes32 hash, CodeType ct, Storage cs, string stor, uint id, uint deposit);
    event Solved(uint id, bytes32 hash, bytes32 init, CodeType ct, Storage cs, string stor, address solver, uint deposit);
    event Finalized(uint id);

    Interactive iactive;
    Filesystem fs;

    constructor(address contr, address fs_addr) public {
        iactive = Interactive(contr);
        fs = Filesystem(fs_addr);
    }

    function getInteractive() public view returns (address) {
        return address(iactive);
    }

    struct RequiredFile {
       bytes32 name_hash;
       Storage file_storage;
       bytes32 file_id;
    }

    struct IO {
       bytes32 name;
       bytes32 size;
       bytes32 data;

       RequiredFile[] uploads;
    }

    struct VMParameters {
        uint8 stack_size;
        uint8 memory_size;
        uint8 call_size;
        uint8 globals_size;
        uint8 table_size;
    }

    struct Task2 {
        address solver;
        bytes32 result;

        bytes32 output_file;

        bool good; // has the file been loaded
        uint blocked; // how long we have to wait to accept solution

        bytes32[] challenges;
    }

    struct Task {
        address giver;
        bytes32 init; // includes code and input roots, the output should be similar
        string stor;

        CodeType code_type;
        Storage storage_type;

        uint state;
    }

    Task[] public tasks;
    Task2[] public tasks2;
    VMParameters[] params;
    IO[] io_roots;

    mapping (bytes32 => uint) challenges;

    function defaultParameters(uint id) internal {
        VMParameters storage param = params[id];
        param.stack_size = 14;
        param.memory_size = 16;
        param.globals_size = 8;
        param.table_size = 8;
        param.call_size = 10;
    }

    function add(bytes32 init, CodeType ct, Storage cs, string stor) public returns (uint) {
        uint id = tasks.length;
        tasks.length++;
        tasks2.length++;
        params.length++;
        io_roots.length++;
        Task storage t = tasks[id];
        Task2 storage t2 = tasks2[id];
        t.giver = msg.sender;
        t.init = init;
        t.stor = stor;
        t2.good = true;
        t.code_type = ct;
        t.storage_type = cs;
        defaultParameters(id);
        emit Posted(msg.sender, init, ct, cs, stor, id, DEPOSIT);
        return id;
    }

    function addWithParameters(bytes32 init, CodeType ct, Storage cs, string stor, uint8 stack, uint8 mem, uint8 globals, uint8 table, uint8 call) public returns (uint) {
        uint id = tasks.length;
        tasks.length++;
        tasks2.length++;
        params.length++;
        io_roots.length++;
        Task storage t = tasks[id];
        Task2 storage t2 = tasks2[id];
        t.giver = msg.sender;
        t.init = init;
        t.stor = stor;
        t2.good = true;
        t.code_type = ct;
        t.storage_type = cs;

        VMParameters storage param = params[id];
        param.stack_size = stack;
        param.memory_size = mem;
        param.globals_size = globals;
        param.table_size = table;
        param.call_size = call;
        emit Posted(msg.sender, init, ct, cs, stor, id, DEPOSIT);
        return id;
    }

    // Make sure they won't be required after the task has been posted already
    function requireFile(uint id, bytes32 hash, Storage st) public {
        IO storage io = io_roots[id];
        io.uploads.push(RequiredFile(hash, st, 0));
    }

    function getUploadNames(uint id) public view returns (bytes32[]) {
        RequiredFile[] storage lst = io_roots[id].uploads;
        bytes32[] memory arr = new bytes32[](lst.length);
        for (uint i = 0; i < arr.length; i++) arr[i] = lst[i].name_hash;
        return arr;

    }

    function getUploadTypes(uint id) public view returns (Storage[]) {
        RequiredFile[] storage lst = io_roots[id].uploads;
        Storage[] memory arr = new Storage[](lst.length);
        for (uint i = 0; i < arr.length; i++) arr[i] = lst[i].file_storage;
        return arr;
    }

    function taskInfo(uint unq) public view returns (address giver, bytes32 hash, CodeType ct, Storage cs, string stor, uint id) {
        Task storage t = tasks[unq];
        return (t.giver, t.init, t.code_type, t.storage_type, t.stor, unq);
    }

    function getVMParameters(uint id) public view returns (uint8 stack, uint8 mem, uint8 globals, uint8 table, uint8 call) {
        VMParameters storage param = params[id];
        stack = param.stack_size;
        mem = param.memory_size;
        globals = param.globals_size;
        table = param.table_size;
        call = param.call_size;
    }

    function nextTask() public view returns (uint) {
        return tasks.length;
    }

    function getSolver(uint id) public view returns (address) {
        return tasks2[id].solver;
    }

    function solveIO(uint id, bytes32 code, bytes32 size, bytes32 name, bytes32 data) public returns (bool) {
        Task storage t = tasks[id];
        Task2 storage t2 = tasks2[id];
        IO storage io = io_roots[id];
        require(t2.solver == 0 && t2.good);

        io.size = size;
        io.name = name;
        io.data = data;
        t2.solver = msg.sender;
        t2.result = keccak256(code, size, name, data);
        t.state = 1;
        t2.blocked = block.number + TIMEOUT;
        emit Solved(id, t2.result, t.init, t.code_type, t.storage_type, t.stor, t2.solver, DEPOSIT);
        subDeposit(msg.sender, DEPOSIT);
        return true;
    }

    function solutionInfo(uint unq) public view returns (uint id, bytes32 hash, bytes32 init, CodeType ct, Storage cs, string stor, address solver) {
        Task storage t = tasks[unq];
        Task2 storage t2 = tasks2[unq];
        return (unq, t2.result, t.init, t.code_type, t.storage_type, t.stor, t2.solver);
    }

    /*
    function getCodeType(uint id) public view returns (CodeType) {
        return tasks[id].code_type;
    }

    function getCodeStorage(uint id) public view returns (Storage) {
        // return tasks[id].code_storage;
    }
    */

    function challenge(uint id) public {
        Task storage t = tasks[id];
        Task2 storage t2 = tasks2[id];
        // VMParameters storage p = params[id];
        require(t.state == 1);
        bytes32 uniq = iactive.make(id, t2.solver, msg.sender, t.init, t2.result, 1, TIMEOUT);
        challenges[uniq] = id;
        t2.challenges.push(uniq);
        subDeposit(msg.sender, DEPOSIT);
    }

    function queryChallenge(bytes32 uniq) constant public returns (uint) {
        return challenges[uniq];
    }

    function getChallenges(uint id) public view returns (bytes32[]) {
        return tasks2[id].challenges;
    }

    function uploadFile(uint id, uint num, bytes32 file_id, bytes32[] name_proof, bytes32[] data_proof, uint file_num) public returns (bool) {
        IO storage io = io_roots[id];
        RequiredFile storage file = io.uploads[num];
        if (!iactive.checkProof(fs.getRoot(file_id), io.data, data_proof, file_num) || !iactive.checkProof(fs.getNameHash(file_id), io.name, name_proof, file_num)) return false;
        require(iactive.checkProof(fs.getRoot(file_id), io.data, data_proof, file_num));
        require(iactive.checkProof(fs.getNameHash(file_id), io.name, name_proof, file_num));

        file.file_id = file_id;
        return true;
    }

    function finalizeTask(uint id) public returns (bool) {
        Task storage t = tasks[id];
        Task2 storage t2 = tasks2[id];
        IO storage io = io_roots[id];
        if (t.state != 1 || t2.blocked >= block.number || iactive.isRejected(id) || iactive.blockedTime(id) >= block.number) return false;
        // if (!(t.state == 1 && t2.blocked < block.number && !iactive.isRejected(id) && iactive.blockedTime(id) < block.number)) return false;

        // require(t.state == 1 && t2.blocked < block.number && !iactive.isRejected(id) && iactive.blockedTime(id) < block.number);
        t.state = 3;

        bytes32[] memory files = new bytes32[](io.uploads.length);
        for (uint i = 0; i < io.uploads.length; i++) {
           if (io.uploads[i].file_id == 0) return false;
           // require(io.uploads[i].file_id != 0);
           files[i] = io.uploads[i].file_id;
        }

        if (files.length > 0) Callback(t.giver).solved(id, files);

        emit Finalized(id);
        addDeposit(t2.solver, DEPOSIT);

        return true;
    }

    function claimDeposit(bytes32 cid) public {
        uint id = iactive.getTask(cid);
        require(iactive.isRejected(id));
        require(iactive.getChallenger(cid) == msg.sender);
        iactive.deleteChallenge(cid);
        addDeposit(msg.sender, DEPOSIT);
    }

    uint tick_var;

    // For testing, mine this to create new block
    function tick() public  {
        tick_var++;
    }

}

pragma solidity ^0.4.16;

import "./DepositsManager.sol";
import "./interactive.sol";
import "./fs.sol";

/*
interface InteractiveI {
    function make(uint task_id, address p, address c, bytes32 s, bytes32 e, uint256 par, uint to) external returns (bytes32);

    function calcStateHash(bytes32[10] roots, uint[4] pointers) external returns (bytes32);
    function checkFileProof(bytes32 state, bytes32[10] roots, uint[4] pointers, bytes32[] proof, uint loc) external returns (bool);
    function checkProof(bytes32 hash, bytes32 root, bytes32[] proof, uint loc) external returns (bool);

    // Check if a task has been rejected
    function isRejected(uint id) external returns (bool);
    // Check if a task is blocked, returns the block when it can be accepted
    function blockedTime(uint id) external returns (uint);
    function getChallenger(bytes32 id) external returns (address);
    function getTask(bytes32 id) external view returns (uint);
    function deleteChallenge(bytes32 id) external;
    function getProver(bytes32 id) external returns (address);
}
*/

interface Callback {
    function solved(uint id, bytes32[] files) external;
    function rejected(uint id) external;
}

/*
interface FilesystemI {
  function getRoot(bytes32 id) external view returns (bytes32);
  function getNameHash(bytes32 id) external view returns (bytes32);
}
*/

contract Tasks is DepositsManager {

    uint constant DEPOSIT = 0.01 ether;
    uint constant TIMEOUT = 10;

    enum CodeType {
        WAST,
        WASM,
        INTERNAL
    }

    enum Storage {
        IPFS,
        BLOCKCHAIN
    }

    event Posted(address giver, bytes32 hash, CodeType ct, Storage cs, string stor, uint id, uint deposit);
    event Solved(uint id, bytes32 hash, bytes32 init, CodeType ct, Storage cs, string stor, address solver, uint deposit);
    event Finalized(uint id);

    Interactive iactive;
    Filesystem fs;

    constructor(address contr, address fs_addr) public {
        iactive = Interactive(contr);
        fs = Filesystem(fs_addr);
    }

    function getInteractive() public view returns (address) {
        return address(iactive);
    }

    struct RequiredFile {
       bytes32 name_hash;
       Storage file_storage;
       bytes32 file_id;
    }

    struct IO {
       bytes32 name;
       bytes32 size;
       bytes32 data;

       RequiredFile[] uploads;
    }

    struct VMParameters {
        uint8 stack_size;
        uint8 memory_size;
        uint8 call_size;
        uint8 globals_size;
        uint8 table_size;
    }

    struct Task2 {
        address solver;
        bytes32 result;

        bytes32 output_file;

        bool good; // has the file been loaded
        uint blocked; // how long we have to wait to accept solution

        bytes32[] challenges;
    }

    struct Task {
        address giver;
        bytes32 init; // includes code and input roots, the output should be similar
        string stor;

        CodeType code_type;
        Storage storage_type;

        uint state;
    }

    Task[] public tasks;
    Task2[] public tasks2;
    VMParameters[] params;
    IO[] io_roots;

    mapping (bytes32 => uint) challenges;

    function defaultParameters(uint id) internal {
        VMParameters storage param = params[id];
        param.stack_size = 14;
        param.memory_size = 16;
        param.globals_size = 8;
        param.table_size = 8;
        param.call_size = 10;
    }

    function add(bytes32 init, CodeType ct, Storage cs, string stor) public returns (uint) {
        uint id = tasks.length;
        tasks.length++;
        tasks2.length++;
        params.length++;
        io_roots.length++;
        Task storage t = tasks[id];
        Task2 storage t2 = tasks2[id];
        t.giver = msg.sender;
        t.init = init;
        t.stor = stor;
        t2.good = true;
        t.code_type = ct;
        t.storage_type = cs;
        defaultParameters(id);
        emit Posted(msg.sender, init, ct, cs, stor, id, DEPOSIT);
        return id;
    }

    function addWithParameters(bytes32 init, CodeType ct, Storage cs, string stor, uint8 stack, uint8 mem, uint8 globals, uint8 table, uint8 call) public returns (uint) {
        uint id = tasks.length;
        tasks.length++;
        tasks2.length++;
        params.length++;
        io_roots.length++;
        Task storage t = tasks[id];
        Task2 storage t2 = tasks2[id];
        t.giver = msg.sender;
        t.init = init;
        t.stor = stor;
        t2.good = true;
        t.code_type = ct;
        t.storage_type = cs;

        VMParameters storage param = params[id];
        param.stack_size = stack;
        param.memory_size = mem;
        param.globals_size = globals;
        param.table_size = table;
        param.call_size = call;
        emit Posted(msg.sender, init, ct, cs, stor, id, DEPOSIT);
        return id;
    }

    // Make sure they won't be required after the task has been posted already
    function requireFile(uint id, bytes32 hash, Storage st) public {
        IO storage io = io_roots[id];
        io.uploads.push(RequiredFile(hash, st, 0));
    }

    function getUploadNames(uint id) public view returns (bytes32[]) {
        RequiredFile[] storage lst = io_roots[id].uploads;
        bytes32[] memory arr = new bytes32[](lst.length);
        for (uint i = 0; i < arr.length; i++) arr[i] = lst[i].name_hash;
        return arr;

    }

    function getUploadTypes(uint id) public view returns (Storage[]) {
        RequiredFile[] storage lst = io_roots[id].uploads;
        Storage[] memory arr = new Storage[](lst.length);
        for (uint i = 0; i < arr.length; i++) arr[i] = lst[i].file_storage;
        return arr;
    }

    function taskInfo(uint unq) public view returns (address giver, bytes32 hash, CodeType ct, Storage cs, string stor, uint id) {
        Task storage t = tasks[unq];
        return (t.giver, t.init, t.code_type, t.storage_type, t.stor, unq);
    }

    function getVMParameters(uint id) public view returns (uint8 stack, uint8 mem, uint8 globals, uint8 table, uint8 call) {
        VMParameters storage param = params[id];
        stack = param.stack_size;
        mem = param.memory_size;
        globals = param.globals_size;
        table = param.table_size;
        call = param.call_size;
    }

    function nextTask() public view returns (uint) {
        return tasks.length;
    }

    function getSolver(uint id) public view returns (address) {
        return tasks2[id].solver;
    }

    function solveIO(uint id, bytes32 code, bytes32 size, bytes32 name, bytes32 data) public returns (bool) {
        Task storage t = tasks[id];
        Task2 storage t2 = tasks2[id];
        IO storage io = io_roots[id];
        require(t2.solver == 0 && t2.good);

        io.size = size;
        io.name = name;
        io.data = data;
        t2.solver = msg.sender;
        t2.result = keccak256(code, size, name, data);
        t.state = 1;
        t2.blocked = block.number + TIMEOUT;
        emit Solved(id, t2.result, t.init, t.code_type, t.storage_type, t.stor, t2.solver, DEPOSIT);
        subDeposit(msg.sender, DEPOSIT);
        return true;
    }

    function solutionInfo(uint unq) public view returns (uint id, bytes32 hash, bytes32 init, CodeType ct, Storage cs, string stor, address solver) {
        Task storage t = tasks[unq];
        Task2 storage t2 = tasks2[unq];
        return (unq, t2.result, t.init, t.code_type, t.storage_type, t.stor, t2.solver);
    }

    /*
    function getCodeType(uint id) public view returns (CodeType) {
        return tasks[id].code_type;
    }

    function getCodeStorage(uint id) public view returns (Storage) {
        // return tasks[id].code_storage;
    }
    */

    function challenge(uint id) public {
        Task storage t = tasks[id];
        Task2 storage t2 = tasks2[id];
        // VMParameters storage p = params[id];
        require(t.state == 1);
        bytes32 uniq = iactive.make(id, t2.solver, msg.sender, t.init, t2.result, 1, TIMEOUT);
        challenges[uniq] = id;
        t2.challenges.push(uniq);
        subDeposit(msg.sender, DEPOSIT);
    }

    function queryChallenge(bytes32 uniq) constant public returns (uint) {
        return challenges[uniq];
    }

    function getChallenges(uint id) public view returns (bytes32[]) {
        return tasks2[id].challenges;
    }

    function uploadFile(uint id, uint num, bytes32 file_id, bytes32[] name_proof, bytes32[] data_proof, uint file_num) public returns (bool) {
        IO storage io = io_roots[id];
        RequiredFile storage file = io.uploads[num];
        if (!iactive.checkProof(fs.getRoot(file_id), io.data, data_proof, file_num) || !iactive.checkProof(fs.getNameHash(file_id), io.name, name_proof, file_num)) return false;
        require(iactive.checkProof(fs.getRoot(file_id), io.data, data_proof, file_num));
        require(iactive.checkProof(fs.getNameHash(file_id), io.name, name_proof, file_num));

        file.file_id = file_id;
        return true;
    }

    function finalizeTask(uint id) public returns (bool) {
        Task storage t = tasks[id];
        Task2 storage t2 = tasks2[id];
        IO storage io = io_roots[id];
        if (t.state != 1 || t2.blocked >= block.number || iactive.isRejected(id) || iactive.blockedTime(id) >= block.number) return false;
        // if (!(t.state == 1 && t2.blocked < block.number && !iactive.isRejected(id) && iactive.blockedTime(id) < block.number)) return false;

        // require(t.state == 1 && t2.blocked < block.number && !iactive.isRejected(id) && iactive.blockedTime(id) < block.number);
        t.state = 3;

        bytes32[] memory files = new bytes32[](io.uploads.length);
        for (uint i = 0; i < io.uploads.length; i++) {
           if (io.uploads[i].file_id == 0) return false;
           // require(io.uploads[i].file_id != 0);
           files[i] = io.uploads[i].file_id;
        }

        if (files.length > 0) Callback(t.giver).solved(id, files);

        emit Finalized(id);
        addDeposit(t2.solver, DEPOSIT);

        return true;
    }

    function claimDeposit(bytes32 cid) public {
        uint id = iactive.getTask(cid);
        require(iactive.isRejected(id));
        require(iactive.getChallenger(cid) == msg.sender);
        iactive.deleteChallenge(cid);
        addDeposit(msg.sender, DEPOSIT);
    }

    uint tick_var;

    // For testing, mine this to create new block
    function tick() public  {
        tick_var++;
    }

}


Make storage type explicit

Make storage type explicit

pragma solidity ^0.4.15;

import './zeppelin/ownership/Ownable.sol';

contract StarMarket is Ownable {

// You can use this hash to verify the csv file containing all the stars
    string public csvHash = "";

    address owner;

    string public standard = 'Stars';
    string public name;
    string public symbol;
    uint8 public decimals;
    uint256 public totalSupply;

    uint public nextStarIndexToAssign = 0;

    bool public allStarsAssigned = false;
    uint public starsRemainingToAssign = 0;

//mapping (address => uint) public addressToStarIndex;
    mapping (uint => address) public starIndexToAddress;

/* This creates an array with all balances */
    mapping (address => uint256) public balanceOf;

    struct Offer {
    bool isForSale;
    uint starIndex;
    address seller;
    uint minValue;          // in ether
    address onlySellTo;     // specify to sell only to a specific person
    }

    struct Bid {
    bool hasBid;
    uint starIndex;
    address bidder;
    uint value;
    }

// A record of stars that are offered for sale at a specific minimum value, and perhaps to a specific person
    mapping (uint => Offer) public starsOfferedForSale;

// A record of the highest star bid
    mapping (uint => Bid) public starBids;

    mapping (address => uint) public pendingWithdrawals;

    event Assign(address indexed to, uint256 starIndex);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event StarTransfer(address indexed from, address indexed to, uint256 starIndex);
    event StarOffered(uint indexed starIndex, uint minValue, address indexed toAddress);
    event StarBidEntered(uint indexed starIndex, uint value, address indexed fromAddress);
    event StarBidWithdrawn(uint indexed starIndex, uint value, address indexed fromAddress);
    event StarBought(uint indexed starIndex, uint value, address indexed fromAddress, address indexed toAddress);
    event StarNoLongerForSale(uint indexed starIndex);

/* Initializes contract with initial supply tokens to the creator of the contract */
    function StarMarket() payable {
    //        balanceOf[msg.sender] = initialSupply;        // Give the creator all initial tokens
        owner = msg.sender;
        totalSupply = 10000;                               // Update total supply
        starsRemainingToAssign = totalSupply;
        name = "STARS";                                     // Set the name for display purposes
        symbol = "★";                                       // Set the symbol for display purposes
        decimals = 0;                                       // Amount of decimals for display purposes
    }

    function setInitialOwner(address to, uint starIndex) onlyOwner {
        if (allStarsAssigned) revert();
        if (starIndex >= 10000) revert();
        if (starIndexToAddress[starIndex] != to) {
            if (starIndexToAddress[starIndex] != 0x0) {
                balanceOf[starIndexToAddress[starIndex]]--;
            } else {
                starsRemainingToAssign--;
            }
            starIndexToAddress[starIndex] = to;
            balanceOf[to]++;
            Assign(to, starIndex);
        }
    }

    function setInitialOwners(address[] addresses, uint[] indices) onlyOwner {
        uint n = addresses.length;
        for (uint i = 0; i < n; i++) {
            setInitialOwner(addresses[i], indices[i]);
        }
    }

    function allInitialOwnersAssigned() onlyOwner {
        allStarsAssigned = true;
    }

    function getStar(uint starIndex) {
        if (!allStarsAssigned) revert();
        if (starsRemainingToAssign == 0) revert();
        if (starIndexToAddress[starIndex] != 0x0) revert();
        if (starIndex >= 10000) revert();
        starIndexToAddress[starIndex] = msg.sender;
        balanceOf[msg.sender]++;
        starsRemainingToAssign--;
        Assign(msg.sender, starIndex);
    }

// Transfer ownership of a star to another user without requiring payment
    function transferStar(address to, uint starIndex) {
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] != msg.sender) revert();
        if (starIndex >= 10000) revert();
        if (starsOfferedForSale[starIndex].isForSale) {
            starNoLongerForSale(starIndex);
        }
        starIndexToAddress[starIndex] = to;
        balanceOf[msg.sender]--;
        balanceOf[to]++;
        Transfer(msg.sender, to, 1);
        StarTransfer(msg.sender, to, starIndex);
    // Check for the case where there is a bid from the new owner and refund it.
    // Any other bid can stay in place.
        Bid storage bid = starBids[starIndex];
        if (bid.bidder == to) {
        // Kill bid and refund value
            pendingWithdrawals[to] += bid.value;
            starBids[starIndex] = Bid(false, starIndex, 0x0, 0);
        }
    }

    function starNoLongerForSale(uint starIndex) {
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] != msg.sender) revert();
        if (starIndex >= 10000) revert();
        starsOfferedForSale[starIndex] = Offer(false, starIndex, msg.sender, 0, 0x0);
        StarNoLongerForSale(starIndex);
    }

    function offerStarForSale(uint starIndex, uint minSalePriceInWei) {
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] != msg.sender) revert();
        if (starIndex >= 10000) revert();
        starsOfferedForSale[starIndex] = Offer(true, starIndex, msg.sender, minSalePriceInWei, 0x0);
        StarOffered(starIndex, minSalePriceInWei, 0x0);
    }

    function offerStarForSaleToAddress(uint starIndex, uint minSalePriceInWei, address toAddress) {
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] != msg.sender) revert();
        if (starIndex >= 10000) revert();
        starsOfferedForSale[starIndex] = Offer(true, starIndex, msg.sender, minSalePriceInWei, toAddress);
        StarOffered(starIndex, minSalePriceInWei, toAddress);
    }

    function buyStar(uint starIndex) payable {
        if (!allStarsAssigned) revert();
        Offer storage offer = starsOfferedForSale[starIndex];
        if (starIndex >= 10000) revert();
        if (!offer.isForSale) revert();                // star not actually for sale
        if (offer.onlySellTo != 0x0 && offer.onlySellTo != msg.sender) revert();  // star not supposed to be sold to this user
        if (msg.value < offer.minValue) revert();      // Didn't send enough ETH
        if (offer.seller != starIndexToAddress[starIndex]) revert(); // Seller no longer owner of star

        address seller = offer.seller;

        starIndexToAddress[starIndex] = msg.sender;
        balanceOf[seller]--;
        balanceOf[msg.sender]++;
        Transfer(seller, msg.sender, 1);

        starNoLongerForSale(starIndex);
        pendingWithdrawals[seller] += msg.value;
        StarBought(starIndex, msg.value, seller, msg.sender);

    // Check for the case where there is a bid from the new owner and refund it.
    // Any other bid can stay in place.
        Bid storage bid = starBids[starIndex];
        if (bid.bidder == msg.sender) {
        // Kill bid and refund value
            pendingWithdrawals[msg.sender] += bid.value;
            starBids[starIndex] = Bid(false, starIndex, 0x0, 0);
        }
    }

    function withdraw() {
        if (!allStarsAssigned) revert();
        uint amount = pendingWithdrawals[msg.sender];
    // Remember to zero the pending refund before
    // sending to prevent re-entrancy attacks
        pendingWithdrawals[msg.sender] = 0;
        msg.sender.transfer(amount);
    }

    function enterBidForStar(uint starIndex) payable {
        if (starIndex >= 10000) revert();
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] == 0x0) revert();
        if (starIndexToAddress[starIndex] == msg.sender) revert();
        if (msg.value == 0) revert();
        Bid storage existing = starBids[starIndex];
        if (msg.value <= existing.value) revert();
        if (existing.value > 0) {
        // Refund the failing bid
            pendingWithdrawals[existing.bidder] += existing.value;
        }
        starBids[starIndex] = Bid(true, starIndex, msg.sender, msg.value);
        StarBidEntered(starIndex, msg.value, msg.sender);
    }

    function acceptBidForStar(uint starIndex, uint minPrice) {
        if (starIndex >= 10000) revert();
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] != msg.sender) revert();
        address seller = msg.sender;
        Bid storage bid = starBids[starIndex];
        if (bid.value == 0) revert();
        if (bid.value < minPrice) revert();

        starIndexToAddress[starIndex] = bid.bidder;
        balanceOf[seller]--;
        balanceOf[bid.bidder]++;
        Transfer(seller, bid.bidder, 1);

        starsOfferedForSale[starIndex] = Offer(false, starIndex, bid.bidder, 0, 0x0);
        uint amount = bid.value;
        starBids[starIndex] = Bid(false, starIndex, 0x0, 0);
        pendingWithdrawals[seller] += amount;
        StarBought(starIndex, bid.value, seller, bid.bidder);
    }

    function withdrawBidForStar(uint starIndex) {
        if (starIndex >= 10000) revert();
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] == 0x0) revert();
        if (starIndexToAddress[starIndex] == msg.sender) revert();
        Bid storage bid = starBids[starIndex];
        if (bid.bidder != msg.sender) revert();
        StarBidWithdrawn(starIndex, bid.value, msg.sender);
        uint amount = bid.value;
        starBids[starIndex] = Bid(false, starIndex, 0x0, 0);
    // Refund the bid money
        msg.sender.transfer(amount);
    }

}

pragma solidity ^0.4.15;

import './zeppelin/ownership/Ownable.sol';

contract StarMarket is Ownable {

// You can use this hash to verify the csv file containing all the stars
    string public csvHash = "";

    address owner;

    string public standard = 'Stars';
    string public name;
    string public symbol;
    uint8 public decimals;
    uint256 public totalSupply;

    uint public nextStarIndexToAssign = 0;

    bool public allStarsAssigned = false;
    uint public starsRemainingToAssign = 0;

//mapping (address => uint) public addressToStarIndex;
    mapping (uint => address) public starIndexToAddress;

/* This creates an array with all balances */
    mapping (address => uint256) public balanceOf;

    struct Offer {
    bool isForSale;
    uint starIndex;
    address seller;
    uint minValue;          // in ether
    address onlySellTo;     // specify to sell only to a specific person
    }

    struct Bid {
    bool hasBid;
    uint starIndex;
    address bidder;
    uint value;
    }

// A record of stars that are offered for sale at a specific minimum value, and perhaps to a specific person
    mapping (uint => Offer) public starsOfferedForSale;

// A record of the highest star bid
    mapping (uint => Bid) public starBids;

    mapping (address => uint) public pendingWithdrawals;

    event Assign(address indexed to, uint256 starIndex);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event StarTransfer(address indexed from, address indexed to, uint256 starIndex);
    event StarOffered(uint indexed starIndex, uint minValue, address indexed toAddress);
    event StarBidEntered(uint indexed starIndex, uint value, address indexed fromAddress);
    event StarBidWithdrawn(uint indexed starIndex, uint value, address indexed fromAddress);
    event StarBought(uint indexed starIndex, uint value, address indexed fromAddress, address indexed toAddress);
    event StarNoLongerForSale(uint indexed starIndex);

/* Initializes contract with initial supply tokens to the creator of the contract */
    function StarMarket() payable {
    //        balanceOf[msg.sender] = initialSupply;        // Give the creator all initial tokens
        owner = msg.sender;
        totalSupply = 10000;                               // Update total supply
        starsRemainingToAssign = totalSupply;
        name = "STARS";                                     // Set the name for display purposes
        symbol = "★";                                       // Set the symbol for display purposes
        decimals = 0;                                       // Amount of decimals for display purposes
    }

    function setInitialOwner(address to, uint starIndex) onlyOwner {
        if (allStarsAssigned) revert();
        if (starIndex >= 10000) revert();
        if (starIndexToAddress[starIndex] != to) {
            if (starIndexToAddress[starIndex] != 0x0) {
                balanceOf[starIndexToAddress[starIndex]]--;
            } else {
                starsRemainingToAssign--;
            }
            starIndexToAddress[starIndex] = to;
            balanceOf[to]++;
            Assign(to, starIndex);
        }
    }

    function setInitialOwners(address[] addresses, uint[] indices) onlyOwner {
        uint n = addresses.length;
        for (uint i = 0; i < n; i++) {
            setInitialOwner(addresses[i], indices[i]);
        }
    }

    function allInitialOwnersAssigned() onlyOwner {
        allStarsAssigned = true;
    }

    function getStar(uint starIndex) {
        if (!allStarsAssigned) revert();
        if (starsRemainingToAssign == 0) revert();
        if (starIndexToAddress[starIndex] != 0x0) revert();
        if (starIndex >= 10000) revert();
        starIndexToAddress[starIndex] = msg.sender;
        balanceOf[msg.sender]++;
        starsRemainingToAssign--;
        Assign(msg.sender, starIndex);
    }

// Transfer ownership of a star to another user without requiring payment
    function transferStar(address to, uint starIndex) {
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] != msg.sender) revert();
        if (starIndex >= 10000) revert();
        if (starsOfferedForSale[starIndex].isForSale) {
            starNoLongerForSale(starIndex);
        }
        starIndexToAddress[starIndex] = to;
        balanceOf[msg.sender]--;
        balanceOf[to]++;
        Transfer(msg.sender, to, 1);
        StarTransfer(msg.sender, to, starIndex);
    // Check for the case where there is a bid from the new owner and refund it.
    // Any other bid can stay in place.
        Bid bid = starBids[starIndex];
        if (bid.bidder == to) {
        // Kill bid and refund value
            pendingWithdrawals[to] += bid.value;
            starBids[starIndex] = Bid(false, starIndex, 0x0, 0);
        }
    }

    function starNoLongerForSale(uint starIndex) {
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] != msg.sender) revert();
        if (starIndex >= 10000) revert();
        starsOfferedForSale[starIndex] = Offer(false, starIndex, msg.sender, 0, 0x0);
        StarNoLongerForSale(starIndex);
    }

    function offerStarForSale(uint starIndex, uint minSalePriceInWei) {
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] != msg.sender) revert();
        if (starIndex >= 10000) revert();
        starsOfferedForSale[starIndex] = Offer(true, starIndex, msg.sender, minSalePriceInWei, 0x0);
        StarOffered(starIndex, minSalePriceInWei, 0x0);
    }

    function offerStarForSaleToAddress(uint starIndex, uint minSalePriceInWei, address toAddress) {
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] != msg.sender) revert();
        if (starIndex >= 10000) revert();
        starsOfferedForSale[starIndex] = Offer(true, starIndex, msg.sender, minSalePriceInWei, toAddress);
        StarOffered(starIndex, minSalePriceInWei, toAddress);
    }

    function buyStar(uint starIndex) payable {
        if (!allStarsAssigned) revert();
        Offer offer = starsOfferedForSale[starIndex];
        if (starIndex >= 10000) revert();
        if (!offer.isForSale) revert();                // star not actually for sale
        if (offer.onlySellTo != 0x0 && offer.onlySellTo != msg.sender) revert();  // star not supposed to be sold to this user
        if (msg.value < offer.minValue) revert();      // Didn't send enough ETH
        if (offer.seller != starIndexToAddress[starIndex]) revert(); // Seller no longer owner of star

        address seller = offer.seller;

        starIndexToAddress[starIndex] = msg.sender;
        balanceOf[seller]--;
        balanceOf[msg.sender]++;
        Transfer(seller, msg.sender, 1);

        starNoLongerForSale(starIndex);
        pendingWithdrawals[seller] += msg.value;
        StarBought(starIndex, msg.value, seller, msg.sender);

    // Check for the case where there is a bid from the new owner and refund it.
    // Any other bid can stay in place.
        Bid bid = starBids[starIndex];
        if (bid.bidder == msg.sender) {
        // Kill bid and refund value
            pendingWithdrawals[msg.sender] += bid.value;
            starBids[starIndex] = Bid(false, starIndex, 0x0, 0);
        }
    }

    function withdraw() {
        if (!allStarsAssigned) revert();
        uint amount = pendingWithdrawals[msg.sender];
    // Remember to zero the pending refund before
    // sending to prevent re-entrancy attacks
        pendingWithdrawals[msg.sender] = 0;
        msg.sender.transfer(amount);
    }

    function enterBidForStar(uint starIndex) payable {
        if (starIndex >= 10000) revert();
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] == 0x0) revert();
        if (starIndexToAddress[starIndex] == msg.sender) revert();
        if (msg.value == 0) revert();
        Bid existing = starBids[starIndex];
        if (msg.value <= existing.value) revert();
        if (existing.value > 0) {
        // Refund the failing bid
            pendingWithdrawals[existing.bidder] += existing.value;
        }
        starBids[starIndex] = Bid(true, starIndex, msg.sender, msg.value);
        StarBidEntered(starIndex, msg.value, msg.sender);
    }

    function acceptBidForStar(uint starIndex, uint minPrice) {
        if (starIndex >= 10000) revert();
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] != msg.sender) revert();
        address seller = msg.sender;
        Bid bid = starBids[starIndex];
        if (bid.value == 0) revert();
        if (bid.value < minPrice) revert();

        starIndexToAddress[starIndex] = bid.bidder;
        balanceOf[seller]--;
        balanceOf[bid.bidder]++;
        Transfer(seller, bid.bidder, 1);

        starsOfferedForSale[starIndex] = Offer(false, starIndex, bid.bidder, 0, 0x0);
        uint amount = bid.value;
        starBids[starIndex] = Bid(false, starIndex, 0x0, 0);
        pendingWithdrawals[seller] += amount;
        StarBought(starIndex, bid.value, seller, bid.bidder);
    }

    function withdrawBidForStar(uint starIndex) {
        if (starIndex >= 10000) revert();
        if (!allStarsAssigned) revert();
        if (starIndexToAddress[starIndex] == 0x0) revert();
        if (starIndexToAddress[starIndex] == msg.sender) revert();
        Bid bid = starBids[starIndex];
        if (bid.bidder != msg.sender) revert();
        StarBidWithdrawn(starIndex, bid.value, msg.sender);
        uint amount = bid.value;
        starBids[starIndex] = Bid(false, starIndex, 0x0, 0);
    // Refund the bid money
        msg.sender.transfer(amount);
    }

}


Fix errors

Fix errors

pragma solidity ^0.4.4;

contract Shop {

	struct Product {
		uint price;
		string name;
		uint stockBalance;
	}

    uint ownerWithdrawals;

	mapping (address => uint) public payBack;

	mapping (uint => Product) stock;

	uint[] products;

	address administrator;

	address owner;

	event AddProductEvent(uint id, uint price, string name);

	event DeleteProductEvent(uint id);

	event BuyProductEvent(uint id);

    event LogWithdrawEvent(address main, uint quantity);

    event LogPayMeBackEvent(address main, uint quantity);

	function Shop(address administratorAddress)
		public
	{
		if(administratorAddress == address(0)){
			administrator = msg.sender;
		}
		else {
			administrator = administratorAddress;
		}
		owner = msg.sender;
	}

    modifier isOwner
    {
        require(msg.sender == owner);
        _;
    }

    modifier isAdministrator
    {
        require(msg.sender == administrator);
        _;
    }

	function getProductCount()
		constant
		returns (uint length)
	{
		return products.length;
	}

	function getProductIdAt(uint index)
		constant
		returns (uint id)
	{
		return products[index];
	}

	function getProduct(uint id)
		constant
		returns (string name, uint price, uint stockBalance)
	{
		Product product = stock[id];
		return (product.name,
			product.price,
			product.stockBalance);
	}

    function addProduct(uint id, uint price, string name)
   		public
   		isAdministrator
   	{
   		products.push(id);
        stock[id].price = price;
        stock[id].stockBalance += 1;
        stock[id].name = name;
        AddProductEvent(id, price, name);

    }

    function deleteProduct(uint id)
    	public
    	isAdministrator
    {

        uint index = indexOf(id);

        for (uint i = index; i<products.length-1; i++){
            products[i] = products[i+1];
        }
        delete products[products.length-1];
        products.length--;
        delete stock[id];
        DeleteProductEvent(id);
    }

    function indexOf(uint id)
    	private
    	returns(uint)
	{

        for (uint i = 0; i<products.length-1; i++){
             if(products[i] == id) return i;
        }
       	throw;
  	}

    function buyProduct(uint id)
    	payable
    	public
    {
        require(stock[id].price > 0);
        require(stock[id].price <= msg.value);
        require(stock[id].stockBalance > 0);

        stock[id].stockBalance--;
        ownerWithdrawals += stock[id].price;

        int payBack=msg.value-stock[id].price;
        if(payBack>0) payBack[msg.sender]=payBack;

        BuyProductEvent(id);
    }

    function withdraw()
    	public
    	isOwner
    {

        if (ownerWithdrawals<=0) revert();

        ownerWithdrawals = 0;
        msg.sender.transfer(ownerWithdrawals);
        LogWithdrawEvent(msg.sender, ownerWithdrawals);

    }

    function payMeBack()
    	public
    {

        if (payBack[msg.sender]<=0) revert();

        payBack[msg.sender] = 0;
        msg.sender.transfer(payBack[msg.sender]);
        LogPayMeBackEvent(msg.sender, payBack[msg.sender]);

    }
}