Search in sources :

Example 6 with BlockDto

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;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) BlockHeader(io.nuls.core.chain.entity.BlockHeader) BlockDto(io.nuls.rpc.entity.BlockDto)

Example 7 with BlockDto

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;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) Block(io.nuls.core.chain.entity.Block) IOException(java.io.IOException) BlockDto(io.nuls.rpc.entity.BlockDto)

Aggregations

BlockDto (io.nuls.rpc.entity.BlockDto)7 RpcResult (io.nuls.rpc.entity.RpcResult)5 Block (io.nuls.core.chain.entity.Block)2 BlockHeader (io.nuls.core.chain.entity.BlockHeader)2 Page (io.nuls.core.dto.Page)2 BlockHeaderPo (io.nuls.db.entity.BlockHeaderPo)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2