Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.h
Show First 20 Lines • Show All 637 Lines • ▼ Show 20 Lines | |||||
* A CWallet maintains a set of transactions and balances, and provides the | * A CWallet maintains a set of transactions and balances, and provides the | ||||
* ability to create new transactions. | * ability to create new transactions. | ||||
*/ | */ | ||||
class CWallet final : public WalletStorage, | class CWallet final : public WalletStorage, | ||||
public interfaces::Chain::Notifications { | public interfaces::Chain::Notifications { | ||||
private: | private: | ||||
CKeyingMaterial vMasterKey GUARDED_BY(cs_KeyStore); | CKeyingMaterial vMasterKey GUARDED_BY(cs_KeyStore); | ||||
//! if fUseCrypto is true, mapKeys must be empty | |||||
//! if fUseCrypto is false, vMasterKey must be empty | |||||
std::atomic<bool> fUseCrypto; | |||||
//! keeps track of whether Unlock has run a thorough check before | |||||
bool fDecryptionThoroughlyChecked; | |||||
bool SetCrypted(); | |||||
bool Unlock(const CKeyingMaterial &vMasterKeyIn, | bool Unlock(const CKeyingMaterial &vMasterKeyIn, | ||||
bool accept_no_keys = false); | bool accept_no_keys = false); | ||||
std::atomic<bool> fAbortRescan{false}; | std::atomic<bool> fAbortRescan{false}; | ||||
// controlled by WalletRescanReserver | // controlled by WalletRescanReserver | ||||
std::atomic<bool> fScanningWallet{false}; | std::atomic<bool> fScanningWallet{false}; | ||||
std::atomic<int64_t> m_scanning_start{0}; | std::atomic<int64_t> m_scanning_start{0}; | ||||
std::atomic<double> m_scanning_progress{0}; | std::atomic<double> m_scanning_progress{0}; | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | public: | ||||
typedef std::map<unsigned int, CMasterKey> MasterKeyMap; | typedef std::map<unsigned int, CMasterKey> MasterKeyMap; | ||||
MasterKeyMap mapMasterKeys; | MasterKeyMap mapMasterKeys; | ||||
unsigned int nMasterKeyMaxID = 0; | unsigned int nMasterKeyMaxID = 0; | ||||
/** Construct wallet with specified name and database implementation. */ | /** Construct wallet with specified name and database implementation. */ | ||||
CWallet(const CChainParams &chainParamsIn, interfaces::Chain *chain, | CWallet(const CChainParams &chainParamsIn, interfaces::Chain *chain, | ||||
const WalletLocation &location, | const WalletLocation &location, | ||||
std::unique_ptr<WalletDatabase> databaseIn) | std::unique_ptr<WalletDatabase> _database) | ||||
: fUseCrypto(false), fDecryptionThoroughlyChecked(false), | : m_chain(chain), m_location(location), database(std::move(_database)), | ||||
m_chain(chain), m_location(location), database(std::move(databaseIn)), | |||||
chainParams(chainParamsIn) {} | chainParams(chainParamsIn) {} | ||||
~CWallet() { | ~CWallet() { | ||||
// Should not have slots connected at this point. | // Should not have slots connected at this point. | ||||
assert(NotifyUnload.empty()); | assert(NotifyUnload.empty()); | ||||
delete encrypted_batch; | |||||
encrypted_batch = nullptr; | |||||
} | } | ||||
bool IsCrypted() const { return fUseCrypto; } | bool IsCrypted() const; | ||||
bool IsLocked() const override; | bool IsLocked() const override; | ||||
bool Lock(); | bool Lock(); | ||||
/** Interface to assert chain access and if successful lock it */ | /** Interface to assert chain access and if successful lock it */ | ||||
std::unique_ptr<interfaces::Chain::Lock> LockChain() { | std::unique_ptr<interfaces::Chain::Lock> LockChain() { | ||||
return m_chain ? m_chain->lock() : nullptr; | return m_chain ? m_chain->lock() : nullptr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 527 Lines • ▼ Show 20 Lines | public: | ||||
//! Get the SigningProvider for a script | //! Get the SigningProvider for a script | ||||
const SigningProvider *GetSigningProvider(const CScript &script) const; | const SigningProvider *GetSigningProvider(const CScript &script) const; | ||||
const SigningProvider *GetSigningProvider(const CScript &script, | const SigningProvider *GetSigningProvider(const CScript &script, | ||||
SignatureData &sigdata) const; | SignatureData &sigdata) const; | ||||
LegacyScriptPubKeyMan *GetLegacyScriptPubKeyMan() const; | LegacyScriptPubKeyMan *GetLegacyScriptPubKeyMan() const; | ||||
const CKeyingMaterial &GetEncryptionKey() const override; | |||||
bool HasEncryptionKeys() const override; | |||||
// Temporary LegacyScriptPubKeyMan accessors and aliases. | // Temporary LegacyScriptPubKeyMan accessors and aliases. | ||||
friend class LegacyScriptPubKeyMan; | friend class LegacyScriptPubKeyMan; | ||||
std::unique_ptr<LegacyScriptPubKeyMan> m_spk_man = | std::unique_ptr<LegacyScriptPubKeyMan> m_spk_man = | ||||
std::make_unique<LegacyScriptPubKeyMan>(*this); | std::make_unique<LegacyScriptPubKeyMan>(*this); | ||||
RecursiveMutex &cs_KeyStore = m_spk_man->cs_KeyStore; | RecursiveMutex &cs_KeyStore = m_spk_man->cs_KeyStore; | ||||
LegacyScriptPubKeyMan::KeyMap & | LegacyScriptPubKeyMan::KeyMap & | ||||
mapKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapKeys; | mapKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapKeys; | ||||
LegacyScriptPubKeyMan::ScriptMap & | LegacyScriptPubKeyMan::ScriptMap & | ||||
mapScripts GUARDED_BY(cs_KeyStore) = m_spk_man->mapScripts; | mapScripts GUARDED_BY(cs_KeyStore) = m_spk_man->mapScripts; | ||||
LegacyScriptPubKeyMan::CryptedKeyMap & | LegacyScriptPubKeyMan::CryptedKeyMap & | ||||
mapCryptedKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapCryptedKeys; | mapCryptedKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapCryptedKeys; | ||||
LegacyScriptPubKeyMan::WatchOnlySet & | LegacyScriptPubKeyMan::WatchOnlySet & | ||||
setWatchOnly GUARDED_BY(cs_KeyStore) = m_spk_man->setWatchOnly; | setWatchOnly GUARDED_BY(cs_KeyStore) = m_spk_man->setWatchOnly; | ||||
LegacyScriptPubKeyMan::WatchKeyMap & | LegacyScriptPubKeyMan::WatchKeyMap & | ||||
mapWatchKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapWatchKeys; | mapWatchKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapWatchKeys; | ||||
WalletBatch *& | |||||
encrypted_batch GUARDED_BY(cs_wallet) = m_spk_man->encrypted_batch; | |||||
using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap; | |||||
/** Get last block processed height */ | /** Get last block processed height */ | ||||
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { | int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
assert(m_last_block_processed_height >= 0); | assert(m_last_block_processed_height >= 0); | ||||
return m_last_block_processed_height; | return m_last_block_processed_height; | ||||
}; | }; | ||||
/** Set last block processed height, currently only use in unit test */ | /** Set last block processed height, currently only use in unit test */ | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |