use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class ConsensusBlockServiceImpl method getBlock.
@Override
public Result<Block> getBlock(NulsDigestData hash) {
Result result = new Result(true, null);
Block block = new Block();
BlockHeader blockHeader = new BlockHeader();
blockHeader.setHash(hash);
block.setHeader(blockHeader);
block.setTxs(new ArrayList<>());
result.setData(block);
return result;
}
use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class ChainManagerTest method testCheckIsBeforeOrphanChainAndAdd.
@Test
public void testCheckIsBeforeOrphanChainAndAdd() {
testGetBestBlockHeight();
Block block = createBlock();
Block block1 = createBlock();
block1.getHeader().setHeight(1L);
block1.getHeader().setPreHash(block.getHeader().getHash());
ChainContainer orphanChain = new ChainContainer(new Chain());
orphanChain.getChain().addBlock(block1);
chainManager.getOrphanChains().add(orphanChain);
assertEquals(1, chainManager.getOrphanChains().size());
boolean success = chainManager.checkIsBeforeOrphanChainAndAdd(block);
assertTrue(success);
}
use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class BlockQueueProviderTest method testPut.
@Test
public void testPut() {
assertNotNull(blockQueueProvider);
assertEquals(0, blockQueueProvider.size());
Block block = new Block();
boolean result = blockQueueProvider.put(new BlockContainer(block, BlockContainerStatus.RECEIVED));
assertTrue(result);
assertEquals(1, blockQueueProvider.size());
}
use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class BlockQueueProviderTest method testGet.
@Test
public void testGet() {
assertNotNull(blockQueueProvider);
assertEquals(0, blockQueueProvider.size());
if (downloadService.isDownloadSuccess().isSuccess()) {
downloadService.setDownloadSuccess(false);
}
Block block = new Block();
boolean result = blockQueueProvider.put(new BlockContainer(block, BlockContainerStatus.RECEIVED));
assertTrue(result);
assertEquals(1, blockQueueProvider.size());
BlockContainer blockContainer = blockQueueProvider.get();
assertNull(blockContainer);
downloadService.setDownloadSuccess(true);
blockContainer = blockQueueProvider.get();
assertNotNull(blockContainer);
assertEquals(blockContainer.getBlock(), block);
assertEquals(blockContainer.getStatus(), BlockContainerStatus.DOWNLOADING);
assertEquals(0, blockQueueProvider.size());
block = new Block();
result = blockQueueProvider.put(new BlockContainer(block, BlockContainerStatus.RECEIVED));
assertTrue(result);
blockContainer = blockQueueProvider.get();
assertNotNull(blockContainer);
assertEquals(blockContainer.getBlock(), block);
assertEquals(blockContainer.getStatus(), BlockContainerStatus.RECEIVED);
}
use of io.nuls.kernel.model.Block 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();
}
}
Aggregations