mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-04 12:55:02 +02:00
Merge #17373: wallet: Various fixes and cleanup to keypool handling in LegacyScriptPubKeyMan and CWallet
886f1731beKey pool: Fix omitted pre-split count in GetKeyPoolSize (Andrew Chow)386a994b85Key pool: Change ReturnDestination interface to take address instead of key (Andrew Chow)ba41aa4969Key pool: Move LearnRelated and GetDestination calls (Andrew Chow)65833a7407Add OutputType and CPubKey parameters to KeepDestination (Andrew Chow)9fcf8ce7aeRename Keep/ReturnKey to Keep/ReturnDestination and remove the wrapper (Andrew Chow)596f6460f9Key pool: Move CanGetAddresses call (Andrew Chow) Pull request description: * The `pwallet->CanGetAddresses()` call in `ReserveDestination::GetReservedDestination` to `LegacyScriptPubKeyMan::GetReservedDestination` so that the sanity check results in a failure when a `ScriptPubKeyMan` individually cannot get a destination, not when any of the `ScriptPubKeyMan`s can't. * `ScriptPubKeyMan::GetReservedDestination` is changed to return the destination so that future `ScriptPubKeyMan`s can return destinations constructed in other ways. This is implemented for `LegacyScriptPubKeyMan` by moving key-to-destination code from `CWallet` to `LegacyScriptPubKeyMan` * In order for `ScriptPubKeyMan` to be generic and work with future `ScriptPubKeyMan`s, `ScriptPubKeyMan::ReturnDestination` is changed to take a `CTxDestination` instead of a `CPubKey`. Since `LegacyScriptPubKeyMan` still deals with keys internally, a new map `m_reserved_key_to_index` is added in order to track the keypool indexes that have been reserved. * A bug is fixed in how the total keypool size is calculated as it was omitting `set_pre_split_keypool` which is a bug. Split from #17261 ACKs for top commit: ryanofsky: Code review ACK886f1731be. Only change is moving earlier fix to a better commit (same end result). promag: Code review ACK886f1731be. instagibbs: code review re-ACK886f1731beSjors: Code review re-ACK886f1731beTree-SHA512: f4be290759f63fdc920d5c02bd0d09acc4b06a5f053787d4afcd3c921b2e35d2bd97617fadae015da853dc189f559fb8d2c6e58d53e4cabfac9af151cd97ad19
This commit is contained in:
@@ -3295,21 +3295,15 @@ bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool inter
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pwallet->CanGetAddresses(internal)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -3317,21 +3311,18 @@ bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool inter
|
||||
void ReserveDestination::KeepDestination()
|
||||
{
|
||||
if (nIndex != -1) {
|
||||
m_spk_man->KeepDestination(nIndex);
|
||||
m_spk_man->LearnRelatedScripts(vchPubKey, type);
|
||||
m_spk_man->KeepDestination(nIndex, type);
|
||||
}
|
||||
nIndex = -1;
|
||||
vchPubKey = CPubKey();
|
||||
address = CNoDestination();
|
||||
}
|
||||
|
||||
void ReserveDestination::ReturnDestination()
|
||||
{
|
||||
if (nIndex != -1) {
|
||||
m_spk_man->ReturnDestination(nIndex, fInternal, vchPubKey);
|
||||
m_spk_man->ReturnDestination(nIndex, fInternal, address);
|
||||
}
|
||||
nIndex = -1;
|
||||
vchPubKey = CPubKey();
|
||||
address = CNoDestination();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user