Interface JsonRpcClient<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, AutoCloseable, JsonRpcTransport<T>
- All Known Implementing Classes:
BitcoinClient, BitcoinExtendedClient, DefaultRpcClient, RxBitcoinClient
JSON-RPC client interface. Implementations map JSON responses to
JsonRpcResponse and JSON results
to an expected Java type specified by either a Class or by type T. In the default implementation DefaultRpcClient,
T is Jackson's JavaType.
This interface is independent of the JSON conversion library (e.g. Jackson) and is independent of the JsonRpcTransport.
For historical reasons the interface is mostly synchronous, but AsyncSupport makes it easier
to add use of CompletableFuture for special cases. In the future
this interface may change to natively asynchronous.
Both JSON-RPC 1.0 and JSON-RPC 2.0 are supported. Implementations should also be (via configuration, perhaps) lenient enough to support Bitcoin Core and similar servers that don't follow the JSON-RPC specifications exactly.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface AsyncSupport
AsyncSupport.ThrowingSupplier<T>, AsyncSupport.TransientErrorFilter -
Method Summary
Modifier and TypeMethodDescriptiondefault JsonRpcRequestbuildJsonRequest(String method, Object... params) default JsonRpcRequestbuildJsonRequest(String method, List<Object> params) Create a JsonRpcRequest from method and parametersdefault voidclose()Default no-op implementation ofAutoCloseable.close().collectionTypeForClasses(Class<? extends Collection> collectionClazz, Class<?> clazz) collectionTypeForClasses(Class<? extends Collection> collectionClazz, T itemType) Return the JSON-RPC version used by the implementationresponseTypeFor(Class<?> resultType) responseTypeFor(T resultType) default <R> Rdefault <R> RJSON-RPC remote method call that returns 'response.result`default ObjectCall an RPC method and return default object type.default ObjectCall an RPC method and return default object type.default ObjectVarargs versiondefault ObjectJSON-RPC remote method call that returnsresponse.resultdefault <R> CompletableFuture<R> default <R> CompletableFuture<R> default <R> CompletableFuture<R> default <R> CompletableFuture<R> default <R> CompletableFuture<R> typeForClass(Class<?> clazz) Methods inherited from interface AsyncSupport
getDefaultAsyncExecutor, supplyAsync, supplyAsyncMethods inherited from interface JsonRpcTransport
getServerURI, sendRequestForResponse, sendRequestForResponseAsync, syncGet
-
Method Details
-
getJsonRpcVersion
Return the JSON-RPC version used by the implementation- Returns:
- JSON-RPC version
-
send
Call an RPC method and return default object type.Caller should cast returned object to the correct type.
Useful for:
- Dynamically-dispatched JSON-RPC methods calls via Groovy subclasses
- Simple (not client-side validated) command line utilities
- Functional tests that need to send incorrect types to the server to test error handling
- Parameters:
method- JSON RPC method call to sendparams- JSON RPC parameters as a `List`- Returns:
- the 'response.result' field of the JSON RPC response cast to type R
- Throws:
IOException- network errorJsonRpcStatusException- JSON RPC status error
-
sendAsync
-
send
Call an RPC method and return default object type.Convenience version that takes
paramsas array/varargs.- Parameters:
method- JSON RPC method call to sendparams- JSON RPC parameters as array or varargs- Returns:
- the 'response.result' field of the JSON RPC response cast to type R
- Throws:
IOException- network errorJsonRpcStatusException- JSON RPC status error
-
send
default <R> R send(String method, Class<R> resultType, Object... params) throws IOException, JsonRpcStatusException - Throws:
IOExceptionJsonRpcStatusException
-
sendAsync
-
send
default <R> R send(String method, Class<R> resultType, List<Object> params) throws IOException, JsonRpcStatusException JSON-RPC remote method call that returns 'response.result`- Type Parameters:
R- Type of result object- Parameters:
method- JSON RPC method call to sendresultType- desired result type as a Java class objectparams- JSON RPC params- Returns:
- the 'response.result' field of the JSON RPC response converted to type R
- Throws:
IOExceptionJsonRpcStatusException
-
sendAsync
-
sendAsync
-
send
default Object send(String method, T resultType, List<Object> params) throws IOException, JsonRpcStatusException JSON-RPC remote method call that returnsresponse.result- Parameters:
method- JSON RPC method call to sendresultType- desired result type as a Jackson JavaType objectparams- JSON RPC params- Returns:
- the 'response.result' field of the JSON RPC response converted to type R
- Throws:
IOExceptionJsonRpcStatusException
-
send
default Object send(String method, T resultType, Object... params) throws IOException, JsonRpcStatusException Varargs version- Throws:
IOExceptionJsonRpcStatusException
-
sendAsync
-
buildJsonRequest
Create a JsonRpcRequest from method and parameters- Parameters:
method- name of method to callparams- parameter Java objects- Returns:
- A ready-to-send JsonRpcRequest
-
buildJsonRequest
-
close
Default no-op implementation ofAutoCloseable.close(). Subclasses can override if they have something they need to close properly.- Specified by:
closein interfaceAutoCloseable
-
defaultType
T defaultType() -
responseTypeFor
-
responseTypeFor
-
typeForClass
-
collectionTypeForClasses
-
collectionTypeForClasses
-