CloudSystem.sol 2.65 KB
Newer Older
duanjinfei's avatar
duanjinfei committed
1 2 3 4 5 6 7 8
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

import "./BaseAuth.sol";

contract CloudSystem is Callee {
    constructor(address const) Callee(const) {}

duanjinfei's avatar
duanjinfei committed
9
    mapping(uint256 => uint256) vm_system;
duanjinfei's avatar
duanjinfei committed
10

duanjinfei's avatar
duanjinfei committed
11
    mapping(uint256 => string) systemNameInfo;
duanjinfei's avatar
duanjinfei committed
12

duanjinfei's avatar
duanjinfei committed
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
    mapping(uint256 => string) systemVersionInfo;

    mapping(uint256 => uint8) systemSupportInfo;

    mapping(uint256 => string) systemStorageInfo;

    mapping(uint256 => uint256[]) system_app;

    mapping(uint256 => string) appNameInfo;

    mapping(uint256 => string) appVersionInfo;

    function bindSystemVm(uint256 vmId, uint256 systemId) external {
        vm_system[vmId] = systemId;
    }

    function getSysId(uint256 vmId) external view returns (uint256) {
        return vm_system[vmId];
    }

    function bindSystemApp(uint256 systemId, uint256 appId) external {
        system_app[systemId].push(appId);
    }

    function getAppId(
        uint256 sysId,
        uint8 start,
        uint8 count
    ) external view returns (uint256[] memory res) {
        uint256 appCount = system_app[sysId].length;
        uint256 end = start + count;
        if (end > appCount) {
            end = appCount;
        }
        res = new uint256[](end - start);
        if (appCount >= start) {
            for (uint8 i = start; i < end; i++) {
                res[i - start] = system_app[sysId][i];
            }
        }
        return res;
    }

    function addSystemInfo(
        uint256 sysId,
duanjinfei's avatar
duanjinfei committed
58 59
        string memory name,
        string memory version,
duanjinfei's avatar
duanjinfei committed
60 61
        uint8 supportType,
        string memory ipfsUrl
duanjinfei's avatar
duanjinfei committed
62
    ) external {
duanjinfei's avatar
duanjinfei committed
63 64 65 66 67
        require(supportType == 1 || supportType == 2 || supportType == 3, "");
        systemNameInfo[sysId] = name;
        systemVersionInfo[sysId] = version;
        systemSupportInfo[sysId] = supportType;
        systemStorageInfo[sysId] = ipfsUrl;
duanjinfei's avatar
duanjinfei committed
68 69
    }

duanjinfei's avatar
duanjinfei committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    function getSystemInfo(
        uint256 sysId
    )
        external
        view
        returns (
            string memory name,
            string memory version,
            uint8 supportType,
            string memory ipfsUrl
        )
    {
        name = systemNameInfo[sysId];
        version = systemVersionInfo[sysId];
        supportType = systemSupportInfo[sysId];
        ipfsUrl = systemStorageInfo[sysId];
duanjinfei's avatar
duanjinfei committed
86 87
    }

duanjinfei's avatar
duanjinfei committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101
    function getAppInfo(
        uint256 appId
    ) external view returns (string memory name, string memory version) {
        name = appNameInfo[appId];
        version = appVersionInfo[appId];
    }

    function addAppInfo(
        uint256 appId,
        string memory name,
        string memory version
    ) external {
        appNameInfo[appId] = name;
        appVersionInfo[appId] = version;
duanjinfei's avatar
duanjinfei committed
102 103
    }
}