mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
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:
parent
65833a7407
commit
ba41aa4969
4 changed files with 8 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Add table
Reference in a new issue