Search in sources :

Example 1 with NulsVersion

use of io.nuls.core.chain.intf.NulsVersion in project nuls by nuls-io.

the class VersionManager method start.

public static void start() throws NulsException {
    URL libsUrl = VersionUtils.class.getClassLoader().getResource("libs");
    if (null == libsUrl) {
        // devlopment
        return;
    }
    List<NulsVersion> versionList = NulsContext.getServiceBeanList(NulsVersion.class);
    String localVersion = null;
    for (NulsVersion version : versionList) {
        if (null == localVersion) {
            localVersion = version.getVersion();
            continue;
        }
        if (VersionUtils.higherThan(version.getVersion(), localVersion)) {
            localVersion = version.getVersion();
            continue;
        }
    }
    NulsContext.VERSION = localVersion;
    String jsonStr = null;
    try {
        jsonStr = new String(HttpDownloadUtils.download(HIGHEST_VERDION_FILE_URL), NulsContext.DEFAULT_ENCODING);
    } catch (IOException e) {
        Log.error(e);
        return;
    }
    Map<String, Object> map = null;
    try {
        map = JSONUtils.json2map(jsonStr);
    } catch (Exception e) {
        Log.error(e);
        throw new NulsException(ErrorCode.FAILED, "Parse version json faild!");
    }
    String version = (String) map.get("version");
    String sign = (String) map.get("sign");
    // todo 验证签名
    NulsContext.NEWEST_VERSION = version;
    // todo 自动更新开关
    boolean autoUpdate = true;
    if (VersionUtils.equalsWith(version, localVersion)) {
        return;
    } else if (autoUpdate) {
        try {
            updateFile(localVersion, version, versionList, libsUrl);
        } catch (IOException e) {
            throw new NulsException(e);
        }
    }
}
Also used : NulsException(io.nuls.core.exception.NulsException) NulsVersion(io.nuls.core.chain.intf.NulsVersion) VersionUtils(io.nuls.core.utils.str.VersionUtils) URL(java.net.URL) NulsException(io.nuls.core.exception.NulsException)

Aggregations

NulsVersion (io.nuls.core.chain.intf.NulsVersion)1 NulsException (io.nuls.core.exception.NulsException)1 VersionUtils (io.nuls.core.utils.str.VersionUtils)1 URL (java.net.URL)1