Search in sources :

Example 26 with NulsDigestData

use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.

the class TxSerializeTest method signTransaction.

protected void signTransaction(Transaction tx, ECKey ecKey) {
    NulsDigestData hash = null;
    try {
        hash = NulsDigestData.calcDigestData(tx.serializeForHash());
    } catch (IOException e) {
        Log.error(e);
    }
    tx.setHash(hash);
    List<ECKey> keys = new ArrayList<>();
    keys.add(ecKey);
    try {
        SignatureUtil.createTransactionSignture(tx, null, keys);
    } catch (Exception e) {
        Log.error(e);
    }
}
Also used : ArrayList(java.util.ArrayList) NulsDigestData(io.nuls.kernel.model.NulsDigestData) ECKey(io.nuls.core.tools.crypto.ECKey) IOException(java.io.IOException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) NulsException(io.nuls.kernel.exception.NulsException)

Example 27 with NulsDigestData

use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.

the class PoConvertUtilTest method getAgentId.

@Test
public void getAgentId() {
    NulsDigestData hash = NulsDigestData.calcDigestData("123123".getBytes());
    System.out.println(PoConvertUtil.getAgentId(hash));
    System.out.println(hash);
    assertTrue(true);
}
Also used : NulsDigestData(io.nuls.kernel.model.NulsDigestData) Test(org.junit.Test)

Example 28 with NulsDigestData

use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.

the class Bootstrap method sysStart.

private static void sysStart() throws Exception {
    do {
        MicroKernelBootstrap mk = MicroKernelBootstrap.getInstance();
        mk.init();
        mk.start();
        WalletVersionManager.start();
        initModules();
        String ip = NulsConfig.MODULES_CONFIG.getCfgValue(RpcConstant.CFG_RPC_SECTION, RpcConstant.CFG_RPC_SERVER_IP, RpcConstant.DEFAULT_IP);
        int port = NulsConfig.MODULES_CONFIG.getCfgValue(RpcConstant.CFG_RPC_SECTION, RpcConstant.CFG_RPC_SERVER_PORT, RpcConstant.DEFAULT_PORT);
        copyWebFiles();
        if (NULSParams.BOOTSTRAP.getRpcIp() != null) {
            ip = NULSParams.BOOTSTRAP.getRpcIp();
        }
        if (NULSParams.BOOTSTRAP.getRpcPort() != null) {
            port = NULSParams.BOOTSTRAP.getRpcPort();
        }
        RpcServerManager.getInstance().startServer(ip, port);
        LanguageService languageService = NulsContext.getServiceBean(LanguageService.class);
        String languageDB = (String) languageService.getLanguage().getData();
        String language = null == languageDB ? I18nUtils.getLanguage() : languageDB;
        I18nUtils.setLanguage(language);
        if (null == languageDB) {
            languageService.saveLanguage(language);
        }
    } while (false);
    // if isDaemon flag is true, don't launch the WebView
    boolean isDaemon = NulsConfig.MODULES_CONFIG.getCfgValue(RpcConstant.CFG_RPC_SECTION, RpcConstant.CFG_RPC_DAEMON, false);
    if (!isDaemon) {
        TaskManager.asynExecuteRunnable(new WebViewBootstrap());
    }
    int i = 0;
    Map<NulsDigestData, List<Node>> map = new HashMap<>();
    NulsContext context = NulsContext.getInstance();
    DownloadService downloadService = NulsContext.getServiceBean(DownloadService.class);
    while (true) {
        if (context.getStop() > 0) {
            if (context.getStop() == 2) {
                Runtime.getRuntime().addShutdownHook(new ShutdownHook());
            }
            System.exit(0);
        }
        if (NulsContext.mastUpGrade) {
            // 如果强制升级标志开启,停止网络连接
            ModuleManager.getInstance().stopModule(NetworkConstant.NETWORK_MODULE_ID);
            Log.error(">>>>>> The new protocol version has taken effect, the network connection has been disconnected,please upgrade immediately **********");
        }
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            Log.error(e);
        }
        if (i > 10) {
            i = 0;
            if (!downloadService.isDownloadSuccess().isSuccess() && CollectThread.getInstance().getStartHeight() > 0) {
                Log.info("collect-start:{},request-start:{},BlockQueueSize:{}", CollectThread.getInstance().getStartHeight(), CollectThread.getInstance().getRequestStartHeight(), BlockQueueProvider.getInstance().size());
            }
            Block bestBlock = NulsContext.getInstance().getBestBlock();
            Collection<Node> nodes = NulsContext.getServiceBean(NetworkService.class).getAvailableNodes();
            Log.info("bestHeight:" + bestBlock.getHeader().getHeight() + " , txCount : " + bestBlock.getHeader().getTxCount() + " , tx memory pool count : " + TxMemoryPool.getInstance().size() + " - " + TxMemoryPool.getInstance().getOrphanPoolSize() + " , hash : " + bestBlock.getHeader().getHash() + ",nodeCount:" + nodes.size());
            map.clear();
            for (Node node : nodes) {
                List<Node> ips = map.get(node.getBestBlockHash());
                if (null == ips) {
                    ips = new ArrayList<>();
                    map.put(node.getBestBlockHash(), ips);
                }
                ips.add(node);
            }
            for (NulsDigestData key : map.keySet()) {
                if (key == null)
                    continue;
                List<Node> nodeList = map.get(key);
                long height = nodeList.get(0).getBestBlockHeight();
                StringBuilder ids = new StringBuilder();
                for (Node node : nodeList) {
                    ids.append("," + node.getId());
                }
                Log.info("height:" + height + ",count:" + nodeList.size() + ", hash:" + key.getDigestHex() + ids);
            }
        } else {
            i++;
        }
    }
}
Also used : ShutdownHook(io.nuls.client.rpc.resources.thread.ShutdownHook) Node(io.nuls.network.model.Node) DownloadService(io.nuls.protocol.service.DownloadService) MicroKernelBootstrap(io.nuls.kernel.MicroKernelBootstrap) WebViewBootstrap(io.nuls.client.web.view.WebViewBootstrap) LanguageService(io.nuls.client.storage.LanguageService) NulsContext(io.nuls.kernel.context.NulsContext) NulsDigestData(io.nuls.kernel.model.NulsDigestData) Block(io.nuls.kernel.model.Block) NetworkService(io.nuls.network.service.NetworkService)

