transaction.h raw

   1  // Copyright (c) 2017-present The Bitcoin Core developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #ifndef BITCOIN_NODE_TRANSACTION_H
   6  #define BITCOIN_NODE_TRANSACTION_H
   7  
   8  #include <common/messages.h>
   9  #include <node/types.h>
  10  #include <policy/feerate.h>
  11  #include <primitives/transaction.h>
  12  
  13  class CBlockIndex;
  14  class CTxMemPool;
  15  namespace Consensus {
  16  struct Params;
  17  }
  18  
  19  namespace node {
  20  class BlockManager;
  21  struct NodeContext;
  22  
  23  /** Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
  24   * Also used by the GUI when broadcasting a completed PSBT.
  25   * By default, a transaction with a fee rate higher than this will be rejected
  26   * by these RPCs and the GUI. This can be overridden with the maxfeerate argument.
  27   */
  28  static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
  29  
  30  /** Maximum burn value for sendrawtransaction, submitpackage, and testmempoolaccept RPC calls.
  31   * By default, a transaction with a burn value higher than this will be rejected
  32   * by these RPCs and the GUI. This can be overridden with the maxburnamount argument.
  33   */
  34  static const CAmount DEFAULT_MAX_BURN_AMOUNT{0};
  35  
  36  /**
  37   * Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
  38   *
  39   * Mempool submission can be synchronous (will await mempool entry notification
  40   * over the CValidationInterface) or asynchronous (will submit and not wait for
  41   * notification), depending on the value of wait_callback. wait_callback MUST
  42   * NOT be set while cs_main, cs_mempool or cs_wallet are held to avoid
  43   * deadlock.
  44   *
  45   * @param[in]  node reference to node context
  46   * @param[in]  tx the transaction to broadcast
  47   * @param[out] err_string reference to std::string to fill with error string if available
  48   * @param[in]  max_tx_fee reject txs with fees higher than this (if 0, accept any fee)
  49   * @param[in]  broadcast_method whether to add the transaction to the mempool and how to broadcast it
  50   * @param[in]  wait_callback wait until callbacks have been processed to avoid stale result due to a sequentially RPC.
  51   * return error
  52   */
  53  [[nodiscard]] TransactionError BroadcastTransaction(NodeContext& node,
  54                                                      CTransactionRef tx,
  55                                                      std::string& err_string,
  56                                                      const CAmount& max_tx_fee,
  57                                                      TxBroadcast broadcast_method,
  58                                                      bool wait_callback);
  59  
  60  /**
  61   * Return transaction with a given hash.
  62   * If mempool is provided and block_index is not provided, check it first for the tx.
  63   * If -txindex is available, check it next for the tx.
  64   * Finally, if block_index is provided, check for tx by reading entire block from disk.
  65   *
  66   * @param[in]  block_index     The block to read from disk, or nullptr
  67   * @param[in]  mempool         If provided, check mempool for tx
  68   * @param[in]  hash            The txid
  69   * @param[in]  blockman        Used to access and read blocks from disk
  70   * @param[out] hashBlock       The block hash, if the tx was found via -txindex or block_index
  71   * @returns                    The tx if found, otherwise nullptr
  72   */
  73  CTransactionRef GetTransaction(const CBlockIndex* block_index, const CTxMemPool* mempool, const Txid& hash, const BlockManager& blockman, uint256& hashBlock);
  74  } // namespace node
  75  
  76  #endif // BITCOIN_NODE_TRANSACTION_H
  77