use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class BlockResource method getBlock.
@GET
@Path("/height/{height}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBlock(@PathParam("height") Long height) {
RpcResult result;
if (height < 0) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
Block block = blockService.getBlock(height);
if (block == null) {
result = RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
} else {
result = RpcResult.getSuccess();
long reward = ledgerService.getBlockReward(block.getHeader().getHeight());
long fee = ledgerService.getBlockFee(block.getHeader().getHeight());
try {
result.setData(new BlockDto(block, reward, fee));
} catch (IOException e) {
// todo
e.printStackTrace();
}
}
return result;
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class BlockManager method checkNextblock.
private void checkNextblock(String hash) {
String nextHash = blockCacheBuffer.getNextHash(hash);
if (null == nextHash) {
return;
}
Block block = blockCacheBuffer.getBlock(nextHash);
if (null == block) {
return;
}
blockCacheBuffer.removeBlock(nextHash);
this.addBlock(block, true, null);
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class BlockEventHandler method onEvent.
@Override
public void onEvent(BlockEvent event, String fromId) {
Block block = event.getEventBody();
if (null == block) {
Log.warn("recieved a null blockEvent form " + fromId);
return;
}
ValidateResult result = block.verify();
if (result.isFailed() && result.getErrorCode() != ErrorCode.ORPHAN_TX) {
if (result.getLevel() == SeverityLevelEnum.FLAGRANT_FOUL) {
networkService.blackNode(fromId, NodePo.YELLOW);
}
Log.warn("recieved a wrong blockEvent:{},form:{}", result.getMessage(), fromId);
return;
}
if (BlockBatchDownloadUtils.getInstance().downloadedBlock(fromId, block)) {
return;
}
blockCacheManager.addBlock(block, false, fromId);
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class GetTxGroupHandler method onEvent.
@Override
public void onEvent(GetTxGroupRequest event, String fromId) {
GetTxGroupParam eventBody = event.getEventBody();
Block block = blockService.getBlock(eventBody.getBlockHash().getDigestHex());
if (null == block) {
return;
}
TxGroupEvent txGroupEvent = new TxGroupEvent();
TxGroup txGroup = new TxGroup();
txGroup.setBlockHash(block.getHeader().getHash());
List<Transaction> txList = getTxList(block, eventBody.getTxHashList());
txGroup.setTxList(txList);
txGroupEvent.setEventBody(txGroup);
eventBroadcaster.sendToNode(txGroupEvent, fromId);
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class ConfrimingBlockCacheManager method getBlock.
public Block getBlock(String hash) {
if (null == txsCacheMap || headerCacheMap == null) {
return null;
}
BlockHeader header = headerCacheMap.get(hash);
List<Transaction> txs = txsCacheMap.get(hash);
if (null == header || null == txs || txs.isEmpty()) {
return null;
}
Block block = new Block();
block.setHeader(header);
block.setTxs(txs);
return block;
}
Aggregations