rawtransaction_util.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_RPC_RAWTRANSACTION_UTIL_H
   6  #define BITCOIN_RPC_RAWTRANSACTION_UTIL_H
   7  
   8  #include <addresstype.h>
   9  #include <consensus/amount.h>
  10  #include <rpc/util.h>
  11  #include <map>
  12  #include <string>
  13  #include <optional>
  14  
  15  struct bilingual_str;
  16  struct FlatSigningProvider;
  17  class UniValue;
  18  struct CMutableTransaction;
  19  class Coin;
  20  class COutPoint;
  21  class SigningProvider;
  22  
  23  /**
  24   * Sign a transaction with the given keystore and previous transactions
  25   *
  26   * @param  mtx           The transaction to-be-signed
  27   * @param  keystore      Temporary keystore containing signing keys
  28   * @param  coins         Map of unspent outputs
  29   * @param  hashType      The signature hash type
  30   * @param result         JSON object where signed transaction results accumulate
  31   */
  32  void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result);
  33  void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, bilingual_str>& input_errors, UniValue& result);
  34  
  35  /**
  36    * Parse a prevtxs UniValue array and get the map of coins from it
  37    *
  38    * @param  prevTxsUnival Array of previous txns outputs that tx depends on but may not yet be in the block chain
  39    * @param  keystore      A pointer to the temporary keystore if there is one
  40    * @param  coins         Map of unspent outputs - coins in mempool and current chain UTXO set, may be extended by previous txns outputs after call
  41    */
  42  void ParsePrevouts(const UniValue& prevTxsUnival, FlatSigningProvider* keystore, std::map<COutPoint, Coin>& coins);
  43  
  44  /** Normalize univalue-represented inputs and add them to the transaction */
  45  void AddInputs(CMutableTransaction& rawTx, const UniValue& inputs_in, bool rbf);
  46  
  47  /** Normalize univalue-represented outputs */
  48  UniValue NormalizeOutputs(const UniValue& outputs_in);
  49  
  50  /** Parse normalized outputs into destination, amount tuples */
  51  std::vector<std::pair<CTxDestination, CAmount>> ParseOutputs(const UniValue& outputs);
  52  
  53  /** Normalize, parse, and add outputs to the transaction */
  54  void AddOutputs(CMutableTransaction& rawTx, const UniValue& outputs_in);
  55  
  56  /** Create a transaction from univalue parameters */
  57  CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, std::optional<bool> rbf, uint32_t version);
  58  
  59  enum class ElisionMode {
  60      None,        ///< no elision, all top-level fields rendered normally
  61      WithSummary, ///< first field carries elision_summary as "...", rest skipped
  62      Silent,      ///< all top-level fields skipped silently (no "..." line)
  63  };
  64  
  65  struct TxDocOptions {
  66      /// The description of the txid field
  67      std::string txid_field_doc{"The transaction id"};
  68      /// Include wallet-related fields (e.g. ischange on outputs)
  69      bool wallet{false};
  70      /// Controls top-level field elision in the help
  71      ElisionMode elision_mode{ElisionMode::None};
  72      /// Summary text shown as "..." required for elision_mode == WithSummary
  73      std::optional<std::string> elision_summary{};
  74      /// Include prevout field
  75      bool prevout{false};
  76      /// Mark prevout field as optional (omitted when undo data unavailable)
  77      bool prevout_optional{false};
  78      /// Include fee field
  79      bool fee{false};
  80      /// Include hex field
  81      bool hex{false};
  82      /// Customize the vin item object's description (only meaningful when vin_inner_elision is set)
  83      std::optional<std::string> vin_item_doc{};
  84      /// Customize the prevout field's description (only meaningful when prevout is true)
  85      std::optional<std::string> prevout_doc{};
  86      /// Customize the fee field's description (only meaningful when fee is true)
  87      std::optional<std::string> fee_doc{};
  88      /// Elide vin inner fields but keep vin array with prevout expanded.
  89      std::optional<std::string> vin_inner_elision{};
  90  };
  91  /** Explain the UniValue "decoded" transaction object, may include extra fields if processed by wallet **/
  92  std::vector<RPCResult> TxDoc(const TxDocOptions& opts = {});
  93  
  94  #endif // BITCOIN_RPC_RAWTRANSACTION_UTIL_H
  95