use of io.nuls.rpc.entity.BlockDto in project nuls by nuls-io.
the class BlockResource method getHeaderByHeight.
@GET
@Path("/header/height/{height}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getHeaderByHeight(@PathParam("height") Integer height) throws NulsException, IOException {
RpcResult result = RpcResult.getSuccess();
BlockHeader blockHeader = blockService.getBlockHeader(height);
if (blockHeader == null) {
return RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
}
long reward = ledgerService.getBlockReward(blockHeader.getHeight());
long fee = ledgerService.getBlockFee(blockHeader.getHeight());
result.setData(new BlockDto(blockHeader, reward, fee));
return result;
}
use of io.nuls.rpc.entity.BlockDto 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;
}
Aggregations