Skip to content

Commit ca2a096

Browse files
committed
Change SetType to SetInternal and remove m_address_type
m_address_type was used for two things: 1. Determine the type of descriptor to generate during SetupDescriptorGeneration 2. Sanity check during GetNewDestination. There is no need to have this variable to accomplish those things. 1. Add a argument to SetupDescriptorGeneration indicating the address type to use 2. Use Descriptor::GetOutputType for the sanity check.
1 parent 89b1ce1 commit ca2a096

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
14971497
return set_address;
14981498
}
14991499

1500-
void LegacyScriptPubKeyMan::SetType(OutputType type, bool internal) {}
1500+
void LegacyScriptPubKeyMan::SetInternal(bool internal) {}
15011501

15021502
bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
15031503
{
@@ -1509,7 +1509,9 @@ bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDest
15091509
{
15101510
LOCK(cs_desc_man);
15111511
assert(m_wallet_descriptor.descriptor->IsSingleType()); // This is a combo descriptor which should not be an active descriptor
1512-
if (type != m_address_type) {
1512+
Optional<OutputType> desc_addr_type = m_wallet_descriptor.descriptor->GetOutputType();
1513+
assert(desc_addr_type);
1514+
if (type != *desc_addr_type) {
15131515
throw std::runtime_error(std::string(__func__) + ": Types are inconsistent");
15141516
}
15151517

@@ -1777,7 +1779,7 @@ bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const
17771779
}
17781780
}
17791781

1780-
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key)
1782+
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key, OutputType addr_type)
17811783
{
17821784
LOCK(cs_desc_man);
17831785
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
@@ -1794,7 +1796,7 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
17941796
// Build descriptor string
17951797
std::string desc_prefix;
17961798
std::string desc_suffix = "/*)";
1797-
switch (m_address_type) {
1799+
switch (addr_type) {
17981800
case OutputType::LEGACY: {
17991801
desc_prefix = "pkh(" + xpub + "/44'";
18001802
break;
@@ -2076,9 +2078,8 @@ uint256 DescriptorScriptPubKeyMan::GetID() const
20762078
return id;
20772079
}
20782080

2079-
void DescriptorScriptPubKeyMan::SetType(OutputType type, bool internal)
2081+
void DescriptorScriptPubKeyMan::SetInternal(bool internal)
20802082
{
2081-
this->m_address_type = type;
20822083
this->m_internal = internal;
20832084
}
20842085

src/wallet/scriptpubkeyman.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class ScriptPubKeyMan
224224

225225
virtual uint256 GetID() const { return uint256(); }
226226

227-
virtual void SetType(OutputType type, bool internal) {}
227+
virtual void SetInternal(bool internal) {}
228228

229229
/** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */
230230
template<typename... Params>
@@ -370,7 +370,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
370370

371371
uint256 GetID() const override;
372372

373-
void SetType(OutputType type, bool internal) override;
373+
void SetInternal(bool internal) override;
374374

375375
// Map from Key ID to key metadata.
376376
std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_KeyStore);
@@ -497,7 +497,6 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
497497
PubKeyMap m_map_pubkeys GUARDED_BY(cs_desc_man);
498498
int32_t m_max_cached_index = -1;
499499

500-
OutputType m_address_type;
501500
bool m_internal = false;
502501

503502
KeyMap m_map_keys GUARDED_BY(cs_desc_man);
@@ -522,9 +521,9 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
522521
: ScriptPubKeyMan(storage),
523522
m_wallet_descriptor(descriptor)
524523
{}
525-
DescriptorScriptPubKeyMan(WalletStorage& storage, OutputType address_type, bool internal)
524+
DescriptorScriptPubKeyMan(WalletStorage& storage, bool internal)
526525
: ScriptPubKeyMan(storage),
527-
m_address_type(address_type), m_internal(internal)
526+
m_internal(internal)
528527
{}
529528

530529
mutable RecursiveMutex cs_desc_man;
@@ -549,7 +548,7 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
549548
bool IsHDEnabled() const override;
550549

551550
//! Setup descriptors based on the given CExtkey
552-
bool SetupDescriptorGeneration(const CExtKey& master_key);
551+
bool SetupDescriptorGeneration(const CExtKey& master_key, OutputType addr_type);
553552

554553
bool HavePrivateKeys() const override;
555554

@@ -573,7 +572,7 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
573572

574573
uint256 GetID() const override;
575574

576-
void SetType(OutputType type, bool internal) override;
575+
void SetInternal(bool internal) override;
577576

578577
void SetCache(const DescriptorCache& cache);
579578

src/wallet/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,7 +4369,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
43694369

43704370
for (bool internal : {false, true}) {
43714371
for (OutputType t : OUTPUT_TYPES) {
4372-
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, t, internal));
4372+
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, internal));
43734373
if (IsCrypted()) {
43744374
if (IsLocked()) {
43754375
throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors");
@@ -4378,7 +4378,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
43784378
throw std::runtime_error(std::string(__func__) + ": Could not encrypt new descriptors");
43794379
}
43804380
}
4381-
spk_manager->SetupDescriptorGeneration(master_key);
4381+
spk_manager->SetupDescriptorGeneration(master_key, t);
43824382
uint256 id = spk_manager->GetID();
43834383
m_spk_managers[id] = std::move(spk_manager);
43844384
SetActiveScriptPubKeyMan(id, t, internal);
@@ -4391,7 +4391,7 @@ void CWallet::SetActiveScriptPubKeyMan(uint256 id, OutputType type, bool interna
43914391
WalletLogPrintf("Setting spkMan to active: id = %s, type = %d, internal = %d\n", id.ToString(), static_cast<int>(type), static_cast<int>(internal));
43924392
auto& spk_mans = internal ? m_internal_spk_managers : m_external_spk_managers;
43934393
auto spk_man = m_spk_managers.at(id).get();
4394-
spk_man->SetType(type, internal);
4394+
spk_man->SetInternal(internal);
43954395
spk_mans[type] = spk_man;
43964396

43974397
if (!memonly) {

0 commit comments

Comments
 (0)