fix:
- authTokens - throw errors - sendTransaction's nonce
This commit is contained in:
parent
b524d23463
commit
bc6b9bcb4c
@ -77,7 +77,7 @@ public class Client {
|
||||
|
||||
if (token != null) {
|
||||
Metadata fixedHeaders = new Metadata();
|
||||
fixedHeaders.put(Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER), token);
|
||||
fixedHeaders.put(Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER), "bearer " + token);
|
||||
nodeFutureStub = MetadataUtils.attachHeaders(nodeFutureStub, fixedHeaders);
|
||||
nodeBlockingStub = MetadataUtils.attachHeaders(nodeBlockingStub, fixedHeaders);
|
||||
ledgerFutureStub = MetadataUtils.attachHeaders(ledgerFutureStub, fixedHeaders);
|
||||
@ -124,7 +124,7 @@ public class Client {
|
||||
return nodeBlockingStub.clientVersion(Empty.getDefaultInstance());
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ public class Client {
|
||||
return ledgerBlockingStub.createLedger(createLedgerRequest(name));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ public class Client {
|
||||
return ledgerBlockingStub.getLedgers(Empty.getDefaultInstance());
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,14 +202,14 @@ public class Client {
|
||||
* (非阻塞)
|
||||
*/
|
||||
public ListenableFuture<SendTransactionResponse> sendTransaction(
|
||||
String ledger, TransactionType type, String from, String to, byte[] data) {
|
||||
String ledger, TransactionType type, String from, long nonce, String to, byte[] data) {
|
||||
|
||||
info(
|
||||
"*** sendTransaction: ledger={0} type={1} from={2} to={3} data={4}",
|
||||
ledger, type, from, to, data);
|
||||
|
||||
try {
|
||||
return ledgerFutureStub.sendTransaction(SendTransactionRequest(ledger, type, from, to, data));
|
||||
return ledgerFutureStub.sendTransaction(SendTransactionRequest(ledger, type, from, nonce, to, data));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
@ -222,28 +222,29 @@ public class Client {
|
||||
* (阻塞)
|
||||
*/
|
||||
public SendTransactionResponse sendTransactionSync(
|
||||
String ledger, TransactionType type, String from, String to, byte[] data) {
|
||||
String ledger, TransactionType type, String from, long nonce, String to, byte[] data) {
|
||||
|
||||
info(
|
||||
"*** sendTransactionSync: ledger={0} type={1} from={2} to={3} data={4}",
|
||||
ledger, type, from, to, data);
|
||||
|
||||
try {
|
||||
return ledgerBlockingStub.sendTransaction(SendTransactionRequest(ledger, type, from, to, data));
|
||||
return ledgerBlockingStub.sendTransaction(SendTransactionRequest(ledger, type, from, nonce, to, data));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private SendTransactionRequest SendTransactionRequest(
|
||||
String ledger, TransactionType type, String from, String to, byte[] data) {
|
||||
String ledger, TransactionType type, String from, long nonce, String to, byte[] data) {
|
||||
|
||||
SendTransactionRequest.Transaction.Builder txBuilder =
|
||||
SendTransactionRequest.Transaction.newBuilder().setType(type);
|
||||
if (from != null) {
|
||||
txBuilder.setFrom(ByteString.copyFrom(Utils.hexStringToByteArray(from)));
|
||||
}
|
||||
txBuilder.setNonce(nonce);
|
||||
if (to != null) {
|
||||
txBuilder.setTo(ByteString.copyFrom(Utils.hexStringToByteArray(to)));
|
||||
}
|
||||
@ -289,7 +290,7 @@ public class Client {
|
||||
return queryBlockingStub.getBlockByHash(getBlockByHashRequest(ledger, hash, fullTransactions));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,7 +394,7 @@ public class Client {
|
||||
return queryBlockingStub.getBlocks(blocksRequest(ledger, startUnixTime, endUnixTime, includeTransactions));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -427,7 +428,7 @@ public class Client {
|
||||
return queryBlockingStub.countBlocks(blocksRequest(ledger, -1, -1, null));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,7 +484,7 @@ public class Client {
|
||||
return queryBlockingStub.getRecentBlocks(getRecentBlocksRequest(ledger, count, includeTransactions));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -531,7 +532,7 @@ public class Client {
|
||||
return queryBlockingStub.getTransactionByHash(getTransactionByHashRequest(ledger, hash));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -584,7 +585,7 @@ public class Client {
|
||||
getTransactionByBlockHashAndIndexRequest(ledger, blockHash, index));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -689,7 +690,7 @@ public class Client {
|
||||
return queryBlockingStub.getTransactions(transactionsRequest(ledger, startUnixTime, endUnixTime));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -723,7 +724,7 @@ public class Client {
|
||||
return queryBlockingStub.countTransactions(transactionsRequest(ledger, -1, -1));
|
||||
} catch (StatusRuntimeException e) {
|
||||
warning("RPC failed: {0}", e.getStatus());
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user