Bitcoin Core  25.99.0
P2P Digital Currency
Classes | Typedefs | Enumerations | Functions | Variables
standard.h File Reference
#include <attributes.h>
#include <pubkey.h>
#include <script/interpreter.h>
#include <uint256.h>
#include <util/hash_type.h>
#include <map>
#include <string>
#include <variant>
Include dependency graph for standard.h:

Go to the source code of this file.

Classes

class  CScriptID
 A reference to a CScript: the Hash160 of its serialization (see script.h) More...
 
class  CNoDestination
 
struct  PKHash
 
struct  ScriptHash
 
struct  WitnessV0ScriptHash
 
struct  WitnessV0KeyHash
 
struct  WitnessV1Taproot
 
struct  WitnessUnknown
 CTxDestination subtype to encode any future Witness version. More...
 
struct  ShortestVectorFirstComparator
 
struct  TaprootSpendData
 
class  TaprootBuilder
 Utility class to construct Taproot outputs from internal key and script tree. More...
 
struct  TaprootBuilder::LeafInfo
 Information about a tracked leaf in the Merkle tree. More...
 
struct  TaprootBuilder::NodeInfo
 Information associated with a node in the Merkle tree. More...
 

Typedefs

using CTxDestination = std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown >
 A txout script template with a specific destination. More...
 

Enumerations

enum class  TxoutType {
  NONSTANDARD , PUBKEY , PUBKEYHASH , SCRIPTHASH ,
  MULTISIG , NULL_DATA , WITNESS_V0_SCRIPTHASH , WITNESS_V0_KEYHASH ,
  WITNESS_V1_TAPROOT , WITNESS_UNKNOWN
}
 

Functions

CKeyID ToKeyID (const PKHash &key_hash)
 
CKeyID ToKeyID (const WitnessV0KeyHash &key_hash)
 
bool IsValidDestination (const CTxDestination &dest)
 Check whether a CTxDestination is a CNoDestination. More...
 
std::string GetTxnOutputType (TxoutType t)
 Get the name of a TxoutType as a string. More...
 
constexpr bool IsPushdataOp (opcodetype opcode)
 
