transaction.h raw

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