Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
CScript Class Reference

Serialized script, used inside transaction inputs and outputs. More...

#include <script.h>

Inheritance diagram for CScript:
[legend]
Collaboration diagram for CScript:
[legend]

Public Member Functions

 CScript ()=default
template<std::input_iterator InputIterator>
 CScript (InputIterator first, InputIterator last)
 SERIALIZE_METHODS (CScript, obj)
 CScript (int64_t b)
 CScript (opcodetype b)
 CScript (const CScriptNum &b)
 CScript (const std::vector< unsigned char > &b)=delete
CScriptoperator<< (const CScript &b)=delete
 Delete non-existent operator to defend against future introduction.
CScriptoperator<< (int64_t b) LIFETIMEBOUND
CScriptoperator<< (opcodetype opcode) LIFETIMEBOUND
CScriptoperator<< (const CScriptNum &b) LIFETIMEBOUND
CScriptoperator<< (std::span< const std::byte > b) LIFETIMEBOUND
CScriptoperator<< (std::span< const value_type > b) LIFETIMEBOUND
bool GetOp (const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
bool GetOp (const_iterator &pc, opcodetype &opcodeRet) const
unsigned int GetSigOpCount (bool fAccurate) const
 Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.
unsigned int GetSigOpCount (const CScript &scriptSig) const
 Accurately count sigOps, including sigOps in pay-to-script-hash transactions:
bool IsPayToAnchor () const
bool IsPayToScriptHash () const
bool IsPayToWitnessScriptHash () const
bool IsWitnessProgram (int &version, std::vector< unsigned char > &program) const
bool IsPayToTaproot () const
bool IsPushOnly (const_iterator pc) const
 Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical).
bool IsPushOnly () const
bool HasValidOps () const
 Check if the script contains valid OP_CODES.
bool IsUnspendable () const
 Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
void clear ()
Public Member Functions inherited from prevector< 36, uint8_t >
void assign (size_type n, const uint8_t &val)
void assign (InputIterator first, InputIterator last)
 prevector ()=default
 prevector (size_type n)
 prevector (size_type n, const uint8_t &val)
 prevector (InputIterator first, InputIterator last)
 prevector (const prevector< N, uint8_t, uint32_t, int32_t > &other)
 prevector (prevector< N, uint8_t, uint32_t, int32_t > &&other) noexcept
prevectoroperator= (const prevector< N, uint8_t, uint32_t, int32_t > &other)
prevectoroperator= (prevector< N, uint8_t, uint32_t, int32_t > &&other) noexcept
size_type size () const
bool empty () const
iterator begin ()
const_iterator begin () const
iterator end ()
const_iterator end () const
size_t capacity () const
uint8_t & operator[] (size_type pos)
const uint8_t & operator[] (size_type pos) const
void resize (size_type new_size)
void reserve (size_type new_capacity)
void shrink_to_fit ()
void clear ()
iterator insert (iterator pos, const uint8_t &value)
void insert (iterator pos, size_type count, const uint8_t &value)
void insert (iterator pos, InputIterator first, InputIterator last)
void resize_uninitialized (size_type new_size)
iterator erase (iterator pos)
iterator erase (iterator first, iterator last)
void emplace_back (Args &&... args)
void push_back (const uint8_t &value)
void pop_back ()
uint8_t & front ()
const uint8_t & front () const
uint8_t & back ()
const uint8_t & back () const
void swap (prevector< N, uint8_t, uint32_t, int32_t > &other) noexcept
 ~prevector ()
bool operator== (const prevector< N, uint8_t, uint32_t, int32_t > &other) const
bool operator< (const prevector< N, uint8_t, uint32_t, int32_t > &other) const
size_t allocated_memory () const
value_typedata ()
const value_typedata () const

Static Public Member Functions

static int DecodeOP_N (opcodetype opcode)
 Encode/decode small integers:
static opcodetype EncodeOP_N (int n)
static bool IsPayToAnchor (int version, const std::vector< unsigned char > &program)
 Checks if output of IsWitnessProgram comes from a P2A output script.

Protected Member Functions

CScriptpush_int64 (int64_t n)

Private Member Functions

void AppendDataSize (const uint32_t size)
void AppendData (std::span< const value_type > data)

Additional Inherited Members

Public Types inherited from prevector< 36, uint8_t >
typedef uint32_t size_type
typedef int32_t difference_type
typedef uint8_t value_type
typedef value_typereference
typedef const value_typeconst_reference
typedef value_typepointer
typedef const value_typeconst_pointer
Static Public Attributes inherited from prevector< 36, uint8_t >
static constexpr unsigned int STATIC_SIZE

Detailed Description

Serialized script, used inside transaction inputs and outputs.

Definition at line 404 of file script.h.

Constructor & Destructor Documentation

◆ CScript() [1/6]

CScript::CScript ( )
default
Here is the caller graph for this function:

◆ CScript() [2/6]

template<std::input_iterator InputIterator>
CScript::CScript ( InputIterator first,
InputIterator last )
inline

Definition at line 453 of file script.h.

◆ CScript() [3/6]

CScript::CScript ( int64_t b)
inlineexplicit

Definition at line 457 of file script.h.

Here is the call graph for this function:

◆ CScript() [4/6]

