feat: add getRecentBlocks method
This commit is contained in:
parent
5a38f7ed81
commit
1278255c37
@ -449,6 +449,58 @@ public class Client {
|
|||||||
return reqBuilder.build();
|
return reqBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <a
|
||||||
|
* href="#">返回时间戳最新的若干区块</a>
|
||||||
|
* (非阻塞)
|
||||||
|
*/
|
||||||
|
public ListenableFuture<GetBlocksResponse> getRecentBlocks(String ledger, int count, IncludeTransactions includeTransactions) {
|
||||||
|
|
||||||
|
info(
|
||||||
|
"*** getRecentBlocks: ledger={0} count={1} includeTransactions={2}",
|
||||||
|
ledger, count, includeTransactions);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return queryFutureStub.getRecentBlocks(getRecentBlocksRequest(ledger, count, includeTransactions));
|
||||||
|
} catch (StatusRuntimeException e) {
|
||||||
|
warning("RPC failed: {0}", e.getStatus());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <a
|
||||||
|
* href="#">返回时间戳最新的若干区块</a>
|
||||||
|
* (阻塞)
|
||||||
|
*/
|
||||||
|
public GetBlocksResponse getRecentBlocksSync(String ledger, int count, IncludeTransactions includeTransactions) {
|
||||||
|
|
||||||
|
info(
|
||||||
|
"*** getRecentBlocksSync: ledger={0} count={1} includeTransactions={2}",
|
||||||
|
ledger, count, includeTransactions);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return queryBlockingStub.getRecentBlocks(getRecentBlocksRequest(ledger, count, includeTransactions));
|
||||||
|
} catch (StatusRuntimeException e) {
|
||||||
|
warning("RPC failed: {0}", e.getStatus());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RecentBlocksRequest getRecentBlocksRequest(String ledger, int count, IncludeTransactions includeTransactions) {
|
||||||
|
|
||||||
|
RecentBlocksRequest.Builder reqBuilder =
|
||||||
|
RecentBlocksRequest.newBuilder()
|
||||||
|
.setLedger(ledger)
|
||||||
|
.setCount(count);
|
||||||
|
if (includeTransactions == null) {
|
||||||
|
includeTransactions = IncludeTransactions.NONE;
|
||||||
|
}
|
||||||
|
reqBuilder.setIncludeTransactions(includeTransactions);
|
||||||
|
|
||||||
|
return reqBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <a
|
* <a
|
||||||
* href="#">返回哈希所指定的事务</a>
|
* href="#">返回哈希所指定的事务</a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user