14
14
#include < algorithm>
15
15
16
16
class CNoDestination {
17
+ private:
18
+ CScript m_script;
19
+
17
20
public:
18
- friend bool operator ==(const CNoDestination &a, const CNoDestination &b) { return true ; }
19
- friend bool operator <(const CNoDestination &a, const CNoDestination &b) { return true ; }
21
+ CNoDestination () = default ;
22
+ CNoDestination (const CScript& script) : m_script(script) {}
23
+
24
+ const CScript& GetScript () const { return m_script; }
25
+
26
+ friend bool operator ==(const CNoDestination& a, const CNoDestination& b) { return a.GetScript () == b.GetScript (); }
27
+ friend bool operator <(const CNoDestination& a, const CNoDestination& b) { return a.GetScript () < b.GetScript (); }
20
28
};
21
29
22
30
struct PKHash : public BaseHash <uint160>
@@ -93,14 +101,14 @@ struct WitnessUnknown
93
101
};
94
102
95
103
/* *
96
- * A txout script template with a specific destination. It is either:
97
- * * CNoDestination: no destination set
98
- * * PKHash: TxoutType::PUBKEYHASH destination (P2PKH)
99
- * * ScriptHash: TxoutType::SCRIPTHASH destination (P2SH)
100
- * * WitnessV0ScriptHash: TxoutType::WITNESS_V0_SCRIPTHASH destination (P2WSH)
101
- * * WitnessV0KeyHash: TxoutType::WITNESS_V0_KEYHASH destination (P2WPKH)
102
- * * WitnessV1Taproot: TxoutType::WITNESS_V1_TAPROOT destination (P2TR)
103
- * * WitnessUnknown: TxoutType::WITNESS_UNKNOWN destination (P2W???)
104
+ * A txout script categorized into standard templates.
105
+ * * CNoDestination: Optionally a script, no corresponding address.
106
+ * * PKHash: TxoutType::PUBKEYHASH destination (P2PKH address )
107
+ * * ScriptHash: TxoutType::SCRIPTHASH destination (P2SH address )
108
+ * * WitnessV0ScriptHash: TxoutType::WITNESS_V0_SCRIPTHASH destination (P2WSH address )
109
+ * * WitnessV0KeyHash: TxoutType::WITNESS_V0_KEYHASH destination (P2WPKH address )
110
+ * * WitnessV1Taproot: TxoutType::WITNESS_V1_TAPROOT destination (P2TR address )
111
+ * * WitnessUnknown: TxoutType::WITNESS_UNKNOWN destination (P2W??? address )
104
112
* A CTxDestination is the internal data type encoded in a bitcoin address
105
113
*/
106
114
using CTxDestination = std::variant<CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown>;
@@ -109,9 +117,14 @@ using CTxDestination = std::variant<CNoDestination, PKHash, ScriptHash, WitnessV
109
117
bool IsValidDestination (const CTxDestination& dest);
110
118
111
119
/* *
112
- * Parse a standard scriptPubKey for the destination address. Assigns result to
113
- * the addressRet parameter and returns true if successful. Currently only works for P2PK,
114
- * P2PKH, P2SH, P2WPKH, and P2WSH scripts.
120
+ * Parse a scriptPubKey for the destination.
121
+ *
122
+ * For standard scripts that have addresses (and P2PK as an exception), a corresponding CTxDestination
123
+ * is assigned to addressRet.
124
+ * For all other scripts. addressRet is assigned as a CNoDestination containing the scriptPubKey.
125
+ *
126
+ * Returns true for standard destinations - P2PK, P2PKH, P2SH, P2WPKH, P2WSH, and P2TR scripts.
127
+ * Returns false for non-standard destinations - P2PK with invalid pubkeys, P2W???, bare multisig, null data, and nonstandard scripts.
115
128
*/
116
129
bool ExtractDestination (const CScript& scriptPubKey, CTxDestination& addressRet);
117
130
0 commit comments