Bitcoin
Classes | Namespaces | Typedefs | Functions | Variables
standard.cpp File Reference
#include <script/standard.h>
#include <crypto/sha256.h>
#include <pubkey.h>
#include <script/script.h>

Classes

class  anonymous_namespace{standard.cpp}::CScriptVisitor
 

Namespaces

 anonymous_namespace{standard.cpp}
 

Typedefs

typedef std::vector< unsigned char > valtype
 

Functions

const char * GetTxnOutputType (txnouttype t)
 
static bool MatchPayToPubkey (const CScript &script, valtype &pubkey)
 
static bool MatchPayToPubkeyHash (const CScript &script, valtype &pubkeyhash)
 
static constexpr bool IsSmallInteger (opcodetype opcode)
 
static bool MatchMultisig (const CScript &script, unsigned int &required, std::vector< valtype > &pubkeys)
 
txnouttype Solver (const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
 
bool ExtractDestination (const CScript &scriptPubKey, CTxDestination &addressRet)
 
bool ExtractDestinations (const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
 
CScript GetScriptForDestination (const CTxDestination &dest)
 
CScript GetScriptForRawPubKey (const CPubKey &pubKey)
 
CScript GetScriptForMultisig (int nRequired, const std::vector< CPubKey > &keys)
 
CScript GetScriptForWitness (const CScript &redeemscript)
 
bool IsValidDestination (const CTxDestination &dest)
 

Variables

bool fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER
 
unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY
 

Typedef Documentation

◆ valtype

typedef std::vector<unsigned char> valtype

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. For multisig scripts, instead use ExtractDestinations. Currently only works for P2PK, P2PKH, P2SH, P2WPKH, and P2WSH scripts.

◆ ExtractDestinations()

bool ExtractDestinations ( const CScript scriptPubKey,
txnouttype 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.

◆ 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.

◆ GetScriptForMultisig()

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

Generate a multisig script.

◆ GetScriptForRawPubKey()

CScript GetScriptForRawPubKey ( const CPubKey pubkey)

Generate a P2PK script for the given pubkey.

◆ GetScriptForWitness()

CScript GetScriptForWitness ( const CScript redeemscript)

Generate a pay-to-witness script for the given redeem script. If the redeem script is P2PK or P2PKH, this returns a P2WPKH script, otherwise it returns a P2WSH script.

TODO: replace calls to GetScriptForWitness with GetScriptForDestination using the various witness-specific CTxDestination subtypes.

◆ GetTxnOutputType()

const char* GetTxnOutputType ( txnouttype  t)

Get the name of a txnouttype as a C string, or nullptr if unknown.

◆ IsSmallInteger()

static constexpr bool IsSmallInteger ( opcodetype  opcode)
static

Test for "small positive integer" script opcodes - OP_1 through OP_16.

◆ IsValidDestination()

bool IsValidDestination ( const CTxDestination dest)

Check whether a CTxDestination is a CNoDestination.

◆ MatchMultisig()

static bool MatchMultisig ( const CScript script,
unsigned int &  required,
std::vector< valtype > &  pubkeys 
)
static

◆ MatchPayToPubkey()

static bool MatchPayToPubkey ( const CScript script,
valtype pubkey 
)
static

◆ MatchPayToPubkeyHash()

static bool MatchPayToPubkeyHash ( const CScript script,
valtype pubkeyhash 
)
static

◆ Solver()

txnouttype 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. TX_NONSTANDARD represents a failed solve.

Variable Documentation

◆ fAcceptDatacarrier

bool fAcceptDatacarrier = DEFAULT_ACCEPT_DATACARRIER

A data carrying output is an unspendable output containing data. The script type is designated as TX_NULL_DATA.

◆ nMaxDatacarrierBytes

unsigned nMaxDatacarrierBytes = MAX_OP_RETURN_RELAY

Maximum size of TX_NULL_DATA scripts that this node considers standard.