Package org.consensusj.jsonrpc
Interface JsonRpcClient<T extends Type>
- All Superinterfaces:
AsyncSupport
,AutoCloseable
,JsonRpcTransport<T>
- All Known Implementing Classes:
BitcoinClient
,BitcoinExtendedClient
,DefaultRpcClient
,EthereumClient
,NamecoinClient
,RxBitcoinClient
JSON-RPC client interface. This interface is independent of the JSON conversion library
(the default implementation uses Jackson) and HTTP client library (currently
HttpURLConnection
).
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 org.consensusj.jsonrpc.AsyncSupport
AsyncSupport.ThrowingSupplier<T>, AsyncSupport.TransientErrorFilter
-
Method Summary
Modifier and TypeMethodDescriptiondefault JsonRpcRequest
buildJsonRequest
(String method, Object... params) default JsonRpcRequest
buildJsonRequest
(String method, List<Object> params) Create a JsonRpcRequest from method and parametersdefault void
close()
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> R
default <R> R
JSON-RPC remote method call that returns 'response.result`default <R> R
Call an RPC method and return default object type.default <R> R
Call an RPC method and return default object type.default <R> R
Varargs versiondefault <R> R
JSON-RPC remote method call that returnsresponse.result
default <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 org.consensusj.jsonrpc.AsyncSupport
getDefaultAsyncExecutor, supplyAsync, supplyAsync
Methods inherited from interface org.consensusj.jsonrpc.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
- Type Parameters:
R
- Type of result object- 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
params
as array/varargs.- Type Parameters:
R
- Type of result object- 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:
IOException
JsonRpcStatusException
-
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:
IOException
JsonRpcStatusException
-
sendAsync
-
sendAsync
-
send
default <R> R send(String method, T resultType, List<Object> params) throws IOException, JsonRpcStatusException JSON-RPC remote method call that returnsresponse.result
- Type Parameters:
R
- Type of result object- 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:
IOException
JsonRpcStatusException
-
send
default <R> R send(String method, T resultType, Object... params) throws IOException, JsonRpcStatusException Varargs version- Throws:
IOException
JsonRpcStatusException
-
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()
. Classes should override when they have something they need to close properly.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- if something happens during closeException
-
defaultType
T defaultType() -
responseTypeFor
-
responseTypeFor
-
typeForClass
-
collectionTypeForClasses
-
collectionTypeForClasses
-