Package monero.common
Class MoneroRpcConnection
java.lang.Object
monero.common.MoneroRpcConnection
Maintains a connection and sends requests to a Monero RPC API.
TODO: refactor MoneroRpcConnection extends MoneroConnection?
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMoneroRpcConnection
(String uri, String username, String password) MoneroRpcConnection
(String uri, String username, String password, String zmqUri) MoneroRpcConnection
(URI uri) MoneroRpcConnection
(URI uri, String username, String password) MoneroRpcConnection
(URI uri, String username, String password, URI zmqUri) MoneroRpcConnection
(MoneroRpcConnection connection) -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkConnection
(long timeoutMs) Check the connection and update online, authentication, and response time status.boolean
getAttribute
(String key) int
Get the response time of the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.getUri()
int
hashCode()
Indicates if the connection is authenticated according to the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.Indicates if the connection is connected according to the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.boolean
isOnion()
isOnline()
Indicates if the connection is online according to the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.byte[]
sendBinaryRequest
(String path, Map<String, Object> params) Send a binary RPC request.byte[]
Send a binary RPC request.sendJsonRequest
(String method) Send a request to the RPC API.sendJsonRequest
(String method, Object params) Send a request to the RPC API.sendJsonRequest
(String method, Object params, Long timeoutMs) Send a request to the RPC API.sendPathRequest
(String path) Send a RPC request to the given path and with the given paramters.sendPathRequest
(String path, Map<String, Object> params) Send a RPC request to the given path and with the given paramters.Send a RPC request to the given path and with the given paramters.setAttribute
(String key, Object value) setCredentials
(String username, String password) void
setPrintStackTrace
(boolean printStackTrace) Enable or disable printing a stack trace on each request for debug.setPriority
(int priority) Set the connection's priority relative to other connections.setProxyUri
(String proxyUri) setTimeout
(Long timeoutMs) Set the RPC request timeout in milliseconds.toString()
-
Field Details
-
MAPPER
public static com.fasterxml.jackson.databind.ObjectMapper MAPPER
-
-
Constructor Details
-
MoneroRpcConnection
-
MoneroRpcConnection
-
MoneroRpcConnection
-
MoneroRpcConnection
-
MoneroRpcConnection
-
MoneroRpcConnection
-
MoneroRpcConnection
-
-
Method Details
-
getUri
-
setUri
-
setUri
-
isOnion
public boolean isOnion() -
setCredentials
-
getUsername
-
getPassword
-
getZmqUri
-
setZmqUri
-
setProxyUri
-
getProxyUri
-
setPriority
Set the connection's priority relative to other connections. Priority 1 is highest, then priority 2, etc. The default priority of 0 is lowest priority.- Parameters:
priority
- is the connection priority (default 0)- Returns:
- this connection
-
getPriority
public int getPriority() -
setTimeout
Set the RPC request timeout in milliseconds.- Parameters:
timeoutMs
- is the timeout in milliseconds, 0 to disable timeout, or null to use default- Returns:
- this connection
-
getTimeout
-
setAttribute
-
getAttribute
-
checkConnection
public boolean checkConnection(long timeoutMs) Check the connection and update online, authentication, and response time status.- Parameters:
timeoutMs
- the maximum response time before considered offline- Returns:
- true if there is a change in status, false otherwise
-
isConnected
Indicates if the connection is connected according to the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.- Returns:
- true or false to indicate if connected, or null if checkConnection() has not been called
-
isOnline
Indicates if the connection is online according to the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.- Returns:
- true or false to indicate if online, or null if checkConnection() has not been called
-
isAuthenticated
Indicates if the connection is authenticated according to the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.- Returns:
- true if authenticated or no authentication, false if not authenticated, or null if checkConnection() has not been called
-
getResponseTime
Get the response time of the last call to checkConnection().
Note: must call checkConnection() manually unless using MoneroConnectionManager.- Returns:
- the response time of the last call to checkConnection() or null if checkConnection() has not been called
-
sendJsonRequest
Send a request to the RPC API.- Parameters:
method
- specifies the method to request- Returns:
- the RPC API response as a map
-
sendJsonRequest
Send a request to the RPC API.- Parameters:
method
- is the method to requestparams
- are the request's input parameters (supports <Map<String, Object>, List<Object></code>, String, etc)- Returns:
- the RPC API response as a map
-
sendJsonRequest
Send a request to the RPC API.- Parameters:
method
- is the method to requestparams
- are the request's input parameters (supports <Map<String, Object>, List<Object></code>, String, etc)timeoutMs
- overrides the request timeout in milliseconds- Returns:
- the RPC API response as a map
-
sendPathRequest
Send a RPC request to the given path and with the given paramters. E.g. "/get_transactions" with params- Parameters:
path
- is the url path of the request to invoke- Returns:
- the request's deserialized response
-
sendPathRequest
Send a RPC request to the given path and with the given paramters. E.g. "/get_transactions" with params- Parameters:
path
- is the url path of the request to invokeparams
- are request parameters sent in the body- Returns:
- the request's deserialized response
-
sendPathRequest
Send a RPC request to the given path and with the given paramters. E.g. "/get_transactions" with params- Parameters:
path
- is the url path of the request to invokeparams
- are request parameters sent in the bodytimeoutMs
- overrides the request timeout in milliseconds- Returns:
- the request's deserialized response
-
sendBinaryRequest
Send a binary RPC request.- Parameters:
path
- is the path of the binary RPC method to invokeparams
- are the request parameters- Returns:
- byte[] is the binary response
-
sendBinaryRequest
Send a binary RPC request.- Parameters:
path
- is the path of the binary RPC method to invokeparams
- are the request parameterstimeoutMs
- overrides the request timeout in milliseconds- Returns:
- byte[] is the binary response
-
setPrintStackTrace
public void setPrintStackTrace(boolean printStackTrace) Enable or disable printing a stack trace on each request for debug.- Parameters:
printStackTrace
- sets if the stack trace should be printed
-
toString
-
hashCode
public int hashCode() -
equals
-