Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2017-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_RPC_RAWTRANSACTION_UTIL_H6#define BITCOIN_RPC_RAWTRANSACTION_UTIL_H8#include <addresstype.h>9#include <consensus/amount.h>10#include <rpc/util.h>12#include <cstdint>13#include <map>14#include <optional>15#include <string>16#include <utility>17#include <vector>19struct bilingual_str;20struct FlatSigningProvider;21class UniValue;22struct CMutableTransaction;23class Coin;24class COutPoint;25class SigningProvider;27/**28* Sign a transaction with the given keystore and previous transactions29*30* @param mtx The transaction to-be-signed31* @param keystore Temporary keystore containing signing keys32* @param coins Map of unspent outputs33* @param hashType The signature hash type34* @param result JSON object where signed transaction results accumulate35*/36void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result);37void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const std::map<COutPoint, Coin>& coins, const std::map<int, bilingual_str>& input_errors, UniValue& result);39/**40* Parse a prevtxs UniValue array and get the map of coins from it41*42* @param prevTxsUnival Array of previous txns outputs that tx depends on but may not yet be in the block chain43* @param keystore A pointer to the temporary keystore if there is one44* @param coins Map of unspent outputs - coins in mempool and current chain UTXO set, may be extended by previous txns outputs after call45*/46void ParsePrevouts(const UniValue& prevTxsUnival, FlatSigningProvider* keystore, std::map<COutPoint, Coin>& coins);48/** Normalize univalue-represented inputs and add them to the transaction */49void AddInputs(CMutableTransaction& rawTx, const UniValue& inputs_in, bool rbf);51/** Normalize univalue-represented outputs */52UniValue NormalizeOutputs(const UniValue& outputs_in);54/** Parse normalized outputs into destination, amount tuples */55std::vector<std::pair<CTxDestination, CAmount>> ParseOutputs(const UniValue& outputs);57/** Normalize, parse, and add outputs to the transaction */58void AddOutputs(CMutableTransaction& rawTx, const UniValue& outputs_in);60/** Create a transaction from univalue parameters */61CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, std::optional<bool> rbf, uint32_t version);63enum class ElisionMode {64None, ///< no elision, all top-level fields rendered normally65WithSummary, ///< first field carries elision_summary as "...", rest skipped66Silent, ///< all top-level fields skipped silently (no "..." line)67};69struct TxDocOptions {70/// The description of the txid field71std::string txid_field_doc{"The transaction id"};72/// Include wallet-related fields (e.g. ischange on outputs)73bool wallet{false};74/// Controls top-level field elision in the help75ElisionMode elision_mode{ElisionMode::None};76/// Summary text shown as "..." required for elision_mode == WithSummary77std::optional<std::string> elision_summary{};78/// Include prevout field79bool prevout{false};80/// Mark prevout field as optional (omitted when undo data unavailable)81bool prevout_optional{false};82/// Include fee field83bool fee{false};84/// Include hex field85bool hex{false};86/// Customize the vin item object's description (only meaningful when vin_inner_elision is set)87std::optional<std::string> vin_item_doc{};88/// Customize the prevout field's description (only meaningful when prevout is true)89std::optional<std::string> prevout_doc{};90/// Customize the fee field's description (only meaningful when fee is true)91std::optional<std::string> fee_doc{};92/// Elide vin inner fields but keep vin array with prevout expanded.93std::optional<std::string> vin_inner_elision{};94};95/** Explain the UniValue "decoded" transaction object, may include extra fields if processed by wallet **/96std::vector<RPCResult> TxDoc(const TxDocOptions& opts = {});98#endif // BITCOIN_RPC_RAWTRANSACTION_UTIL_H