Bitcoin
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
CWallet Class Referencefinalabstract

#include <wallet.h>

Inheritance diagram for CWallet:
FillableSigningProvider interfaces::Chain::Notifications SigningProvider

Classes

struct  Balance
 
struct  ScanResult
 

Public Types

typedef std::map< unsigned int, CMasterKeyMasterKeyMap
 
typedef std::multimap< int64_t, CWalletTx * > TxItems
 

Public Member Functions

WalletDatabaseGetDBHandle ()
 
bool SelectCoins (const std::vector< COutput > &vAvailableCoins, const CAmount &nTargetValue, std::set< CInputCoin > &setCoinsRet, CAmount &nValueRet, const CCoinControl &coin_control, CoinSelectionParams &coin_selection_params, bool &bnb_used) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
const WalletLocationGetLocation () const
 
const std::string & GetName () const
 
void LoadKeyPool (int64_t nIndex, const CKeyPool &keypool) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void MarkPreSplitKeys () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
std::map< CKeyID, CKeyMetadata > mapKeyMetadata GUARDED_BY (cs_wallet)
 
std::map< CScriptID, CKeyMetadata > m_script_metadata GUARDED_BY (cs_wallet)
 
 CWallet (interfaces::Chain *chain, const WalletLocation &location, std::unique_ptr< WalletDatabase > database)
 
 ~CWallet ()
 
bool IsCrypted () const
 
bool IsLocked () const
 
bool Lock ()
 
std::map< uint256, CWalletTx > mapWallet GUARDED_BY (cs_wallet)
 
int64_t nOrderPosNext GUARDED_BY (cs_wallet)=0
 
std::map< CTxDestination, CAddressBookData > mapAddressBook GUARDED_BY (cs_wallet)
 
std::set< COutPoint > setLockedCoins GUARDED_BY (cs_wallet)
 
void handleNotifications ()
 
interfaces::Chainchain () const
 
const CWalletTxGetWalletTx (const uint256 &hash) const
 
bool CanSupportFeature (enum WalletFeature wf) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 check whether we are allowed to upgrade (or already support) to the named feature More...
 
