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.
This commit is contained in:
1 parent
65833a7407
commit
ba41aa4969
4 files changed
+8
-7
No files matched your search
@@ -262,7 +262,7 @@ bool LegacyScriptPubKeyMan::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
|
|||||||
return true;
|
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)) {
|
if (!CanGetAddresses(internal)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -271,6 +271,7 @@ bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool i
|
|||||||
if (!ReserveKeyFromKeyPool(index, keypool, internal)) {
|
if (!ReserveKeyFromKeyPool(index, keypool, internal)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
address = GetDestinationForKey(keypool.vchPubKey, type);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1091,6 +1092,7 @@ void LegacyScriptPubKeyMan::KeepDestination(int64_t nIndex, const OutputType& ty
|
|||||||
// Remove from key pool
|
// Remove from key pool
|
||||||
WalletBatch batch(m_storage.GetDatabase());
|
WalletBatch batch(m_storage.GetDatabase());
|
||||||
batch.ErasePool(nIndex);
|
batch.ErasePool(nIndex);
|
||||||
|
LearnRelatedScripts(pubkey, type);
|
||||||
WalletLogPrintf("keypool keep %d\n", nIndex);
|
WalletLogPrintf("keypool keep %d\n", nIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ public:
|
|||||||
virtual bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) { return false; }
|
virtual bool GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error) { return false; }
|
||||||
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
|
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 KeepDestination(int64_t index, const OutputType& type, const CPubKey& pubkey) {}
|
||||||
virtual void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) {}
|
virtual void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) {}
|
||||||
|
|
||||||
@@ -273,7 +273,7 @@ public:
|
|||||||
//! will encrypt previously unencrypted keys
|
//! will encrypt previously unencrypted keys
|
||||||
bool EncryptKeys(CKeyingMaterial& vMasterKeyIn);
|
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 KeepDestination(int64_t index, const OutputType& type, const CPubKey& pubkey) override;
|
||||||
void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) override;
|
void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) override;
|
||||||
|
|
||||||
|
|||||||
@@ -3302,14 +3302,13 @@ bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool inter
|
|||||||
if (nIndex == -1)
|
if (nIndex == -1)
|
||||||
{
|
{
|
||||||
CKeyPool keypool;
|
CKeyPool keypool;
|
||||||
if (!m_spk_man->GetReservedDestination(type, internal, nIndex, keypool)) {
|
if (!m_spk_man->GetReservedDestination(type, internal, address, nIndex, keypool)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
vchPubKey = keypool.vchPubKey;
|
vchPubKey = keypool.vchPubKey;
|
||||||
fInternal = keypool.fInternal;
|
fInternal = keypool.fInternal;
|
||||||
}
|
}
|
||||||
assert(vchPubKey.IsValid());
|
assert(vchPubKey.IsValid());
|
||||||
address = GetDestinationForKey(vchPubKey, type);
|
|
||||||
dest = address;
|
dest = address;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -3318,7 +3317,6 @@ void ReserveDestination::KeepDestination()
|
|||||||
{
|
{
|
||||||
if (nIndex != -1) {
|
if (nIndex != -1) {
|
||||||
m_spk_man->KeepDestination(nIndex, type, vchPubKey);
|
m_spk_man->KeepDestination(nIndex, type, vchPubKey);
|
||||||
m_spk_man->LearnRelatedScripts(vchPubKey, type);
|
|
||||||
}
|
}
|
||||||
nIndex = -1;
|
nIndex = -1;
|
||||||
vchPubKey = CPubKey();
|
vchPubKey = CPubKey();
|
||||||
|
|||||||
+2
-1
@@ -141,7 +141,8 @@ class ReserveDestination
|
|||||||
protected:
|
protected:
|
||||||
//! The wallet to reserve from
|
//! The wallet to reserve from
|
||||||
CWallet* const pwallet;
|
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;
|
OutputType const type;
|
||||||
//! The index of the address's key in the keypool
|
//! The index of the address's key in the keypool
|
||||||
int64_t nIndex{-1};
|
int64_t nIndex{-1};
|
||||||
|
|||||||
Reference in new issue
Block a user