diff --git a/src/main/java/bdledger/api/Client.java b/src/main/java/bdledger/api/Client.java index 9f95f32..db2c90f 100644 --- a/src/main/java/bdledger/api/Client.java +++ b/src/main/java/bdledger/api/Client.java @@ -1,10 +1,8 @@ package bdledger.api; -import bdledger.api.grpc.common.Block; -import bdledger.api.grpc.common.Transaction; -import bdledger.api.grpc.node.ClientVersionResponse; import bdledger.api.grpc.common.TransactionType; import bdledger.api.grpc.ledger.*; +import bdledger.api.grpc.node.ClientVersionResponse; import bdledger.api.grpc.node.NodeGrpc; import bdledger.api.grpc.query.*; import com.google.common.util.concurrent.ListenableFuture; @@ -278,7 +276,7 @@ public class Client { /** * 返回全网区块的数量 + * href="#">返回符合条件的区块的数量 * (非阻塞) */ public ListenableFuture countBlocks(String ledger) { @@ -295,7 +293,7 @@ public class Client { /** * 返回全网区块的数量 + * href="#">返回符合条件的区块的数量 * (阻塞) */ public CountBlocksResponse countBlocksSync(String ledger) { @@ -414,6 +412,44 @@ public class Client { return reqBuilder.build(); } + /** + * 返回符合条件的数量 + * (非阻塞) + */ + public ListenableFuture countTransactions(String ledger) { + + info("*** blockNumber: ledger={0}", ledger); + + try { + return queryFutureStub.countTransactions(transactionsRequest(ledger)); + } catch (StatusRuntimeException e) { + warning("RPC failed: {0}", e.getStatus()); + return null; + } + } + + /** + * 返回符合条件的事务的数量 + * (阻塞) + */ + public CountTransactionsResponse countTransactionsSync(String ledger) { + + info("*** blockNumberSync: ledger={0}", ledger); + + try { + return queryBlockingStub.countTransactions(transactionsRequest(ledger)); + } catch (StatusRuntimeException e) { + warning("RPC failed: {0}", e.getStatus()); + return null; + } + } + + private TransactionsRequest transactionsRequest(String ledger) { + return TransactionsRequest.newBuilder().setLedger(ledger).build(); + } + private void info(String msg, Object... params) { logger.log(Level.INFO, msg, params); }