mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-23 05:09:26 +02:00
Separate WitnessV1Taproot variant in CTxDestination
This commit is contained in:
@@ -645,6 +645,7 @@ static std::optional<OutputType> OutputTypeFromDestination(const CTxDestination&
|
||||
}
|
||||
if (std::holds_alternative<WitnessV0KeyHash>(dest) ||
|
||||
std::holds_alternative<WitnessV0ScriptHash>(dest) ||
|
||||
std::holds_alternative<WitnessV1Taproot>(dest) ||
|
||||
std::holds_alternative<WitnessUnknown>(dest)) {
|
||||
return OutputType::BECH32;
|
||||
}
|
||||
|
||||
@@ -242,13 +242,9 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
|
||||
return true;
|
||||
}
|
||||
case TxoutType::WITNESS_V1_TAPROOT: {
|
||||
/* For now, no WitnessV1Taproot variant in CTxDestination exists, so map
|
||||
* this to WitnessUnknown. */
|
||||
WitnessUnknown unk;
|
||||
unk.version = 1;
|
||||
std::copy(vSolutions[0].begin(), vSolutions[0].end(), unk.program);
|
||||
unk.length = vSolutions[0].size();
|
||||
addressRet = unk;
|
||||
WitnessV1Taproot tap;
|
||||
std::copy(vSolutions[0].begin(), vSolutions[0].end(), tap.begin());
|
||||
addressRet = tap;
|
||||
return true;
|
||||
}
|
||||
case TxoutType::WITNESS_UNKNOWN: {
|
||||
@@ -337,6 +333,11 @@ public:
|
||||
return CScript() << OP_0 << ToByteVector(id);
|
||||
}
|
||||
|
||||
CScript operator()(const WitnessV1Taproot& tap) const
|
||||
{
|
||||
return CScript() << OP_1 << ToByteVector(tap);
|
||||
}
|
||||
|
||||
CScript operator()(const WitnessUnknown& id) const
|
||||
{
|
||||
return CScript() << CScript::EncodeOP_N(id.version) << std::vector<unsigned char>(id.program, id.program + id.length);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#ifndef BITCOIN_SCRIPT_STANDARD_H
|
||||
#define BITCOIN_SCRIPT_STANDARD_H
|
||||
|
||||
#include <pubkey.h>
|
||||
#include <script/interpreter.h>
|
||||
#include <uint256.h>
|
||||
#include <util/hash_type.h>
|
||||
@@ -113,6 +114,12 @@ struct WitnessV0KeyHash : public BaseHash<uint160>
|
||||
};
|
||||
CKeyID ToKeyID(const WitnessV0KeyHash& key_hash);
|
||||
|
||||
struct WitnessV1Taproot : public XOnlyPubKey
|
||||
{
|
||||
WitnessV1Taproot() : XOnlyPubKey() {}
|
||||
explicit WitnessV1Taproot(const XOnlyPubKey& xpk) : XOnlyPubKey(xpk) {}
|
||||
};
|
||||
|
||||
//! CTxDestination subtype to encode any future Witness version
|
||||
struct WitnessUnknown
|
||||
{
|
||||
@@ -142,11 +149,11 @@ struct WitnessUnknown
|
||||
* * ScriptHash: TxoutType::SCRIPTHASH destination (P2SH)
|
||||
* * WitnessV0ScriptHash: TxoutType::WITNESS_V0_SCRIPTHASH destination (P2WSH)
|
||||
* * WitnessV0KeyHash: TxoutType::WITNESS_V0_KEYHASH destination (P2WPKH)
|
||||
* * WitnessUnknown: TxoutType::WITNESS_UNKNOWN/WITNESS_V1_TAPROOT destination (P2W???)
|
||||
* (taproot outputs do not require their own type as long as no wallet support exists)
|
||||
* * WitnessV1Taproot: TxoutType::WITNESS_V1_TAPROOT destination (P2TR)
|
||||
* * WitnessUnknown: TxoutType::WITNESS_UNKNOWN destination (P2W???)
|
||||
* A CTxDestination is the internal data type encoded in a bitcoin address
|
||||
*/
|
||||
using CTxDestination = std::variant<CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown>;
|
||||
using CTxDestination = std::variant<CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown>;
|
||||
|
||||
/** Check whether a CTxDestination is a CNoDestination. */
|
||||
bool IsValidDestination(const CTxDestination& dest);
|
||||
|
||||
Reference in New Issue
Block a user