Skip to content

Commit ba41aa4

Browse files
committed
Key pool: Move LearnRelated and GetDestination calls
Addresses are determined by LegacyScriptPubKeyMan::GetReservedDestination instead of ReserveDestination::GetReservedDestination as other ScriptPubKeyMan implementations may construct addresses differently This does not change behavior.
1 parent 65833a7 commit ba41aa4

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ bool LegacyScriptPubKeyMan::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
262262
return true;
263263
}
264264

265-
bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool)
265+
bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool)
266266
{
267267
if (!CanGetAddresses(internal)) {
268268
return false;
@@ -271,6 +271,7 @@ bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool i
271271
if (!ReserveKeyFromKeyPool(index, keypool, internal)) {
272272
return false;
273273
}
274+
address = GetDestinationForKey(keypool.vchPubKey, type);
274275
return true;
275276
}
276277

@@ -1091,6 +1092,7 @@ void LegacyScriptPubKeyMan::KeepDestination(int64_t nIndex, const OutputType& ty
10911092
// Remove from key pool
10921093
WalletBatch batch(m_storage.GetDatabase());
10931094
batch.ErasePool(nIndex);
1095+
LearnRelatedScripts(pubkey, type);
10941096
WalletLogPrintf("keypool keep %d\n", nIndex);
10951097
}
10961098

src/wallet/scriptpubkeyman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class ScriptPubKeyMan
150150
virtual bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) { return false; }
151151
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
152152

153-
virtual bool GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) { return false; }
153+
virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) { return false; }
154154
virtual void KeepDestination(int64_t index, const OutputType& type, const CPubKey& pubkey) {}
155155
virtual void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) {}
156156

@@ -273,7 +273,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
273273
//! will encrypt previously unencrypted keys
274274
bool EncryptKeys(CKeyingMaterial& vMasterKeyIn);
275275

276-
bool GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) override;
276+
bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) override;
277277
void KeepDestination(int64_t index, const OutputType& type, const CPubKey& pubkey) override;
278278
void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) override;
279279

src/wallet/wallet.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3302,14 +3302,13 @@ bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool inter
33023302
if (nIndex == -1)
33033303
{
33043304
CKeyPool keypool;
3305-
if (!m_spk_man->GetReservedDestination(type, internal, nIndex, keypool)) {
3305+
if (!m_spk_man->GetReservedDestination(type, internal, address, nIndex, keypool)) {
33063306
return false;
33073307
}
33083308
vchPubKey = keypool.vchPubKey;
33093309
fInternal = keypool.fInternal;
33103310
}
33113311
assert(vchPubKey.IsValid());
3312-
address = GetDestinationForKey(vchPubKey, type);
33133312
dest = address;
33143313
return true;
33153314
}
@@ -3318,7 +3317,6 @@ void ReserveDestination::KeepDestination()
33183317
{
33193318
if (nIndex != -1) {
33203319
m_spk_man->KeepDestination(nIndex, type, vchPubKey);
3321-
m_spk_man->LearnRelatedScripts(vchPubKey, type);
33223320
}
33233321
nIndex = -1;
33243322
vchPubKey = CPubKey();

src/wallet/wallet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ class ReserveDestination
141141
protected:
142142
//! The wallet to reserve from
143143
CWallet* const pwallet;
144-
LegacyScriptPubKeyMan* m_spk_man{nullptr};
144+
//! The ScriptPubKeyMan to reserve from. Based on type when GetReservedDestination is called
145+
ScriptPubKeyMan* m_spk_man{nullptr};
145146
OutputType const type;
146147
//! The index of the address's key in the keypool
147148
int64_t nIndex{-1};

0 commit comments

Comments
 (0)