From 596f6460f9fd8273665c8754ccd673d93a4f25f0 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 7 Oct 2019 14:11:34 -0400 Subject: [PATCH] Key pool: Move CanGetAddresses call Call LegacyScriptPubKeyMan::CanGetAddresses directly instead of calling CWallet::CanGetAddresses to only query the relevant key manager This is a minor change in behavior: call now only happens if a new key needs to be reserved, since if a key is already reserved it might fail unnecessarily. This change also serves as a sanity check https://github.com/bitcoin/bitcoin/pull/16341#discussion_r331238394 --- src/wallet/scriptpubkeyman.cpp | 4 ++++ src/wallet/wallet.cpp | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 3eaaf3786c3..9c5f2b5098d 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -264,6 +264,10 @@ bool LegacyScriptPubKeyMan::EncryptKeys(CKeyingMaterial& vMasterKeyIn) bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) { + if (!CanGetAddresses(internal)) { + return false; + } + if (!ReserveKeyFromKeyPool(index, keypool, internal)) { return false; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b1e1385ca36..89309a01d66 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3298,9 +3298,6 @@ bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool inter return false; } - if (!pwallet->CanGetAddresses(internal)) { - return false; - } if (nIndex == -1) {