dash/src/wallet/scriptpubkeyman.h

437 lines
20 KiB
C
Raw Normal View History

Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
// Copyright (c) 2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_WALLET_SCRIPTPUBKEYMAN_H
#define BITCOIN_WALLET_SCRIPTPUBKEYMAN_H
#include <script/signingprovider.h>
#include <script/standard.h>
#include <wallet/crypter.h>
#include <wallet/ismine.h>
#include <wallet/walletdb.h>
#include <wallet/walletutil.h>
#include <boost/signals2/signal.hpp>
// Wallet storage things that ScriptPubKeyMans need in order to be able to store things to the wallet database.
// It provides access to things that are part of the entire wallet and not specific to a ScriptPubKeyMan such as
// wallet flags, wallet version, encryption keys, encryption status, and the database itself. This allows a
// ScriptPubKeyMan to have callbacks into CWallet without causing a circular dependency.
// WalletStorage should be the same for all ScriptPubKeyMans of a wallet.
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
class WalletStorage
{
public:
virtual ~WalletStorage() = default;
virtual const std::string GetDisplayName() const = 0;
virtual WalletDatabase& GetDatabase() = 0;
virtual bool IsWalletFlagSet(uint64_t) const = 0;
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
virtual void UnsetBlankWalletFlag(WalletBatch&) = 0;
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
virtual bool CanSupportFeature(enum WalletFeature) const = 0;
virtual void SetMinVersion(enum WalletFeature, WalletBatch* = nullptr, bool = false) = 0;
virtual bool IsLocked(bool fForMixing = false) const = 0;
};
//! Default for -keypool
static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
std::vector<CKeyID> GetAffectedKeys(const CScript& spk, const SigningProvider& provider);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
/** A key from a CWallet's keypool
*
* The wallet holds several keypools. These are sets of keys that have not
* yet been used to provide addresses or receive change.
*
* The Bitcoin Core wallet was originally a collection of unrelated private
* keys with their associated addresses. If a non-HD wallet generated a
* key/address, gave that address out and then restored a backup from before
* that key's generation, then any funds sent to that address would be
* lost definitively.
*
* The keypool was implemented to avoid this scenario (commit: 10384941). The
* wallet would generate a set of keys (100 by default). When a new public key
* was required, either to give out as an address or to use in a change output,
* it would be drawn from the keypool. The keypool would then be topped up to
* maintain 100 keys. This ensured that as long as the wallet hadn't used more
* than 100 keys since the previous backup, all funds would be safe, since a
* restored wallet would be able to scan for all owned addresses.
*
* A keypool also allowed encrypted wallets to give out addresses without
* having to be decrypted to generate a new private key.
*
* With the introduction of HD wallets (commit: f1902510), the keypool
* essentially became an address look-ahead pool. Restoring old backups can no
* longer definitively lose funds as long as the addresses used were from the
* wallet's HD seed (since all private keys can be rederived from the seed).
* However, if many addresses were used since the backup, then the wallet may
* not know how far ahead in the HD chain to look for its addresses. The
* keypool is used to implement a 'gap limit'. The keypool maintains a set of
* keys (by default 1000) ahead of the last used key and scans for the
* addresses of those keys. This avoids the risk of not seeing transactions
* involving the wallet's addresses, or of re-using the same address.
Merge #17719: Document better -keypool as a look-ahead safety mechanism f41d58966995fe69df433fa684117fae74a56e66 Document better -keypool as a look-ahead safety mechanism (Antoine Riard) Pull request description: If after a backup, an address is issued beyond the initial keypool range and none of the addresses in this range is seen onchain, if a wallet is restored from backup, even in case of rescan, funds may be loss due to the look-ahead buffer not being incremented and so restored wallet not detecting onchain out-of-range address as derived from its seed. This scenario is theoretically unavoidable due to the requirement of the keypool to have a max size. However, given the default keypool size, this is unlikely. Document better keypool size implications to avoid user setting a too low value. While reviewing #17681, it took me a while to figure out the safety implications of keypool, I find it would be better to document this a bit farther to avoid users shooting themselves in the foot. For further context & discussion, see https://github.com/bitcoin/bitcoin/pull/17681#issuecomment-563613452 ACKs for top commit: ryanofsky: Code review ACK f41d58966995fe69df433fa684117fae74a56e66. Just "Warning:" prefix added since the last review jonatack: ACK f41d58966995fe69df433fa684117fae74a56e66 code review and build/test. The added `Warning:` since last review is a good addition. Tree-SHA512: d3d0ee88fcdfc5c8841a2bd4bada0e4eeb412a0dce5054e5fb023643c2fa57206a0f3efb06890c245528dc4431413ed2fd5645b9319d26245d044c490b7f0db0
2020-01-29 21:09:48 +01:00
* In the unlikely case where none of the addresses in the `gap limit` are
* used on-chain, the look-ahead will not be incremented to keep
* a constant size and addresses beyond this range will not be detected by an
* old backup. For this reason, it is not recommended to decrease keypool size
* lower than default value.
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
*
* There is an external keypool (for addresses to hand out) and an internal keypool
* (for change addresses).
*
* Keypool keys are stored in the wallet/keystore's keymap. The keypool data is
* stored as sets of indexes in the wallet (setInternalKeyPool and
* setExternalKeyPool), and a map from the key to the
* index (m_pool_key_to_index). The CKeyPool object is used to
* serialize/deserialize the pool data to/from the database.
*/
class CKeyPool
{
public:
//! The time at which the key was generated. Set in AddKeypoolPubKeyWithDB
int64_t nTime;
//! The public key
CPubKey vchPubKey;
//! Whether this keypool entry is in the internal keypool (for change outputs)
bool fInternal;
CKeyPool();
CKeyPool(const CPubKey& vchPubKeyIn, bool fInternalIn);
template<typename Stream>
void Serialize(Stream& s) const
{
int nVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH)) {
s << nVersion;
}
s << nTime << vchPubKey << fInternal;
}
template<typename Stream>
void Unserialize(Stream& s)
{
int nVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH)) {
s >> nVersion;
}
s >> nTime >> vchPubKey;
try {
s >> fInternal;
} catch (std::ios_base::failure&) {
/* flag as external address if we can't read the internal boolean
(this will be the case for any wallet before the HD chain split version) */
fInternal = false;
}
}
};
/*
* A class implementing ScriptPubKeyMan manages some (or all) scriptPubKeys used in a wallet.
* It contains the scripts and keys related to the scriptPubKeys it manages.
* A ScriptPubKeyMan will be able to give out scriptPubKeys to be used, as well as marking
* when a scriptPubKey has been used. It also handles when and how to store a scriptPubKey
* and its related scripts and keys, including encryption.
*/
class ScriptPubKeyMan
{
protected:
WalletStorage& m_storage;
public:
ScriptPubKeyMan(WalletStorage& storage) : m_storage(storage) {}
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
virtual ~ScriptPubKeyMan() {};
virtual bool GetNewDestination(CTxDestination& dest, std::string& error) { return false; }
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
virtual isminetype IsMine(const CTxDestination& dest) const { return ISMINE_NO; }
Merge #17373: wallet: Various fixes and cleanup to keypool handling in LegacyScriptPubKeyMan and CWallet 886f1731bec4393dd342403ac34069a3a4f95eea Key pool: Fix omitted pre-split count in GetKeyPoolSize (Andrew Chow) 386a994b853bc5b3a2ed0d812673465b8ffa4849 Key pool: Change ReturnDestination interface to take address instead of key (Andrew Chow) ba41aa4969169cd73d6b4f57444ed7d8d875de10 Key pool: Move LearnRelated and GetDestination calls (Andrew Chow) 65833a74076cddf986037c6eb3b29a9b9dbe31c5 Add OutputType and CPubKey parameters to KeepDestination (Andrew Chow) 9fcf8ce7ae02bf170b9bf0c2887fd709d752cbf7 Rename Keep/ReturnKey to Keep/ReturnDestination and remove the wrapper (Andrew Chow) 596f6460f9fd8273665c8754ccd673d93a4f25f0 Key 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 ACK 886f1731bec4393dd342403ac34069a3a4f95eea. Only change is moving earlier fix to a better commit (same end result). promag: Code review ACK 886f1731bec4393dd342403ac34069a3a4f95eea. instagibbs: code review re-ACK https://github.com/bitcoin/bitcoin/pull/17373/commits/886f1731bec4393dd342403ac34069a3a4f95eea Sjors: Code review re-ACK 886f1731bec4393dd342403ac34069a3a4f95eea Tree-SHA512: f4be290759f63fdc920d5c02bd0d09acc4b06a5f053787d4afcd3c921b2e35d2bd97617fadae015da853dc189f559fb8d2c6e58d53e4cabfac9af151cd97ad19
2019-12-06 19:37:12 +01:00
virtual bool GetReservedDestination(bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) { return false; }
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
virtual void KeepDestination(int64_t index) {}
Merge #17373: wallet: Various fixes and cleanup to keypool handling in LegacyScriptPubKeyMan and CWallet 886f1731bec4393dd342403ac34069a3a4f95eea Key pool: Fix omitted pre-split count in GetKeyPoolSize (Andrew Chow) 386a994b853bc5b3a2ed0d812673465b8ffa4849 Key pool: Change ReturnDestination interface to take address instead of key (Andrew Chow) ba41aa4969169cd73d6b4f57444ed7d8d875de10 Key pool: Move LearnRelated and GetDestination calls (Andrew Chow) 65833a74076cddf986037c6eb3b29a9b9dbe31c5 Add OutputType and CPubKey parameters to KeepDestination (Andrew Chow) 9fcf8ce7ae02bf170b9bf0c2887fd709d752cbf7 Rename Keep/ReturnKey to Keep/ReturnDestination and remove the wrapper (Andrew Chow) 596f6460f9fd8273665c8754ccd673d93a4f25f0 Key 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 ACK 886f1731bec4393dd342403ac34069a3a4f95eea. Only change is moving earlier fix to a better commit (same end result). promag: Code review ACK 886f1731bec4393dd342403ac34069a3a4f95eea. instagibbs: code review re-ACK https://github.com/bitcoin/bitcoin/pull/17373/commits/886f1731bec4393dd342403ac34069a3a4f95eea Sjors: Code review re-ACK 886f1731bec4393dd342403ac34069a3a4f95eea Tree-SHA512: f4be290759f63fdc920d5c02bd0d09acc4b06a5f053787d4afcd3c921b2e35d2bd97617fadae015da853dc189f559fb8d2c6e58d53e4cabfac9af151cd97ad19
2019-12-06 19:37:12 +01:00
virtual void ReturnDestination(int64_t index, bool internal, const CTxDestination& addr) {}
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
virtual bool TopUp(unsigned int size = 0) { return false; }
//! Mark unused addresses as being used
virtual void MarkUnusedAddresses(WalletBatch &batch, const CScript& script, const uint256& hashBlock) {}
/* Returns true if HD is enabled */
virtual bool IsHDEnabled() const { return false; }
/* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */
virtual bool CanGetAddresses(bool internal = false) { return false; }
virtual bool HavePrivateKeys() const { return false; }
//! The action to do when the DB needs rewrite
virtual void RewriteDB() {}
virtual int64_t GetOldestKeyPoolTime() { return GetTime(); }
virtual size_t KeypoolCountExternalKeys() { return 0; }
virtual size_t KeypoolCountInternalKeys() { return 0; }
virtual unsigned int GetKeyPoolSize() const { return 0; }
virtual int64_t GetTimeFirstKey() const { return 0; }
//! Return address metadata
virtual const CKeyMetadata* GetMetadata(const CTxDestination& dest) const { return nullptr; }
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
};
class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProvider
{
private:
using WatchOnlySet = std::set<CScript>;
using WatchKeyMap = std::map<CKeyID, CPubKey>;
using HDPubKeyMap = std::map<CKeyID, CHDPubKey>;
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
WalletBatch *encrypted_batch GUARDED_BY(cs_wallet) = nullptr;
using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
CryptedKeyMap mapCryptedKeys GUARDED_BY(cs_KeyStore);
WatchOnlySet setWatchOnly GUARDED_BY(cs_KeyStore);
WatchKeyMap mapWatchKeys GUARDED_BY(cs_KeyStore);
HDPubKeyMap mapHdPubKeys GUARDED_BY(cs_KeyStore); //<! memory map of HD extended pubkeys
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
int64_t nTimeFirstKey GUARDED_BY(cs_wallet) = 0;
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
bool HaveKeyInner(const CKeyID &address) const;
bool AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey);
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
bool AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
bool GetKeyInner(const CKeyID &address, CKey& keyOut) const;
bool GetPubKeyInner(const CKeyID &address, CPubKey& vchPubKeyOut) const;
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
/**
* Private version of AddWatchOnly method which does not accept a
* timestamp, and which will reset the wallet's nTimeFirstKey value to 1 if
* the watch key did not previously have a timestamp associated with it.
* Because this is an inherited virtual method, it is accessible despite
* being marked private, but it is marked private anyway to encourage use
* of the other AddWatchOnly which accepts a timestamp and sets
* nTimeFirstKey more intelligently for more efficient rescans.
*/
bool AddWatchOnly(const CScript& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool AddWatchOnlyInMem(const CScript &dest);
void AddKeypoolPubkeyWithDB(const CPubKey& pubkey, const bool internal, WalletBatch& batch);
/** Add a KeyOriginInfo to the wallet */
bool AddKeyOriginWithDB(WalletBatch& batch, const CPubKey& pubkey, const KeyOriginInfo& info);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
/* the HD chain data model (external chain counters) */
CHDChain hdChain GUARDED_BY(cs_KeyStore);
CHDChain cryptedHDChain GUARDED_BY(cs_KeyStore);
/* HD derive new child key (on internal or external chain) */
void DeriveNewChildKey(WalletBatch& batch, CKeyMetadata& metadata, CKey& secretRet, uint32_t nAccountIndex, bool fInternal /*= false*/) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
std::set<int64_t> setInternalKeyPool GUARDED_BY(cs_wallet);
std::set<int64_t> setExternalKeyPool GUARDED_BY(cs_wallet);
int64_t m_max_keypool_index GUARDED_BY(cs_wallet) = 0;
std::map<CKeyID, int64_t> m_pool_key_to_index;
Merge #17373: wallet: Various fixes and cleanup to keypool handling in LegacyScriptPubKeyMan and CWallet 886f1731bec4393dd342403ac34069a3a4f95eea Key pool: Fix omitted pre-split count in GetKeyPoolSize (Andrew Chow) 386a994b853bc5b3a2ed0d812673465b8ffa4849 Key pool: Change ReturnDestination interface to take address instead of key (Andrew Chow) ba41aa4969169cd73d6b4f57444ed7d8d875de10 Key pool: Move LearnRelated and GetDestination calls (Andrew Chow) 65833a74076cddf986037c6eb3b29a9b9dbe31c5 Add OutputType and CPubKey parameters to KeepDestination (Andrew Chow) 9fcf8ce7ae02bf170b9bf0c2887fd709d752cbf7 Rename Keep/ReturnKey to Keep/ReturnDestination and remove the wrapper (Andrew Chow) 596f6460f9fd8273665c8754ccd673d93a4f25f0 Key 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 ACK 886f1731bec4393dd342403ac34069a3a4f95eea. Only change is moving earlier fix to a better commit (same end result). promag: Code review ACK 886f1731bec4393dd342403ac34069a3a4f95eea. instagibbs: code review re-ACK https://github.com/bitcoin/bitcoin/pull/17373/commits/886f1731bec4393dd342403ac34069a3a4f95eea Sjors: Code review re-ACK 886f1731bec4393dd342403ac34069a3a4f95eea Tree-SHA512: f4be290759f63fdc920d5c02bd0d09acc4b06a5f053787d4afcd3c921b2e35d2bd97617fadae015da853dc189f559fb8d2c6e58d53e4cabfac9af151cd97ad19
2019-12-06 19:37:12 +01:00
// Tracks keypool indexes to CKeyIDs of keys that have been taken out of the keypool but may be returned to it
std::map<int64_t, CKeyID> m_index_to_reserved_key;
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
//! Fetches a key from the keypool
bool GetKeyFromPool(CPubKey &key, bool fInternal /*= false*/);
Merge #17373: wallet: Various fixes and cleanup to keypool handling in LegacyScriptPubKeyMan and CWallet 886f1731bec4393dd342403ac34069a3a4f95eea Key pool: Fix omitted pre-split count in GetKeyPoolSize (Andrew Chow) 386a994b853bc5b3a2ed0d812673465b8ffa4849 Key pool: Change ReturnDestination interface to take address instead of key (Andrew Chow) ba41aa4969169cd73d6b4f57444ed7d8d875de10 Key pool: Move LearnRelated and GetDestination calls (Andrew Chow) 65833a74076cddf986037c6eb3b29a9b9dbe31c5 Add OutputType and CPubKey parameters to KeepDestination (Andrew Chow) 9fcf8ce7ae02bf170b9bf0c2887fd709d752cbf7 Rename Keep/ReturnKey to Keep/ReturnDestination and remove the wrapper (Andrew Chow) 596f6460f9fd8273665c8754ccd673d93a4f25f0 Key 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 ACK 886f1731bec4393dd342403ac34069a3a4f95eea. Only change is moving earlier fix to a better commit (same end result). promag: Code review ACK 886f1731bec4393dd342403ac34069a3a4f95eea. instagibbs: code review re-ACK https://github.com/bitcoin/bitcoin/pull/17373/commits/886f1731bec4393dd342403ac34069a3a4f95eea Sjors: Code review re-ACK 886f1731bec4393dd342403ac34069a3a4f95eea Tree-SHA512: f4be290759f63fdc920d5c02bd0d09acc4b06a5f053787d4afcd3c921b2e35d2bd97617fadae015da853dc189f559fb8d2c6e58d53e4cabfac9af151cd97ad19
2019-12-06 19:37:12 +01:00
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
/**
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
* Reserves a key from the keypool and sets nIndex to its index
*
* @param[out] nIndex the index of the key in keypool
* @param[out] keypool the keypool the key was drawn from, which could be the
* the pre-split pool if present, or the internal or external pool
* @param fRequestedInternal true if the caller would like the key drawn
* from the internal keypool, false if external is preferred
*
* @return true if succeeded, false if failed due to empty keypool
* @throws std::runtime_error if keypool read failed, key was invalid,
* was not found in the wallet, or was misclassified in the internal
* or external keypool
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
*/
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
bool ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fRequestedInternal);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
public:
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
bool GetNewDestination(CTxDestination& dest, std::string& error) override;
isminetype IsMine(const CScript& script) const override;
isminetype IsMine(const CTxDestination& dest) const override;
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
//! will encrypt previously unencrypted keys
bool EncryptKeys(CKeyingMaterial& vMasterKeyIn);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
Merge #17373: wallet: Various fixes and cleanup to keypool handling in LegacyScriptPubKeyMan and CWallet 886f1731bec4393dd342403ac34069a3a4f95eea Key pool: Fix omitted pre-split count in GetKeyPoolSize (Andrew Chow) 386a994b853bc5b3a2ed0d812673465b8ffa4849 Key pool: Change ReturnDestination interface to take address instead of key (Andrew Chow) ba41aa4969169cd73d6b4f57444ed7d8d875de10 Key pool: Move LearnRelated and GetDestination calls (Andrew Chow) 65833a74076cddf986037c6eb3b29a9b9dbe31c5 Add OutputType and CPubKey parameters to KeepDestination (Andrew Chow) 9fcf8ce7ae02bf170b9bf0c2887fd709d752cbf7 Rename Keep/ReturnKey to Keep/ReturnDestination and remove the wrapper (Andrew Chow) 596f6460f9fd8273665c8754ccd673d93a4f25f0 Key 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 ACK 886f1731bec4393dd342403ac34069a3a4f95eea. Only change is moving earlier fix to a better commit (same end result). promag: Code review ACK 886f1731bec4393dd342403ac34069a3a4f95eea. instagibbs: code review re-ACK https://github.com/bitcoin/bitcoin/pull/17373/commits/886f1731bec4393dd342403ac34069a3a4f95eea Sjors: Code review re-ACK 886f1731bec4393dd342403ac34069a3a4f95eea Tree-SHA512: f4be290759f63fdc920d5c02bd0d09acc4b06a5f053787d4afcd3c921b2e35d2bd97617fadae015da853dc189f559fb8d2c6e58d53e4cabfac9af151cd97ad19
2019-12-06 19:37:12 +01:00
bool GetReservedDestination(bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool) override;
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
void KeepDestination(int64_t index) override;
Merge #17373: wallet: Various fixes and cleanup to keypool handling in LegacyScriptPubKeyMan and CWallet 886f1731bec4393dd342403ac34069a3a4f95eea Key pool: Fix omitted pre-split count in GetKeyPoolSize (Andrew Chow) 386a994b853bc5b3a2ed0d812673465b8ffa4849 Key pool: Change ReturnDestination interface to take address instead of key (Andrew Chow) ba41aa4969169cd73d6b4f57444ed7d8d875de10 Key pool: Move LearnRelated and GetDestination calls (Andrew Chow) 65833a74076cddf986037c6eb3b29a9b9dbe31c5 Add OutputType and CPubKey parameters to KeepDestination (Andrew Chow) 9fcf8ce7ae02bf170b9bf0c2887fd709d752cbf7 Rename Keep/ReturnKey to Keep/ReturnDestination and remove the wrapper (Andrew Chow) 596f6460f9fd8273665c8754ccd673d93a4f25f0 Key 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 ACK 886f1731bec4393dd342403ac34069a3a4f95eea. Only change is moving earlier fix to a better commit (same end result). promag: Code review ACK 886f1731bec4393dd342403ac34069a3a4f95eea. instagibbs: code review re-ACK https://github.com/bitcoin/bitcoin/pull/17373/commits/886f1731bec4393dd342403ac34069a3a4f95eea Sjors: Code review re-ACK 886f1731bec4393dd342403ac34069a3a4f95eea Tree-SHA512: f4be290759f63fdc920d5c02bd0d09acc4b06a5f053787d4afcd3c921b2e35d2bd97617fadae015da853dc189f559fb8d2c6e58d53e4cabfac9af151cd97ad19
2019-12-06 19:37:12 +01:00
void ReturnDestination(int64_t index, bool internal, const CTxDestination&) override;
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
bool TopUp(unsigned int size = 0) override;
void MarkUnusedAddresses(WalletBatch &batch, const CScript& script, const uint256& hashBlock) override;
//! Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/* Returns true if HD is enabled */
bool IsHDEnabled() const override;
bool HavePrivateKeys() const override;
void RewriteDB() override;
int64_t GetOldestKeyPoolTime() override;
size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
size_t KeypoolCountInternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
unsigned int GetKeyPoolSize() const override;
int64_t GetTimeFirstKey() const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
const CKeyMetadata* GetMetadata(const CTxDestination& dest) const override;
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
bool CanGetAddresses(bool internal = false) override;
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
// Map from Key ID to key metadata.
std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_wallet);
// Map from Script ID to key metadata (for watch-only keys).
std::map<CScriptID, CKeyMetadata> m_script_metadata GUARDED_BY(cs_wallet);
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
//! Adds a script to the store and saves it to disk
bool AddCScriptWithDB(WalletBatch& batch, const CScript& script);
//! Adds a key to the store, and saves it to disk.
bool AddKeyPubKeyWithDB(WalletBatch &batch,const CKey& key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
//! Adds a key to the store, and saves it to disk.
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
//! Adds a key to the store, without saving it to disk (used by LoadWallet)
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
bool LoadKey(const CKey& key, const CPubKey &pubkey);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
//! Adds an encrypted key to the store, and saves it to disk.
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
//! Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
void UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
//! Adds a CScript to the store
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
bool LoadCScript(const CScript& redeemScript);
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
//! Load metadata (used by LoadWallet)
void LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, bool overwrite);
void LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
//! Generate a new key
CPubKey GenerateNewKey(WalletBatch& batch, uint32_t nAccountIndex, bool fInternal /*= false*/) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/* Set the HD chain model (chain child index counters) */
bool SetHDChain(WalletBatch &batch, const CHDChain& chain, bool memonly);
bool SetCryptedHDChain(WalletBatch &batch, const CHDChain& chain, bool memonly);
/**
* Set the HD chain model (chain child index counters) using temporary wallet db object
* which causes db flush every time these methods are used
*/
bool SetHDChainSingle(const CHDChain& chain, bool memonly);
bool SetCryptedHDChainSingle(const CHDChain& chain, bool memonly);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
//! Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
bool LoadWatchOnly(const CScript &dest);
//! Returns whether the watch-only script is in the wallet
bool HaveWatchOnly(const CScript &dest) const;
//! Returns whether there are any watch-only things in the wallet
bool HaveWatchOnly() const;
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
//! Remove a watch only script from the keystore
bool RemoveWatchOnly(const CScript &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
//! Adds a watch-only address to the store, and saves it to disk.
bool AddWatchOnly(const CScript& dest, int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
//! Adds a watch-only address to the store, and saves it to disk.
bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript& dest, int64_t create_time) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
//! Fetches a pubkey from mapWatchKeys if it exists there
bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const;
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
/* SigningProvider overrides */
//! HaveKey implementation that also checks the mapHdPubKeys
bool HaveKey(const CKeyID &address) const override;
//! GetKey implementation that can derive a HD private key on the fly
bool GetKey(const CKeyID &address, CKey& keyOut) const override;
//! GetPubKey implementation that also checks the mapHdPubKeys
bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
bool AddCScript(const CScript& redeemScript) override;
/** Implement lookup of key origin information through wallet key metadata. */
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
/** Add a KeyOriginInfo to the wallet */
bool AddKeyOrigin(const CPubKey& pubkey, const KeyOriginInfo& info);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool NewKeyPool();
// Seems as not used now anywhere in code
// void AddKeypoolPubkey(const CPubKey& pubkey, const bool internal);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
bool ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool ImportPubKeys(const std::vector<CKeyID>& ordered_pubkeys, const std::map<CKeyID, CPubKey>& pubkey_map, const std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>>& key_origins, const bool add_keypool, const bool internal, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool ImportScriptPubKeys(const std::set<CScript>& script_pub_keys, const bool have_solving_data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
/* Returns true if the wallet can generate new keys */
bool CanGenerateKeys();
//! Adds a HDPubKey into the wallet(database)
bool AddHDPubKey(WalletBatch &batch, const CExtPubKey &extPubKey, bool fInternal);
//! loads a HDPubKey into the wallets memory
bool LoadHDPubKey(const CHDPubKey &hdPubKey) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
/**
* HD Wallet Functions
*/
bool EncryptHDChain(const CKeyingMaterial& vMasterKeyIn, const CHDChain& chain = CHDChain());
bool DecryptHDChain(CHDChain& hdChainRet) const;
bool SetHDChain(const CHDChain& chain);
bool GetHDChain(CHDChain& hdChainRet) const;
bool SetCryptedHDChain(const CHDChain& chain);
bool GetDecryptedHDChain(CHDChain& hdChainRet);
/* Generates a new HD chain */
void GenerateNewHDChain(const SecureString& secureMnemonic, const SecureString& secureMnemonicPassphrase);
bool GenerateNewHDChainEncrypted(const SecureString& secureMnemonic, const SecureString& secureMnemonicPassphrase, const SecureString& secureWalletPassphrase);
/**
* Explicitly make the wallet learn the related scripts for outputs to the
* given key. This is purely to make the wallet file compatible with older
* software, as FillableSigningProvider automatically does this implicitly for all
* keys now.
*/
// void LearnRelatedScripts(const CPubKey& key, OutputType);
/**
* Same as LearnRelatedScripts, but when the OutputType is not known (and could
* be anything).
*/
// void LearnAllRelatedScripts(const CPubKey& key);
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
/**
* Marks all keys in the keypool up to and including reserve_key as used.
*/
void MarkReserveKeysAsUsed(int64_t keypool_id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
Merge bitcoin#17304: refactor: Move many functions into LegacyScriptPubKeyMan and further separate it from CWallet * MOVEONLY: Reorder LegacyScriptPubKeyMan methods Can verify move-only with: git log -p -n1 --color-moved This commit is move-only and doesn't change code or affect behavior. * Refactor: Declare LegacyScriptPubKeyMan methods as virtual This commit does not change behavior. * Refactor: Add new ScriptPubKeyMan virtual methods This commit does not change behavior. * Refactor: Move SetAddressBook call out of LegacyScriptPubKeyMan::GetNewDestination This commit does not change behavior. * Refactor: Move SetWalletFlag out of LegacyScriptPubKeyMan::UpgradeKeyMetadata This commit does not change behavior. * Remove SetWalletFlag from WalletStorage SetWalletFlag is unused. Does not change any behavior * Refactor: Remove UnsetWalletFlag call from LegacyScriptPubKeyMan::SetHDSeed This commit does not change behavior. * refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan ScriptPubKeyMan is only using UnsetWalletFlagWithDB to unset the blank wallet flag. Just make that it's own function and not expose the flag writing directly. This does not change behavior. * Refactor: Move SetAddressBookWithDB call out of LegacyScriptPubKeyMan::ImportScriptPubKeys This commit does not change behavior. * Refactor: Move LoadKey LegacyScriptPubKeyMan method definition This commit does not change behavior. * Refactor: Move GetMetadata code out of getaddressinfo Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. * Refactor: Move MarkUnusedAddresses code out of CWallet::AddToWalletIfInvolvingMe This commit does not change behavior. * Refactor: Move HavePrivateKeys code out of CWallet::CreateWalletFromFile This commit does not change behavior. * Refactor: Move RewriteDB code out of CWallet This commit does not change behavior. * Refactor: Move GetKeypoolSize code out of CWallet This commit does not change behavior. * Refactor: Move nTimeFirstKey accesses out of CWallet This commit does not change behavior. * Re-order methods of scriptpubkeyman for easier backporting changes in future * Fixup for missing cs_wallet lock: ``` wallet/wallet.cpp:4536:41: error: calling function 'GetTimeFirstKey' requires holding mutex 'spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] int64_t time = spk_man->GetTimeFirstKey(); ^ wallet/wallet.cpp:4570:106: error: calling function 'GetTimeFirstKey' requires holding mutex 'walletInstance->m_spk_man->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis] walletInstance->WalletLogPrintf("nTimeFirstKey = %u\n", walletInstance->m_spk_man->GetTimeFirstKey()); ``` * Fix 2 locks * more of "refactor: Replace UnsetWalletFlagWithDB with UnsetBlankWalletFlag in ScriptPubKeyMan" * Refactoring GetOldestKeyInPool -> GetOldestKeyTimeInPool, partial bitcoin#10235 Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-09-20 09:31:09 +02:00
std::set<CKeyID> GetKeys() const override;
Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan (#4938) * Move wallet enums to walletutil.h * MOVEONLY: Move key handling code out of wallet to keyman file Start moving wallet and ismine code to scriptpubkeyman.h, scriptpubkeyman.cpp The easiest way to review this commit is to run: git log -p -n1 --color-moved=dimmed_zebra And check that everything is a move (other than includes and copyrights comments). This commit is move-only and doesn't change code or affect behavior. * Refactor: Split up CWallet and LegacyScriptPubKeyMan and classes This moves CWallet members and methods dealing with keys to a new LegacyScriptPubKeyMan class, and updates calling code to reference the new class instead of CWallet. Most of the changes are simple text replacements and variable substitutions easily verified with: git log -p -n1 -U0 --word-diff-regex=. The only nontrivial chunk of code added is the new LegacyScriptPubKeyMan class declaration, but this code isn't new and is just selectively copied and moved from the previous CWallet class declaration. This can be verified with: git log -p -n1 --color-moved=dimmed_zebra src/wallet/scriptpubkeyman.h src/wallet/wallet.h or git diff HEAD~1:src/wallet/wallet.h HEAD:src/wallet/scriptpubkeyman.h This commit does not change behavior. * Renamed classes in scriptpubkeyman * Fixes for conflicts, compilation and linkage errors due to previous commits * Reordered methods in scriptpubkeyman to make further backports easier * Reordered methods in scriptpubkeyman to make further backports easier (part II) * Remove HDChain copy from SigningProvider class * fixes/suggestions Co-authored-by: Andrew Chow <achow101-github@achow101.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-08-08 18:05:21 +02:00
// Temporary CWallet accessors and aliases.
friend class CWallet;
friend class ReserveDestination;
LegacyScriptPubKeyMan(CWallet& wallet);
bool SetCrypted();
bool IsCrypted() const;
void NotifyWatchonlyChanged(bool fHaveWatchOnly) const;
void NotifyCanGetAddressesChanged() const;
template<typename... Params> void WalletLogPrintf(const std::string& fmt, const Params&... parameters) const;
CWallet& m_wallet;
CCriticalSection& cs_wallet;
CKeyingMaterial& vMasterKey GUARDED_BY(cs_KeyStore);
std::atomic<bool>& fUseCrypto;
bool& fDecryptionThoroughlyChecked;
};
#endif // BITCOIN_WALLET_SCRIPTPUBKEYMAN_H