use of org.starcoin.bean.UncleBlock in project starcoin-search by starcoinorg.
the class BlockService method getUncleBlockByHash.
public UncleBlock getUncleBlockByHash(String network, String hash) {
SearchRequest searchRequest = new SearchRequest(getIndex(network, Constant.UNCLE_BLOCK_INDEX));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("header.block_hash", hash);
searchSourceBuilder.query(termQueryBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse;
try {
searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
logger.error("get uncle block by hash error:", e);
return null;
}
Result<UncleBlock> result = ServiceUtils.getSearchResult(searchResponse, UncleBlock.class);
List<UncleBlock> blocks = result.getContents();
if (blocks.size() == 1) {
return blocks.get(0);
} else {
logger.warn("get uncle block by hash is null, network: {}, : {}", network, hash);
}
return null;
}
use of org.starcoin.bean.UncleBlock in project starcoin-search by starcoinorg.
the class BlockService method getUncleBlockByHeight.
public UncleBlock getUncleBlockByHeight(String network, long height) {
SearchRequest searchRequest = new SearchRequest(getIndex(network, Constant.UNCLE_BLOCK_INDEX));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
TermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("header.number", height);
searchSourceBuilder.query(termQueryBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse;
try {
searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
logger.error("get uncle block error:", e);
return null;
}
Result<UncleBlock> result = ServiceUtils.getSearchResult(searchResponse, UncleBlock.class);
List<UncleBlock> blocks = result.getContents();
if (blocks.size() == 1) {
return blocks.get(0);
} else {
logger.warn("get uncle block by height is null, network: {}, : {}", network, height);
}
return null;
}
Aggregations