Package monero.common

Class MoneroRpcConnection

java.lang.Object
monero.common.MoneroRpcConnection

public class MoneroRpcConnection extends Object
Maintains a connection and sends requests to a Monero RPC API. TODO: refactor MoneroRpcConnection extends MoneroConnection?
  • Field Details

    • MAPPER

      public static com.fasterxml.jackson.databind.ObjectMapper MAPPER
  • Constructor Details

    • MoneroRpcConnection

      public MoneroRpcConnection(URI uri)
    • MoneroRpcConnection

      public MoneroRpcConnection(String uri)
    • MoneroRpcConnection

      public MoneroRpcConnection(String uri, String username, String password)
    • MoneroRpcConnection

      public MoneroRpcConnection(String uri, String username, String password, String zmqUri)
    • MoneroRpcConnection

      public MoneroRpcConnection(URI uri, String username, String password)
    • MoneroRpcConnection

      public MoneroRpcConnection(URI uri, String username, String password, URI zmqUri)
    • MoneroRpcConnection

      public MoneroRpcConnection(MoneroRpcConnection connection)
  • Method Details

    • getUri

      public String getUri()
    • setUri

      public MoneroRpcConnection setUri(String uri)
    • setUri

      public MoneroRpcConnection setUri(URI uri)
    • isOnion

      public boolean isOnion()
    • setCredentials

      public MoneroRpcConnection setCredentials(String username, String password)
    • getUsername

      public String getUsername()
    • getPassword

      public String getPassword()
    • getZmqUri

      public String getZmqUri()
    • setZmqUri

      public MoneroRpcConnection setZmqUri(String zmqUri)
    • setProxyUri

      public MoneroRpcConnection setProxyUri(String proxyUri)
    • getProxyUri

      public String getProxyUri()
    • setPriority

      public MoneroRpcConnection setPriority(int priority)
      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

      public MoneroRpcConnection setTimeout(Long timeoutMs)
      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

      public Long getTimeout()
    • setAttribute

      public MoneroRpcConnection setAttribute(String key, Object value)
    • getAttribute

      public Object getAttribute(String key)
    • 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

      public Boolean 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

      public Boolean 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

      public Boolean 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

      public Long 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

      public Map<String,Object> sendJsonRequest(String method)
      Send a request to the RPC API.
      Parameters:
      method - specifies the method to request
      Returns:
      the RPC API response as a map
    • sendJsonRequest

      public Map<String,Object> sendJsonRequest(String method, Object params)
      Send a request to the RPC API.
      Parameters:
      method - is the method to request
      params - are the request's input parameters (supports <Map<String, Object>, List<Object></code>, String, etc)
      Returns:
      the RPC API response as a map
    • sendJsonRequest

      public Map<String,Object> sendJsonRequest(String method, Object params, Long timeoutMs)
      Send a request to the RPC API.
      Parameters:
      method - is the method to request
      params - 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

      public Map<String,Object> sendPathRequest(String path)
      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

      public Map<String,Object> sendPathRequest(String path, Map<String,Object> params)
      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
      params - are request parameters sent in the body
      Returns:
      the request's deserialized response
    • sendPathRequest

      public Map<String,Object> sendPathRequest(String path, Map<String,Object> params, Long timeoutMs)
      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
      params - are request parameters sent in the body
      timeoutMs - overrides the request timeout in milliseconds
      Returns:
      the request's deserialized response
    • sendBinaryRequest

      public byte[] sendBinaryRequest(String path, Map<String,Object> params)
      Send a binary RPC request.
      Parameters:
      path - is the path of the binary RPC method to invoke
      params - are the request parameters
      Returns:
      byte[] is the binary response
    • sendBinaryRequest

      public byte[] sendBinaryRequest(String path, Map<String,Object> params, Long timeoutMs)
      Send a binary RPC request.
      Parameters:
      path - is the path of the binary RPC method to invoke
      params - are the request parameters
      timeoutMs - 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

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object