Update proto and bew client methods
This commit is contained in:
parent
20526a8bfc
commit
c7889c1874
@ -328,11 +328,11 @@ public class Client {
|
||||
public ListenableFuture<GetBlocksResponse> getBlocks(String ledger, long startUnixTime, long endUnixTime) {
|
||||
|
||||
info(
|
||||
"*** getBlock: ledger={0} startUnixTime={1} endUnixTime={2}",
|
||||
"*** getBlocks: ledger={0} startUnixTime={1} endUnixTime={2}",
|
||||
ledger, startUnixTime, endUnixTime);
|
||||
|
||||
try {
|
||||
return queryFutureStub.getBlocks(getBlocksRequest(ledger, startUnixTime, endUnixTime));
|
||||
return queryFutureStub.getBlocks(blocksRequest(ledger, startUnixTime, endUnixTime));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
@ -356,11 +356,11 @@ public class Client {
|
||||
public GetBlocksResponse getBlocksSync(String ledger, long startUnixTime, long endUnixTime) {
|
||||
|
||||
info(
|
||||
"*** getBlockSync: ledger={0} startUnixTime={1} endUnixTime={2}",
|
||||
"*** getBlocksSync: ledger={0} startUnixTime={1} endUnixTime={2}",
|
||||
ledger, startUnixTime, endUnixTime);
|
||||
|
||||
try {
|
||||
return queryBlockingStub.getBlocks(getBlocksRequest(ledger, startUnixTime, endUnixTime));
|
||||
return queryBlockingStub.getBlocks(blocksRequest(ledger, startUnixTime, endUnixTime));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
@ -377,7 +377,7 @@ public class Client {
|
||||
info("*** blockNumber: ledger={0}", ledger);
|
||||
|
||||
try {
|
||||
return queryFutureStub.countBlocks(getBlocksRequest(ledger, -1, -1));
|
||||
return queryFutureStub.countBlocks(blocksRequest(ledger, -1, -1));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
@ -394,14 +394,14 @@ public class Client {
|
||||
info("*** blockNumberSync: ledger={0}", ledger);
|
||||
|
||||
try {
|
||||
return queryBlockingStub.countBlocks(getBlocksRequest(ledger, -1, -1));
|
||||
return queryBlockingStub.countBlocks(blocksRequest(ledger, -1, -1));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private BlocksRequest getBlocksRequest(String ledger, long startTimestamp, long endTimestamp) {
|
||||
private BlocksRequest blocksRequest(String ledger, long startTimestamp, long endTimestamp) {
|
||||
|
||||
BlocksRequest.Builder reqBuilder =
|
||||
BlocksRequest.newBuilder().setLedger(ledger);
|
||||
@ -515,6 +515,98 @@ public class Client {
|
||||
return reqBuilder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="#">返回时间范围内的事务</a>
|
||||
* (非阻塞)
|
||||
*/
|
||||
public ListenableFuture<GetTransactionsResponse> getTransactions(String ledger, ZonedDateTime startDateTime) {
|
||||
return getTransactions(ledger, startDateTime.toEpochSecond());
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="#">返回时间范围内的事务</a>
|
||||
* (非阻塞)
|
||||
*/
|
||||
public ListenableFuture<GetTransactionsResponse> getTransactions(String ledger, ZonedDateTime startDateTime, ZonedDateTime endDateTime) {
|
||||
return getTransactions(ledger, startDateTime.toEpochSecond(), endDateTime.toEpochSecond());
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="#">返回时间范围内的事务</a>
|
||||
* (阻塞)
|
||||
*/
|
||||
public GetTransactionsResponse getTransactionsSync(String ledger, ZonedDateTime startDateTime) {
|
||||
return getTransactionsSync(ledger, startDateTime.toEpochSecond());
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="#">返回时间范围内的事务</a>
|
||||
* (阻塞)
|
||||
*/
|
||||
public GetTransactionsResponse getTransactionsSync(String ledger, ZonedDateTime startDateTime, ZonedDateTime endDateTime) {
|
||||
return getTransactionsSync(ledger, startDateTime.toEpochSecond(), endDateTime.toEpochSecond());
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="#">返回时间范围内的事务</a>
|
||||
* (非阻塞)
|
||||
*/
|
||||
public ListenableFuture<GetTransactionsResponse> getTransactions(String ledger, long startUnixTime) {
|
||||
return getTransactions(ledger, startUnixTime, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="#">返回时间范围内的事务</a>
|
||||
* (非阻塞)
|
||||
*/
|
||||
public ListenableFuture<GetTransactionsResponse> getTransactions(String ledger, long startUnixTime, long endUnixTime) {
|
||||
|
||||
info(
|
||||
"*** getTransactions: ledger={0} startUnixTime={1} endUnixTime={2}",
|
||||
ledger, startUnixTime, endUnixTime);
|
||||
|
||||
try {
|
||||
return queryFutureStub.getTransactions(transactionsRequest(ledger, startUnixTime, endUnixTime));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="#">返回时间范围内的事务</a>
|
||||
* (阻塞)
|
||||
*/
|
||||
public GetTransactionsResponse getTransactionsSync(String ledger, long startUnixTime) {
|
||||
return getTransactionsSync(ledger, startUnixTime, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="#">返回时间范围内的事务</a>
|
||||
* (阻塞)
|
||||
*/
|
||||
public GetTransactionsResponse getTransactionsSync(String ledger, long startUnixTime, long endUnixTime) {
|
||||
|
||||
info(
|
||||
"*** getTransactionsSync: ledger={0} startUnixTime={1} endUnixTime={2}",
|
||||
ledger, startUnixTime, endUnixTime);
|
||||
|
||||
try {
|
||||
return queryBlockingStub.getTransactions(transactionsRequest(ledger, startUnixTime, endUnixTime));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <a
|
||||
* href="#">返回账本中的事务数量</a>
|
||||
@ -525,7 +617,7 @@ public class Client {
|
||||
info("*** blockNumber: ledger={0}", ledger);
|
||||
|
||||
try {
|
||||
return queryFutureStub.countTransactions(transactionsRequest(ledger));
|
||||
return queryFutureStub.countTransactions(transactionsRequest(ledger, -1, -1));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
@ -542,15 +634,25 @@ public class Client {
|
||||
info("*** blockNumberSync: ledger={0}", ledger);
|
||||
|
||||
try {
|
||||
return queryBlockingStub.countTransactions(transactionsRequest(ledger));
|
||||
return queryBlockingStub.countTransactions(transactionsRequest(ledger, -1, -1));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private TransactionsRequest transactionsRequest(String ledger) {
|
||||
return TransactionsRequest.newBuilder().setLedger(ledger).build();
|
||||
private TransactionsRequest transactionsRequest(String ledger, long startTimestamp, long endTimestamp) {
|
||||
|
||||
TransactionsRequest.Builder reqBuilder =
|
||||
TransactionsRequest.newBuilder().setLedger(ledger);
|
||||
if (startTimestamp != -1) {
|
||||
reqBuilder.setStartTimestamp(startTimestamp);
|
||||
}
|
||||
if (endTimestamp != -1) {
|
||||
reqBuilder.setEndTimestamp(endTimestamp);
|
||||
}
|
||||
|
||||
return reqBuilder.build();
|
||||
}
|
||||
|
||||
private void info(String msg, Object... params) {
|
||||
|
@ -150,10 +150,6 @@ private static final long serialVersionUID = 0L;
|
||||
public static final int START_TIMESTAMP_FIELD_NUMBER = 2;
|
||||
private long startTimestamp_;
|
||||
/**
|
||||
* <pre>
|
||||
* required
|
||||
* </pre>
|
||||
*
|
||||
* <code>int64 start_timestamp = 2;</code>
|
||||
* @return The startTimestamp.
|
||||
*/
|
||||
@ -679,10 +675,6 @@ private static final long serialVersionUID = 0L;
|
||||
|
||||
private long startTimestamp_ ;
|
||||
/**
|
||||
* <pre>
|
||||
* required
|
||||
* </pre>
|
||||
*
|
||||
* <code>int64 start_timestamp = 2;</code>
|
||||
* @return The startTimestamp.
|
||||
*/
|
||||
@ -690,10 +682,6 @@ private static final long serialVersionUID = 0L;
|
||||
return startTimestamp_;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* required
|
||||
* </pre>
|
||||
*
|
||||
* <code>int64 start_timestamp = 2;</code>
|
||||
* @param value The startTimestamp to set.
|
||||
* @return This builder for chaining.
|
||||
@ -705,10 +693,6 @@ private static final long serialVersionUID = 0L;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* required
|
||||
* </pre>
|
||||
*
|
||||
* <code>int64 start_timestamp = 2;</code>
|
||||
* @return This builder for chaining.
|
||||
*/
|
||||
|
@ -20,10 +20,6 @@ public interface BlocksRequestOrBuilder extends
|
||||
getLedgerBytes();
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* required
|
||||
* </pre>
|
||||
*
|
||||
* <code>int64 start_timestamp = 2;</code>
|
||||
* @return The startTimestamp.
|
||||
*/
|
||||
|
@ -300,6 +300,9 @@ public final class QueryGrpc {
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* start_timestamp is required
|
||||
* </pre>
|
||||
*/
|
||||
public void getBlocks(bdledger.api.grpc.query.BlocksRequest request,
|
||||
io.grpc.stub.StreamObserver<bdledger.api.grpc.query.GetBlocksResponse> responseObserver) {
|
||||
@ -419,6 +422,9 @@ public final class QueryGrpc {
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* start_timestamp is required
|
||||
* </pre>
|
||||
*/
|
||||
public void getBlocks(bdledger.api.grpc.query.BlocksRequest request,
|
||||
io.grpc.stub.StreamObserver<bdledger.api.grpc.query.GetBlocksResponse> responseObserver) {
|
||||
@ -489,6 +495,9 @@ public final class QueryGrpc {
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* start_timestamp is required
|
||||
* </pre>
|
||||
*/
|
||||
public bdledger.api.grpc.query.GetBlocksResponse getBlocks(bdledger.api.grpc.query.BlocksRequest request) {
|
||||
return blockingUnaryCall(
|
||||
@ -554,6 +563,9 @@ public final class QueryGrpc {
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* start_timestamp is required
|
||||
* </pre>
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<bdledger.api.grpc.query.GetBlocksResponse> getBlocks(
|
||||
bdledger.api.grpc.query.BlocksRequest request) {
|
||||
|
@ -226,6 +226,29 @@ class ClientTests {
|
||||
assertEquals(tx, t);
|
||||
}
|
||||
|
||||
// TODO
|
||||
@Test
|
||||
@DisplayName("getTransactions#1")
|
||||
void getTransactions1() throws ExecutionException, InterruptedException {
|
||||
client.getTransactions(ledger, 0).get();
|
||||
}
|
||||
|
||||
// TODO
|
||||
@Test
|
||||
@DisplayName("getTransactions#2")
|
||||
void getTransactions2() throws ExecutionException, InterruptedException {
|
||||
client.getTransactions(ledger, 0, 0).get();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("getTransactions#3")
|
||||
void getTransactions3() {
|
||||
Throwable e = assertThrows(Exception.class, () -> client.getTransactions("", 0, 0).get());
|
||||
Status s = Status.fromThrowable(e);
|
||||
assertEquals(Status.Code.INVALID_ARGUMENT, s.getCode());
|
||||
assertEquals("ledger must not be empty", s.getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("CountTransactions#1")
|
||||
void CountTransactions1() throws ExecutionException, InterruptedException {
|
||||
|
Loading…
Reference in New Issue
Block a user