Example 29 with NulsDigestData

use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.

the class AgentStorageServiceImpl method getList.

@Override
public List<AgentPo> getList() {
    List<Entry<byte[], byte[]>> list = dbService.entryList(ConsensusStorageConstant.DB_NAME_CONSENSUS_AGENT);
    List<AgentPo> resultList = new ArrayList<>();
    if (list == null) {
        return resultList;
    }
    for (Entry<byte[], byte[]> entry : list) {
        AgentPo agentPo = new AgentPo();
        try {
            agentPo.parse(entry.getValue(), 0);
        } catch (NulsException e) {
            Log.error(e);
            throw new NulsRuntimeException(e);
        }
        NulsDigestData hash = new NulsDigestData();
        try {
            hash.parse(entry.getKey(), 0);
        } catch (NulsException e) {
            Log.error(e);
        }
        agentPo.setHash(hash);
        resultList.add(agentPo);
    }
    return resultList;
}
Also used : Entry(io.nuls.db.model.Entry) NulsException(io.nuls.kernel.exception.NulsException) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) NulsDigestData(io.nuls.kernel.model.NulsDigestData) AgentPo(io.nuls.consensus.poc.storage.po.AgentPo)

Example 30 with NulsDigestData

use of io.nuls.kernel.model.NulsDigestData in project nuls by nuls-io.

the class DepositStorageServiceImpl method getList.

@Override
public List<DepositPo> getList() {
    List<Entry<byte[], byte[]>> list = dbService.entryList(ConsensusStorageConstant.DB_NAME_CONSENSUS_DEPOSIT);
    List<DepositPo> resultList = new ArrayList<>();
    if (list == null) {
        return resultList;
    }
    for (Entry<byte[], byte[]> entry : list) {
        DepositPo depositPo = new DepositPo();
        try {
            depositPo.parse(entry.getValue(), 0);
        } catch (NulsException e) {
            Log.error(e);
            throw new NulsRuntimeException(e);
        }
        NulsDigestData hash = new NulsDigestData();
        try {
            hash.parse(entry.getKey(), 0);
        } catch (NulsException e) {
            Log.error(e);
        }
        depositPo.setTxHash(hash);
        resultList.add(depositPo);
    }
    return resultList;
}
Also used : Entry(io.nuls.db.model.Entry) DepositPo(io.nuls.consensus.poc.storage.po.DepositPo) NulsException(io.nuls.kernel.exception.NulsException) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) NulsDigestData(io.nuls.kernel.model.NulsDigestData)

Aggregations

NulsDigestData (io.nuls.kernel.model.NulsDigestData)54 ArrayList (java.util.ArrayList)16 Transaction (io.nuls.kernel.model.Transaction)12 Test (org.junit.Test)12 Block (io.nuls.kernel.model.Block)9 AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)8 NulsException (io.nuls.kernel.exception.NulsException)8 BlockHeader (io.nuls.kernel.model.BlockHeader)7 IOException (java.io.IOException)7 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)5 Result (io.nuls.kernel.model.Result)5 BaseTest (io.nuls.consensus.poc.storage.BaseTest)4 HashSet (java.util.HashSet)4 DepositPo (io.nuls.consensus.poc.storage.po.DepositPo)3 MicroKernelBootstrap (io.nuls.kernel.MicroKernelBootstrap)3 BlockSignature (io.nuls.kernel.script.BlockSignature)3 ValidateResult (io.nuls.kernel.validate.ValidateResult)3 Node (io.nuls.network.model.Node)3 TransferTransaction (io.nuls.protocol.model.tx.TransferTransaction)3 Deposit (io.nuls.consensus.poc.protocol.entity.Deposit)2