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
FieldsModifier and TypeFieldDescriptionprotected org.apache.hc.client5.http.impl.classic.CloseableHttpClientprotected Booleanprotected Booleanstatic com.fasterxml.jackson.databind.ObjectMapperprotected Stringprotected booleanprotected intprotected Stringprotected Longprotected Longprotected Stringprotected Stringprotected String -
Constructor Summary
ConstructorsConstructorDescriptionMoneroRpcConnection(String uri, String username, String password) MoneroRpcConnection(URI uri) MoneroRpcConnection(URI uri, String username, String password) MoneroRpcConnection(MoneroRpcConnection connection) -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckConnection(long timeoutMs) Check the connection and update online, authentication, and response time status.booleangetAttribute(String key) intGet the response time, which is set automatically by calling checkConnection().getUri()inthashCode()Indicates if the connection is authenticated, which is set automatically by calling checkConnection().Indicates if the connection is connected, which is set automatically by calling checkConnection().booleanisOnion()isOnline()Indicates if the connection is online, which is set automatically by calling checkConnection().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) voidsetAuthenticated(Boolean isAuthenticated) Set the connection's authentication status.setCredentials(String username, String password) voidSet the connection's online status.voidsetPrintStackTrace(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) voidsetResponseTime(Long responseTimeMs) Set the connection's response time.setTimeout(Long timeoutMs) Set the RPC request timeout in milliseconds.toString()
-
Field Details
-
MAPPER
public static com.fasterxml.jackson.databind.ObjectMapper MAPPER -
client
protected org.apache.hc.client5.http.impl.classic.CloseableHttpClient client -
uri
-
username
-
password
-
zmqUri
-
proxyUri
-
priority
protected int priority -
timeoutMs
-
isOnline
-
isAuthenticated
-
responseTime
-
printStackTrace
protected boolean printStackTrace -
attributes
-
-
Constructor Details
-
MoneroRpcConnection
-
MoneroRpcConnection
-
MoneroRpcConnection
-
MoneroRpcConnection
-
MoneroRpcConnection
-
MoneroRpcConnection
-
MoneroRpcConnection
-
-
Method Details
-
getUri
-
setUri
-
setUri
-
isOnion
public boolean isOnion() -
setCredentials
-
getUsername
-
getPassword
-
getZmqUri
-
setZmqUri
-
getProxyUri
-
setProxyUri
-
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, which is set automatically by calling checkConnection().- Returns:
- true or false to indicate if connected, or null if checkConnection() has not been called
-
isOnline
Indicates if the connection is online, which is set automatically by calling checkConnection().- Returns:
- true or false to indicate if online, or null if checkConnection() has not been called
-
setOnline
Set the connection's online status.- Parameters:
isOnline- sets if the connection is online
-
isAuthenticated
Indicates if the connection is authenticated, which is set automatically by calling checkConnection().- Returns:
- true if authenticated or no authentication, false if not authenticated, or null if not set
-
setAuthenticated
Set the connection's authentication status.- Parameters:
isAuthenticated- sets if the connection is authenticated
-
getResponseTime
Get the response time, which is set automatically by calling checkConnection().- Returns:
- the response time of this connection in milliseconds
-
setResponseTime
Set the connection's response time.- Parameters:
responseTimeMs- is the response time in milliseconds
-
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
-