diff options
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/rpcwallet.cpp | 6 | ||||
-rw-r--r-- | src/wallet/scriptpubkeyman.cpp | 7 | ||||
-rw-r--r-- | src/wallet/scriptpubkeyman.h | 7 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 12 | ||||
-rw-r--r-- | src/wallet/wallet.h | 2 |
5 files changed, 19 insertions, 15 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index babb61b03a..e24d1111c7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2522,7 +2522,6 @@ static RPCHelpMan getwalletinfo() size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); const auto bal = GetBalance(*pwallet); - int64_t kp_oldest = pwallet->GetOldestKeyPoolTime(); obj.pushKV("walletname", pwallet->GetName()); obj.pushKV("walletversion", pwallet->GetVersion()); obj.pushKV("format", pwallet->GetDatabase().Format()); @@ -2530,8 +2529,9 @@ static RPCHelpMan getwalletinfo() obj.pushKV("unconfirmed_balance", ValueFromAmount(bal.m_mine_untrusted_pending)); obj.pushKV("immature_balance", ValueFromAmount(bal.m_mine_immature)); obj.pushKV("txcount", (int)pwallet->mapWallet.size()); - if (kp_oldest > 0) { - obj.pushKV("keypoololdest", kp_oldest); + const auto kp_oldest = pwallet->GetOldestKeyPoolTime(); + if (kp_oldest.has_value()) { + obj.pushKV("keypoololdest", kp_oldest.value()); } obj.pushKV("keypoolsize", (int64_t)kpExternalSize); diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 9173c790d4..faeb6068db 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -528,7 +528,7 @@ static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, Walle return keypool.nTime; } -int64_t LegacyScriptPubKeyMan::GetOldestKeyPoolTime() const +std::optional<int64_t> LegacyScriptPubKeyMan::GetOldestKeyPoolTime() const { LOCK(cs_KeyStore); @@ -1970,11 +1970,10 @@ bool DescriptorScriptPubKeyMan::HavePrivateKeys() const return m_map_keys.size() > 0 || m_map_crypted_keys.size() > 0; } -int64_t DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() const +std::optional<int64_t> DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() const { // This is only used for getwalletinfo output and isn't relevant to descriptor wallets. - // The magic number 0 indicates that it shouldn't be displayed so that's what we return. - return 0; + return std::nullopt; } diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index ef74638751..2d447f1d67 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -19,6 +19,7 @@ #include <boost/signals2/signal.hpp> +#include <optional> #include <unordered_map> enum class OutputType; @@ -203,7 +204,7 @@ public: //! The action to do when the DB needs rewrite virtual void RewriteDB() {} - virtual int64_t GetOldestKeyPoolTime() const { return GetTime(); } + virtual std::optional<int64_t> GetOldestKeyPoolTime() const { return GetTime(); } virtual unsigned int GetKeyPoolSize() const { return 0; } @@ -371,7 +372,7 @@ public: void RewriteDB() override; - int64_t GetOldestKeyPoolTime() const override; + std::optional<int64_t> GetOldestKeyPoolTime() const override; size_t KeypoolCountExternalKeys() const; unsigned int GetKeyPoolSize() const override; @@ -577,7 +578,7 @@ public: bool HavePrivateKeys() const override; - int64_t GetOldestKeyPoolTime() const override; + std::optional<int64_t> GetOldestKeyPoolTime() const override; unsigned int GetKeyPoolSize() const override; int64_t GetTimeFirstKey() const override; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7f60dd6906..e586785c24 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2169,14 +2169,18 @@ bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& des return true; } -int64_t CWallet::GetOldestKeyPoolTime() const +std::optional<int64_t> CWallet::GetOldestKeyPoolTime() const { LOCK(cs_wallet); - int64_t oldestKey = std::numeric_limits<int64_t>::max(); + if (m_spk_managers.empty()) { + return std::nullopt; + } + + std::optional<int64_t> oldest_key{std::numeric_limits<int64_t>::max()}; for (const auto& spk_man_pair : m_spk_managers) { - oldestKey = std::min(oldestKey, spk_man_pair.second->GetOldestKeyPoolTime()); + oldest_key = std::min(oldest_key, spk_man_pair.second->GetOldestKeyPoolTime()); } - return oldestKey; + return oldest_key; } void CWallet::MarkDestinationsDirty(const std::set<CTxDestination>& destinations) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 3855ad821d..bab8314c76 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -632,7 +632,7 @@ public: size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool TopUpKeyPool(unsigned int kpSize = 0); - int64_t GetOldestKeyPoolTime() const; + std::optional<int64_t> GetOldestKeyPoolTime() const; std::set<CTxDestination> GetLabelAddresses(const std::string& label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); |