CScript

Serialized script, used inside transaction inputs and outputs

Synopsis

Declared in <script/script.h>

class CScript
    : public CScriptBase

Base Classes

NameDescription
CScriptBaseWe use a prevector for the script to reduce the considerable memory overhead of vectors in cases where they normally contain a small number of small elements.

Member Functions

NameDescription
CScript [constructor]Constructs an empty script.
CScript [constructor]Constructs a script that pushes a single integer.
CScript [constructor]Constructs a script that holds a single opcode.
CScript [constructor]Constructs a script that pushes a single script number.
CScript [constructor] [deleted]Deleted byte-vector constructor, to defend against future introduction e.g. via prevector.
CScript [constructor]Constructs a script from a range of bytes.
GetOp Reads the next opcode, ignoring any pushed data.
GetOp Reads the next opcode and its pushed data.
GetSigOpCount Counts the signature operations in this script.
GetSigOpCount Accurately count sigOps, including sigOps in pay-to-script-hash transactions:
HasValidOps Returns whether the script contains only valid opcodes.
IsPayToAnchor Returns whether this script is a pay-to-anchor (P2A) output script.
IsPayToScriptHash Returns whether this script is a pay-to-script-hash (P2SH) output.
IsPayToTaproot Returns whether this script is a pay-to-taproot (P2TR) output.
IsPayToWitnessScriptHash Returns whether this script is a pay-to-witness-script-hash (P2WSH) output.
IsPushOnly Returns whether the whole script only pushes data onto the stack.
IsPushOnly Returns whether the script only pushes data onto the stack.
IsUnspendable Returns whether the script is guaranteed to fail at execution, regardless of the initial stack. This allows outputs to be pruned instantly when entering the UTXO set.
IsWitnessProgram Returns whether this script is a witness program and extracts its parts.
clear Empties the script and releases its memory.
operator<< Appends a byte span as a data push (uint8_t overload).
operator<< Appends a byte span as a data push, including its size prefix.
operator<< Appends a script number as pushed data.
operator<< Appends a single opcode.
operator<< Appends an integer using the most compact push encoding.
operator<< [deleted]Delete non-existent operator to defend against future introduction

Static Member Functions

NameDescription
DecodeOP_N Decodes a small-integer opcode to its numeric value.
EncodeOP_N Encodes a small integer as its push opcode.
IsPayToAnchor Checks if output of IsWitnessProgram comes from a P2A output script

Protected Member Functions

NameDescription
push_int64 Appends an integer using the most compact push encoding.

Non-Member Functions

NameDescription
BuildScriptBuild a script by concatenating other scripts, or any argument accepted by CScript::operator<<.
CompressScriptCompresses a script into the compact on-disk representation.
CountWitnessSigOpsCount the signature operations contributed by a witness spend.
DecompressScriptReconstructs a script from its compressed representation.
EvalDescriptorStringOrObjectEvaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range of 1000.
ExtractDestinationParse a scriptPubKey for the destination.
FindAndDeleteRemove every occurrence of a subscript from a script in place.
FormatScriptFormat a script as a compact single-line string for logging and display.
GetScriptForDestinationGenerate 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.
GetScriptForMultisigGenerate a multisig script.
GetScriptForRawPubKeyGenerate a P2PK script for the given pubkey.
InferDescriptorFind a descriptor for the specified script, using information from provider where possible.
IsStandardDetermine whether a scriptPubKey uses a standard output form.
MatchMultiADetermine if script is a "multi_a" script. Returns (threshold, keyspans) if so, and nullopt otherwise. The keyspans refer to bytes in the passed script.
ParseScriptParse a human-readable script (opcodes and push data) into a CScript.
ScriptToAsmStrRender a script as a human-readable assembly string.
ScriptToUnivFill a JSON object with a human-readable description of a script.
SignatureHashCompute the signature hash for one input under the selected signature version.
SolverParse 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.
VerifyScriptVerify that an input's scriptSig and witness satisfy the output's scriptPubKey.
kernel::GetBogoSizeComputes the serialization-agnostic size measure of an output script.
miniscript::FromScriptDecodes a Miniscript from a Bitcoin Script.