Serialized script, used inside transaction inputs and outputs

Synopsis

Declared in <script/script.h>

class CScript
    : public CScriptBase

Base Classes

Name

Description

CScriptBase

We 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

Name

Description

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

Name

Description

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

Name

Description

push_int64

Appends an integer using the most compact push encoding.

Non-Member Functions

Name

Description

BuildScript

Build a script by concatenating other scripts, or any argument accepted by CScript::operator<<.

CompressScript

Compresses a script into the compact on‐disk representation.

CountWitnessSigOps

Count the signature operations contributed by a witness spend.

DecompressScript

Reconstructs a script from its compressed representation.

EvalDescriptorStringOrObject

Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range of 1000.

ExtractDestination

Parse a scriptPubKey for the destination.

FindAndDelete

Remove every occurrence of a subscript from a script in place.

FormatScript

Format a script as a compact single‐line string for logging and display.

GetScriptForDestination

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.

GetScriptForMultisig

Generate a multisig script.

GetScriptForRawPubKey

Generate a P2PK script for the given pubkey.

InferDescriptor

Find a descriptor for the specified script, using information from provider where possible.

IsStandard

Determine whether a scriptPubKey uses a standard output form.

MatchMultiA

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.

ParseScript

Parse a human‐readable script (opcodes and push data) into a CScript.

ScriptToAsmStr

Render a script as a human‐readable assembly string.

ScriptToUniv

Fill a JSON object with a human‐readable description of a script.

SignatureHash

Compute the signature hash for one input under the selected signature version.

Solver

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.

VerifyScript

Verify that an input's scriptSig and witness satisfy the output's scriptPubKey.

kernel::GetBogoSize

Computes the serialization‐agnostic size measure of an output script.

miniscript::FromScript

Decodes a Miniscript from a Bitcoin Script.

Created with MrDocs