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());
}
}
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();
}
}
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;
}
Aggregations