TxoutType Solver (const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
 Parse a scriptPubKey and identify script type for standard scripts. More...
 
bool ExtractDestination (const CScript &scriptPubKey, CTxDestination &addressRet)
 Parse a standard scriptPubKey for the destination address. More...
 
CScript GetScriptForDestination (const CTxDestination &dest)
 Generate a Bitcoin scriptPubKey for the given CTxDestination. More...
 
CScript GetScriptForRawPubKey (const CPubKey &pubkey)
 Generate a P2PK script for the given pubkey. More...
 
std::optional< std::pair< int, std::vector< Span< const unsigned char > > > > MatchMultiA (const CScript &script LIFETIMEBOUND)
 Determine if script is a "multi_a" script. More...
 
CScript GetScriptForMultisig (int nRequired, const std::vector< CPubKey > &keys)
 Generate a multisig script. More...
 
std::optional< std::vector< std::tuple< int, std::vector< unsigned char >, int > > > InferTaprootTree (const TaprootSpendData &spenddata, const XOnlyPubKey &output)
 Given a TaprootSpendData and the output key, reconstruct its script tree. More...
 

Variables

static const bool DEFAULT_ACCEPT_DATACARRIER = true
 
static const unsigned int MAX_OP_RETURN_RELAY = 83
 Default setting for -datacarriersize. More...
 
static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH
 Mandatory script verification flags that all new blocks must comply with for them to be valid. More...
 

Typedef Documentation

◆ CTxDestination

A txout script template with a specific destination.

It is either:

Definition at line 149 of file standard.h.

Enumeration Type Documentation

◆ TxoutType

enum TxoutType
strong
Enumerator
NONSTANDARD 
PUBKEY 
PUBKEYHASH 
SCRIPTHASH 
MULTISIG 
NULL_DATA 

unspendable OP_RETURN script that carries data

WITNESS_V0_SCRIPTHASH 
WITNESS_V0_KEYHASH 
WITNESS_V1_TAPROOT 
WITNESS_UNKNOWN 

Only for Witness versions not already defined above.

Definition at line 51 of file standard.h.

Function Documentation

◆ ExtractDestination()

bool ExtractDestination ( const CScript scriptPubKey,
CTxDestination addressRet 
)

Parse a standard scriptPubKey for the destination address.

Assigns result to the addressRet parameter and returns true if successful. Currently only works for P2PK, P2PKH, P2SH, P2WPKH, and P2WSH scripts.

Definition at line 237 of file standard.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetScriptForDestination()

CScript GetScriptForDestination ( const CTxDestination dest)

Generate a Bitcoin scriptPubKey for the given CTxDestination.

Returns a P2PKH script for a CKeyID destination, a P2SH script for a CScriptID, and an empty script for CNoDestination.

Definition at line 334 of file standard.cpp.

◆ GetScriptForMultisig()

CScript GetScriptForMultisig ( int  nRequired,
const std::vector< CPubKey > &  keys 
)

Generate a multisig script.

Definition at line 344 of file standard.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetScriptForRawPubKey()

CScript GetScriptForRawPubKey ( const CPubKey pubkey)

Generate a P2PK script for the given pubkey.

Definition at line 339 of file standard.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTxnOutputType()

std::string GetTxnOutputType ( TxoutType  t)

Get the name of a TxoutType as a string.

Definition at line 46 of file standard.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InferTaprootTree()

std::optional<std::vector<std::tuple<int, std::vector<unsigned char>, int> > > InferTaprootTree ( const TaprootSpendData spenddata,
const XOnlyPubKey output 
)

Given a TaprootSpendData and the output key, reconstruct its script tree.

If the output doesn't match the spenddata, or if the data in spenddata is incomplete, std::nullopt is returned. Otherwise, a vector of (depth, script, leaf_ver) tuples is returned, corresponding to a depth-first traversal of the script tree.

Data structure to represent the nodes of the tree we're going to build.

Hash of this node, if known; 0 otherwise.

The left and right subtrees (note that their order is irrelevant).

If this is known to be a leaf node, a pointer to the (script, leaf_ver) pair. nullptr otherwise.

Whether or not this node has been explored (is known to be a leaf, or known to have children).

Whether or not this node is an inner node (unknown until explored = true).

Whether or not we have produced output for this subtree.

Definition at line 504 of file standard.cpp.

Here is the call graph for this function:

◆ IsPushdataOp()

constexpr bool IsPushdataOp ( opcodetype  opcode)
constexpr

Definition at line 157 of file standard.h.

Here is the caller graph for this function:

◆ IsValidDestination()

bool IsValidDestination ( const CTxDestination dest)

Check whether a CTxDestination is a CNoDestination.

Definition at line 356 of file standard.cpp.

Here is the caller graph for this function:

◆ MatchMultiA()

std::optional<std::pair<int, std::vector<Span<const unsigned char> > > > MatchMultiA ( const CScript &script  LIFETIMEBOUND)

Determine if script is a "multi_a" script.

Returns (threshold, keyspans) if so, and nullopt otherwise. The keyspans refer to bytes in the passed script.

◆ Solver()

TxoutType Solver ( const CScript scriptPubKey,
std::vector< std::vector< unsigned char >> &  vSolutionsRet 
)

Parse a scriptPubKey and identify script type for standard scripts.

If successful, returns script type and parsed pubkeys or hashes, depending on the type. For example, for a P2SH script, vSolutionsRet will contain the script hash, for P2PKH it will contain the key hash, etc.

Parameters
[in]scriptPubKeyScript to parse
[out]vSolutionsRetVector of parsed pubkeys and hashes
Returns
The script type. TxoutType::NONSTANDARD represents a failed solve.

Definition at line 168 of file standard.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToKeyID() [1/2]

CKeyID ToKeyID ( const PKHash key_hash)

Definition at line 31 of file standard.cpp.

Here is the caller graph for this function:

◆ ToKeyID() [2/2]

CKeyID ToKeyID ( const WitnessV0KeyHash key_hash)

Definition at line 36 of file standard.cpp.

Variable Documentation

◆ DEFAULT_ACCEPT_DATACARRIER

const bool DEFAULT_ACCEPT_DATACARRIER = true
static

Definition at line 19 of file standard.h.

◆ MANDATORY_SCRIPT_VERIFY_FLAGS

const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH
static

Mandatory script verification flags that all new blocks must comply with for them to be valid.

(but old blocks may not comply with) Currently just P2SH, but in the future other flags may be added.

Failing one of these tests may trigger a DoS ban - see CheckInputScripts() for details.

Definition at line 49 of file standard.h.

◆ MAX_OP_RETURN_RELAY

const unsigned int MAX_OP_RETURN_RELAY = 83
static

Default setting for -datacarriersize.

80 bytes of data, +1 for OP_RETURN, +2 for the pushdata opcodes.

Definition at line 39 of file standard.h.