all files / contracts/ ApplicationAsset.sol

97.67% Statements 42/43
95% Branches 19/20
95.83% Functions 23/24
98.04% Lines 50/51
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188                                                                                      1084×       1065×                 1057× 1057×   1057× 1057× 1057× 1057× 1057×         592× 592×   592×       15467×       50825×       828×                   998× 998× 998×       332×       42× 41× 41× 41×               3196× 3196× 3195×           5246×       6813×       592× 592×             43× 42×       85× 83×       3602× 3600×       3180× 3179×             2770× 2767×       2812× 2807×       396× 396× 392×                  
/*
 
 * @name        Application Asset Contract
 * @package     BlockBitsIO
 * @author      Micky Socaci <micky@nowlive.ro>
 
 Any contract inheriting this will be usable as an Asset in the Application Entity
 
*/
 
pragma solidity ^0.4.17;
import "./ApplicationEntityABI.sol";
 
contract ApplicationAsset {
 
    event EventAppAssetOwnerSet(bytes32 indexed _name, address indexed _owner);
    event EventRunBeforeInit(bytes32 indexed _name);
    event EventRunBeforeApplyingSettings(bytes32 _name);
 
 
    mapping (bytes32 => uint8) public EntityStates;
    mapping (bytes32 => uint8) public RecordStates;
    uint8 public CurrentEntityState;
 
    event EventEntityProcessor(bytes32 indexed _assetName, uint8 indexed _current, uint8 indexed _required);
    event DebugEntityRequiredChanges( bytes32 _assetName, uint8 indexed _current, uint8 indexed _required );
 
    bytes32 public assetName;
 
    /* Asset records */
    uint8 public RecordNum = 0;
 
    /* Asset initialised or not */
    bool public _initialized = false;
 
    /* Asset settings present or not */
    bool public _settingsApplied = false;
 
    /* Asset owner ( ApplicationEntity address ) */
    address public owner = address(0x0) ;
    address public deployerAddress;
 
    function ApplicationAsset() public {
        deployerAddress = msg.sender;
    }
 
    function setInitialApplicationAddress(address _ownerAddress) public onlyDeployer requireNotInitialised {
        owner = _ownerAddress;
    }
 
    function setInitialOwnerAndName(bytes32 _name) external
        requireNotInitialised
    //    onlyOwner
        returns (bool)
    {
        // init states
        setAssetStates();
        assetName = _name;
        // set initial state
        CurrentEntityState = getEntityState("NEW");
        runBeforeInitialization();
        _initialized = true;
        EventAppAssetOwnerSet(_name, owner);
        return true;
    }
 
    function setAssetStates() internal {
        // Asset States
        EntityStates["__IGNORED__"]     = 0;
        EntityStates["NEW"]             = 1;
        // Funding Stage States
        RecordStates["__IGNORED__"]     = 0;
    }
 
    function getRecordState(bytes32 name) public view returns (uint8) {
        return RecordStates[name];
    }
 
    function getEntityState(bytes32 name) public view returns (uint8) {
        return EntityStates[name];
    }
 
    function runBeforeInitialization() internal requireNotInitialised  {
        EventRunBeforeInit(assetName);
    }
 
    function applyAndLockSettings()
        public
        onlyDeployer
        requireInitialised
        requireSettingsNotApplied
        returns(bool)
    {
        runBeforeApplyingSettings();
        _settingsApplied = true;
        return true;
    }
 
    function runBeforeApplyingSettings() internal requireInitialised requireSettingsNotApplied  {
        EventRunBeforeApplyingSettings(assetName);
    }
 
    function transferToNewOwner(address _newOwner) public requireInitialised onlyOwner returns (bool) {
        require(owner != address(0x0) && _newOwner != address(0x0));
        owner = _newOwner;
        EventAppAssetOwnerSet(assetName, owner);
        return true;
    }
 
    function getApplicationAssetAddressByName(bytes32 _name)
        public
        view
        returns(address)
    {
        address asset = ApplicationEntityABI(owner).getAssetAddressByName(_name);
        if( asset != address(0x0) ) {
            return asset;
        } else {
            revert();
        }
    }
 
    function getApplicationState() public view returns (uint8) {
        return ApplicationEntityABI(owner).CurrentEntityState();
    }
 
    function getApplicationEntityState(bytes32 name) public view returns (uint8) {
        return ApplicationEntityABI(owner).getEntityState(name);
    }
 
    function getAppBylawUint256(bytes32 name) public view requireInitialised returns (uint256) {
        ApplicationEntityABI CurrentApp = ApplicationEntityABI(owner);
        return CurrentApp.getBylawUint256(name);
    }
 
    function getAppBylawBytes32(bytes32 name) public view requireInitialised returns (bytes32) {
        ApplicationEntityABI CurrentApp = ApplicationEntityABI(owner);
        return CurrentApp.getBylawBytes32(name);
    }
 
    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }
 
    modifier onlyApplicationEntity() {
        require(msg.sender == owner);
        _;
    }
 
    modifier requireInitialised() {
        require(_initialized == true);
        _;
    }
 
    modifier requireNotInitialised() {
        require(_initialized == false);
        _;
    }
 
    modifier requireSettingsApplied() {
        Erequire(_settingsApplied == true);
        _;
    }
 
    modifier requireSettingsNotApplied() {
        require(_settingsApplied == false);
        _;
    }
 
    modifier onlyDeployer() {
        require(msg.sender == deployerAddress);
        _;
    }
 
    modifier onlyAsset(bytes32 _name) {
        address AssetAddress = getApplicationAssetAddressByName(_name);
        require( msg.sender == AssetAddress);
        _;
    }
 
    function getTimestamp() view public returns (uint256) {
        return now;
    }
 
 
}