Package monero.daemon

Class MoneroDaemonRpc

All Implemented Interfaces:
MoneroDaemon

public class MoneroDaemonRpc extends MoneroDaemonDefault
Implements a Monero daemon using monerod. TODO: every call needs to checkResponseStatus
  • Constructor Details

    • MoneroDaemonRpc

      public MoneroDaemonRpc(URI uri)
    • MoneroDaemonRpc

      public MoneroDaemonRpc(String uri)
    • MoneroDaemonRpc

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

      public MoneroDaemonRpc(MoneroRpcConnection rpc)
    • MoneroDaemonRpc

      public MoneroDaemonRpc(List<String> cmd) throws IOException
      Create an internal process running monerod and connect to it. Use `stopProcess()` to stop the newly created process.
      Parameters:
      cmd - path then arguments to external monerod executable
      Throws:
      IOException - if input/output error with process
  • Method Details

    • getProcess

      public Process getProcess()
      Get the internal process running monero-wallet-rpc.
      Returns:
      the process running monero-wallet-rpc, null if not created from new process
    • stopProcess

      public int stopProcess()
      Stop the internal process running monero-wallet-rpc, if applicable.
      Returns:
      the error code from stopping the process
    • stopProcess

      public int stopProcess(boolean force)
      Stop the internal process running monerod, if applicable.
      Parameters:
      force - specifies if the process should be destroyed forcibly
      Returns:
      the error code from stopping the process
    • addListener

      public void addListener(MoneroDaemonListener listener)
      Description copied from interface: MoneroDaemon
      Register a listener to receive daemon notifications.
      Parameters:
      listener - the listener to unregister
    • removeListener

      public void removeListener(MoneroDaemonListener listener)
      Description copied from interface: MoneroDaemon
      Unregister a listener to receive daemon notifications.
      Parameters:
      listener - a previously registered listener to be unregistered
    • getListeners

      public List<MoneroDaemonListener> getListeners()
      Description copied from interface: MoneroDaemon
      Get the listeners registered with the daemon.
      Returns:
      the registered listeners
    • getRpcConnection

      public MoneroRpcConnection getRpcConnection()
      Get the daemon's RPC connection.
      Returns:
      the daemon's rpc connection
    • setProxyUri

      public void setProxyUri(String uri)
      Set the Tor proxy to the daemon.
      Parameters:
      uri - the Tor proxy URI
    • isConnected

      public boolean isConnected()
      Indicates if the client is connected to the daemon via RPC.
      Returns:
      true if the client is connected to the daemon, false otherwise
    • getVersion

      public MoneroVersion getVersion()
      Description copied from interface: MoneroDaemon
      Gets the version of the daemon.
      Returns:
      the version of the daemon
    • isTrusted

      public boolean isTrusted()
      Description copied from interface: MoneroDaemon
      Indicates if the daemon is trusted or untrusted.
      Returns:
      true if the daemon is trusted, false otherwise
    • getHeight

      public long getHeight()
      Description copied from interface: MoneroDaemon
      Get the number of blocks in the longest chain known to the node.
      Returns:
      the number of blocks
    • getBlockHash

      public String getBlockHash(long height)
      Description copied from interface: MoneroDaemon
      Get a block's hash by its height.
      Parameters:
      height - is the height of the block hash to get
      Returns:
      the block's hash at the given height
    • getBlockTemplate

      public MoneroBlockTemplate getBlockTemplate(String walletAddress, Integer reserveSize)
      Description copied from interface: MoneroDaemon
      Get a block template for mining a new block.
      Parameters:
      walletAddress - is the address of the wallet to receive miner transactions if block is successfully mined
      reserveSize - is the reserve size (optional)
      Returns:
      a block template for mining a new block
    • getLastBlockHeader

      public MoneroBlockHeader getLastBlockHeader()
      Description copied from interface: MoneroDaemon
      Get the last block's header.
      Returns:
      the last block's header
    • getBlockHeaderByHash

      public MoneroBlockHeader getBlockHeaderByHash(String blockHash)
      Description copied from interface: MoneroDaemon
      Get a block header by its hash.
      Parameters:
      blockHash - is the hash of the block to get the header of
      Returns:
      the block's header
    • getBlockHeaderByHeight

      public MoneroBlockHeader getBlockHeaderByHeight(long height)
      Description copied from interface: MoneroDaemon
      Get a block header by its height.
      Parameters:
      height - is the height of the block to get the header of
      Returns:
      the block's header
    • getBlockHeadersByRange

      public List<MoneroBlockHeader> getBlockHeadersByRange(Long startHeight, Long endHeight)
      Description copied from interface: MoneroDaemon
      Get block headers for the given range.
      Parameters:
      startHeight - is the start height lower bound inclusive (optional)
      endHeight - is the end height upper bound inclusive (optional)
      Returns:
      block headers in the given range
    • getBlockByHash

      public MoneroBlock getBlockByHash(String blockHash)
      Description copied from interface: MoneroDaemon
      Get a block by hash.
      Parameters:
      blockHash - is the hash of the block to get
      Returns:
      the block with the given hash
    • getBlocksByHash

      public List<MoneroBlock> getBlocksByHash(List<String> blockHashes, Long startHeight, Boolean prune)
      Description copied from interface: MoneroDaemon
      Get blocks by hash.
      Parameters:
      blockHashes - are array of hashes; first 10 blocks hash goes sequential, next goes in pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block
      startHeight - is the start height to get blocks by hash
      prune - specifies if returned blocks should be pruned (defaults to false) // TODO: test default
      Returns:
      the retrieved blocks
    • getBlockByHeight

      public MoneroBlock getBlockByHeight(long height)
      Description copied from interface: MoneroDaemon
      Get a block by height.
      Parameters:
      height - is the height of the block to get
      Returns:
      the block at the given height
    • getBlocksByHeight

      public List<MoneroBlock> getBlocksByHeight(List<Long> heights)
      Description copied from interface: MoneroDaemon
      Get blocks at the given heights.
      Parameters:
      heights - are the heights of the blocks to get
      Returns:
      blocks at the given heights
    • getBlocksByRange

      public List<MoneroBlock> getBlocksByRange(Long startHeight, Long endHeight)
      Description copied from interface: MoneroDaemon
      Get blocks in the given height range.
      Parameters:
      startHeight - is the start height lower bound inclusive (optional)
      endHeight - is the end height upper bound inclusive (optional)
      Returns:
      blocks in the given height range
    • getBlocksByRangeChunked

      public List<MoneroBlock> getBlocksByRangeChunked(Long startHeight, Long endHeight, Long maxChunkSize)
      Description copied from interface: MoneroDaemon
      Get blocks in the given height range as chunked requests so that each request is not too big.
      Parameters:
      startHeight - is the start height lower bound inclusive (optional)
      endHeight - is the end height upper bound inclusive (optional)
      maxChunkSize - is the maximum chunk size in any one request (default 3,000,000 bytes)
      Returns:
      blocks in the given height range
    • getBlockHashes

      public List<String> getBlockHashes(List<String> blockHashes, Long startHeight)
      Description copied from interface: MoneroDaemon
      Get block hashes as a binary request to the daemon.
      Parameters:
      blockHashes - specify block hashes to fetch; first 10 blocks hash goes sequential, next goes in pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block
      startHeight - is the starting height of block hashes to return
      Returns:
      the requested block hashes
    • getTxs

      public List<MoneroTx> getTxs(Collection<String> txHashes, Boolean prune)
      Description copied from interface: MoneroDaemon
      Get transactions by hashes.
      Parameters:
      txHashes - are hashes of transactions to get
      prune - specifies if the returned txs should be pruned (defaults to false)
      Returns:
      found transactions with the given hashes
    • getTxHexes

      public List<String> getTxHexes(Collection<String> txHashes, Boolean prune)
      Description copied from interface: MoneroDaemon
      Get transaction hexes by hashes.
      Parameters:
      txHashes - are hashes of transactions to get hexes from
      prune - specifies if the returned tx hexes should be pruned (defaults to false)
      Returns:
      are the tx hexes
    • getMinerTxSum

      public MoneroMinerTxSum getMinerTxSum(long height, Long numBlocks)
      Description copied from interface: MoneroDaemon
      Gets the total emissions and fees from the genesis block to the current height.
      Parameters:
      height - is the height to start computing the miner sum
      numBlocks - are the number of blocks to include in the sum
      Returns:
      the sum emission and fees since the geneis block
    • getFeeEstimate

      public MoneroFeeEstimate getFeeEstimate(Integer graceBlocks)
      Description copied from interface: MoneroDaemon
      Get mining fee estimates per kB.
      Parameters:
      graceBlocks - TODO
      Returns:
      mining fee estimates per kB
    • submitTxHex

      public MoneroSubmitTxResult submitTxHex(String txHex, Boolean doNotRelay)
      Description copied from interface: MoneroDaemon
      Submits a transaction to the daemon's pool.
      Parameters:
      txHex - is the raw transaction hex to submit
      doNotRelay - specifies if the tx should be relayed (optional)
      Returns:
      the submission results
    • relayTxsByHash

      public void relayTxsByHash(Collection<String> txHashes)
      Description copied from interface: MoneroDaemon
      Relays transactions by hash.
      Parameters:
      txHashes - identify the transactions to relay
    • getTxPool

      public List<MoneroTx> getTxPool()
      Description copied from interface: MoneroDaemon
      Get valid transactions seen by the node but not yet mined into a block, as well as spent key image information for the tx pool.
      Returns:
      transactions in the transaction pool
    • getTxPoolHashes

      public List<String> getTxPoolHashes()
      Description copied from interface: MoneroDaemon
      Get hashes of transactions in the transaction pool.
      Returns:
      hashes of transactions in the transaction pool
    • getTxPoolBacklog

      public List<MoneroTxBacklogEntry> getTxPoolBacklog()
      Description copied from interface: MoneroDaemon
      Get all transaction pool backlog.
      Returns:
      transaction pool backlog entries
    • getTxPoolStats

      public MoneroTxPoolStats getTxPoolStats()
      Description copied from interface: MoneroDaemon
      Get transaction pool statistics.
      Returns:
      statistics about the transaction pool
    • flushTxPool

      public void flushTxPool()
      Description copied from interface: MoneroDaemon
      Flushes all transactions from the tx pool.
    • flushTxPool

      public void flushTxPool(String... hashes)
      Description copied from interface: MoneroDaemon
      Flush transactions from the tx pool.
      Parameters:
      hashes - are hashes of transactions to flush
    • flushTxPool

      public void flushTxPool(Collection<String> hashes)
      Description copied from interface: MoneroDaemon
      Flush transactions from the tx pool.
      Parameters:
      hashes - are hashes of transactions to flush
    • getKeyImageSpentStatuses

      public List<MoneroKeyImageSpentStatus> getKeyImageSpentStatuses(Collection<String> keyImages)
      Description copied from interface: MoneroDaemon
      Get the spent status of each given key image.
      Parameters:
      keyImages - are hex key images to get the statuses of
      Returns:
      the spent status for each key image
    • getOutputs

      public List<MoneroOutput> getOutputs(Collection<MoneroOutput> outputs)
      Description copied from interface: MoneroDaemon
      Get outputs identified by a list of output amounts and indices as a binary request.
      Parameters:
      outputs - identify each output by amount and index
      Returns:
      the identified outputs
    • getOutputHistogram

      public List<MoneroOutputHistogramEntry> getOutputHistogram(Collection<BigInteger> amounts, Integer minCount, Integer maxCount, Boolean isUnlocked, Integer recentCutoff)
      Description copied from interface: MoneroDaemon
      Get a histogram of output amounts. For all amounts (possibly filtered by parameters), gives the number of outputs on the chain for that amount. RingCT outputs counts as 0 amount.
      Parameters:
      amounts - are amounts of outputs to make the histogram with
      minCount - TODO
      maxCount - TODO
      isUnlocked - makes a histogram with outputs with the specified lock state
      recentCutoff - TODO
      Returns:
      output histogram entries meeting the parameters
    • getOutputDistribution

      public List<MoneroOutputDistributionEntry> getOutputDistribution(Collection<BigInteger> amounts, Boolean isCumulative, Long startHeight, Long endHeight)
      Description copied from interface: MoneroDaemon
      Creates an output distribution.
      Parameters:
      amounts - are amounts of outputs to make the distribution with
      isCumulative - specifies if the results should be cumulative (defaults to TODO)
      startHeight - is the start height lower bound inclusive (optional)
      endHeight - is the end height upper bound inclusive (optional)
      Returns:
      output distribution entries meeting the parameters
    • getInfo

      public MoneroDaemonInfo getInfo()
      Description copied from interface: MoneroDaemon
      Get general information about the state of the node and the network.
      Returns:
      general information about the node and network
    • getSyncInfo

      public MoneroDaemonSyncInfo getSyncInfo()
      Description copied from interface: MoneroDaemon
      Get synchronization information.
      Returns:
      contains sync information
    • getHardForkInfo

      public MoneroHardForkInfo getHardForkInfo()
      Description copied from interface: MoneroDaemon
      Look up information regarding hard fork voting and readiness.
      Returns:
      hard fork information
    • getAltChains

      public List<MoneroAltChain> getAltChains()
      Description copied from interface: MoneroDaemon
      Get alternative chains seen by the node.
      Returns:
      alternative chains seen by the node
    • getAltBlockHashes

      public List<String> getAltBlockHashes()
      Description copied from interface: MoneroDaemon
      Get known block hashes which are not on the main chain.
      Returns:
      known block hashes which are not on the main chain
    • getDownloadLimit

      public int getDownloadLimit()
      Description copied from interface: MoneroDaemon
      Get the download bandwidth limit.
      Returns:
      is the download bandwidth limit
    • setDownloadLimit

      public int setDownloadLimit(int limit)
      Description copied from interface: MoneroDaemon
      Set the download bandwidth limit.
      Parameters:
      limit - is the download limit to set (-1 to reset to default)
      Returns:
      int is the new download limit after setting
    • resetDownloadLimit

      public int resetDownloadLimit()
      Description copied from interface: MoneroDaemon
      Reset the download bandwidth limit.
      Returns:
      the download bandwidth limit after resetting
    • getUploadLimit

      public int getUploadLimit()
      Description copied from interface: MoneroDaemon
      Get the upload bandwidth limit.
      Returns:
      is the upload bandwidth limit
    • setUploadLimit

      public int setUploadLimit(int limit)
      Description copied from interface: MoneroDaemon
      Set the upload bandwidth limit.
      Parameters:
      limit - is the upload limit to set (-1 to reset to default)
      Returns:
      int is the new upload limit after setting
    • resetUploadLimit

      public int resetUploadLimit()
      Description copied from interface: MoneroDaemon
      Reset the upload bandwidth limit.
      Returns:
      the upload bandwidth limit after resetting
    • getPeers

      public List<MoneroPeer> getPeers()
      Description copied from interface: MoneroDaemon
      Get peers with active incoming or outgoing connections to the node.
      Returns:
      the daemon's peers
    • getKnownPeers

      public List<MoneroPeer> getKnownPeers()
      Description copied from interface: MoneroDaemon
      Get all known peers including their last known online status.
      Returns:
      the daemon's known peers
    • setOutgoingPeerLimit

      public void setOutgoingPeerLimit(int limit)
      Description copied from interface: MoneroDaemon
      Limit number of outgoing peers.
      Parameters:
      limit - is the maximum number of outgoing peers
    • setIncomingPeerLimit

      public void setIncomingPeerLimit(int limit)
      Description copied from interface: MoneroDaemon
      Limit number of incoming peers.
      Parameters:
      limit - is the maximum number of incoming peers
    • getPeerBans

      public List<MoneroBan> getPeerBans()
      Description copied from interface: MoneroDaemon
      Get peer bans.
      Returns:
      entries about banned peers
    • setPeerBans

      public void setPeerBans(List<MoneroBan> bans)
      Description copied from interface: MoneroDaemon
      Ban peers nodes.
      Parameters:
      bans - are bans to apply against peer nodes
    • startMining

      public void startMining(String address, Long numThreads, Boolean isBackground, Boolean ignoreBattery)
      Description copied from interface: MoneroDaemon
      Start mining.
      Parameters:
      address - is the address given miner rewards if the daemon mines a block
      numThreads - is the number of mining threads to run
      isBackground - specifies if the miner should run in the background or not
      ignoreBattery - specifies if the battery state (e.g. on laptop) should be ignored or not
    • stopMining

      public void stopMining()
      Description copied from interface: MoneroDaemon
      Stop mining.
    • getMiningStatus

      public MoneroMiningStatus getMiningStatus()
      Description copied from interface: MoneroDaemon
      Get the daemon's mining status.
      Returns:
      the daemon's mining status
    • submitBlocks

      public void submitBlocks(Collection<String> blockBlobs)
      Description copied from interface: MoneroDaemon
      Submit mined blocks to the network.
      Parameters:
      blockBlobs - are the mined blocks to submit
    • pruneBlockchain

      public MoneroPruneResult pruneBlockchain(boolean check)
      Description copied from interface: MoneroDaemon
      Prune the blockchain.
      Parameters:
      check - specifies to check the pruning (default false)
      Returns:
      the prune result
    • checkForUpdate

      public MoneroDaemonUpdateCheckResult checkForUpdate()
      Description copied from interface: MoneroDaemon
      Check for update.
      Returns:
      the result of the update check
    • downloadUpdate

      public MoneroDaemonUpdateDownloadResult downloadUpdate(String path)
      Description copied from interface: MoneroDaemon
      Download an update.
      Parameters:
      path - is the path to download the update (optional)
      Returns:
      the result of the update download
    • stop

      public void stop()
      Description copied from interface: MoneroDaemon
      Safely disconnect and shut down the daemon.
    • waitForNextBlockHeader

      public MoneroBlockHeader waitForNextBlockHeader()
      Description copied from interface: MoneroDaemon
      Get the header of the next block added to the chain.
      Returns:
      the header of the next block added to the chain