use of io.nuls.rpc.entity.BlockDto in project nuls by nuls-io.
the class BlockResource method getBlocks.
@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBlocks(@QueryParam("pageNumber") int pageNumber, @QueryParam("pageSize") int pageSize) {
if (pageNumber < 0 || pageSize < 0) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
if (pageNumber == 0) {
pageNumber = 1;
}
if (pageSize == 0) {
pageSize = 10;
}
Page<BlockHeaderPo> page = blockService.getBlockHeaderList(pageNumber, pageSize);
Page<BlockDto> dtoPage = new Page<>(page);
List<BlockDto> dtoList = new ArrayList<>();
long reward = 0;
for (BlockHeaderPo header : page.getList()) {
reward = ledgerService.getBlockReward(header.getHeight());
dtoList.add(new BlockDto(header, reward, 0));
}
dtoPage.setList(dtoList);
return RpcResult.getSuccess().setData(dtoPage);
}
use of io.nuls.rpc.entity.BlockDto in project nuls by nuls-io.
the class BlockResource method loadBlock.
@GET
@Path("/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult loadBlock(@PathParam("hash") String hash) {
RpcResult result;
if (!StringUtils.validHash(hash)) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
Block block = blockService.getBlock(hash);
if (block == null) {
result = RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
} else {
long reward = ledgerService.getBlockReward(block.getHeader().getHeight());
long fee = ledgerService.getBlockFee(block.getHeader().getHeight());
result = RpcResult.getSuccess();
try {
result.setData(new BlockDto(block, reward, fee));
} catch (IOException e) {
// todo
e.printStackTrace();
}
}
return result;
}
use of io.nuls.rpc.entity.BlockDto in project nuls by nuls-io.
the class BlockResource method getBestBlockHash.
@GET
@Path("/newest")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBestBlockHash() throws IOException {
RpcResult result = RpcResult.getSuccess();
result.setData(new BlockDto(blockService.getLocalBestBlock().getHeader(), 0, 0));
return result;
}
use of io.nuls.rpc.entity.BlockDto in project nuls by nuls-io.
the class BlockResource method getBlocksByAddress.
@GET
@Path("/list/address")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBlocksByAddress(@QueryParam("address") String address, @QueryParam("type") int type, @QueryParam("pageNumber") int pageNumber, @QueryParam("pageSize") int pageSize) {
if (type < 1 || type > 2 || pageNumber < 0 || pageSize < 0 || !Address.validAddress(address)) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
if (pageNumber == 0) {
pageNumber = 1;
}
if (pageSize == 0) {
pageSize = 10;
}
Page<BlockHeaderPo> page = blockService.getBlockHeaderList(address, type, pageNumber, pageSize);
Page<BlockDto> dtoPage = new Page<>(page);
List<BlockDto> dtoList = new ArrayList<>();
long reward = 0;
for (BlockHeaderPo header : page.getList()) {
reward = ledgerService.getBlockReward(header.getHeight());
dtoList.add(new BlockDto(header, reward, 0));
}
dtoPage.setList(dtoList);
return RpcResult.getSuccess().setData(dtoPage);
}
use of io.nuls.rpc.entity.BlockDto in project nuls by nuls-io.
the class BlockResource method getHeader.
@GET
@Path("/header/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getHeader(@PathParam("hash") String hash) throws NulsException, IOException {
RpcResult result = RpcResult.getSuccess();
BlockHeader blockHeader = blockService.getBlockHeader(hash);
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;
}
Aggregations