Skip to content

Commit

Permalink
Merge branch 'develop' into mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
niels1286 committed Apr 24, 2019
2 parents abaa3a6 + ccdfba5 commit 85c8bad
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>nuls-wallet</title><link rel=icon type=image/png href=./static/img/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=./static/img/favicon-16x16.png sizes=16x16><link href=/static/css/app.992816facf4b046c3db3bbd60919a502.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.d59d10a1bd658fa5ef79.js></script><script type=text/javascript src=/static/js/vendor.b7b1d7f8be78cdcff386.js></script><script type=text/javascript src=/static/js/app.855461f7fdd9f2c3d0e9.js></script></body></html>
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>nuls-wallet</title><link rel=icon type=image/png href=./static/img/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=./static/img/favicon-16x16.png sizes=16x16><link href=/static/css/app.992816facf4b046c3db3bbd60919a502.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.d59d10a1bd658fa5ef79.js></script><script type=text/javascript src=/static/js/vendor.b7b1d7f8be78cdcff386.js></script><script type=text/javascript src=/static/js/app.147fb987a066bf8963fd.js></script></body></html>

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.nuls.protocol.service.BlockService;

import java.util.ArrayList;
import java.util.List;

/**
* Created by ln on 2018/5/8.
Expand Down Expand Up @@ -96,6 +97,11 @@ public Result<Block> getBlock(long height, boolean isNeedContractTransfer) {
return null;
}

@Override
public List<String> getBlockTxHash(long height) {
return null;
}

@Override
public Result saveBlock(Block block) throws NulsException {
return new Result(true, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public class BlockHeader extends BaseNulsData {
private transient byte[] packingAddress;
private transient String packingAddressStr;




public BlockHeader() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ public Result<Block> getBlock(long height, boolean isNeedContractTransfer) {
return Result.getSuccess().setData(block);
}

@Override
public List<String> getBlockTxHash(long height) {
BlockHeaderPo headerPo = blockHeaderStorageService.getBlockHeaderPo(height);
List<String> list = new ArrayList<>();
if (null != headerPo && null != headerPo.getTxHashList()) {
for (NulsDigestData hash : headerPo.getTxHashList()) {
list.add(hash.getDigestHex());
}
}
return list;
}

/**
* 保存区块到存储中
* Save the block to the store.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.swagger.annotations.ApiModelProperty;

import java.io.IOException;
import java.util.List;

/**
* @author: Niels Wang
Expand Down Expand Up @@ -98,6 +99,8 @@ public class BlockHeaderDto {
@ApiModelProperty(name = "size", value = "大小")
private int size;

private List<String> txHash;

public BlockHeaderDto(Block block) throws IOException {
this(block.getHeader());
this.size = block.getHeader().size();
Expand Down Expand Up @@ -292,4 +295,12 @@ public String getExtend() {
public void setExtend(String extend) {
this.extend = extend;
}

public List<String> getTxHash() {
return txHash;
}

public void setTxHash(List<String> txHash) {
this.txHash = txHash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,32 @@ public RpcClientResult getHeaderByHeight(@ApiParam(name = "height", value = "区
}


@GET
@Path("/header/txHash/height/{height}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "根据区块高度查询区块头", notes = "result.data: blockHeaderJson 返回对应的区块头信息")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "success", response = BlockDto.class)
})
public RpcClientResult getHeaderHashesByHeight(@ApiParam(name = "height", value = "区块高度", required = true)
@PathParam("height") Integer height) {
AssertUtil.canNotEmpty(height);
Result<Block> blockResult = blockService.getBlock(height);
if (blockResult.isFailed()) {
return blockResult.toRpcClientResult();
}
BlockHeaderDto dto = null;
try {
dto = new BlockHeaderDto(blockResult.getData());
List<String> list = blockService.getBlockTxHash(height);
dto.setTxHash(list);
} catch (IOException e) {
Log.error(e);
return Result.getFailed(KernelErrorCode.IO_ERROR).toRpcClientResult();
}
return Result.getSuccess().setData(dto).toRpcClientResult();
}

@GET
@Path("/header/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -118,6 +144,42 @@ public RpcClientResult getHeader(@ApiParam(name = "hash", value = "区块hash",
return result.toRpcClientResult();
}

@GET
@Path("/header/txHash/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "根据区块hash查询区块头", notes = "result.data: blockHeaderJson 返回对应的区块头信息")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "success", response = BlockDto.class)
})
public RpcClientResult getHeaderHash(@ApiParam(name = "hash", value = "区块hash", required = true)
@PathParam("hash") String hash) {
AssertUtil.canNotEmpty(hash);
hash = StringUtils.formatStringPara(hash);
if (!NulsDigestData.validHash(hash)) {
return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
Result result = Result.getSuccess();
Block block = null;
try {
block = blockService.getBlock(NulsDigestData.fromDigestHex(hash)).getData();
} catch (NulsException e) {
Log.error(e);
}
if (block == null) {
return Result.getFailed(ProtocolErroeCode.BLOCK_IS_NULL).toRpcClientResult();
}
try {
BlockHeaderDto dto = new BlockHeaderDto(block);
List<String> list = blockService.getBlockTxHash(block.getHeader().getHeight());
dto.setTxHash(list);
result.setData(dto);
} catch (IOException e) {
Log.error(e);
return Result.getFailed(KernelErrorCode.IO_ERROR).toRpcClientResult();
}
return result.toRpcClientResult();
}

@GET
@Path("/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import io.nuls.network.model.Node;
import io.nuls.protocol.model.SmallBlock;

import java.util.List;

/**
* 区块处理服务接口
* The block handles the service interface.
Expand Down Expand Up @@ -113,6 +115,8 @@ public interface BlockService {
*/
Result<Block> getBlock(long height, boolean isNeedContractTransfer);

List<String> getBlockTxHash(long height);

/**
* 保存区块到存储中
* Save the block to the store.
Expand Down

0 comments on commit 85c8bad

Please sign in to comment.