Class BitcoinJSONRPCClient

  • All Implemented Interfaces:
    BitcoindRpcClient

    public class BitcoinJSONRPCClient
    extends java.lang.Object
    implements BitcoindRpcClient
    Author:
    Mikhail Yevchenko m.ṥῥẚɱ.ѓѐḿởύḙ at azazar.com Small modifications by Alessandro Polverini polverini at gmail.com
    • Field Detail

      • DEFAULT_JSONRPC_URL

        public static final java.net.URL DEFAULT_JSONRPC_URL
      • DEFAULT_JSONRPC_TESTNET_URL

        public static final java.net.URL DEFAULT_JSONRPC_TESTNET_URL
      • DEFAULT_JSONRPC_REGTEST_URL

        public static final java.net.URL DEFAULT_JSONRPC_REGTEST_URL
      • QUERY_CHARSET

        public static final java.nio.charset.Charset QUERY_CHARSET
      • CONNECT_TIMEOUT

        public static final int CONNECT_TIMEOUT
      • READ_TIMEOUT

        public static final int READ_TIMEOUT
      • rpcURL

        public final java.net.URL rpcURL
    • Constructor Detail

      • BitcoinJSONRPCClient

        public BitcoinJSONRPCClient​(java.lang.String rpcUrl)
                             throws java.net.MalformedURLException
        Throws:
        java.net.MalformedURLException
      • BitcoinJSONRPCClient

        public BitcoinJSONRPCClient​(java.net.URL rpc)
      • BitcoinJSONRPCClient

        public BitcoinJSONRPCClient​(boolean testNet)
      • BitcoinJSONRPCClient

        public BitcoinJSONRPCClient()
    • Method Detail

      • getHostnameVerifier

        public javax.net.ssl.HostnameVerifier getHostnameVerifier()
      • setHostnameVerifier

        public void setHostnameVerifier​(javax.net.ssl.HostnameVerifier hostnameVerifier)
      • getSslSocketFactory

        public javax.net.ssl.SSLSocketFactory getSslSocketFactory()
      • setSslSocketFactory

        public void setSslSocketFactory​(javax.net.ssl.SSLSocketFactory sslSocketFactory)
      • prepareRequest

        protected byte[] prepareRequest​(java.lang.String method,
                                        java.lang.Object... params)
      • prepareBatchRequest

        protected byte[] prepareBatchRequest​(java.lang.String method,
                                             java.util.List<wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient.BatchParam> paramsList)
      • loadResponse

        public java.lang.Object loadResponse​(java.io.InputStream in,
                                             java.lang.Object expectedID,
                                             boolean close)
                                      throws java.io.IOException,
                                             GenericRpcException
        Throws:
        java.io.IOException
        GenericRpcException
      • loadBatchResponse

        public java.lang.Object loadBatchResponse​(java.io.InputStream in,
                                                  java.util.List<wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient.BatchParam> batchParams,
                                                  boolean close)
                                           throws java.io.IOException,
                                                  GenericRpcException
        Throws:
        java.io.IOException
        GenericRpcException
      • batchQuery

        public java.lang.Object batchQuery​(java.lang.String method,
                                           java.util.List<wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient.BatchParam> batchParams)
                                    throws GenericRpcException
        Throws:
        GenericRpcException
      • createRawTransaction

        public java.lang.String createRawTransaction​(java.util.List<BitcoindRpcClient.TxInput> inputs,
                                                     java.util.List<BitcoindRpcClient.TxOutput> outputs)
                                              throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The createrawtransaction RPC creates an unsigned serialized transaction that spends a previous output to a new output with a P2PKH or P2SH address. The transaction is not stored in the wallet or transmitted to the network.
        Specified by:
        createRawTransaction in interface BitcoindRpcClient
        Parameters:
        inputs - An array of objects, each one to be used as an input to the transaction
        outputs - The addresses and amounts to pay
        Returns:
        The resulting unsigned raw transaction in serialized transaction format encoded as hex.
        Throws:
        GenericRpcException
        See Also:
        createrawtransaction
      • dumpPrivKey

        public java.lang.String dumpPrivKey​(java.lang.String address)
                                     throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The dumpprivkey RPC returns the wallet-import-format (WIF) private key corresponding to an address. (But does not remove it from the wallet.)
        Specified by:
        dumpPrivKey in interface BitcoindRpcClient
        Parameters:
        address - The P2PKH address corresponding to the private key you want returned.
        Throws:
        GenericRpcException
        See Also:
        dumpprivkey
      • getAccount

        public java.lang.String getAccount​(java.lang.String address)
                                    throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getaccount RPC returns the name of the account associated with the given address.
        Specified by:
        getAccount in interface BitcoindRpcClient
        Parameters:
        address - A P2PKH or P2SH Bitcoin address belonging either to a specific account or the default account
        Returns:
        The name of an account, or an empty string
        Throws:
        GenericRpcException
        See Also:
        getaccount
      • getAccountAddress

        public java.lang.String getAccountAddress​(java.lang.String account)
                                           throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getaccountaddress RPC returns the current Bitcoin address for receiving payments to this account. If the account doesn’t exist, it creates both the account and a new address for receiving payment. Once a payment has been received to an address, future calls to this RPC for the same account will return a different address.
        Specified by:
        getAccountAddress in interface BitcoindRpcClient
        Parameters:
        account - The name of an account.
        Returns:
        An address, belonging to the account specified, which has not yet received any payments
        Throws:
        GenericRpcException
        See Also:
        getaccountaddress
      • getBalance

        public java.math.BigDecimal getBalance​(java.lang.String account,
                                               int minConf)
                                        throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getbalance RPC gets the balance in decimal bitcoins across all accounts or for a particular account.
        Specified by:
        getBalance in interface BitcoindRpcClient
        Parameters:
        account - The name of an account to get the balance for.
        minConf - The minimum number of confirmations
        Throws:
        GenericRpcException
        See Also:
        getbalance
      • estimateSmartFee

        public BitcoindRpcClient.SmartFeeResult estimateSmartFee​(int blocks)
        Description copied from interface: BitcoindRpcClient
        Estimates the approximate fee per kilobyte needed for a transaction to begin confirmation within conf_target blocks if possible and return the number of blocks for which the estimate is valid. Uses virtual transaction size as defined in BIP 141 (witness data is discounted).
        Specified by:
        estimateSmartFee in interface BitcoindRpcClient
        Parameters:
        blocks - Confirmation target in blocks
        Returns:
        estimate fee rate in BTC/kB [TODO] Add to https://bitcoin.org/en/developer-reference
      • getRawBlock

        public java.lang.String getRawBlock​(java.lang.String blockHash)
                                     throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getblock RPC gets a block with a particular header hash from the local block database as a serialized block.
        Specified by:
        getRawBlock in interface BitcoindRpcClient
        Parameters:
        blockHash - The hash of the header of the block to get, encoded as hex in RPC byte order
        Throws:
        GenericRpcException
        See Also:
        getblock
      • getBlockHash

        public java.lang.String getBlockHash​(int height)
                                      throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getblockhash RPC returns the header hash of a block at the given height in the local best block chain.
        Specified by:
        getBlockHash in interface BitcoindRpcClient
        Parameters:
        height - The height of the block whose header hash should be returned.
        Returns:
        The hash of the block at the requested height, encoded as hex in RPC byte order, or JSON null if an error occurred
        Throws:
        GenericRpcException
        See Also:
        getblockhash
      • getAddedNodeInfo

        public java.util.List<BitcoindRpcClient.NodeInfo> getAddedNodeInfo​(boolean dummy,
                                                                           java.lang.String node)
                                                                    throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getaddednodeinfo RPC returns information about the given added node, or all added nodes (except onetry nodes). Only nodes which have been manually added using the addnode RPC will have their information displayed.
        Specified by:
        getAddedNodeInfo in interface BitcoindRpcClient
        Parameters:
        dummy - Removed in Bitcoin Core 0.14.0
        node - The node to get information about in the same : format as the addnode RPC.
        Returns:
        An array containing objects describing each added node.
        Throws:
        GenericRpcException
        See Also:
        getaddednodeinfo
      • getNewAddress

        public java.lang.String getNewAddress​(java.lang.String account,
                                              java.lang.String addressType)
                                       throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getnewaddress RPC returns a new Bitcoin address for receiving payments. If an account is specified, payments received with the address will be credited to that account. The address type to use. Options are "legacy", "p2sh-segwit", and "bech32".
        Specified by:
        getNewAddress in interface BitcoindRpcClient
        Throws:
        GenericRpcException
        See Also:
        getnewaddress
      • getRawMemPool

        public java.util.List<java.lang.String> getRawMemPool()
                                                       throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getrawmempool RPC returns all transaction identifiers (TXIDs) in the memory pool as a JSON array, or detailed information about each transaction in the memory pool as a JSON object.
        Specified by:
        getRawMemPool in interface BitcoindRpcClient
        Returns:
        An array of TXIDs belonging to transactions in the memory pool.
        Throws:
        GenericRpcException
        See Also:
        getrawmempool
      • getRawTransaction

        public BitcoindRpcClient.RawTransaction getRawTransaction​(java.lang.String txId)
                                                           throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getrawtransaction RPC gets a hex-encoded serialized transaction or a JSON object describing the transaction. By default, Bitcoin Core only stores complete transaction data for UTXOs and your own transactions, so the RPC may fail on historic transactions unless you use the non-default txindex=1 in your Bitcoin Core startup settings.
        Specified by:
        getRawTransaction in interface BitcoindRpcClient
        Parameters:
        txId - The TXID of the transaction to get, encoded as hex in RPC byte order
        Throws:
        GenericRpcException
        See Also:
        getrawtransaction
      • getReceivedByAddress

        public java.math.BigDecimal getReceivedByAddress​(java.lang.String address)
                                                  throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getreceivedbyaddress RPC returns the total amount received by the specified address in transactions with the specified number of confirmations. It does not count coinbase transactions.
        Specified by:
        getReceivedByAddress in interface BitcoindRpcClient
        Parameters:
        address - The address whose transactions should be tallied
        Returns:
        The number of bitcoins received by the address
        Throws:
        GenericRpcException
        See Also:
        getreceivedbyaddress
      • getReceivedByAddress

        public java.math.BigDecimal getReceivedByAddress​(java.lang.String address,
                                                         int minConf)
                                                  throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getreceivedbyaddress RPC returns the total amount received by the specified address in transactions with the specified number of confirmations. It does not count coinbase transactions.
        Specified by:
        getReceivedByAddress in interface BitcoindRpcClient
        Parameters:
        address - The address whose transactions should be tallied
        minConf - The minimum number of confirmations
        Returns:
        The number of bitcoins received by the address
        Throws:
        GenericRpcException
        See Also:
        getreceivedbyaddress
      • importPrivKey

        public void importPrivKey​(java.lang.String bitcoinPrivKey)
                           throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The importprivkey RPC adds a private key to your wallet. The key should be formatted in the wallet import format created by the dumpprivkey RPC.
        Specified by:
        importPrivKey in interface BitcoindRpcClient
        Parameters:
        bitcoinPrivKey - The private key to import into the wallet encoded in base58check using wallet import format (WIF)
        Throws:
        GenericRpcException
        See Also:
        importprivkey
      • importPrivKey

        public void importPrivKey​(java.lang.String bitcoinPrivKey,
                                  java.lang.String label)
                           throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The importprivkey RPC adds a private key to your wallet. The key should be formatted in the wallet import format created by the dumpprivkey RPC.
        Specified by:
        importPrivKey in interface BitcoindRpcClient
        Parameters:
        bitcoinPrivKey - The private key to import into the wallet encoded in base58check using wallet import format (WIF)
        label - The name of an account to which transactions involving the key should be assigned.
        Throws:
        GenericRpcException
        See Also:
        importprivkey
      • importPrivKey

        public void importPrivKey​(java.lang.String bitcoinPrivKey,
                                  java.lang.String label,
                                  boolean rescan)
                           throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The importprivkey RPC adds a private key to your wallet. The key should be formatted in the wallet import format created by the dumpprivkey RPC.
        Specified by:
        importPrivKey in interface BitcoindRpcClient
        Parameters:
        bitcoinPrivKey - The private key to import into the wallet encoded in base58check using wallet import format (WIF)
        label - The name of an account to which transactions involving the key should be assigned.
        rescan - Set to true (the default) to rescan the entire local block database for transactions affecting any address or pubkey script in the wallet.
        Throws:
        GenericRpcException
        See Also:
        importprivkey
      • importAddress

        public java.lang.Object importAddress​(java.lang.String address,
                                              java.lang.String label,
                                              boolean rescan)
                                       throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The importaddress RPC adds an address or pubkey script to the wallet without the associated private key, allowing you to watch for transactions affecting that address or pubkey script without being able to spend any of its outputs.
        Specified by:
        importAddress in interface BitcoindRpcClient
        Parameters:
        address - Either a P2PKH or P2SH address encoded in base58check, or a pubkey script encoded as hex
        label - An account name into which the address should be placed.
        rescan - Set to true (the default) to rescan the entire local block database
        Returns:
        Null on success
        Throws:
        GenericRpcException
        See Also:
        importaddress [TODO] Should this really return Object?
      • listAccounts

        public java.util.Map<java.lang.String,​java.lang.Number> listAccounts​(int minConf)
                                                                            throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The listaccounts RPC lists accounts and their balances.
        Specified by:
        listAccounts in interface BitcoindRpcClient
        Parameters:
        minConf - The minimum number of confirmations an externally-generated transaction must have before it is counted towards the balance.
        Returns:
        Map that has account names as keys, account balances as values
        Throws:
        GenericRpcException
        See Also:
        listaccounts
      • listAccounts

        public java.util.Map<java.lang.String,​java.lang.Number> listAccounts​(int minConf,
                                                                                   boolean watchonly)
                                                                            throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The listaccounts RPC lists accounts and their balances.
        Specified by:
        listAccounts in interface BitcoindRpcClient
        Parameters:
        minConf - The minimum number of confirmations an externally-generated transaction must have before it is counted towards the balance.
        watchonly - Include balances in watch-only addresses.
        Returns:
        Map that has account names as keys, account balances as values
        Throws:
        GenericRpcException
        See Also:
        listaccounts
      • listReceivedByAddress

        public java.util.List<BitcoindRpcClient.ReceivedAddress> listReceivedByAddress​(int minConf,
                                                                                       boolean includeEmpty)
                                                                                throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The listreceivedbyaddress RPC lists the total number of bitcoins received by each address.
        Specified by:
        listReceivedByAddress in interface BitcoindRpcClient
        Parameters:
        minConf - The minimum number of confirmations an externally-generated transaction must have before it is counted towards the balance.
        includeEmpty - Set to true to display accounts which have never received a payment.
        Returns:
        An array containing objects each describing a particular address
        Throws:
        GenericRpcException
        See Also:
        listreceivedbyaddress
      • listSinceBlock

        public BitcoindRpcClient.TransactionsSinceBlock listSinceBlock​(java.lang.String blockHash,
                                                                       int targetConfirmations)
                                                                throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The listsinceblock RPC gets all transactions affecting the wallet which have occurred since a particular block, plus the header hash of a block at a particular depth.
        Specified by:
        listSinceBlock in interface BitcoindRpcClient
        Parameters:
        blockHash - The hash of a block header encoded as hex in RPC byte order.
        targetConfirmations - Sets the lastblock field of the results to the header hash of a block with this many confirmations.
        Returns:
        An object containing an array of transactions and the lastblock field
        Throws:
        GenericRpcException
        See Also:
        listsinceblock
      • listSinceBlock

        public BitcoindRpcClient.TransactionsSinceBlock listSinceBlock​(java.lang.String blockHash,
                                                                       int targetConfirmations,
                                                                       boolean includeWatchOnly)
                                                                throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The listsinceblock RPC gets all transactions affecting the wallet which have occurred since a particular block, plus the header hash of a block at a particular depth.
        Specified by:
        listSinceBlock in interface BitcoindRpcClient
        Parameters:
        blockHash - The hash of a block header encoded as hex in RPC byte order.
        targetConfirmations - Sets the lastblock field of the results to the header hash of a block with this many confirmations.
        includeWatchOnly - Include transactions to watch-only addresses
        Returns:
        An object containing an array of transactions and the lastblock field
        Throws:
        GenericRpcException
        See Also:
        listsinceblock, Bitcoin Core Documentation for listsinceblock
      • listTransactions

        public java.util.List<BitcoindRpcClient.Transaction> listTransactions​(java.lang.String account,
                                                                              int count)
                                                                       throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The listtransactions RPC returns the most recent transactions that affect the wallet.
        Specified by:
        listTransactions in interface BitcoindRpcClient
        Parameters:
        account - The name of an account to get transactinos from (deprecated).
        count - The number of the most recent transactions to list.
        Returns:
        An array containing objects, with each object describing a payment or internal accounting entry (not a transaction).
        Throws:
        GenericRpcException
        See Also:
        listtransactions
      • listTransactions

        public java.util.List<BitcoindRpcClient.Transaction> listTransactions​(java.lang.String account,
                                                                              int count,
                                                                              int skip)
                                                                       throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The listtransactions RPC returns the most recent transactions that affect the wallet.
        Specified by:
        listTransactions in interface BitcoindRpcClient
        Parameters:
        account - The name of an account to get transactinos from (deprecated).
        count - The number of the most recent transactions to list.
        skip - The number of the most recent transactions which should not be returned.
        Returns:
        An array containing objects, with each object describing a payment or internal accounting entry (not a transaction).
        Throws:
        GenericRpcException
        See Also:
        listtransactions
      • listUnspent

        public java.util.List<BitcoindRpcClient.Unspent> listUnspent​(int minConf,
                                                                     int maxConf)
                                                              throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The listunspent RPC returns an array of unspent transaction outputs belonging to this wallet.
        Specified by:
        listUnspent in interface BitcoindRpcClient
        Parameters:
        minConf - The minimum number of confirmations the transaction containing an output must have in order to be returned.
        maxConf - The maximum number of confirmations the transaction containing an output may have in order to be returned.
        Returns:
        An array of objects each describing an unspent output.
        Throws:
        GenericRpcException
        See Also:
        listunspent
      • listUnspent

        public java.util.List<BitcoindRpcClient.Unspent> listUnspent​(int minConf,
                                                                     int maxConf,
                                                                     java.lang.String... addresses)
                                                              throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The listunspent RPC returns an array of unspent transaction outputs belonging to this wallet.
        Specified by:
        listUnspent in interface BitcoindRpcClient
        Parameters:
        minConf - The minimum number of confirmations the transaction containing an output must have in order to be returned.
        maxConf - The maximum number of confirmations the transaction containing an output may have in order to be returned.
        addresses - Only outputs which pay an address in this array will be returned
        Returns:
        An array of objects each describing an unspent output.
        Throws:
        GenericRpcException
        See Also:
        listunspent
      • lockUnspent

        public boolean lockUnspent​(boolean unlock,
                                   java.lang.String txid,
                                   int vout)
                            throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The lockunspent RPC temporarily locks or unlocks specified transaction outputs. A locked transaction output will not be chosen by automatic coin selection when spending bitcoins.
        Specified by:
        lockUnspent in interface BitcoindRpcClient
        Parameters:
        unlock - Set to false to lock the outputs specified in the following parameter. Set to true to unlock the outputs specified.
        txid - The TXID of the transaction containing the output to lock or unlock, encoded as hex.
        vout - The output index number (vout) of the output to lock or unlock.
        Returns:
        true if successful.
        Throws:
        GenericRpcException
        See Also:
        lockunspent
      • move

        public boolean move​(java.lang.String fromAccount,
                            java.lang.String toAddress,
                            java.math.BigDecimal amount)
                     throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The move RPC moves a specified amount from one account in your wallet to another using an off-block-chain transaction.
        Specified by:
        move in interface BitcoindRpcClient
        Parameters:
        fromAccount - The name of the account to move the funds from
        toAddress - The name of the account to move the funds to
        amount - The amount of bitcoins to move
        Throws:
        GenericRpcException
        See Also:
        move
      • move

        public boolean move​(java.lang.String fromAccount,
                            java.lang.String toAddress,
                            java.math.BigDecimal amount,
                            java.lang.String comment)
                     throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The move RPC moves a specified amount from one account in your wallet to another using an off-block-chain transaction.
        Specified by:
        move in interface BitcoindRpcClient
        Parameters:
        fromAccount - The name of the account to move the funds from
        toAddress - The name of the account to move the funds to
        amount - The amount of bitcoins to move
        comment - A comment to assign to this move payment
        Throws:
        GenericRpcException
        See Also:
        move
      • sendFrom

        public java.lang.String sendFrom​(java.lang.String fromAccount,
                                         java.lang.String toAddress,
                                         java.math.BigDecimal amount)
                                  throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The sendfrom RPC spends an amount from a local account to a bitcoin address.
        Specified by:
        sendFrom in interface BitcoindRpcClient
        Parameters:
        fromAccount - The name of the account from which the bitcoins should be spent.
        toAddress - A P2PKH or P2SH address to which the bitcoins should be sent
        amount - The amount to spend in bitcoins.
        Returns:
        The TXID of the sent transaction, encoded as hex in RPC byte order
        Throws:
        GenericRpcException
        See Also:
        sendfrom
      • sendFrom

        public java.lang.String sendFrom​(java.lang.String fromAccount,
                                         java.lang.String toAddress,
                                         java.math.BigDecimal amount,
                                         int minConf)
                                  throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The sendfrom RPC spends an amount from a local account to a bitcoin address.
        Specified by:
        sendFrom in interface BitcoindRpcClient
        Parameters:
        fromAccount - The name of the account from which the bitcoins should be spent.
        toAddress - A P2PKH or P2SH address to which the bitcoins should be sent
        amount - The amount to spend in bitcoins.
        minConf - The minimum number of confirmations an incoming transaction must have for its outputs to be credited to this account’s balance.
        Returns:
        The TXID of the sent transaction, encoded as hex in RPC byte order
        Throws:
        GenericRpcException
        See Also:
        sendfrom
      • sendFrom

        public java.lang.String sendFrom​(java.lang.String fromAccount,
                                         java.lang.String toAddress,
                                         java.math.BigDecimal amount,
                                         int minConf,
                                         java.lang.String comment)
                                  throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The sendfrom RPC spends an amount from a local account to a bitcoin address.
        Specified by:
        sendFrom in interface BitcoindRpcClient
        Parameters:
        fromAccount - The name of the account from which the bitcoins should be spent.
        toAddress - A P2PKH or P2SH address to which the bitcoins should be sent
        amount - The amount to spend in bitcoins.
        minConf - The minimum number of confirmations an incoming transaction must have for its outputs to be credited to this account’s balance.
        comment - A locally-stored (not broadcast) comment assigned to this transaction.
        Returns:
        The TXID of the sent transaction, encoded as hex in RPC byte order
        Throws:
        GenericRpcException
        See Also:
        sendfrom
      • sendFrom

        public java.lang.String sendFrom​(java.lang.String fromAccount,
                                         java.lang.String toAddress,
                                         java.math.BigDecimal amount,
                                         int minConf,
                                         java.lang.String comment,
                                         java.lang.String commentTo)
                                  throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The sendfrom RPC spends an amount from a local account to a bitcoin address.
        Specified by:
        sendFrom in interface BitcoindRpcClient
        Parameters:
        fromAccount - The name of the account from which the bitcoins should be spent.
        toAddress - A P2PKH or P2SH address to which the bitcoins should be sent
        amount - The amount to spend in bitcoins.
        minConf - The minimum number of confirmations an incoming transaction must have for its outputs to be credited to this account’s balance.
        comment - A locally-stored (not broadcast) comment assigned to this transaction.
        commentTo - A locally-stored (not broadcast) comment assigned to this transaction
        Returns:
        The TXID of the sent transaction, encoded as hex in RPC byte order
        Throws:
        GenericRpcException
        See Also:
        sendfrom
      • sendRawTransaction

        public java.lang.String sendRawTransaction​(java.lang.String hex)
                                            throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The sendrawtransaction RPC validates a transaction and broadcasts it to the peer-to-peer network.
        Specified by:
        sendRawTransaction in interface BitcoindRpcClient
        Parameters:
        hex - The serialized transaction to broadcast encoded as hex
        Returns:
        If the transaction was accepted by the node for broadcast, this will be the TXID of the transaction encoded as hex in RPC byte order.
        Throws:
        GenericRpcException
        See Also:
        sendrawtransaction
      • sendToAddress

        public java.lang.String sendToAddress​(java.lang.String toAddress,
                                              java.math.BigDecimal amount)
                                       throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The sendtoaddress RPC spends an amount to a given address.
        Specified by:
        sendToAddress in interface BitcoindRpcClient
        Parameters:
        toAddress - A P2PKH or P2SH address to which the bitcoins should be sent
        amount - The amount to spent in bitcoins
        Returns:
        The TXID of the sent transaction, encoded as hex in RPC byte order
        Throws:
        GenericRpcException
        See Also:
        sendtoaddress
      • sendToAddress

        public java.lang.String sendToAddress​(java.lang.String toAddress,
                                              java.math.BigDecimal amount,
                                              java.lang.String comment)
                                       throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The sendtoaddress RPC spends an amount to a given address.
        Specified by:
        sendToAddress in interface BitcoindRpcClient
        Parameters:
        toAddress - A P2PKH or P2SH address to which the bitcoins should be sent
        amount - The amount to spent in bitcoins
        comment - A locally-stored (not broadcast) comment assigned to this transaction.
        Returns:
        The TXID of the sent transaction, encoded as hex in RPC byte order
        Throws:
        GenericRpcException
        See Also:
        sendtoaddress
      • sendToAddress

        public java.lang.String sendToAddress​(java.lang.String toAddress,
                                              java.math.BigDecimal amount,
                                              java.lang.String comment,
                                              java.lang.String commentTo)
                                       throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The sendtoaddress RPC spends an amount to a given address.
        Specified by:
        sendToAddress in interface BitcoindRpcClient
        Parameters:
        toAddress - A P2PKH or P2SH address to which the bitcoins should be sent
        amount - The amount to spent in bitcoins
        comment - A locally-stored (not broadcast) comment assigned to this transaction.
        commentTo - A locally-stored (not broadcast) comment assigned to this transaction
        Returns:
        The TXID of the sent transaction, encoded as hex in RPC byte order
        Throws:
        GenericRpcException
        See Also:
        sendtoaddress
      • signRawTransaction

        @Deprecated
        public java.lang.String signRawTransaction​(java.lang.String hex,
                                                   java.util.List<? extends BitcoindRpcClient.TxInput> inputs,
                                                   java.util.List<java.lang.String> privateKeys)
                                            throws GenericRpcException
        Deprecated.
        Description copied from interface: BitcoindRpcClient
        The signrawtransaction RPC signs a transaction in the serialized transaction format using private keys stored in the wallet or provided in the call.
        Specified by:
        signRawTransaction in interface BitcoindRpcClient
        Parameters:
        hex - The transaction to sign as a serialized transaction
        inputs - The previous outputs being spent by this transaction
        privateKeys - An array holding private keys.
        Returns:
        The results of the signature
        Throws:
        GenericRpcException
        See Also:
        signrawtransaction
      • signRawTransaction

        @Deprecated
        public java.lang.String signRawTransaction​(java.lang.String hex,
                                                   java.util.List<? extends BitcoindRpcClient.TxInput> inputs,
                                                   java.util.List<java.lang.String> privateKeys,
                                                   java.lang.String sigHashType)
        Deprecated.
      • generate

        @Deprecated
        public java.util.List<java.lang.String> generate​(int numBlocks)
                                                  throws BitcoinRPCException
        Deprecated.
        Description copied from interface: BitcoindRpcClient
        The generate RPC nearly instantly generates blocks.
        Specified by:
        generate in interface BitcoindRpcClient
        Parameters:
        numBlocks - The number of blocks to generate.
        Returns:
        An array containing the block header hashes of the generated blocks
        Throws:
        BitcoinRPCException
        See Also:
        generate
      • generate

        @Deprecated
        public java.util.List<java.lang.String> generate​(int numBlocks,
                                                         long maxTries)
                                                  throws BitcoinRPCException
        Deprecated.
        Description copied from interface: BitcoindRpcClient
        The generate RPC nearly instantly generates blocks.
        Specified by:
        generate in interface BitcoindRpcClient
        Parameters:
        numBlocks - The number of blocks to generate.
        maxTries - The maximum number of iterations that are tried to create the requested number of blocks.
        Returns:
        An array containing the block header hashes of the generated blocks
        Throws:
        BitcoinRPCException
        See Also:
        generate
      • generateToAddress

        public java.util.List<java.lang.String> generateToAddress​(int numBlocks,
                                                                  java.lang.String address,
                                                                  long maxTries)
                                                           throws BitcoinRPCException
        Description copied from interface: BitcoindRpcClient
        The generatetoaddress RPC mines blocks immediately to a specified address.
        Specified by:
        generateToAddress in interface BitcoindRpcClient
        Parameters:
        numBlocks - The number of blocks to generate.
        address - The address to send the newly generated Bitcoin to
        maxTries - The maximum number of iterations that are tried to create the requested number of blocks.
        Throws:
        BitcoinRPCException
        See Also:
        generatetoaddress
      • estimateFee

        public java.math.BigDecimal estimateFee​(int nBlocks)
                                         throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The estimatefee RPC estimates the transaction fee per kilobyte that needs to be paid for a transaction to be included within a certain number of blocks.
        Specified by:
        estimateFee in interface BitcoindRpcClient
        Parameters:
        nBlocks - The maximum number of blocks a transaction should have to wait before it is predicted to be included in a block.
        Returns:
        The estimated fee the transaction should pay in order to be included within the specified number of blocks.
        Throws:
        GenericRpcException
        See Also:
        estimatefee
      • invalidateBlock

        public void invalidateBlock​(java.lang.String hash)
                             throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        Permanently marks a block as invalid, as if it violated a consensus rule.
        Specified by:
        invalidateBlock in interface BitcoindRpcClient
        Parameters:
        hash - the hash of the block to mark as invalid [TODO] Add to https://bitcoin.org/en/developer-reference
        Throws:
        GenericRpcException
      • reconsiderBlock

        public void reconsiderBlock​(java.lang.String hash)
                             throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        Removes invalidity status of a block and its descendants, reconsider them for activation. This can be used to undo the effects of invalidateblock.
        Specified by:
        reconsiderBlock in interface BitcoindRpcClient
        Parameters:
        hash - The hash of the block to reconsider [TODO] Add to https://bitcoin.org/en/developer-reference
        Throws:
        GenericRpcException
      • getNetworkHashPs

        public java.math.BigDecimal getNetworkHashPs()
                                              throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getnetworkhashps RPC returns the estimated current or historical network hashes per second based on the last n blocks.
        Specified by:
        getNetworkHashPs in interface BitcoindRpcClient
        Returns:
        The estimated number of hashes per second based on the parameters provided.
        Throws:
        GenericRpcException
        See Also:
        getgenerate [TODO] Add parameters blocks, height
      • setTxFee

        public boolean setTxFee​(java.math.BigDecimal amount)
                         throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The settxfee RPC sets the transaction fee per kilobyte paid by transactions created by this wallet.
        Specified by:
        setTxFee in interface BitcoindRpcClient
        Parameters:
        amount - The transaction fee to pay, in bitcoins, for each kilobyte of transaction data.
        Throws:
        GenericRpcException
        See Also:
        settxfee
      • addNode

        public void addNode​(java.lang.String node,
                            java.lang.String command)
                     throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The addnode RPC attempts to add or remove a node from the addnode list, or to try a connection to a node once.
        Specified by:
        addNode in interface BitcoindRpcClient
        Parameters:
        node - example: "192.168.0.6:8333"
        command - must be either "add", "remove" or "onetry"
        Throws:
        GenericRpcException
        See Also:
        addnode
      • signMessage

        public java.lang.String signMessage​(java.lang.String bitcoinAdress,
                                            java.lang.String message)
                                     throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The signmessage RPC signs a message with the private key of an address.
        Specified by:
        signMessage in interface BitcoindRpcClient
        Parameters:
        bitcoinAdress - A P2PKH address whose private key belongs to this wallet
        message - The message to sign
        Returns:
        The signature of the message, encoded in base64.
        Throws:
        GenericRpcException
        See Also:
        signmessage
      • importWallet

        public void importWallet​(java.lang.String filename)
                          throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The importwallet RPC imports private keys from a file in wallet dump file format (see the dumpwallet RPC). These keys will be added to the keys currently in the wallet.
        Specified by:
        importWallet in interface BitcoindRpcClient
        Parameters:
        filename - The file to import. The path is relative to Bitcoin Core’s working directory
        Throws:
        GenericRpcException
        See Also:
        importwallet
      • getReceivedByAccount

        public java.math.BigDecimal getReceivedByAccount​(java.lang.String account)
                                                  throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The getreceivedbyaccount RPC returns the total amount received by addresses in a particular account from transactions with the specified number of confirmations.
        Specified by:
        getReceivedByAccount in interface BitcoindRpcClient
        Parameters:
        account - The name of the account containing the addresses to get.
        Returns:
        The number of bitcoins received by the account.
        Throws:
        GenericRpcException
        See Also:
        getreceivedbyaccount
      • encryptWallet

        public void encryptWallet​(java.lang.String passPhrase)
                           throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The encryptwallet RPC encrypts the wallet with a passphrase. This is only to enable encryption for the first time. After encryption is enabled, you will need to enter the passphrase to use private keys.
        Specified by:
        encryptWallet in interface BitcoindRpcClient
        Parameters:
        passPhrase - The passphrase to use for the encrypted wallet.
        Throws:
        GenericRpcException
        See Also:
        encryptwallet
      • walletPassPhrase

        public void walletPassPhrase​(java.lang.String passPhrase,
                                     long timeOut)
                              throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The walletpassphrase RPC stores the wallet decryption key in memory for the indicated number of seconds. Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock time that overrides the old one.
        Specified by:
        walletPassPhrase in interface BitcoindRpcClient
        Parameters:
        passPhrase - The passphrase that unlocks the wallet
        timeOut - The number of seconds after which the decryption key will be automatically deleted from memory
        Throws:
        GenericRpcException
        See Also:
        walletpassphrase
      • verifyMessage

        public boolean verifyMessage​(java.lang.String bitcoinAddress,
                                     java.lang.String signature,
                                     java.lang.String message)
                              throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The verifymessage RPC verifies a signed message.
        Specified by:
        verifyMessage in interface BitcoindRpcClient
        Parameters:
        bitcoinAddress - The P2PKH address corresponding to the private key which made the signature.
        signature - The signature created by the signer encoded as base-64 (the format output by the signmessage RPC)
        message - The message exactly as it was signed
        Throws:
        GenericRpcException
        See Also:
        verifymessage
      • addMultiSigAddress

        public BitcoindRpcClient.MultiSig addMultiSigAddress​(int nRequired,
                                                             java.util.List<java.lang.String> keyObject,
                                                             java.lang.String account)
                                                      throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The addmultisigaddress RPC adds a P2SH multisig address to the wallet.
        Specified by:
        addMultiSigAddress in interface BitcoindRpcClient
        Parameters:
        nRequired - The minimum (m) number of signatures required to spend this m-of-n multisig script
        keyObject - An array of strings with each string being a public key or address
        account - The account name in which the address should be stored.
        Returns:
        The P2SH multisig address.
        Throws:
        GenericRpcException
        See Also:
        addmultisigaddress
      • verifyChain

        public boolean verifyChain()
        Description copied from interface: BitcoindRpcClient
        The verifychain RPC verifies each entry in the local block chain database.
        Specified by:
        verifyChain in interface BitcoindRpcClient
        See Also:
        verifychain [TODO] Add parameters checkLevel, numOfBlocks
      • verifyChain

        public boolean verifyChain​(int checklevel,
                                   int numblocks)
      • submitBlock

        public void submitBlock​(java.lang.String hexData)
        Attempts to submit new block to network. The 'jsonparametersobject' parameter is currently ignored, therefore left out.
        Specified by:
        submitBlock in interface BitcoindRpcClient
        Parameters:
        hexData -
        See Also:
        submitblock
      • getTxOut

        public BitcoindRpcClient.TxOut getTxOut​(java.lang.String txId,
                                                long vout)
                                         throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The gettxout RPC returns details about an unspent transaction output (UTXO).
        Specified by:
        getTxOut in interface BitcoindRpcClient
        Parameters:
        txId - The TXID of the transaction containing the output to get, encoded as hex in RPC byte order
        vout - The output index number (vout) of the output within the transaction
        Returns:
        Information about the output.
        Throws:
        GenericRpcException
        See Also:
        gettxout
      • scanTxOutSet

        public BitcoindRpcClient.UtxoSet scanTxOutSet​(java.util.List<BitcoindRpcClient.ScanObject> scanObjects)
                                               throws GenericRpcException
        Description copied from interface: BitcoindRpcClient
        The scantxoutset RPC scans the unspent transaction output set for entries that match certain output descriptors.

        Examples of output descriptors are:

        • addr(<address>}) Outputs whose scriptPubKey corresponds to the specified address (does not include P2PK)
        • raw(<hex script>) Outputs whose scriptPubKey equals the specified hex scripts
        • combo(<pubkey>) P2PK, P2PKH, P2WPKH, and P2SH-P2WPKH outputs for the given pubkey
        • pkh(<pubkey>) P2PKH outputs for the given pubkey
        • sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys
        In the above, either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one or more path elements separated by "/", and optionally ending in "/*" (unhardened), or "/*'" or "/*h" (hardened) to specify all unhardened or hardened child keys. In the latter case, a range needs to be specified by below if different from 1000. For more information on output descriptors, see the documentation in the doc/descriptors.md file.
        Specified by:
        scanTxOutSet in interface BitcoindRpcClient
        Parameters:
        scanObjects - Output descriptors
        Returns:
        Throws:
        GenericRpcException
        See Also:
        scantxoutset