Skip to content

Commit 4b65fa5

Browse files
committed
Merge #11058: Comments: More comments on functions/globals in standard.h.
360b464 Comments: More comments on functions/globals in standard.h. (Jim Posen) Pull request description: I was confused about what "data carrier" meant, so I wanted to comment the `fAcceptDatacarrier` and `nMaxDatacarrierBytes` fields specifically. Then I figured I'd add docs for the rest of the functions. Tree-SHA512: e6d0cfe6f4a2ab52ae76f984b1f5d8de371ae938e7832be8b02517d868f1caea62fec8888c917a2bd3d8ef74025de7f00dc96923fa56436dc6b190626652bf29
2 parents 7ed57d3 + 360b464 commit 4b65fa5

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

src/script/standard.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ const char* GetTxnOutputType(txnouttype t)
3434
return nullptr;
3535
}
3636

37-
/**
38-
* Return public keys or hashes from scriptPubKey, for 'standard' transaction types.
39-
*/
4037
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet)
4138
{
4239
// Templates

src/script/standard.h

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,27 @@ class CScriptID : public uint160
2727
CScriptID(const uint160& in) : uint160(in) {}
2828
};
2929

30-
static const unsigned int MAX_OP_RETURN_RELAY = 83; //!< bytes (+1 for OP_RETURN, +2 for the pushdata opcodes)
30+
/**
31+
* Default setting for nMaxDatacarrierBytes. 80 bytes of data, +1 for OP_RETURN,
32+
* +2 for the pushdata opcodes.
33+
*/
34+
static const unsigned int MAX_OP_RETURN_RELAY = 83;
35+
36+
/**
37+
* A data carrying output is an unspendable output containing data. The script
38+
* type is designated as TX_NULL_DATA.
39+
*/
3140
extern bool fAcceptDatacarrier;
41+
42+
/** Maximum size of TX_NULL_DATA scripts that this node considers standard. */
3243
extern unsigned nMaxDatacarrierBytes;
3344

3445
/**
3546
* Mandatory script verification flags that all new blocks must comply with for
3647
* them to be valid. (but old blocks may not comply with) Currently just P2SH,
3748
* but in the future other flags may be added, such as a soft-fork to enforce
3849
* strict DER encoding.
39-
*
50+
*
4051
* Failing one of these tests may trigger a DoS ban - see CheckInputs() for
4152
* details.
4253
*/
@@ -50,7 +61,7 @@ enum txnouttype
5061
TX_PUBKEYHASH,
5162
TX_SCRIPTHASH,
5263
TX_MULTISIG,
53-
TX_NULL_DATA,
64+
TX_NULL_DATA, //!< unspendable OP_RETURN script that carries data
5465
TX_WITNESS_V0_SCRIPTHASH,
5566
TX_WITNESS_V0_KEYHASH,
5667
};
@@ -61,7 +72,7 @@ class CNoDestination {
6172
friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
6273
};
6374

64-
/**
75+
/**
6576
* A txout script template with a specific destination. It is either:
6677
* * CNoDestination: no destination set
6778
* * CKeyID: TX_PUBKEYHASH destination
@@ -70,15 +81,58 @@ class CNoDestination {
7081
*/
7182
typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
7283

84+
/** Get the name of a txnouttype as a C string, or nullptr if unknown. */
7385
const char* GetTxnOutputType(txnouttype t);
7486

87+
/**
88+
* Parse a scriptPubKey and identify script type for standard scripts. If
89+
* successful, returns script type and parsed pubkeys or hashes, depending on
90+
* the type. For example, for a P2SH script, vSolutionsRet will contain the
91+
* script hash, for P2PKH it will contain the key hash, etc.
92+
*
93+
* @param[in] scriptPubKey Script to parse
94+
* @param[out] typeRet The script type
95+
* @param[out] vSolutionsRet Vector of parsed pubkeys and hashes
96+
* @return True if script matches standard template
97+
*/
7598
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
99+
100+
/**
101+
* Parse a standard scriptPubKey for the destination address. Assigns result to
102+
* the addressRet parameter and returns true if successful. For multisig
103+
* scripts, instead use ExtractDestinations. Currently only works for P2PK,
104+
* P2PKH, and P2SH scripts.
105+
*/
76106
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
107+
108+
/**
109+
* Parse a standard scriptPubKey with one or more destination addresses. For
110+
* multisig scripts, this populates the addressRet vector with the pubkey IDs
111+
* and nRequiredRet with the n required to spend. For other destinations,
112+
* addressRet is populated with a single value and nRequiredRet is set to 1.
113+
* Returns true if successful. Currently does not extract address from
114+
* pay-to-witness scripts.
115+
*/
77116
bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
78117

118+
/**
119+
* Generate a Bitcoin scriptPubKey for the given CTxDestination. Returns a P2PKH
120+
* script for a CKeyID destination, a P2SH script for a CScriptID, and an empty
121+
* script for CNoDestination.
122+
*/
79123
CScript GetScriptForDestination(const CTxDestination& dest);
124+
125+
/** Generate a P2PK script for the given pubkey. */
80126
CScript GetScriptForRawPubKey(const CPubKey& pubkey);
127+
128+
/** Generate a multisig script. */
81129
CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);
130+
131+
/**
132+
* Generate a pay-to-witness script for the given redeem script. If the redeem
133+
* script is P2PK or P2PKH, this returns a P2WPKH script, otherwise it returns a
134+
* P2WSH script.
135+
*/
82136
CScript GetScriptForWitness(const CScript& redeemscript);
83137

84138
#endif // BITCOIN_SCRIPT_STANDARD_H

0 commit comments

Comments
 (0)