@@ -64,6 +64,7 @@ enum txnouttype
6464 TX_NULL_DATA, // !< unspendable OP_RETURN script that carries data
6565 TX_WITNESS_V0_SCRIPTHASH,
6666 TX_WITNESS_V0_KEYHASH,
67+ TX_WITNESS_UNKNOWN, // !< Only for Witness versions not already defined above
6768};
6869
6970class CNoDestination {
@@ -72,14 +73,42 @@ class CNoDestination {
7273 friend bool operator <(const CNoDestination &a, const CNoDestination &b) { return true ; }
7374};
7475
76+ struct WitnessV0ScriptHash : public uint256 {};
77+ struct WitnessV0KeyHash : public uint160 {};
78+
79+ // ! CTxDestination subtype to encode any future Witness version
80+ struct WitnessUnknown
81+ {
82+ unsigned int version;
83+ unsigned int length;
84+ unsigned char program[40 ];
85+
86+ friend bool operator ==(const WitnessUnknown& w1, const WitnessUnknown& w2) {
87+ if (w1.version != w2.version ) return false ;
88+ if (w1.length != w2.length ) return false ;
89+ return std::equal (w1.program , w1.program + w1.length , w2.program );
90+ }
91+
92+ friend bool operator <(const WitnessUnknown& w1, const WitnessUnknown& w2) {
93+ if (w1.version < w2.version ) return true ;
94+ if (w1.version > w2.version ) return false ;
95+ if (w1.length < w2.length ) return true ;
96+ if (w1.length > w2.length ) return false ;
97+ return std::lexicographical_compare (w1.program , w1.program + w1.length , w2.program , w2.program + w2.length );
98+ }
99+ };
100+
75101/* *
76102 * A txout script template with a specific destination. It is either:
77103 * * CNoDestination: no destination set
78- * * CKeyID: TX_PUBKEYHASH destination
79- * * CScriptID: TX_SCRIPTHASH destination
104+ * * CKeyID: TX_PUBKEYHASH destination (P2PKH)
105+ * * CScriptID: TX_SCRIPTHASH destination (P2SH)
106+ * * WitnessV0ScriptHash: TX_WITNESS_V0_SCRIPTHASH destination (P2WSH)
107+ * * WitnessV0KeyHash: TX_WITNESS_V0_KEYHASH destination (P2WPKH)
108+ * * WitnessUnknown: TX_WITNESS_UNKNOWN destination (P2W???)
80109 * A CTxDestination is the internal data type encoded in a bitcoin address
81110 */
82- typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
111+ typedef boost::variant<CNoDestination, CKeyID, CScriptID, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination;
83112
84113/* * Check whether a CTxDestination is a CNoDestination. */
85114bool IsValidDestination (const CTxDestination& dest);
@@ -104,7 +133,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
104133 * Parse a standard scriptPubKey for the destination address. Assigns result to
105134 * the addressRet parameter and returns true if successful. For multisig
106135 * scripts, instead use ExtractDestinations. Currently only works for P2PK,
107- * P2PKH, and P2SH scripts.
136+ * P2PKH, P2SH, P2WPKH, and P2WSH scripts.
108137 */
109138bool ExtractDestination (const CScript& scriptPubKey, CTxDestination& addressRet);
110139
0 commit comments