Search in sources :

Example 66 with NulsRuntimeException

use of io.nuls.kernel.exception.NulsRuntimeException in project nuls by nuls-io.

the class BlockHeaderStorageServiceImpl method afterPropertiesSet.

/**
 * 创建存储表,创建失败时如果是因为已存在则正常,否则抛出异常
 * Create a storage table, or throw an exception if it is normal if it is already existing.
 */
@Override
public void afterPropertiesSet() {
    Result result = this.dbService.createArea(ProtocolStorageConstant.DB_NAME_BLOCK_HEADER_INDEX);
    if (result.isFailed() && !DBErrorCode.DB_AREA_EXIST.equals(result.getErrorCode())) {
        throw new NulsRuntimeException(result.getErrorCode());
    }
    result = this.dbService.createArea(ProtocolStorageConstant.DB_NAME_BLOCK_HEADER);
    if (result.isFailed() && !DBErrorCode.DB_AREA_EXIST.equals(result.getErrorCode())) {
        throw new NulsRuntimeException(result.getErrorCode());
    }
    try {
        bestBlockKey = NulsDigestData.calcDigestData(ProtocolStorageConstant.BEST_BLOCK_HASH_INDEX.getBytes()).serialize();
    } catch (IOException e) {
        throw new NulsRuntimeException(e.getCause());
    }
}
Also used : NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) IOException(java.io.IOException) Result(io.nuls.kernel.model.Result)

Example 67 with NulsRuntimeException

use of io.nuls.kernel.exception.NulsRuntimeException in project nuls by nuls-io.

the class BaseProtocolsModuleBootstrap method start.

@Override
public void start() {
    this.waitForDependencyRunning(MessageBusConstant.MODULE_ID_MESSAGE_BUS);
    this.waitForDependencyInited(ConsensusConstant.MODULE_ID_CONSENSUS, NetworkConstant.NETWORK_MODULE_ID);
    BlockService blockService = NulsContext.getServiceBean(BlockService.class);
    Block block0 = blockService.getGengsisBlock().getData();
    Block genesisBlock = NulsContext.getInstance().getGenesisBlock();
    if (null == block0) {
        try {
            blockService.saveBlock(genesisBlock);
        } catch (NulsException e) {
            Log.error(e);
            throw new NulsRuntimeException(e);
        }
    }
    Block block = blockService.getBestBlock().getData();
    while (null != block && block.verify().isFailed()) {
        try {
            blockService.rollbackBlock(block);
        } catch (NulsException e) {
            Log.error(e);
        }
        block = blockService.getBlock(block.getHeader().getPreHash()).getData();
    }
    if (null != block) {
        NulsContext.getInstance().setBestBlock(block);
        this.initHandlers();
        ((DownloadServiceImpl) NulsContext.getServiceBean(DownloadService.class)).start();
    } else {
        start();
    }
}
Also used : DownloadServiceImpl(io.nuls.protocol.base.service.DownloadServiceImpl) NulsException(io.nuls.kernel.exception.NulsException) BlockService(io.nuls.protocol.service.BlockService) Block(io.nuls.kernel.model.Block) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) DownloadService(io.nuls.protocol.service.DownloadService)

Example 68 with NulsRuntimeException

use of io.nuls.kernel.exception.NulsRuntimeException in project nuls by nuls-io.

the class AssemblyBlockUtil method assemblyBlock.

public static Block assemblyBlock(BlockHeader header, Map<NulsDigestData, Transaction> txMap, List<NulsDigestData> txHashList) {
    Block block = new Block();
    block.setHeader(header);
    List<Transaction> txs = new ArrayList<>();
    for (NulsDigestData txHash : txHashList) {
        Transaction tx = txMap.get(txHash);
        if (null == tx) {
            throw new NulsRuntimeException(TransactionErrorCode.TX_NOT_EXIST);
        }
        tx.setBlockHeight(header.getHeight());
        txs.add(tx);
    }
    block.setTxs(txs);
    return block;
}
Also used : Transaction(io.nuls.kernel.model.Transaction) ArrayList(java.util.ArrayList) Block(io.nuls.kernel.model.Block) NulsDigestData(io.nuls.kernel.model.NulsDigestData) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException)

Aggregations

NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)68 IOException (java.io.IOException)35 NulsException (io.nuls.kernel.exception.NulsException)26 ArrayList (java.util.ArrayList)21 CoinDataResult (io.nuls.account.ledger.model.CoinDataResult)10 Result (io.nuls.kernel.model.Result)9 Account (io.nuls.account.model.Account)8 MultiSigAccount (io.nuls.account.model.MultiSigAccount)8 Entry (io.nuls.db.model.Entry)8 Agent (io.nuls.consensus.poc.protocol.entity.Agent)7 VarInt (io.nuls.kernel.utils.VarInt)7 CreateAgentTransaction (io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction)6 ValidateResult (io.nuls.kernel.validate.ValidateResult)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 Deposit (io.nuls.consensus.poc.protocol.entity.Deposit)5 DepositTransaction (io.nuls.consensus.poc.protocol.tx.DepositTransaction)5 DepositPo (io.nuls.consensus.poc.storage.po.DepositPo)5 PunishLogPo (io.nuls.consensus.poc.storage.po.PunishLogPo)5 TransferTransaction (io.nuls.protocol.model.tx.TransferTransaction)5 StopAgent (io.nuls.consensus.poc.protocol.entity.StopAgent)4