Interface JsonRpcTransport<T extends Type>
- Type Parameters:
T- Type that can be used (in addition toClass) to declare expected result types for JSON-RPC method calls.
- All Superinterfaces:
AsyncSupport
- All Known Subinterfaces:
JsonRpcClient<T>
- All Known Implementing Classes:
BitcoinClient, BitcoinExtendedClient, DefaultRpcClient, JsonRpcClientHttpUrlConnection, JsonRpcClientJavaNet, RxBitcoinClient
Defines the interface for a network-layer implementation of a JSON-RPC client.
-
Nested Class Summary
Nested classes/interfaces inherited from interface AsyncSupport
AsyncSupport.ThrowingSupplier<T>, AsyncSupport.TransientErrorFilter -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringbase64Encode(String authString) Encode username password as Base64 for basic authenticationstatic SSLContextReturn the defaultSSLContextwithout declaring a checked exceptionGet the URI of the remote serverdefault <R> JsonRpcResponse<R> sendRequestForResponse(JsonRpcRequest request, T responseType) Send aJsonRpcRequestfor aJsonRpcResponse<R> CompletableFuture<JsonRpcResponse<R>> sendRequestForResponseAsync(JsonRpcRequest request, T responseType) Send aJsonRpcRequestfor aJsonRpcResponseasynchronously.default <R> RsyncGet(CompletableFuture<R> future) Synchronously complete a JSON-RPC request by callingCompletableFuture.get(), unwrapping nestedJsonRpcExceptionorIOExceptionfromExecutionException.Methods inherited from interface AsyncSupport
getDefaultAsyncExecutor, supplyAsync, supplyAsync
-
Method Details
-
getServerURI
-
sendRequestForResponse
default <R> JsonRpcResponse<R> sendRequestForResponse(JsonRpcRequest request, T responseType) throws IOException, JsonRpcStatusException Send aJsonRpcRequestfor aJsonRpcResponseSynchronous subclasses should override this method to prevent
CompletableFuture.supplyAsync(Supplier)from being called twice whenAsyncSupportis being used. Eventually we'll migrate more of the codebase to native async, and then we won't have to worry about callingsupplyAsynctwice.- Type Parameters:
R- Type of result object- Parameters:
request- The request to sendresponseType- The response type expected (used by Jackson for conversion)- Returns:
- A JSON RPC Response with `result` of type `R`
- Throws:
IOException- network errorJsonRpcStatusException- JSON RPC status error
-
sendRequestForResponseAsync
<R> CompletableFuture<JsonRpcResponse<R>> sendRequestForResponseAsync(JsonRpcRequest request, T responseType) Send aJsonRpcRequestfor aJsonRpcResponseasynchronously.- Type Parameters:
R- Type of result object- Parameters:
request- The request to sendresponseType- The response type expected (used by Jackson for conversion)- Returns:
- A future JSON RPC Response with `result` of type `R`
-
syncGet
Synchronously complete a JSON-RPC request by callingCompletableFuture.get(), unwrapping nestedJsonRpcExceptionorIOExceptionfromExecutionException.- Type Parameters:
R- The expected result type- Parameters:
future- TheCompletableFuture(result of JSON-RPC request) to unwrap- Returns:
- A JSON-RPC result
- Throws:
IOException- IfCompletableFuture.get()threwExecutionExceptioncaused byIOExceptionJsonRpcException- IfCompletableFuture.get()threwExecutionExceptioncaused byJsonRpcExceptionRuntimeException- IfCompletableFuture.get()threwInterruptedExceptionor otherExecutionException.
-
base64Encode
Encode username password as Base64 for basic authenticationWe're using
Base64, which requires Android 8.0 or later.- Parameters:
authString- An authorization string of the form `username:password`- Returns:
- A compliant Base64 encoding of `authString`
-
getDefaultSSLContext
Return the defaultSSLContextwithout declaring a checked exception- Returns:
- The default
SSLContext
-