Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.h
Show First 20 Lines • Show All 660 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* A CWallet is an extension of a keystore, which also maintains a set of | * A CWallet is an extension of a keystore, which also maintains a set of | ||||
* transactions and balances, and provides the ability to create new | * transactions and balances, and provides the ability to create new | ||||
* transactions. | * transactions. | ||||
*/ | */ | ||||
class CWallet final : public CCryptoKeyStore, public CValidationInterface { | class CWallet final : public CCryptoKeyStore, public CValidationInterface { | ||||
private: | private: | ||||
static std::atomic<bool> fFlushScheduled; | static std::atomic<bool> fFlushScheduled; | ||||
std::atomic<bool> fAbortRescan; | std::atomic<bool> fAbortRescan{false}; | ||||
// controlled by WalletRescanReserver | // controlled by WalletRescanReserver | ||||
std::atomic<bool> fScanningWallet; | std::atomic<bool> fScanningWallet{false}; | ||||
std::mutex mutexScanning; | std::mutex mutexScanning; | ||||
friend class WalletRescanReserver; | friend class WalletRescanReserver; | ||||
CWalletDB *pwalletdbEncryption; | CWalletDB *pwalletdbEncryption = nullptr; | ||||
//! the current wallet version: clients below this version are not able to | //! the current wallet version: clients below this version are not able to | ||||
//! load the wallet | //! load the wallet | ||||
int nWalletVersion; | int nWalletVersion = FEATURE_BASE; | ||||
//! the maximum wallet format version: memory-only variable that specifies | //! the maximum wallet format version: memory-only variable that specifies | ||||
//! to what version this wallet may be upgraded | //! to what version this wallet may be upgraded | ||||
int nWalletMaxVersion; | int nWalletMaxVersion = FEATURE_BASE; | ||||
int64_t nNextResend; | int64_t nNextResend = 0; | ||||
int64_t nLastResend; | int64_t nLastResend = 0; | ||||
bool fBroadcastTransactions; | bool fBroadcastTransactions = false; | ||||
/** | /** | ||||
* Used to keep track of spent outpoints, and detect and report conflicts | * Used to keep track of spent outpoints, and detect and report conflicts | ||||
* (double-spends or mutated transactions where the mutant gets mined). | * (double-spends or mutated transactions where the mutant gets mined). | ||||
*/ | */ | ||||
typedef std::multimap<COutPoint, TxId> TxSpends; | typedef std::multimap<COutPoint, TxId> TxSpends; | ||||
TxSpends mapTxSpends; | TxSpends mapTxSpends; | ||||
void AddToSpends(const COutPoint &outpoint, const TxId &wtxid); | void AddToSpends(const COutPoint &outpoint, const TxId &wtxid); | ||||
Show All 20 Lines | private: | ||||
CHDChain hdChain; | CHDChain hdChain; | ||||
/* HD derive new child key (on internal or external chain) */ | /* HD derive new child key (on internal or external chain) */ | ||||
void DeriveNewChildKey(CWalletDB &walletdb, CKeyMetadata &metadata, | void DeriveNewChildKey(CWalletDB &walletdb, CKeyMetadata &metadata, | ||||
CKey &secret, bool internal = false); | CKey &secret, bool internal = false); | ||||
std::set<int64_t> setInternalKeyPool; | std::set<int64_t> setInternalKeyPool; | ||||
std::set<int64_t> setExternalKeyPool; | std::set<int64_t> setExternalKeyPool; | ||||
int64_t m_max_keypool_index; | int64_t m_max_keypool_index = 0; | ||||
std::map<CKeyID, int64_t> m_pool_key_to_index; | std::map<CKeyID, int64_t> m_pool_key_to_index; | ||||
int64_t nTimeFirstKey; | int64_t nTimeFirstKey = 0; | ||||
/** | /** | ||||
* Private version of AddWatchOnly method which does not accept a timestamp, | * 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 | * 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 | * key did not previously have a timestamp associated with it. Because this | ||||
* is an inherited virtual method, it is accessible despite being marked | * is an inherited virtual method, it is accessible despite being marked | ||||
* private, but it is marked private anyway to encourage use of the other | * private, but it is marked private anyway to encourage use of the other | ||||
* AddWatchOnly which accepts a timestamp and sets nTimeFirstKey more | * AddWatchOnly which accepts a timestamp and sets nTimeFirstKey more | ||||
Show All 16 Lines | private: | ||||
* from the chain sync, and to allow clients to block on us being caught up. | * from the chain sync, and to allow clients to block on us being caught up. | ||||
* | * | ||||
* Note that this is *not* how far we've processed, we may need some rescan | * Note that this is *not* how far we've processed, we may need some rescan | ||||
* to have seen all transactions in the chain, but is only used to track | * to have seen all transactions in the chain, but is only used to track | ||||
* live BlockConnected callbacks. | * live BlockConnected callbacks. | ||||
* | * | ||||
* Protected by cs_main (see BlockUntilSyncedToCurrentChain) | * Protected by cs_main (see BlockUntilSyncedToCurrentChain) | ||||
*/ | */ | ||||
const CBlockIndex *m_last_block_processed; | const CBlockIndex *m_last_block_processed = nullptr; | ||||
public: | public: | ||||
const CChainParams &chainParams; | const CChainParams &chainParams; | ||||
/* | /* | ||||
* Main wallet lock. | * Main wallet lock. | ||||
* This lock protects all the fields added by CWallet. | * This lock protects all the fields added by CWallet. | ||||
*/ | */ | ||||
mutable CCriticalSection cs_wallet; | mutable CCriticalSection cs_wallet; | ||||
Show All 26 Lines | public: | ||||
// Map from Key ID to key metadata. | // Map from Key ID to key metadata. | ||||
std::map<CKeyID, CKeyMetadata> mapKeyMetadata; | std::map<CKeyID, CKeyMetadata> mapKeyMetadata; | ||||
// Map from Script ID to key metadata (for watch-only keys). | // Map from Script ID to key metadata (for watch-only keys). | ||||
std::map<CScriptID, CKeyMetadata> m_script_metadata; | std::map<CScriptID, CKeyMetadata> m_script_metadata; | ||||
typedef std::map<unsigned int, CMasterKey> MasterKeyMap; | typedef std::map<unsigned int, CMasterKey> MasterKeyMap; | ||||
MasterKeyMap mapMasterKeys; | MasterKeyMap mapMasterKeys; | ||||
unsigned int nMasterKeyMaxID; | unsigned int nMasterKeyMaxID = 0; | ||||
/** Construct wallet with specified name and database implementation. */ | /** Construct wallet with specified name and database implementation. */ | ||||
CWallet(const CChainParams &chainParamsIn, std::string name, | CWallet(const CChainParams &chainParamsIn, std::string name, | ||||
std::unique_ptr<CWalletDBWrapper> dbw_in) | std::unique_ptr<CWalletDBWrapper> dbwIn) | ||||
: m_name(std::move(name)), dbw(std::move(dbw_in)), | : m_name(std::move(name)), dbw(std::move(dbwIn)), | ||||
chainParams(chainParamsIn) { | chainParams(chainParamsIn) {} | ||||
SetNull(); | |||||
} | |||||
~CWallet() { | ~CWallet() { | ||||
delete pwalletdbEncryption; | delete pwalletdbEncryption; | ||||
pwalletdbEncryption = nullptr; | pwalletdbEncryption = nullptr; | ||||
} | } | ||||
void SetNull() { | |||||
nWalletVersion = FEATURE_BASE; | |||||
nWalletMaxVersion = FEATURE_BASE; | |||||
nMasterKeyMaxID = 0; | |||||
pwalletdbEncryption = nullptr; | |||||
nOrderPosNext = 0; | |||||
nAccountingEntryNumber = 0; | |||||
nNextResend = 0; | |||||
nLastResend = 0; | |||||
m_max_keypool_index = 0; | |||||
nTimeFirstKey = 0; | |||||
fBroadcastTransactions = false; | |||||
fAbortRescan = false; | |||||
fScanningWallet = false; | |||||
nRelockTime = 0; | |||||
} | |||||
std::map<TxId, CWalletTx> mapWallet; | std::map<TxId, CWalletTx> mapWallet; | ||||
std::list<CAccountingEntry> laccentries; | std::list<CAccountingEntry> laccentries; | ||||
typedef std::pair<CWalletTx *, CAccountingEntry *> TxPair; | typedef std::pair<CWalletTx *, CAccountingEntry *> TxPair; | ||||
typedef std::multimap<int64_t, TxPair> TxItems; | typedef std::multimap<int64_t, TxPair> TxItems; | ||||
TxItems wtxOrdered; | TxItems wtxOrdered; | ||||
int64_t nOrderPosNext; | int64_t nOrderPosNext = 0; | ||||
uint64_t nAccountingEntryNumber; | uint64_t nAccountingEntryNumber = 0; | ||||
std::map<CTxDestination, CAddressBookData> mapAddressBook; | std::map<CTxDestination, CAddressBookData> mapAddressBook; | ||||
std::set<COutPoint> setLockedCoins; | std::set<COutPoint> setLockedCoins; | ||||
const CWalletTx *GetWalletTx(const TxId &txid) const; | const CWalletTx *GetWalletTx(const TxId &txid) const; | ||||
//! check whether we are allowed to upgrade (or already support) to the | //! check whether we are allowed to upgrade (or already support) to the | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | public: | ||||
bool RemoveWatchOnly(const CScript &dest) override; | bool RemoveWatchOnly(const CScript &dest) override; | ||||
//! Adds a watch-only address to the store, without saving it to disk (used | //! Adds a watch-only address to the store, without saving it to disk (used | ||||
//! by LoadWallet) | //! by LoadWallet) | ||||
bool LoadWatchOnly(const CScript &dest); | bool LoadWatchOnly(const CScript &dest); | ||||
//! Holds a timestamp at which point the wallet is scheduled (externally) to | //! Holds a timestamp at which point the wallet is scheduled (externally) to | ||||
//! be relocked. Caller must arrange for actual relocking to occur via | //! be relocked. Caller must arrange for actual relocking to occur via | ||||
//! Lock(). | //! Lock(). | ||||
int64_t nRelockTime; | int64_t nRelockTime = 0; | ||||
bool Unlock(const SecureString &strWalletPassphrase); | bool Unlock(const SecureString &strWalletPassphrase); | ||||
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, | bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, | ||||
const SecureString &strNewWalletPassphrase); | const SecureString &strNewWalletPassphrase); | ||||
bool EncryptWallet(const SecureString &strWalletPassphrase); | bool EncryptWallet(const SecureString &strWalletPassphrase); | ||||
void GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) const; | void GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) const; | ||||
unsigned int ComputeTimeSmart(const CWalletTx &wtx) const; | unsigned int ComputeTimeSmart(const CWalletTx &wtx) const; | ||||
▲ Show 20 Lines • Show All 412 Lines • Show Last 20 Lines |