Skip to content

Commit 177c15d

Browse files
committed
Limit LegacyScriptPubKeyMan address types
Make sure that LegacyScriptPubKeyMan can only be used for legacy, p2sh-segwit, and bech32 address types.
1 parent c93e123 commit 177c15d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;
2222

2323
bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
2424
{
25+
if (LEGACY_OUTPUT_TYPES.count(type) == 0) {
26+
error = _("Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types").translated;
27+
return false;
28+
}
29+
2530
LOCK(cs_KeyStore);
2631
error.clear();
2732

@@ -291,6 +296,10 @@ bool LegacyScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, WalletBat
291296

292297
bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool)
293298
{
299+
if (LEGACY_OUTPUT_TYPES.count(type) == 0) {
300+
return false;
301+
}
302+
294303
LOCK(cs_KeyStore);
295304
if (!CanGetAddresses(internal)) {
296305
return false;

src/wallet/scriptpubkeyman.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@ class ScriptPubKeyMan
254254
boost::signals2::signal<void ()> NotifyCanGetAddressesChanged;
255255
};
256256

257+
/** OutputTypes supported by the LegacyScriptPubKeyMan */
258+
static const std::unordered_set<OutputType> LEGACY_OUTPUT_TYPES {
259+
OutputType::LEGACY,
260+
OutputType::P2SH_SEGWIT,
261+
OutputType::BECH32,
262+
};
263+
257264
class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProvider
258265
{
259266
private:

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,7 @@ void CWallet::SetupLegacyScriptPubKeyMan()
30333033
}
30343034

30353035
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new LegacyScriptPubKeyMan(*this));
3036-
for (const auto& type : OUTPUT_TYPES) {
3036+
for (const auto& type : LEGACY_OUTPUT_TYPES) {
30373037
m_internal_spk_managers[type] = spk_manager.get();
30383038
m_external_spk_managers[type] = spk_manager.get();
30393039
}

0 commit comments

Comments
 (0)