![]() |
Bitcoin Core
22.0.0
P2P Digital Currency
|
#include <script/standard.h>#include <crypto/sha256.h>#include <hash.h>#include <pubkey.h>#include <script/interpreter.h>#include <script/script.h>#include <util/strencodings.h>#include <string>Go to the source code of this file.
Typedefs | |
| typedef std::vector< unsigned char > | valtype |
Functions | |
| CKeyID | ToKeyID (const PKHash &key_hash) |
| CKeyID | ToKeyID (const WitnessV0KeyHash &key_hash) |
| std::string | GetTxnOutputType (TxoutType t) |
| Get the name of a TxoutType as a string. More... | |
| static bool | MatchPayToPubkey (const CScript &script, valtype &pubkey) |
| static bool | MatchPayToPubkeyHash (const CScript &script, valtype &pubkeyhash) |
| static constexpr bool | IsSmallInteger (opcodetype opcode) |
| Test for "small positive integer" script opcodes - OP_1 through OP_16. More... | |
| static constexpr bool | IsPushdataOp (opcodetype opcode) |
| static constexpr bool | IsValidMultisigKeyCount (int n_keys) |
| static bool | GetMultisigKeyCount (opcodetype opcode, valtype data, int &count) |
| static bool | MatchMultisig (const CScript &script, int &required_sigs, std::vector< valtype > &pubkeys) |
| 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... | |
| bool | ExtractDestinations (const CScript &scriptPubKey, TxoutType &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet) |
| Parse a standard scriptPubKey with one or more destination addresses. 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... | |
| CScript | GetScriptForMultisig (int nRequired, const std::vector< CPubKey > &keys) |
| Generate a multisig script. More... | |
| bool | IsValidDestination (const CTxDestination &dest) |
| Check whether a CTxDestination is a CNoDestination. More... | |
| std::optional< std::vector< std::tuple< int, CScript, int > > > | InferTaprootTree (const TaprootSpendData &spenddata, const XOnlyPubKey &output) |
| Given a TaprootSpendData and the output key, reconstruct its script tree. More... | |
Variables | |
| bool | fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER |
| A data carrying output is an unspendable output containing data. More... | |
| unsigned | nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY |
| Maximum size of TxoutType::NULL_DATA scripts that this node considers standard. More... | |
| typedef std::vector<unsigned char> valtype |
Definition at line 17 of file standard.cpp.
| 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. For multisig scripts, instead use ExtractDestinations. Currently only works for P2PK, P2PKH, P2SH, P2WPKH, and P2WSH scripts.
Definition at line 213 of file standard.cpp.
| bool ExtractDestinations | ( | const CScript & | scriptPubKey, |
| TxoutType & | typeRet, | ||
| std::vector< CTxDestination > & | addressRet, | ||
| int & | nRequiredRet | ||
| ) |
Parse a standard scriptPubKey with one or more destination addresses.
For multisig scripts, this populates the addressRet vector with the pubkey IDs and nRequiredRet with the n required to spend. For other destinations, addressRet is populated with a single value and nRequiredRet is set to 1. Returns true if successful.
Note: this function confuses destinations (a subset of CScripts that are encodable as an address) with key identifiers (of keys involved in a CScript), and its use should be phased out.
TODO: from v23 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
Definition at line 270 of file standard.cpp.
|
static |
Definition at line 104 of file standard.cpp.
| 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 351 of file standard.cpp.
Generate a multisig script.
Definition at line 361 of file standard.cpp.
Generate a P2PK script for the given pubkey.
Definition at line 356 of file standard.cpp.
| std::string GetTxnOutputType | ( | TxoutType | t | ) |
Get the name of a TxoutType as a string.
Definition at line 49 of file standard.cpp.
| std::optional<std::vector<std::tuple<int, CScript, 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 530 of file standard.cpp.
|
static |
|
static |
Test for "small positive integer" script opcodes - OP_1 through OP_16.
Definition at line 89 of file standard.cpp.
| bool IsValidDestination | ( | const CTxDestination & | dest | ) |
Check whether a CTxDestination is a CNoDestination.
Definition at line 373 of file standard.cpp.
|
static |
|
static |
Definition at line 124 of file standard.cpp.
Definition at line 66 of file standard.cpp.
Definition at line 79 of file standard.cpp.
| 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.
| [in] | scriptPubKey | Script to parse |
| [out] | vSolutionsRet | Vector of parsed pubkeys and hashes |
Definition at line 144 of file standard.cpp.
| CKeyID ToKeyID | ( | const WitnessV0KeyHash & | key_hash | ) |
Definition at line 39 of file standard.cpp.
| bool fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER |
A data carrying output is an unspendable output containing data.
The script type is designated as TxoutType::NULL_DATA.
Definition at line 19 of file standard.cpp.
| unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY |
Maximum size of TxoutType::NULL_DATA scripts that this node considers standard.
Definition at line 20 of file standard.cpp.
1.8.14