void AvailableCoins (interfaces::Chain::Lock &locked_chain, std::vector< COutput > &vCoins, bool fOnlySafe=true, const CCoinControl *coinControl=nullptr, const CAmount &nMinimumAmount=1, const CAmount &nMaximumAmount=MAX_MONEY, const CAmount &nMinimumSumAmount=MAX_MONEY, const uint64_t nMaximumCount=0, const int nMinDepth=0, const int nMaxDepth=9999999) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
std::map< CTxDestination, std::vector< COutput > > ListCoins (interfaces::Chain::Lock &locked_chain) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
const CTxOutFindNonChangeParentOutput (const CTransaction &tx, int output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool SelectCoinsMinConf (const CAmount &nTargetValue, const CoinEligibilityFilter &eligibility_filter, std::vector< OutputGroup > groups, std::set< CInputCoin > &setCoinsRet, CAmount &nValueRet, const CoinSelectionParams &coin_selection_params, bool &bnb_used) const
 
bool IsSpent (interfaces::Chain::Lock &locked_chain, const uint256 &hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool IsUsedDestination (const CTxDestination &dst) const
 
bool IsUsedDestination (const uint256 &hash, unsigned int n) const
 
void SetUsedDestinationState (const uint256 &hash, unsigned int n, bool used)
 
std::vector< OutputGroupGroupOutputs (const std::vector< COutput > &outputs, bool single_coin) const
 
bool IsLockedCoin (uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void LockCoin (const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void UnlockCoin (const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void UnlockAllCoins () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void ListLockedCoins (std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void AbortRescan ()
 
bool IsAbortingRescan ()
 
bool IsScanning ()
 
int64_t ScanningDuration () const
 
double ScanningProgress () const
 
CPubKey GenerateNewKey (WalletBatch &batch, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool AddKeyPubKey (const CKey &key, const CPubKey &pubkey) override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Adds a key to the store, and saves it to disk. More...
 
bool LoadKey (const CKey &key, const CPubKey &pubkey)
 Adds a key to the store, without saving it to disk (used by LoadWallet) More...
 
void LoadKeyMetadata (const CKeyID &keyID, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Load metadata (used by LoadWallet) More...
 
void LoadScriptMetadata (const CScriptID &script_id, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void UpgradeKeyMetadata () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo. More...
 
bool LoadMinVersion (int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void UpdateTimeFirstKey (int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool AddCryptedKey (const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
 Adds an encrypted key to the store, and saves it to disk. More...
 
bool LoadCryptedKey (const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
 Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) More...
 
bool GetKey (const CKeyID &address, CKey &keyOut) const override
 
bool GetPubKey (const CKeyID &address, CPubKey &vchPubKeyOut) const override
 
bool HaveKey (const CKeyID &address) const override
 
std::set< CKeyIDGetKeys () const override
 
bool AddCScript (const CScript &redeemScript) override
 
bool LoadCScript (const CScript &redeemScript)
 
bool AddDestData (const CTxDestination &dest, const std::string &key, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Adds a destination data tuple to the store, and saves it to disk. More...
 
bool EraseDestData (const CTxDestination &dest, const std::string &key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Erases a destination data tuple in the store and on disk. More...
 
void LoadDestData (const CTxDestination &dest, const std::string &key, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Adds a destination data tuple to the store, without saving it to disk. More...
 
bool GetDestData (const CTxDestination &dest, const std::string &key, std::string *value) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Look up a destination data tuple in the store, return true if found false otherwise. More...
 
std::vector< std::string > GetDestValues (const std::string &prefix) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Get all destination values matching a prefix. More...
 
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. More...
 
bool RemoveWatchOnly (const CScript &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool LoadWatchOnly (const CScript &dest)
 Adds a watch-only address to the store, without saving it to disk (used by LoadWallet) More...
 
bool HaveWatchOnly (const CScript &dest) const
 Returns whether the watch-only script is in the wallet. More...
 
bool HaveWatchOnly () const
 Returns whether there are any watch-only things in the wallet. More...
 
bool GetWatchPubKey (const CKeyID &address, CPubKey &pubkey_out) const
 Fetches a pubkey from mapWatchKeys if it exists there. More...
 
bool Unlock (const SecureString &strWalletPassphrase, bool accept_no_keys=false)
 
bool ChangeWalletPassphrase (const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
 
bool EncryptWallet (const SecureString &strWalletPassphrase)
 
void GetKeyBirthTimes (interfaces::Chain::Lock &locked_chain, std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
unsigned int ComputeTimeSmart (const CWalletTx &wtx) const
 
int64_t IncOrderPosNext (WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
DBErrors ReorderTransactions ()
 
void MarkDirty ()
 
bool AddToWallet (const CWalletTx &wtxIn, bool fFlushOnClose=true)
 
void LoadToWallet (const CWalletTx &wtxIn) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void TransactionAddedToMempool (const CTransactionRef &tx) override
 
void BlockConnected (const CBlock &block, const std::vector< CTransactionRef > &vtxConflicted) override
 
void BlockDisconnected (const CBlock &block) override
 
void UpdatedBlockTip () override
 
int64_t RescanFromTime (int64_t startTime, const WalletRescanReserver &reserver, bool update)
 
ScanResult ScanForWalletTransactions (const uint256 &first_block, const uint256 &last_block, const WalletRescanReserver &reserver, bool fUpdate)
 
void TransactionRemovedFromMempool (const CTransactionRef &ptx) override
 
void ReacceptWalletTransactions (interfaces::Chain::Lock &locked_chain) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void ResendWalletTransactions ()
 
Balance GetBalance (int min_depth=0, bool avoid_reuse=true) const
 
CAmount GetAvailableBalance (const CCoinControl *coinControl=nullptr) const
 
OutputType TransactionChangeType (OutputType change_type, const std::vector< CRecipient > &vecSend)
 
bool FundTransaction (CMutableTransaction &tx, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, bool lockUnspents, const std::set< int > &setSubtractFeeFromOutputs, CCoinControl)
 
bool SignTransaction (CMutableTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool CreateTransaction (interfaces::Chain::Lock &locked_chain, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, ReserveDestination &reservedest, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coin_control, bool sign=true)
 
bool CommitTransaction (CTransactionRef tx, mapValue_t mapValue, std::vector< std::pair< std::string, std::string >> orderForm, ReserveDestination &reservedest, CValidationState &state)
 
bool DummySignTx (CMutableTransaction &txNew, const std::set< CTxOut > &txouts, bool use_max_sig=false) const
 
bool DummySignTx (CMutableTransaction &txNew, const std::vector< CTxOut > &txouts, bool use_max_sig=false) const
 
bool DummySignInput (CTxIn &tx_in, const CTxOut &txout, bool use_max_sig=false) const
 
bool ImportScripts (const std::set< CScript > scripts) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
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::string &label, const std::set< CScript > &script_pub_keys, const bool have_solving_data, const bool internal, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool NewKeyPool ()
 
size_t KeypoolCountExternalKeys () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool TopUpKeyPool (unsigned int kpSize=0)
 
bool ReserveKeyFromKeyPool (int64_t &nIndex, CKeyPool &keypool, bool fRequestedInternal)
 
void KeepKey (int64_t nIndex)
 
void ReturnKey (int64_t nIndex, bool fInternal, const CPubKey &pubkey)
 
int64_t GetOldestKeyPoolTime ()
 
void MarkReserveKeysAsUsed (int64_t keypool_id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
const std::map< CKeyID, int64_t > & GetAllReserveKeys () const
 
std::set< std::set< CTxDestination > > GetAddressGroupings () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
std::map< CTxDestination, CAmountGetAddressBalances (interfaces::Chain::Lock &locked_chain)
 
std::set< CTxDestinationGetLabelAddresses (const std::string &label) const
 
bool GetNewDestination (const OutputType type, const std::string label, CTxDestination &dest, std::string &error)
 
bool GetNewChangeDestination (const OutputType type, CTxDestination &dest, std::string &error)
 
isminetype IsMine (const CTxIn &txin) const
 
CAmount GetDebit (const CTxIn &txin, const isminefilter &filter) const
 
isminetype IsMine (const CTxOut &txout) const
 
CAmount GetCredit (const CTxOut &txout, const isminefilter &filter) const
 
bool IsChange (const CTxOut &txout) const
 
bool IsChange (const CScript &script) const
 
CAmount GetChange (const CTxOut &txout) const
 
bool IsMine (const CTransaction &tx) const
 
bool IsFromMe (const CTransaction &tx) const
 
CAmount GetDebit (const CTransaction &tx, const isminefilter &filter) const
 
bool IsAllFromMe (const CTransaction &tx, const isminefilter &filter) const
 
CAmount GetCredit (const CTransaction &tx, const isminefilter &filter) const
 
CAmount GetChange (const CTransaction &tx) const
 
void ChainStateFlushed (const CBlockLocator &loc) override
 
DBErrors LoadWallet (bool &fFirstRunRet)
 
DBErrors ZapWalletTx (std::vector< CWalletTx > &vWtx)
 
DBErrors ZapSelectTx (std::vector< uint256 > &vHashIn, std::vector< uint256 > &vHashOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool SetAddressBook (const CTxDestination &address, const std::string &strName, const std::string &purpose)
 
bool DelAddressBook (const CTxDestination &address)
 
const std::string & GetLabelName (const CScript &scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
unsigned int GetKeyPoolSize () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void SetMinVersion (enum WalletFeature, WalletBatch *batch_in=nullptr, bool fExplicit=false)
 signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower More...
 
bool SetMaxVersion (int nVersion)
 change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format) More...
 
int GetVersion ()
 get the current wallet format (the oldest client version guaranteed to understand this wallet) More...
 
std::set< uint256GetConflicts (const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Get wallet transactions that conflict with given transaction (spend same outputs) More...
 
bool HasWalletSpend (const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Check if a given transaction has any of its outputs spent by another transaction in the wallet. More...
 
void Flush (bool shutdown=false)
 Flush wallet (bitdb flush) More...
 
bool GetBroadcastTransactions () const
 
void SetBroadcastTransactions (bool broadcast)
 
bool TransactionCanBeAbandoned (const uint256 &hashTx) const
 
bool AbandonTransaction (interfaces::Chain::Lock &locked_chain, const uint256 &hashTx)
 
bool MarkReplaced (const uint256 &originalHash, const uint256 &newHash)
 
void postInitProcess ()
 
bool BackupWallet (const std::string &strDest)
 
void SetHDChain (const CHDChain &chain, bool memonly)
 
const CHDChainGetHDChain () const
 
bool IsHDEnabled () const
 
bool CanGenerateKeys ()
 
bool CanGetAddresses (bool internal=false)
 
CPubKey GenerateNewSeed ()
 
CPubKey DeriveNewSeed (const CKey &key)
 
void SetHDSeed (const CPubKey &key)
 
void BlockUntilSyncedToCurrentChain () LOCKS_EXCLUDED(cs_main
 
void LearnRelatedScripts (const CPubKey &key, OutputType)
 
void LearnAllRelatedScripts (const CPubKey &key)
 
void SetWalletFlag (uint64_t flags)
 
void UnsetWalletFlag (uint64_t flag)
 
bool IsWalletFlagSet (uint64_t flag) const
 
bool SetWalletFlags (uint64_t overwriteFlags, bool memOnly)
 
const std::string GetDisplayName () const
 
template<typename... Params>
void WalletLogPrintf (std::string fmt, Params... parameters) const
 
bool GetKeyOrigin (const CKeyID &keyid, KeyOriginInfo &info) const override
 
- Public Member Functions inherited from FillableSigningProvider
virtual bool AddKey (const CKey &key)
 
virtual bool HaveCScript (const CScriptID &hash) const override
 
virtual std::set< CScriptIDGetCScripts () const
 
virtual bool GetCScript (const CScriptID &hash, CScript &redeemScriptOut) const override
 
- Public Member Functions inherited from SigningProvider
virtual ~SigningProvider ()
 

Static Public Member Functions

static bool Verify (interfaces::Chain &chain, const WalletLocation &location, bool salvage_wallet, std::string &error_string, std::string &warning_string)
 Verify wallet naming and perform salvage on the wallet if required. More...
 
static std::shared_ptr< CWalletCreateWalletFromFile (interfaces::Chain &chain, const WalletLocation &location, uint64_t wallet_creation_flags=0)
 

Public Attributes

CCriticalSection cs_wallet
 
MasterKeyMap mapMasterKeys
 
unsigned int nMasterKeyMaxID = 0
 
TxItems wtxOrdered
 
uint64_t nAccountingEntryNumber = 0
 
std::unique_ptr< interfaces::Handlerm_chain_notifications_handler
 
int64_t nRelockTime = 0
 Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock(). More...
 
CFeeRate m_pay_tx_fee {DEFAULT_PAY_TX_FEE}
 
unsigned int m_confirm_target {DEFAULT_TX_CONFIRM_TARGET}
 
bool m_spend_zero_conf_change {DEFAULT_SPEND_ZEROCONF_CHANGE}
 
bool m_signal_rbf {DEFAULT_WALLET_RBF}
 
bool m_allow_fallback_fee {true}
 will be defined via chainparams More...
 
CFeeRate m_min_fee {DEFAULT_TRANSACTION_MINFEE}
 Override with -mintxfee. More...
 
CFeeRate m_fallback_fee {DEFAULT_FALLBACK_FEE}
 
CFeeRate m_discard_rate {DEFAULT_DISCARD_FEE}
 
OutputType m_default_address_type {DEFAULT_ADDRESS_TYPE}
 
OutputType m_default_change_type {DEFAULT_CHANGE_TYPE}
 
CAmount m_default_max_tx_fee {DEFAULT_TRANSACTION_MAXFEE}
 
boost::signals2::signal< void()> NotifyUnload
 
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
 
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
 
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
 
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
 
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
 
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
 
void cs_wallet
 

Private Types

using CryptedKeyMap = std::map< CKeyID, std::pair< CPubKey, std::vector< unsigned char > >>
 
using WatchOnlySet = std::set< CScript >
 
using WatchKeyMap = std::map< CKeyID, CPubKey >
 
typedef std::multimap< COutPoint, uint256TxSpends
 

Private Member Functions

CKeyingMaterial vMasterKey GUARDED_BY (cs_KeyStore)
 
bool SetCrypted ()
 
bool EncryptKeys (CKeyingMaterial &vMasterKeyIn)
 will encrypt previously unencrypted keys More...
 
bool Unlock (const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
 
CryptedKeyMap mapCryptedKeys GUARDED_BY (cs_KeyStore)
 
WatchOnlySet setWatchOnly GUARDED_BY (cs_KeyStore)
 
WatchKeyMap mapWatchKeys GUARDED_BY (cs_KeyStore)
 
bool AddCryptedKeyInner (const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
 
bool AddKeyPubKeyInner (const CKey &key, const CPubKey &pubkey)
 
WalletBatch *encrypted_batch GUARDED_BY (cs_wallet)
 
int nWalletVersion GUARDED_BY (cs_wallet)
 the current wallet version: clients below this version are not able to load the wallet More...
 
int nWalletMaxVersion GUARDED_BY (cs_wallet)
 the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded More...
 
TxSpends mapTxSpends GUARDED_BY (cs_wallet)
 
void AddToSpends (const COutPoint &outpoint, const uint256 &wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void AddToSpends (const uint256 &wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool AddToWalletIfInvolvingMe (const CTransactionRef &tx, const uint256 &block_hash, int posInBlock, bool fUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void MarkConflicted (const uint256 &hashBlock, const uint256 &hashTx)
 
void MarkInputsDirty (const CTransactionRef &tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void SyncMetaData (std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void SyncTransaction (const CTransactionRef &tx, const uint256 &block_hash, int posInBlock=0, bool update_tx=true) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void DeriveNewChildKey (WalletBatch &batch, CKeyMetadata &metadata, CKey &secret, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
std::set< int64_t > setInternalKeyPool GUARDED_BY (cs_wallet)
 
std::set< int64_t > setExternalKeyPool GUARDED_BY (cs_wallet)
 
std::set< int64_t > set_pre_split_keypool GUARDED_BY (cs_wallet)
 
int64_t m_max_keypool_index GUARDED_BY (cs_wallet)=0
 
int64_t nTimeFirstKey GUARDED_BY (cs_wallet)=0
 
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)
 
bool AddKeyOriginWithDB (WalletBatch &batch, const CPubKey &pubkey, const KeyOriginInfo &info)
 
bool AddKeyPubKeyWithDB (WalletBatch &batch, const CKey &key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Adds a key to the store, and saves it to disk. More...
 
bool AddWatchOnlyWithDB (WalletBatch &batch, const CScript &dest, int64_t create_time) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Adds a watch-only address to the store, and saves it to disk. More...
 
void AddKeypoolPubkeyWithDB (const CPubKey &pubkey, const bool internal, WalletBatch &batch)
 
bool SetAddressBookWithDB (WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::string &strPurpose)
 
bool AddCScriptWithDB (WalletBatch &batch, const CScript &script)
 Adds a script to the store and saves it to disk. More...
 
void UnsetWalletFlagWithDB (WalletBatch &batch, uint64_t flag)
 Unsets a wallet flag and saves it to disk. More...
 
uint256 m_last_block_processed GUARDED_BY (cs_wallet)
 
bool GetKeyFromPool (CPubKey &key, bool internal=false)
 Fetches a key from the keypool. More...
 
- Private Member Functions inherited from interfaces::Chain::Notifications
virtual ~Notifications ()
 

Private Attributes

std::atomic< bool > fUseCrypto
 
bool fDecryptionThoroughlyChecked
 keeps track of whether Unlock has run a thorough check before More...
 
std::atomic< bool > fAbortRescan {false}
 
std::atomic< bool > fScanningWallet {false}
 
std::atomic< int64_tm_scanning_start {0}
 
std::atomic< double > m_scanning_progress {0}
 
std::mutex mutexScanning
 
int64_t nNextResend = 0
 
int64_t nLastResend = 0
 
bool fBroadcastTransactions = false
 
std::atomic< int64_tm_best_block_time {0}
 
CHDChain hdChain
 
std::map< CKeyID, int64_tm_pool_key_to_index
 
std::atomic< uint64_tm_wallet_flags {0}
 
interfaces::Chainm_chain
 
WalletLocation m_location
 
std::unique_ptr< WalletDatabasedatabase
 

Friends

class WalletRescanReserver
 

Additional Inherited Members

- Protected Types inherited from FillableSigningProvider
using KeyMap = std::map< CKeyID, CKey >
 
using ScriptMap = std::map< CScriptID, CScript >
 
- Protected Member Functions inherited from FillableSigningProvider
KeyMap mapKeys GUARDED_BY (cs_KeyStore)
 
ScriptMap mapScripts GUARDED_BY (cs_KeyStore)
 
void ImplicitlyLearnRelatedKeyScripts (const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
 
- Protected Attributes inherited from FillableSigningProvider
CCriticalSection cs_KeyStore
 

Detailed Description

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.

Member Typedef Documentation

◆ CryptedKeyMap

using CWallet::CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char> >>
private

◆ MasterKeyMap

typedef std::map<unsigned int, CMasterKey> CWallet::MasterKeyMap

◆ TxItems

typedef std::multimap<int64_t, CWalletTx*> CWallet::TxItems

◆ TxSpends

typedef std::multimap<COutPoint, uint256> CWallet::TxSpends
private

Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated transactions where the mutant gets mined).

◆ WatchKeyMap

using CWallet::WatchKeyMap = std::map<CKeyID, CPubKey>
private

◆ WatchOnlySet

using CWallet::WatchOnlySet = std::set<CScript>
private

Constructor & Destructor Documentation

◆ CWallet()

CWallet::CWallet ( interfaces::Chain chain,
const WalletLocation location,
std::unique_ptr< WalletDatabase database 
)
inline

Construct wallet with specified name and database implementation.

◆ ~CWallet()

CWallet::~CWallet ( )
inline

Member Function Documentation

◆ AbortRescan()

void CWallet::AbortRescan ( )
inline

◆ AddCryptedKeyInner()

bool CWallet::AddCryptedKeyInner ( const CPubKey vchPubKey,
const std::vector< unsigned char > &  vchCryptedSecret 
)
private

◆ AddDestData()

bool CWallet::AddDestData ( const CTxDestination dest,
const std::string &  key,
const std::string &  value 
)

Adds a destination data tuple to the store, and saves it to disk.

◆ AddKeyOriginWithDB()

bool CWallet::AddKeyOriginWithDB ( WalletBatch batch,
const CPubKey pubkey,
const KeyOriginInfo info 
)
private

Add a KeyOriginInfo to the wallet

◆ AddKeyPubKeyInner()

bool CWallet::AddKeyPubKeyInner ( const CKey key,
const CPubKey pubkey 
)
private

◆ BackupWallet()

bool CWallet::BackupWallet ( const std::string &  strDest)

◆ CanSupportFeature()

bool CWallet::CanSupportFeature ( enum WalletFeature  wf) const
inline

check whether we are allowed to upgrade (or already support) to the named feature

◆ chain()

interfaces::Chain& CWallet::chain ( ) const
inline

Interface for accessing chain state.

◆ ComputeTimeSmart()

unsigned int CWallet::ComputeTimeSmart ( const CWalletTx wtx) const

Compute smart timestamp for a transaction being added to the wallet.

Logic:

  • If sending a transaction, assign its timestamp to the current time.
  • If receiving a transaction outside a block, assign its timestamp to the current time.
  • If receiving a block with a future timestamp, assign all its (not already known) transactions' timestamps to the current time.
  • If receiving a block with a past timestamp, before the most recent known transaction (that we care about), assign all its (not already known) transactions' timestamps to the same timestamp as that most-recent-known transaction.
  • If receiving a block with a past timestamp, but after the most recent known transaction, assign all its (not already known) transactions' timestamps to the block time.

For more information see CWalletTx::nTimeSmart, https://bitcointalk.org/?topic=54527, or https://github.com/bitcoin/bitcoin/pull/1393.

◆ CreateWalletFromFile()

std::shared_ptr< CWallet > CWallet::CreateWalletFromFile ( interfaces::Chain chain,
const WalletLocation location,
uint64_t  wallet_creation_flags = 0 
)
static

◆ DummySignTx()

bool CWallet::DummySignTx ( CMutableTransaction txNew,
const std::set< CTxOut > &  txouts,
bool  use_max_sig = false 
) const
inline

◆ EncryptKeys()

bool CWallet::EncryptKeys ( CKeyingMaterial vMasterKeyIn)
private

will encrypt previously unencrypted keys

◆ EraseDestData()

bool CWallet::EraseDestData ( const CTxDestination dest,
const std::string &  key 
)

Erases a destination data tuple in the store and on disk.

◆ GetAllReserveKeys()

const std::map<CKeyID, int64_t>& CWallet::GetAllReserveKeys ( ) const
inline

◆ GetBroadcastTransactions()

bool CWallet::GetBroadcastTransactions ( ) const
inline

Inquire whether this wallet broadcasts transactions.

◆ GetDBHandle()

WalletDatabase& CWallet::GetDBHandle ( )
inline

Get database handle used by this wallet. Ideally this function would not be necessary.

◆ GetDestData()

bool CWallet::GetDestData ( const CTxDestination dest,
const std::string &  key,
std::string *  value 
) const

Look up a destination data tuple in the store, return true if found false otherwise.

◆ GetDestValues()

std::vector< std::string > CWallet::GetDestValues ( const std::string &  prefix) const

Get all destination values matching a prefix.

◆ GetDisplayName()

const std::string CWallet::GetDisplayName ( ) const
inline

Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet has no name

◆ GetHDChain()

const CHDChain& CWallet::GetHDChain ( ) const
inline

◆ GetKey()

bool CWallet::GetKey ( const CKeyID address,
CKey keyOut 
) const
overridevirtual

Reimplemented from FillableSigningProvider.

◆ GetKeyBirthTimes()

void CWallet::GetKeyBirthTimes ( interfaces::Chain::Lock locked_chain,
std::map< CKeyID, int64_t > &  mapKeyBirth 
) const

◆ GetKeyOrigin()

bool CWallet::GetKeyOrigin ( const CKeyID keyid,
KeyOriginInfo info 
) const
overridevirtual

Implement lookup of key origin information through wallet key metadata.

Reimplemented from SigningProvider.

◆ GetKeyPoolSize()

unsigned int CWallet::GetKeyPoolSize ( )
inline

◆ GetKeys()

std::set< CKeyID > CWallet::GetKeys ( ) const
overridevirtual

Reimplemented from FillableSigningProvider.

◆ GetLocation()

const WalletLocation& CWallet::GetLocation ( ) const
inline

◆ GetName()

const std::string& CWallet::GetName ( ) const
inline

Get a name for this wallet for logging/debugging purposes.

◆ GetPubKey()

bool CWallet::GetPubKey ( const CKeyID address,
CPubKey vchPubKeyOut 
) const
overridevirtual

Reimplemented from FillableSigningProvider.

◆ GetVersion()

int CWallet::GetVersion ( )
inline

get the current wallet format (the oldest client version guaranteed to understand this wallet)

◆ GetWatchPubKey()

bool CWallet::GetWatchPubKey ( const CKeyID address,
CPubKey pubkey_out 
) const

Fetches a pubkey from mapWatchKeys if it exists there.

◆ GroupOutputs()

std::vector< OutputGroup > CWallet::GroupOutputs ( const std::vector< COutput > &  outputs,
bool  single_coin 
) const

◆ GUARDED_BY() [1/20]

CKeyingMaterial vMasterKey CWallet::GUARDED_BY ( cs_KeyStore  )
private

◆ GUARDED_BY() [2/20]

CryptedKeyMap mapCryptedKeys CWallet::GUARDED_BY ( cs_KeyStore  )
private

◆ GUARDED_BY() [3/20]

WatchOnlySet setWatchOnly CWallet::GUARDED_BY ( cs_KeyStore  )
private

◆ GUARDED_BY() [4/20]

WatchKeyMap mapWatchKeys CWallet::GUARDED_BY ( cs_KeyStore  )
private

◆ GUARDED_BY() [5/20]

WalletBatch* encrypted_batch CWallet::GUARDED_BY ( cs_wallet  )
private

◆ GUARDED_BY() [6/20]

int nWalletVersion CWallet::GUARDED_BY ( cs_wallet  )
inlineprivate

the current wallet version: clients below this version are not able to load the wallet

◆ GUARDED_BY() [7/20]

int nWalletMaxVersion CWallet::GUARDED_BY ( cs_wallet  )
private

the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded

◆ GUARDED_BY() [8/20]

TxSpends mapTxSpends CWallet::GUARDED_BY ( cs_wallet  )
private

◆ GUARDED_BY() [9/20]

std::set<int64_t> setInternalKeyPool CWallet::GUARDED_BY ( cs_wallet  )
private

◆ GUARDED_BY() [10/20]

std::set<int64_t> setExternalKeyPool CWallet::GUARDED_BY ( cs_wallet  )
private

◆ GUARDED_BY() [11/20]

std::set<int64_t> set_pre_split_keypool CWallet::GUARDED_BY ( cs_wallet  )
private

◆ GUARDED_BY() [12/20]

int64_t m_max_keypool_index CWallet::GUARDED_BY ( cs_wallet  )
privatepure virtual

◆ GUARDED_BY() [13/20]

int64_t nTimeFirstKey CWallet::GUARDED_BY ( cs_wallet  )
privatepure virtual

◆ GUARDED_BY() [14/20]

uint256 m_last_block_processed CWallet::GUARDED_BY ( cs_wallet  )
private

The following is used to keep track of how far behind the wallet is 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 to have seen all transactions in the chain, but is only used to track live BlockConnected callbacks.

◆ GUARDED_BY() [15/20]

std::map<CKeyID, CKeyMetadata> mapKeyMetadata CWallet::GUARDED_BY ( cs_wallet  )

◆ GUARDED_BY() [16/20]

std::map<CScriptID, CKeyMetadata> m_script_metadata CWallet::GUARDED_BY ( cs_wallet  )

◆ GUARDED_BY() [17/20]

std::map<uint256, CWalletTx> mapWallet CWallet::GUARDED_BY ( cs_wallet  )

◆ GUARDED_BY() [18/20]

int64_t nOrderPosNext CWallet::GUARDED_BY ( cs_wallet  )
pure virtual

◆ GUARDED_BY() [19/20]

std::map<CTxDestination, CAddressBookData> mapAddressBook CWallet::GUARDED_BY ( cs_wallet  )

◆ GUARDED_BY() [20/20]

std::set<COutPoint> setLockedCoins CWallet::GUARDED_BY ( cs_wallet  )

◆ handleNotifications()

void CWallet::handleNotifications ( )

Register the wallet for chain notifications

◆ HaveKey()

bool CWallet::HaveKey ( const CKeyID address) const
overridevirtual

Reimplemented from FillableSigningProvider.

◆ IsAbortingRescan()

bool CWallet::IsAbortingRescan ( )
inline

◆ IsCrypted()

bool CWallet::IsCrypted ( ) const
inline

◆ IsLocked()

bool CWallet::IsLocked ( ) const

◆ IsScanning()

bool CWallet::IsScanning ( )
inline

◆ LearnAllRelatedScripts()

void CWallet::LearnAllRelatedScripts ( const CPubKey key)

Same as LearnRelatedScripts, but when the OutputType is not known (and could be anything).

◆ LearnRelatedScripts()

void CWallet::LearnRelatedScripts ( const CPubKey key,
OutputType  type 
)

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.

◆ LoadDestData()

void CWallet::LoadDestData ( const CTxDestination dest,
const std::string &  key,
const std::string &  value 
)

Adds a destination data tuple to the store, without saving it to disk.

◆ LoadKey()

bool CWallet::LoadKey ( const CKey key,
const CPubKey pubkey 
)
inline

Adds a key to the store, without saving it to disk (used by LoadWallet)

◆ LoadMinVersion()

bool CWallet::LoadMinVersion ( int  nVersion)
inline

◆ Lock()

bool CWallet::Lock ( )

◆ MarkPreSplitKeys()

void CWallet::MarkPreSplitKeys ( )

◆ postInitProcess()

void CWallet::postInitProcess ( )

Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init tasks

◆ ScanningDuration()

int64_t CWallet::ScanningDuration ( ) const
inline

◆ ScanningProgress()

double CWallet::ScanningProgress ( ) const
inline

◆ SetBroadcastTransactions()

void CWallet::SetBroadcastTransactions ( bool  broadcast)
inline

Set whether this wallet broadcasts transactions.

◆ SetCrypted()

bool CWallet::SetCrypted ( )
private

◆ Unlock()

bool CWallet::Unlock ( const CKeyingMaterial vMasterKeyIn,
bool  accept_no_keys = false 
)
private

◆ Verify()

bool CWallet::Verify ( interfaces::Chain chain,
const WalletLocation location,
bool  salvage_wallet,
std::string &  error_string,
std::string &  warning_string 
)
static

Verify wallet naming and perform salvage on the wallet if required.

◆ WalletLogPrintf()

template<typename... Params>
void CWallet::WalletLogPrintf ( std::string  fmt,
Params...  parameters 
) const
inline

Prepends the wallet name in logging output to ease debugging in multi-wallet use cases

Friends And Related Function Documentation

◆ WalletRescanReserver

friend class WalletRescanReserver
friend

Member Data Documentation

◆ cs_wallet [1/2]

CCriticalSection CWallet::cs_wallet
mutable

◆ cs_wallet [2/2]

void CWallet::cs_wallet

◆ database

std::unique_ptr<WalletDatabase> CWallet::database
private

Internal database handle.

◆ fAbortRescan

std::atomic<bool> CWallet::fAbortRescan {false}
private

◆ fBroadcastTransactions

bool CWallet::fBroadcastTransactions = false
private

◆ fDecryptionThoroughlyChecked

bool CWallet::fDecryptionThoroughlyChecked
private

keeps track of whether Unlock has run a thorough check before

◆ fScanningWallet

std::atomic<bool> CWallet::fScanningWallet {false}
private

◆ fUseCrypto

std::atomic<bool> CWallet::fUseCrypto
private

if fUseCrypto is true, mapKeys must be empty if fUseCrypto is false, vMasterKey must be empty

◆ hdChain

CHDChain CWallet::hdChain
private

◆ m_allow_fallback_fee

bool CWallet::m_allow_fallback_fee {true}

will be defined via chainparams

◆ m_best_block_time

std::atomic<int64_t> CWallet::m_best_block_time {0}
private

◆ m_chain

interfaces::Chain* CWallet::m_chain
private

Interface for accessing chain state.

◆ m_chain_notifications_handler

std::unique_ptr<interfaces::Handler> CWallet::m_chain_notifications_handler

Registered interfaces::Chain::Notifications handler.

◆ m_confirm_target

unsigned int CWallet::m_confirm_target {DEFAULT_TX_CONFIRM_TARGET}

◆ m_default_address_type

OutputType CWallet::m_default_address_type {DEFAULT_ADDRESS_TYPE}

◆ m_default_change_type

OutputType CWallet::m_default_change_type {DEFAULT_CHANGE_TYPE}

◆ m_default_max_tx_fee

CAmount CWallet::m_default_max_tx_fee {DEFAULT_TRANSACTION_MAXFEE}

Absolute maximum transaction fee (in satoshis) used by default for the wallet

◆ m_discard_rate

CFeeRate CWallet::m_discard_rate {DEFAULT_DISCARD_FEE}

◆ m_fallback_fee

CFeeRate CWallet::m_fallback_fee {DEFAULT_FALLBACK_FEE}

If fee estimation does not have enough data to provide estimates, use this fee instead. Has no effect if not using fee estimation Override with -fallbackfee

◆ m_location

WalletLocation CWallet::m_location
private

Wallet location which includes wallet name (see WalletLocation).

◆ m_min_fee

CFeeRate CWallet::m_min_fee {DEFAULT_TRANSACTION_MINFEE}

Override with -mintxfee.

◆ m_pay_tx_fee

CFeeRate CWallet::m_pay_tx_fee {DEFAULT_PAY_TX_FEE}

◆ m_pool_key_to_index

std::map<CKeyID, int64_t> CWallet::m_pool_key_to_index
private

◆ m_scanning_progress

std::atomic<double> CWallet::m_scanning_progress {0}
private

◆ m_scanning_start

std::atomic<int64_t> CWallet::m_scanning_start {0}
private

◆ m_signal_rbf

bool CWallet::m_signal_rbf {DEFAULT_WALLET_RBF}

◆ m_spend_zero_conf_change

bool CWallet::m_spend_zero_conf_change {DEFAULT_SPEND_ZEROCONF_CHANGE}

◆ m_wallet_flags

std::atomic<uint64_t> CWallet::m_wallet_flags {0}
private

◆ mapMasterKeys

MasterKeyMap CWallet::mapMasterKeys

◆ mutexScanning

std::mutex CWallet::mutexScanning
private

◆ nAccountingEntryNumber

uint64_t CWallet::nAccountingEntryNumber = 0

◆ nLastResend

int64_t CWallet::nLastResend = 0
private

◆ nMasterKeyMaxID

unsigned int CWallet::nMasterKeyMaxID = 0

◆ nNextResend

int64_t CWallet::nNextResend = 0
private

◆ NotifyAddressBookChanged

boost::signals2::signal<void (CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> CWallet::NotifyAddressBookChanged

Address book entry changed.

Note
called with lock cs_wallet held.

◆ NotifyCanGetAddressesChanged

boost::signals2::signal<void ()> CWallet::NotifyCanGetAddressesChanged

Keypool has new keys

◆ NotifyStatusChanged

boost::signals2::signal<void (CWallet* wallet)> CWallet::NotifyStatusChanged

Wallet status (encrypted, locked) changed. Note: Called without locks held.

◆ NotifyTransactionChanged

boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx, ChangeType status)> CWallet::NotifyTransactionChanged

Wallet transaction added, removed or updated.

Note
called with lock cs_wallet held.

◆ NotifyUnload

boost::signals2::signal<void ()> CWallet::NotifyUnload

Wallet is about to be unloaded

◆ NotifyWatchonlyChanged

boost::signals2::signal<void (bool fHaveWatchOnly)> CWallet::NotifyWatchonlyChanged

Watch-only address added

◆ nRelockTime

int64_t CWallet::nRelockTime = 0

Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock().

◆ ShowProgress

boost::signals2::signal<void (const std::string &title, int nProgress)> CWallet::ShowProgress

Show progress e.g. for rescan

◆ wtxOrdered

TxItems CWallet::wtxOrdered

The documentation for this class was generated from the following files: