all files / contracts/Entity/ NewsContract.sol

100% Statements 11/11
100% Branches 4/4
100% Functions 4/4
100% Lines 11/11
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                                                                                                               
/*
 
 * @name        News Contract
 * @package     BlockBitsIO
 * @author      Micky Socaci <micky@nowlive.ro>
 
Contains This Application's News Items
*/
 
pragma solidity ^0.4.17;
 
import "./../ApplicationAsset.sol";
import "./../ApplicationEntityABI.sol";
 
contract NewsContract is ApplicationAsset {
 
    // state types
    // 1 - generic news item
 
    // 2 - FUNDING FAILED
    // 3 - FUNDING SUCCESSFUL
    // 4 - MEETING DATE AND TIME SET
    // 5 - VOTING INITIATED
 
    // 10 - GLOBAL CASHBACK AVAILABLE
    // 50 - CODE UPGRADE PROPOSAL INITIATED
 
    // 100 - DEVELOPMENT COMPLETE, HELLO SKYNET
 
    // news items
    struct item {
        bytes32 hash;
        uint8 itemType;
        uint256 length;
    }
 
    mapping ( uint256 => item ) public items;
    uint256 public itemNum = 0;
 
    event EventNewsItem(bytes32 _hash);
    event EventNewsState(uint8 itemType);
 
    function NewsContract() ApplicationAsset() public {
 
    }
 
    function addInternalMessage(uint8 state) public requireInitialised {
        require(msg.sender == owner); // only application
        item storage child = items[++itemNum];
        child.itemType = state;
        EventNewsState(state);
    }
 
    function addItem(bytes32 _hash, uint256 _length) public onlyAppDeployer requireInitialised {
        item storage child = items[++itemNum];
        child.hash = _hash;
        child.itemType = 1;
        child.length = _length;
        EventNewsItem(_hash);
    }
 
    modifier onlyAppDeployer() {
        ApplicationEntityABI currentApp = ApplicationEntityABI(owner);
        require(msg.sender == currentApp.deployerAddress());
        _;
    }
}