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-12-02 11:57:20 -0500
commitba41aa4969169cd73d6b4f57444ed7d8d875de10 (patch)
tree1645f6defd962dc195bde34031a862a9bc84eed3 /src
parent65833a74076cddf986037c6eb3b29a9b9dbe31c5 (diff)
downloadbitcoin-ba41aa4969169cd73d6b4f57444ed7d8d875de10.tar.xz
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.
Diffstat (limited to 'src')
-rw-r--r--src/wallet/scriptpubkeyman.cpp4
-rw-r--r--src/wallet/scriptpubkeyman.h4
-rw-r--r--src/wallet/wallet.cpp4
-rw-r--r--src/wallet/wallet.h3
4 files changed, 8 insertions, 7 deletions
diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp
index f7153a751f..4986871fb7 100644
--- a/src/wallet/scriptpubkeyman.cpp
+++ b/src/wallet/scriptpubkeyman.cpp
@@ -262,7 +262,7 @@ bool LegacyScriptPubKeyMan::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
return true;
}
-bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool)
+bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool)
{
if (!CanGetAddresses(internal)) {
return false;
@@ -271,6 +271,7 @@ bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool i
if (!ReserveKeyFromKeyPool(index, keypool, internal)) {
return false;
}
+ address = GetDestinationForKey(keypool.vchPubKey, type);
return true;
}
@@ -1091,6 +1092,7 @@ void LegacyScriptPubKeyMan::KeepDestination(int64_t nIndex, const OutputType& ty
// Remove from key pool
WalletBatch batch(m_storage.GetDatabase());
batch.ErasePool(nIndex);
+ LearnRelatedScripts(pubkey, type);
WalletLogPrintf("keypool keep %d\n", nIndex);
}
diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h
index 16901952a6..bcc62ece1e 100644
--- a/src/wallet/scriptpubkeyman.h
+++ b/src/wallet/scriptpubkeyman.h
@@ -150,7 +150,7 @@ public:
virtual bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) { return false; }
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
- virtual bool GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) { return false; }
+ virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) { return false; }
virtual void KeepDestination(int64_t index, const OutputType& type, const CPubKey& pubkey) {}
virtual void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) {}
@@ -273,7 +273,7 @@ public:
//! will encrypt previously unencrypted keys
bool EncryptKeys(CKeyingMaterial& vMasterKeyIn);
- bool GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) override;
+ bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) override;
void KeepDestination(int64_t index, const OutputType& type, const CPubKey& pubkey) override;
void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) override;
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 179e7b39ea..2bdec16f28 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -3302,14 +3302,13 @@ bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool inter
if (nIndex == -1)
{
CKeyPool keypool;
- if (!m_spk_man->GetReservedDestination(type, internal, nIndex, keypool)) {
+ if (!m_spk_man->GetReservedDestination(type, internal, address, nIndex, keypool)) {
return false;
}
vchPubKey = keypool.vchPubKey;
fInternal = keypool.fInternal;
}
assert(vchPubKey.IsValid());
- address = GetDestinationForKey(vchPubKey, type);
dest = address;
return true;
}
@@ -3318,7 +3317,6 @@ void ReserveDestination::KeepDestination()
{
if (nIndex != -1) {
m_spk_man->KeepDestination(nIndex, type, vchPubKey);
- m_spk_man->LearnRelatedScripts(vchPubKey, type);
}
nIndex = -1;
vchPubKey = CPubKey();
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index fce49ec56c..f6cbe6f6de 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -141,7 +141,8 @@ class ReserveDestination
protected:
//! The wallet to reserve from
CWallet* const pwallet;
- LegacyScriptPubKeyMan* m_spk_man{nullptr};
+ //! The ScriptPubKeyMan to reserve from. Based on type when GetReservedDestination is called
+ ScriptPubKeyMan* m_spk_man{nullptr};
OutputType const type;
//! The index of the address's key in the keypool
int64_t nIndex{-1};