Update clients according to API updates
This commit is contained in:
@@ -93,10 +93,8 @@ public class TransactionLedgerClient {
|
||||
|
||||
info("*** createLedger: name={0}", name);
|
||||
|
||||
CreateLedgerRequest request = CreateLedgerRequest.newBuilder().setName(name).build();
|
||||
|
||||
try {
|
||||
return futureStub.createLedger(request);
|
||||
return futureStub.createLedger(createLedgerRequest(name));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
@@ -111,16 +109,18 @@ public class TransactionLedgerClient {
|
||||
|
||||
info("*** createLedgerSync: name={0}", name);
|
||||
|
||||
CreateLedgerRequest request = CreateLedgerRequest.newBuilder().setName(name).build();
|
||||
|
||||
try {
|
||||
return blockingStub.createLedger(request);
|
||||
return blockingStub.createLedger(createLedgerRequest(name));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private CreateLedgerRequest createLedgerRequest(String name) {
|
||||
return CreateLedgerRequest.newBuilder().setName(name).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* <a href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#getledgers">返回账本列表</a>
|
||||
* (非阻塞)
|
||||
@@ -165,19 +165,8 @@ public class TransactionLedgerClient {
|
||||
"*** sendTransaction: ledger={0} type={1} from={2} to={3} data={4}",
|
||||
ledger, type, from, to, data);
|
||||
|
||||
SendTransactionRequest request =
|
||||
SendTransactionRequest.newBuilder()
|
||||
.setLedger(ledger)
|
||||
.setTransaction(
|
||||
SendTransactionRequest.Transaction.newBuilder()
|
||||
.setType(type)
|
||||
.setFrom(ByteString.copyFrom(Utils.hexStringToByteArray(from)))
|
||||
.setTo(ByteString.copyFrom(Utils.hexStringToByteArray(from)))
|
||||
.setData(ByteString.copyFrom(data)))
|
||||
.build();
|
||||
|
||||
try {
|
||||
return futureStub.sendTransaction(request);
|
||||
return futureStub.sendTransaction(SendTransactionRequest(ledger, type, from, to, data));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
@@ -196,25 +185,35 @@ public class TransactionLedgerClient {
|
||||
"*** sendTransactionSync: ledger={0} type={1} from={2} to={3} data={4}",
|
||||
ledger, type, from, to, data);
|
||||
|
||||
SendTransactionRequest request =
|
||||
SendTransactionRequest.newBuilder()
|
||||
.setLedger(ledger)
|
||||
.setTransaction(
|
||||
SendTransactionRequest.Transaction.newBuilder()
|
||||
.setType(type)
|
||||
.setFrom(ByteString.copyFrom(Utils.hexStringToByteArray(from)))
|
||||
.setTo(ByteString.copyFrom(Utils.hexStringToByteArray(from)))
|
||||
.setData(ByteString.copyFrom(data)))
|
||||
.build();
|
||||
|
||||
try {
|
||||
return blockingStub.sendTransaction(request);
|
||||
return blockingStub.sendTransaction(SendTransactionRequest(ledger, type, from, to, data));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private SendTransactionRequest SendTransactionRequest(
|
||||
String ledger, TransactionType type, String from, String to, byte[] data) {
|
||||
|
||||
SendTransactionRequest.Transaction.Builder txBuilder =
|
||||
SendTransactionRequest.Transaction.newBuilder().setType(type);
|
||||
if (from != null) {
|
||||
txBuilder.setFrom(ByteString.copyFrom(Utils.hexStringToByteArray(from)));
|
||||
}
|
||||
if (to != null) {
|
||||
txBuilder.setTo(ByteString.copyFrom(Utils.hexStringToByteArray(to)));
|
||||
}
|
||||
if (data != null) {
|
||||
txBuilder.setData(ByteString.copyFrom(data));
|
||||
}
|
||||
|
||||
SendTransactionRequest request =
|
||||
SendTransactionRequest.newBuilder().setLedger(ledger).setTransaction(txBuilder).build();
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
private void info(String msg, Object... params) {
|
||||
logger.log(Level.INFO, msg, params);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user