all files / contracts/Entity/ ListingContract.sol

100% Statements 24/24
80% Branches 8/10
100% Functions 7/7
100% Lines 23/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101                                                                                              12× 12× 12× 12× 12×   12×                             12× 12× 12× 12×       11×                          
/*
 
 * @name        Funding Contract
 * @package     BlockBitsIO
 * @author      Micky Socaci <micky@nowlive.ro>
 
 Contains the Listing Contract
 - used by the platform to find child campaigns
 - used by mobile application to retrieve News Items
 
ropsten - 0x1ec6988a826c4236b3b07c5eed9059e3aa033fe2
 
*/
 
pragma solidity ^0.4.17;
 
import "./../ApplicationAsset.sol";
import "./../ApplicationEntityABI.sol";
 
contract ListingContract is ApplicationAsset {
 
    address public managerAddress;
 
    // child items
    struct item {
        bytes32 name;
        address itemAddress;
        bool    status;
        uint256 index;
    }
 
    mapping ( uint256 => item ) public items;
    uint256 public itemNum = 0;
 
    event EventNewChildItem(bytes32 _name, address _address, uint256 _index);
 
    function ListingContract() ApplicationAsset() public {
 
    }
 
    // deployer address, sets the address who is allowed to add entries, in order to avoid a code upgrade at first milestone.
    function setManagerAddress(address _manager) public onlyDeployer {
        managerAddress = _manager;
    }
 
    function addItem(bytes32 _name, address _address) public requireInitialised {
        require(msg.sender == owner || msg.sender == managerAddress); // only application
 
        item storage child = items[++itemNum];
        child.name = _name;
        child.itemAddress = _address;
        child.status = true;
        child.index = itemNum;
 
        EventNewChildItem( _name, _address, itemNum);
    }
 
    /*
    * Get current News Contract address
    *
    * @return       address NewsContractEntity
    */
    function getNewsContractAddress(uint256 _childId) external view returns (address) {
        item memory child = items[_childId];
        if(child.itemAddress != address(0x0)) {
            ApplicationEntityABI ChildApp = ApplicationEntityABI(child.itemAddress);
            return ChildApp.NewsContractEntity();
        } else {
            revert();
        }
    }
 
    function canBeDelisted(uint256 _childId) public view returns (bool) {
 
        item memory child = items[_childId];
        Eif(child.status == true) {
            ApplicationEntityABI ChildApp = ApplicationEntityABI(child.itemAddress);
            if(
                ChildApp.CurrentEntityState() == ChildApp.getEntityState("WAITING") ||
                ChildApp.CurrentEntityState() == ChildApp.getEntityState("NEW"))
            {
                return true;
            }
        }
        return ;
    }
 
    function getChildStatus( uint256 _childId ) public view returns (bool) {
        item memory child = items[_childId];
        return child.status;
    }
 
    // update so that this checks the child status, and only delists IF funding has not started yet.
    function delistChild( uint256 _childId ) public onlyAsset("Proposals") requireInitialised {
        Erequire(canBeDelisted(_childId) == true );
 
        item storage child = items[_childId];
            child.status = false;
    }
 
}