CScript::CScript ( opcodetype b)
inlineexplicit

Definition at line 458 of file script.h.

Here is the call graph for this function:

◆ CScript() [5/6]

CScript::CScript ( const CScriptNum & b)
inlineexplicit

Definition at line 459 of file script.h.

Here is the call graph for this function:

◆ CScript() [6/6]

CScript::CScript ( const std::vector< unsigned char > & b)
explicitdelete

Member Function Documentation

◆ AppendData()

void CScript::AppendData ( std::span< const value_type > data)
inlineprivate

Definition at line 427 of file script.h.

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

◆ AppendDataSize()

void CScript::AppendDataSize ( const uint32_t size)
inlineprivate

Definition at line 407 of file script.h.

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

◆ clear()

void CScript::clear ( )
inline

Definition at line 568 of file script.h.

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

◆ DecodeOP_N()

int CScript::DecodeOP_N ( opcodetype opcode)
inlinestatic

Encode/decode small integers:

Definition at line 507 of file script.h.

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

◆ EncodeOP_N()

opcodetype CScript::EncodeOP_N ( int n)
inlinestatic

Definition at line 514 of file script.h.

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

◆ GetOp() [1/2]

bool CScript::GetOp ( const_iterator & pc,
opcodetype & opcodeRet ) const
inline

Definition at line 501 of file script.h.

Here is the call graph for this function:

◆ GetOp() [2/2]

bool CScript::GetOp ( const_iterator & pc,
opcodetype & opcodeRet,
std::vector< unsigned char > & vchRet ) const
inline

Definition at line 496 of file script.h.

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

◆ GetSigOpCount() [1/2]

unsigned int CScript::GetSigOpCount ( bool fAccurate) const

Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.

With pay-to-script-hash, that changed: CHECKMULTISIGs serialized in scriptSigs are counted more accurately, assuming they are of the form ... OP_N CHECKMULTISIG ...

Definition at line 159 of file script.cpp.

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

◆ GetSigOpCount() [2/2]

unsigned int CScript::GetSigOpCount ( const CScript & scriptSig) const

Accurately count sigOps, including sigOps in pay-to-script-hash transactions:

... and return its opcount:

Definition at line 183 of file script.cpp.

Here is the call graph for this function:

◆ HasValidOps()

bool CScript::HasValidOps ( ) const

Check if the script contains valid OP_CODES.

Definition at line 300 of file script.cpp.

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

◆ IsPayToAnchor() [1/2]

bool CScript::IsPayToAnchor ( ) const

Definition at line 207 of file script.cpp.

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

◆ IsPayToAnchor() [2/2]

bool CScript::IsPayToAnchor ( int version,
const std::vector< unsigned char > & program )
static

Checks if output of IsWitnessProgram comes from a P2A output script.

Definition at line 216 of file script.cpp.

◆ IsPayToScriptHash()

bool CScript::IsPayToScriptHash ( ) const

Definition at line 224 of file script.cpp.

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

◆ IsPayToTaproot()

bool CScript::IsPayToTaproot ( ) const

Definition at line 241 of file script.cpp.

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

◆ IsPayToWitnessScriptHash()

bool CScript::IsPayToWitnessScriptHash ( ) const

Definition at line 233 of file script.cpp.

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

◆ IsPushOnly() [1/2]

bool CScript::IsPushOnly ( ) const

Definition at line 283 of file script.cpp.

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

◆ IsPushOnly() [2/2]

bool CScript::IsPushOnly ( const_iterator pc) const

Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical).

Definition at line 266 of file script.cpp.

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

◆ IsUnspendable()

bool CScript::IsUnspendable ( ) const
inline

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.

Definition at line 563 of file script.h.

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

◆ IsWitnessProgram()

bool CScript::IsWitnessProgram ( int & version,
std::vector< unsigned char > & program ) const

Definition at line 250 of file script.cpp.

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

◆ operator<<() [1/6]

CScript & CScript::operator<< ( const CScript & b)
delete

Delete non-existent operator to defend against future introduction.

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

◆ operator<<() [2/6]

CScript & CScript::operator<< ( const CScriptNum & b)
inline

Definition at line 477 of file script.h.

Here is the call graph for this function:

◆ operator<<() [3/6]

CScript & CScript::operator<< ( int64_t b)
inline

Definition at line 467 of file script.h.

Here is the call graph for this function:

◆ operator<<() [4/6]

CScript & CScript::operator<< ( opcodetype opcode)
inline

Definition at line 469 of file script.h.

Here is the call graph for this function:

◆ operator<<() [5/6]

CScript & CScript::operator<< ( std::span< const std::byte > b)
inline

Definition at line 483 of file script.h.

Here is the call graph for this function:

◆ operator<<() [6/6]

CScript & CScript::operator<< ( std::span< const value_type > b)
inline

Definition at line 491 of file script.h.

Here is the call graph for this function:

◆ push_int64()

CScript & CScript::push_int64 ( int64_t n)
inlineprotected

Definition at line 433 of file script.h.

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

◆ SERIALIZE_METHODS()

CScript::SERIALIZE_METHODS ( CScript ,
obj  )
inline

Definition at line 455 of file script.h.

Here is the call graph for this function:

The documentation for this class was generated from the following files: