Skip to content

Commit 0262536

Browse files
committed
Add OutputType::BECH32M
Bech32m addresses need their own OutputType We are not ready to create DescriptorScriptPubKeyMans which produce bech32m addresses. So don't allow generating them.
1 parent 177c15d commit 0262536

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

src/outputtype.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
static const std::string OUTPUT_TYPE_STRING_LEGACY = "legacy";
1919
static const std::string OUTPUT_TYPE_STRING_P2SH_SEGWIT = "p2sh-segwit";
2020
static const std::string OUTPUT_TYPE_STRING_BECH32 = "bech32";
21+
static const std::string OUTPUT_TYPE_STRING_BECH32M = "bech32m";
2122

2223
bool ParseOutputType(const std::string& type, OutputType& output_type)
2324
{
@@ -30,6 +31,9 @@ bool ParseOutputType(const std::string& type, OutputType& output_type)
3031
} else if (type == OUTPUT_TYPE_STRING_BECH32) {
3132
output_type = OutputType::BECH32;
3233
return true;
34+
} else if (type == OUTPUT_TYPE_STRING_BECH32M) {
35+
output_type = OutputType::BECH32M;
36+
return true;
3337
}
3438
return false;
3539
}
@@ -40,6 +44,7 @@ const std::string& FormatOutputType(OutputType type)
4044
case OutputType::LEGACY: return OUTPUT_TYPE_STRING_LEGACY;
4145
case OutputType::P2SH_SEGWIT: return OUTPUT_TYPE_STRING_P2SH_SEGWIT;
4246
case OutputType::BECH32: return OUTPUT_TYPE_STRING_BECH32;
47+
case OutputType::BECH32M: return OUTPUT_TYPE_STRING_BECH32M;
4348
} // no default case, so the compiler can warn about missing cases
4449
assert(false);
4550
}
@@ -59,6 +64,7 @@ CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
5964
return witdest;
6065
}
6166
}
67+
case OutputType::BECH32M: {} // This function should never be used with BECH32M, so let it assert
6268
} // no default case, so the compiler can warn about missing cases
6369
assert(false);
6470
}
@@ -98,6 +104,7 @@ CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore,
98104
return ScriptHash(witprog);
99105
}
100106
}
107+
case OutputType::BECH32M: {} // This function should not be used for BECH32M, so let it assert
101108
} // no default case, so the compiler can warn about missing cases
102109
assert(false);
103110
}

src/outputtype.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ enum class OutputType {
1818
LEGACY,
1919
P2SH_SEGWIT,
2020
BECH32,
21+
BECH32M,
2122
};
2223

2324
static constexpr auto OUTPUT_TYPES = std::array{
2425
OutputType::LEGACY,
2526
OutputType::P2SH_SEGWIT,
2627
OutputType::BECH32,
28+
OutputType::BECH32M,
2729
};
2830

2931
[[nodiscard]] bool ParseOutputType(const std::string& str, OutputType& output_type);

src/wallet/scriptpubkeyman.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,12 @@ bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const
18891889

18901890
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key, OutputType addr_type)
18911891
{
1892+
if (addr_type == OutputType::BECH32M) {
1893+
// Don't allow setting up taproot descriptors yet
1894+
// TODO: Allow setting up taproot descriptors
1895+
return false;
1896+
}
1897+
18921898
LOCK(cs_desc_man);
18931899
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
18941900

@@ -1918,6 +1924,7 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
19181924
desc_prefix = "wpkh(" + xpub + "/84'";
19191925
break;
19201926
}
1927+
case OutputType::BECH32M: assert(false); // TODO: Setup taproot descriptor
19211928
} // no default case, so the compiler can warn about missing cases
19221929
assert(!desc_prefix.empty());
19231930

src/wallet/wallet.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,6 +3086,11 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
30863086

30873087
for (bool internal : {false, true}) {
30883088
for (OutputType t : OUTPUT_TYPES) {
3089+
if (t == OutputType::BECH32M) {
3090+
// Skip taproot (bech32m) for now
3091+
// TODO: Setup taproot (bech32m) descriptors by default
3092+
continue;
3093+
}
30893094
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, internal));
30903095
if (IsCrypted()) {
30913096
if (IsLocked()) {

0 commit comments

Comments
 (0)