aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2019-10-07 14:11:34 -0400
committerAndrew Chow <achow101-github@achow101.com>2019-11-01 22:58:05 -0400
commit152b0a00d8e681dd098f6b548447b82ab54ebe3c (patch)
treecb55db76e9f2ebdca3476c4304673ef8c3fa09ee /src
parent7ef47b88e67718766c92d23973742d08436176e0 (diff)
downloadbitcoin-152b0a00d8e681dd098f6b548447b82ab54ebe3c.tar.xz
Refactor: Move nTimeFirstKey accesses out of CWallet
This commit does not change behavior.
Diffstat (limited to 'src')
-rw-r--r--src/wallet/scriptpubkeyman.cpp6
-rw-r--r--src/wallet/scriptpubkeyman.h4
-rw-r--r--src/wallet/wallet.cpp9
-rw-r--r--src/wallet/wallet.h1
4 files changed, 17 insertions, 3 deletions
diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp
index a046a7c93e..bb13db11ba 100644
--- a/src/wallet/scriptpubkeyman.cpp
+++ b/src/wallet/scriptpubkeyman.cpp
@@ -470,6 +470,12 @@ unsigned int LegacyScriptPubKeyMan::GetKeyPoolSize() const
return setInternalKeyPool.size() + setExternalKeyPool.size();
}
+int64_t LegacyScriptPubKeyMan::GetTimeFirstKey() const
+{
+ AssertLockHeld(cs_wallet);
+ return nTimeFirstKey;
+}
+
const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(uint160 id) const
{
AssertLockHeld(cs_wallet);
diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h
index b9722ea63f..0dbf98ee94 100644
--- a/src/wallet/scriptpubkeyman.h
+++ b/src/wallet/scriptpubkeyman.h
@@ -184,6 +184,8 @@ public:
virtual size_t KeypoolCountExternalKeys() { return 0; }
virtual unsigned int GetKeyPoolSize() const { return 0; }
+ virtual int64_t GetTimeFirstKey() const { return 0; }
+
virtual const CKeyMetadata* GetMetadata(uint160 id) const { return nullptr; }
};
@@ -298,6 +300,8 @@ public:
size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
unsigned int GetKeyPoolSize() const override;
+ int64_t GetTimeFirstKey() const override;
+
const CKeyMetadata* GetMetadata(uint160 id) const override;
bool CanGetAddresses(bool internal = false) override;
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 3dff6f7d61..b10a5deedc 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -3804,8 +3804,13 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
// No need to read and scan block if block was created before
// our wallet birthday (as adjusted for block time variability)
- if (walletInstance->nTimeFirstKey) {
- if (Optional<int> first_block = locked_chain->findFirstBlockWithTimeAndHeight(walletInstance->nTimeFirstKey - TIMESTAMP_WINDOW, rescan_height, nullptr)) {
+ Optional<int64_t> time_first_key;
+ if (auto spk_man = walletInstance->m_spk_man.get()) {
+ int64_t time = spk_man->GetTimeFirstKey();
+ if (!time_first_key || time < *time_first_key) time_first_key = time;
+ }
+ if (time_first_key) {
+ if (Optional<int> first_block = locked_chain->findFirstBlockWithTimeAndHeight(*time_first_key - TIMESTAMP_WINDOW, rescan_height, nullptr)) {
rescan_height = *first_block;
}
}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 49c27eb9f6..7d0fae0bc7 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -1127,7 +1127,6 @@ public:
LegacyScriptPubKeyMan::WatchOnlySet& setWatchOnly GUARDED_BY(cs_KeyStore) = m_spk_man->setWatchOnly;
LegacyScriptPubKeyMan::WatchKeyMap& mapWatchKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapWatchKeys;
WalletBatch*& encrypted_batch GUARDED_BY(cs_wallet) = m_spk_man->encrypted_batch;
- int64_t& nTimeFirstKey GUARDED_BY(cs_wallet) = m_spk_man->nTimeFirstKey;
using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap;
};