Inside Bitcoin
Opening the selected file…
Inside Bitcoin
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) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6// The Solver functions are used by policy and the wallet, but not consensus.8#ifndef BITCOIN_SCRIPT_SOLVER_H9#define BITCOIN_SCRIPT_SOLVER_H11#include <attributes.h>12#include <script/script.h>14#include <optional>15#include <span>16#include <string>17#include <utility>18#include <vector>20class CPubKey;22enum class TxoutType {23NONSTANDARD,24// 'standard' transaction types:25ANCHOR, //!< anyone can spend script26PUBKEY,27PUBKEYHASH,28SCRIPTHASH,29MULTISIG,30NULL_DATA, //!< unspendable OP_RETURN script that carries data31WITNESS_V0_SCRIPTHASH,32WITNESS_V0_KEYHASH,33WITNESS_V1_TAPROOT,34WITNESS_UNKNOWN, //!< Only for Witness versions not already defined above35};37/** Get the name of a TxoutType as a string */38std::string GetTxnOutputType(TxoutType t);40constexpr bool IsPushdataOp(opcodetype opcode)41{42return opcode > OP_FALSE && opcode <= OP_PUSHDATA4;43}45/**46* Parse a scriptPubKey and identify script type for standard scripts. If47* successful, returns script type and parsed pubkeys or hashes, depending on48* the type. For example, for a P2SH script, vSolutionsRet will contain the49* script hash, for P2PKH it will contain the key hash, etc.50*51* @param[in] scriptPubKey Script to parse52* @param[out] vSolutionsRet Vector of parsed pubkeys and hashes53* @return The script type. TxoutType::NONSTANDARD represents a failed solve.54*/55TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned char>>& vSolutionsRet);57/** Generate a P2PK script for the given pubkey. */58CScript GetScriptForRawPubKey(const CPubKey& pubkey);60/** Determine if script is a "multi_a" script. Returns (threshold, keyspans) if so, and nullopt otherwise.61* The keyspans refer to bytes in the passed script. */62std::optional<std::pair<int, std::vector<std::span<const unsigned char>>>> MatchMultiA(const CScript& script LIFETIMEBOUND);64/** Generate a multisig script. */65CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);67#endif // BITCOIN_SCRIPT_SOLVER_H