Bitcoin Core  0.15.99
P2P Digital Currency
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

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. More...

#include <wallet.h>

Inheritance diagram for CWallet:
[legend]
Collaboration diagram for CWallet:
[legend]

Public Types

enum  ScanResult { ScanResult::SUCCESS, ScanResult::FAILURE, ScanResult::USER_ABORT }
 
typedef std::map< unsigned int, CMasterKeyMasterKeyMap
 
typedef std::multimap< int64_t, CWalletTx * > TxItems
 

Public Member Functions

WalletDatabaseGetDBHandle ()
 Get database handle used by this wallet. More...
 
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)
 Select a set of coins such that nValueRet >= nTargetValue and at least all coins from coinControl are selected; Never select unconfirmed coins if they are not ours. More...
 
const WalletLocationGetLocation () const
 
const std::string & GetName () const
 Get a name for this wallet for logging/debugging purposes. More...
 
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)
 Construct wallet with specified name and database implementation. More...
 
 ~CWallet ()
 
std::map< uint256, CWalletTx > mapWallet GUARDED_BY (cs_wallet)
 
int64_t nOrderPosNext GUARDED_BY (cs_wallet)=0
 
std::set< COutPoint > setLockedCoins GUARDED_BY (cs_wallet)
 
interfaces::Chainchain () const
 Interface for accessing chain state. More...
 
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)
 populate vCoins with vector of available COutputs. More...
 
std::map< CTxDestination, std::vector< COutput > > ListCoins (interfaces::Chain::Lock &locked_chain) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Return list of available coins and locked coins grouped by non-change output address. More...
 
const CTxOutFindNonChangeParentOutput (const CTransaction &tx, int output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Find non-change parent output. More...
 
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
 Shuffle and select coins until nTargetValue is reached while avoiding small change; This method is stochastic for some inputs and upon completion the coin set and corresponding actual target value is assembled. More...
 
bool IsSpent (interfaces::Chain::Lock &locked_chain, const uint256 &hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Outpoint is spent if any non-conflicted transaction spends it: More...
 
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 ()
 
CPubKey GenerateNewKey (WalletBatch &batch, bool internal=false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 keystore implementation Generate a new key More...
 
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 AddKeyPubKeyWithDB (WalletBatch &batch, const CKey &key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
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)
 
bool LoadMinVersion (int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
void UpdateTimeFirstKey (int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Update wallet first key creation time. More...
 
bool AddCryptedKey (const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret) override
 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 AddCScript (const CScript &redeemScript) override
 Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki. More...
 
bool LoadCScript (const CScript &redeemScript)
 
bool 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. More...
 
bool EraseDestData (const CTxDestination &dest, const std::string &key)
 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)
 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
 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
 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) override 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 Unlock (const SecureString &strWalletPassphrase)
 
bool ChangeWalletPassphrase (const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
 
bool EncryptWallet (const SecureString &strWalletPassphrase)
 
void GetKeyBirthTimes (interfaces::Chain::Lock &locked_chain, std::map< CTxDestination, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
unsigned int ComputeTimeSmart (const CWalletTx &wtx) const
 Compute smart timestamp for a transaction being added to the wallet. More...
 
int64_t IncOrderPosNext (WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Increment the next transaction order id. More...
 
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
 Notifies listeners of a transaction having been added to mempool. More...
 
void BlockConnected (const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindex, const std::vector< CTransactionRef > &vtxConflicted) override
 Notifies listeners of a block being connected. More...
 
void BlockDisconnected (const std::shared_ptr< const CBlock > &pblock) override
 Notifies listeners of a block being disconnected. More...
 
int64_t RescanFromTime (int64_t startTime, const WalletRescanReserver &reserver, bool update)
 Scan active chain for relevant transactions after importing keys. More...
 
ScanResult ScanForWalletTransactions (const CBlockIndex *const pindexStart, const CBlockIndex *const pindexStop, const WalletRescanReserver &reserver, const CBlockIndex *&failed_block, const CBlockIndex *&stop_block, bool fUpdate=false)
 Scan the block chain (starting in pindexStart) for transactions from or to us. More...
 
void TransactionRemovedFromMempool (const CTransactionRef &ptx) override
 Notifies listeners of a transaction leaving mempool. More...
 
void ReacceptWalletTransactions ()
 
void ResendWalletTransactions (int64_t nBestBlockTime, CConnman *connman) override EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Tells listeners to broadcast their data. More...
 
std::vector< uint256ResendWalletTransactionsBefore (interfaces::Chain::Lock &locked_chain, int64_t nTime, CConnman *connman)
 
CAmount GetBalance (const isminefilter &filter=ISMINE_SPENDABLE, const int min_depth=0) const
 
CAmount GetUnconfirmedBalance () const
 
CAmount GetImmatureBalance () const
 
CAmount GetUnconfirmedWatchOnlyBalance () const
 
CAmount GetImmatureWatchOnlyBalance () const
 
CAmount GetLegacyBalance (const isminefilter &filter, int minDepth) 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)
 Insert additional inputs into the transaction by calling CreateTransaction();. More...
 
bool SignTransaction (CMutableTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool CreateTransaction (interfaces::Chain::Lock &locked_chain, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coin_control, bool sign=true)
 Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also create the change output, when needed. More...
 
bool CommitTransaction (CTransactionRef tx, mapValue_t mapValue, std::vector< std::pair< std::string, std::string >> orderForm, CReserveKey &reservekey, CConnman *connman, CValidationState &state)
 Call after CreateTransaction unless you want to abort. More...
 
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 NewKeyPool ()
 Mark old keypool keys as used, and generate all new keys. More...
 
size_t KeypoolCountExternalKeys () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 
bool TopUpKeyPool (unsigned int kpSize=0)
 
bool ReserveKeyFromKeyPool (int64_t &nIndex, CKeyPool &keypool, bool fRequestedInternal)
 Reserves a key from the keypool and sets nIndex to its index. More...
 
void KeepKey (int64_t nIndex)
 
void ReturnKey (int64_t nIndex, bool fInternal, const CPubKey &pubkey)
 
bool GetKeyFromPool (CPubKey &key, bool internal=false)
 
int64_t GetOldestKeyPoolTime ()
 
void MarkReserveKeysAsUsed (int64_t keypool_id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Marks all keys in the keypool up to and including reserve_key as used. More...
 
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
 
isminetype IsMine (const CTxIn &txin) const
 
CAmount GetDebit (const CTxIn &txin, const isminefilter &filter) const
 Returns amount of debit if the input matches the filter, otherwise returns 0. More...
 
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
 should probably be renamed to IsRelevantToMe More...
 
CAmount GetDebit (const CTransaction &tx, const isminefilter &filter) const
 
bool IsAllFromMe (const CTransaction &tx, const isminefilter &filter) const
 Returns whether all of the inputs match the filter. More...
 
CAmount GetCredit (const CTransaction &tx, const isminefilter &filter) const
 
CAmount GetChange (const CTransaction &tx) const
 
void ChainStateFlushed (const CBlockLocator &loc) override
 Notifies listeners of the new active block chain on-disk. More...
 
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
 
void GetScriptForMining (std::shared_ptr< CReserveScript > &script)
 
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
 Inquire whether this wallet broadcasts transactions. More...
 
void SetBroadcastTransactions (bool broadcast)
 Set whether this wallet broadcasts transactions. More...
 
bool TransactionCanBeAbandoned (const uint256 &hashTx) const
 Return whether transaction can be abandoned. More...
 
bool AbandonTransaction (interfaces::Chain::Lock &locked_chain, const uint256 &hashTx)
 
bool MarkReplaced (const uint256 &originalHash, const uint256 &newHash)
 Mark a transaction as replaced by another transaction (e.g., BIP 125). More...
 
void postInitProcess ()
 Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init tasks. More...
 
bool BackupWallet (const std::string &strDest)
 
void SetHDChain (const CHDChain &chain, bool memonly)
 
const CHDChainGetHDChain () const
 
bool IsHDEnabled () const
 
CPubKey GenerateNewSeed ()
 
CPubKey DeriveNewSeed (const CKey &key)
 
void SetHDSeed (const CPubKey &key)
 
void BlockUntilSyncedToCurrentChain () LOCKS_EXCLUDED(cs_main
 Blocks until the wallet state is up-to-date to /at least/ the current chain at the time this function is entered Obviously holding cs_main/cs_wallet when going into this call may cause deadlock. More...
 
void LearnRelatedScripts (const CPubKey &key, OutputType)
 Explicitly make the wallet learn the related scripts for outputs to the given key. More...
 
void LearnAllRelatedScripts (const CPubKey &key)
 Same as LearnRelatedScripts, but when the OutputType is not known (and could be anything). More...
 
void SetWalletFlag (uint64_t flags)
 set a single wallet flag More...
 
bool IsWalletFlagSet (uint64_t flag)
 check if a certain wallet flag is set More...
 
bool SetWalletFlags (uint64_t overwriteFlags, bool memOnly)
 overwrite all flags by the given uint64_t returns false if unknown, non-tolerable flags are present More...
 
const std::string GetDisplayName () const
 Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet has no name. More...
 
template<typename... Params>
void WalletLogPrintf (std::string fmt, Params... parameters) const
 Prepends the wallet name in logging output to ease debugging in multi-wallet use cases. More...
 
bool GetKeyOrigin (const CKeyID &keyid, KeyOriginInfo &info) const override
 Implement lookup of key origin information through wallet key metadata. More...
 
- Public Member Functions inherited from CCryptoKeyStore
 CCryptoKeyStore ()
 
bool IsCrypted () const
 
bool IsLocked () const
 
bool Lock ()
 
bool HaveKey (const CKeyID &address) const override
 Check whether a key corresponding to a given address is present in the store. More...
 
bool GetKey (const CKeyID &address, CKey &keyOut) const override
 
bool GetPubKey (const CKeyID &address, CPubKey &vchPubKeyOut) const override
 
std::set< CKeyIDGetKeys () const override
 
- Public Member Functions inherited from CBasicKeyStore
bool AddKey (const CKey &key)
 
bool HaveCScript (const CScriptID &hash) const override
 
std::set< CScriptIDGetCScripts () const override
 
bool GetCScript (const CScriptID &hash, CScript &redeemScriptOut) const override
 
bool HaveWatchOnly (const CScript &dest) const override
 
bool HaveWatchOnly () 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::map< CTxDestination, CAddressBookDatamapAddressBook
 
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}
 If fee estimation does not have enough data to provide estimates, use this fee instead. More...
 
CFeeRate m_discard_rate {DEFAULT_DISCARD_FEE}
 
OutputType m_default_address_type {DEFAULT_ADDRESS_TYPE}
 
OutputType m_default_change_type {DEFAULT_CHANGE_TYPE}
 
boost::signals2::signal< void()> NotifyUnload
 Wallet is about to be unloaded. More...
 
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
 Address book entry changed. More...
 
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
 Wallet transaction added, removed or updated. More...
 
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
 Show progress e.g. More...
 
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
 Watch-only address added. More...
 
void cs_wallet
 
- Public Attributes inherited from CCryptoKeyStore
boost::signals2::signal< void(CCryptoKeyStore *wallet)> NotifyStatusChanged
 Wallet status (encrypted, locked) changed. More...
 

Private Types

typedef std::multimap< COutPoint, uint256TxSpends
 Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated transactions where the mutant gets mined). More...
 

Private Member Functions

WalletBatch *encrypted_batch GUARDED_BY (cs_wallet)
 
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 CBlockIndex *pIndex, int posInBlock, bool fUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Add a transaction to the wallet, or update it. More...
 
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 CBlockIndex *pindex=nullptr, 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 > setExternalKeyPool 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) override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 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. More...
 

Private Attributes

std::atomic< bool > fAbortRescan {false}
 
std::atomic< bool > fScanningWallet {false}
 
std::mutex mutexScanning
 
int nWalletVersion = FEATURE_BASE
 the current wallet version: clients below this version are not able to load the wallet More...
 
int64_t nNextResend = 0
 
int64_t nLastResend = 0
 
bool fBroadcastTransactions = false
 
CHDChain hdChain
 
std::set< int64_t > setInternalKeyPool
 
std::set< int64_t > set_pre_split_keypool
 
std::map< CKeyID, int64_t > m_pool_key_to_index
 
std::atomic< uint64_t > m_wallet_flags {0}
 
interfaces::Chainm_chain
 Interface for accessing chain state. More...
 
WalletLocation m_location
 Wallet location which includes wallet name (see WalletLocation). More...
 
std::unique_ptr< WalletDatabasedatabase
 Internal database handle. More...
 
const CBlockIndexm_last_block_processed = nullptr
 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. More...
 

Friends

class WalletRescanReserver
 

Additional Inherited Members

- Protected Types inherited from CCryptoKeyStore
using CryptedKeyMap = std::map< CKeyID, std::pair< CPubKey, std::vector< unsigned char > >>
 
- Protected Types inherited from CBasicKeyStore
using KeyMap = std::map< CKeyID, CKey >
 
using WatchKeyMap = std::map< CKeyID, CPubKey >
 
using ScriptMap = std::map< CScriptID, CScript >
 
using WatchOnlySet = std::set< CScript >
 
- Protected Member Functions inherited from CCryptoKeyStore
bool SetCrypted ()
 
bool EncryptKeys (CKeyingMaterial &vMasterKeyIn)
 will encrypt previously unencrypted keys More...
 
bool Unlock (const CKeyingMaterial &vMasterKeyIn)
 
CryptedKeyMap mapCryptedKeys GUARDED_BY (cs_KeyStore)
 
- Protected Member Functions inherited from CBasicKeyStore
KeyMap mapKeys GUARDED_BY (cs_KeyStore)
 
WatchKeyMap mapWatchKeys GUARDED_BY (cs_KeyStore)
 
ScriptMap mapScripts GUARDED_BY (cs_KeyStore)
 
WatchOnlySet setWatchOnly GUARDED_BY (cs_KeyStore)
 
void ImplicitlyLearnRelatedKeyScripts (const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
 
- Protected Member Functions inherited from CValidationInterface
 ~CValidationInterface ()=default
 Protected destructor so that instances can only be deleted by derived classes. More...
 
virtual void UpdatedBlockTip (const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
 Notifies listeners when the block chain tip advances. More...
 
virtual void BlockChecked (const CBlock &, const CValidationState &)
 Notifies listeners of a block validation result. More...
 
virtual void NewPoWValidBlock (const CBlockIndex *pindex, const std::shared_ptr< const CBlock > &block)
 Notifies listeners that a block which builds directly on our current tip has been received and connected to the headers tree, though not validated yet. More...
 
friend void ::RegisterValidationInterface (CValidationInterface *)
 
friend void ::UnregisterValidationInterface (CValidationInterface *)
 
friend void ::UnregisterAllValidationInterfaces ()
 
- Protected Attributes inherited from CBasicKeyStore
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.

Definition at line 620 of file wallet.h.

Member Typedef Documentation

◆ MasterKeyMap

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

Definition at line 762 of file wallet.h.

◆ TxItems

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

Definition at line 779 of file wallet.h.

◆ 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).

Definition at line 645 of file wallet.h.

Member Enumeration Documentation

◆ ScanResult

enum CWallet::ScanResult
strong
Enumerator
SUCCESS 
FAILURE 
USER_ABORT 

Definition at line 903 of file wallet.h.

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.

Definition at line 767 of file wallet.h.

◆ ~CWallet()

CWallet::~CWallet ( )
inline

Definition at line 771 of file wallet.h.

Member Function Documentation

◆ AbortRescan()

void CWallet::AbortRescan ( )
inline

Definition at line 833 of file wallet.h.

Here is the caller graph for this function:

◆ 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.

Definition at line 3748 of file wallet.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BackupWallet()

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

Definition at line 4190 of file wallet.cpp.

◆ CanSupportFeature()

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

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

Definition at line 795 of file wallet.h.

◆ chain()

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

Interface for accessing chain state.

Definition at line 790 of file wallet.h.

Here is the caller graph for this function:

◆ 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.

Definition at line 3709 of file wallet.cpp.

Here is the call graph for this function:

◆ CreateWalletFromFile()

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

Definition at line 3866 of file wallet.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DummySignTx()

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

Definition at line 940 of file wallet.h.

Here is the caller graph for this function:

◆ EraseDestData()

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

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

Definition at line 3757 of file wallet.cpp.

Here is the call graph for this function:

◆ GetAllReserveKeys()

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

Definition at line 992 of file wallet.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBroadcastTransactions()

bool CWallet::GetBroadcastTransactions ( ) const
inline

Inquire whether this wallet broadcasts transactions.

Definition at line 1082 of file wallet.h.

◆ GetDBHandle()

WalletDatabase& CWallet::GetDBHandle ( )
inline

Get database handle used by this wallet.

Ideally this function would not be necessary.

Definition at line 734 of file wallet.h.

◆ 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.

Definition at line 3769 of file wallet.cpp.

◆ GetDestValues()

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

Get all destination values matching a prefix.

Definition at line 3785 of file wallet.cpp.

Here is the caller graph for this function:

◆ 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.

Definition at line 1161 of file wallet.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHDChain()

const CHDChain& CWallet::GetHDChain ( ) const
inline

Definition at line 1111 of file wallet.h.

Here is the caller graph for this function:

◆ GetKeyBirthTimes()

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

Definition at line 3640 of file wallet.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetKeyOrigin()

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

Implement lookup of key origin information through wallet key metadata.

Reimplemented from SigningProvider.

Definition at line 4317 of file wallet.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetKeyPoolSize()

unsigned int CWallet::GetKeyPoolSize ( )
inline

Definition at line 1032 of file wallet.h.

◆ GetLocation()

const WalletLocation& CWallet::GetLocation ( ) const
inline

Definition at line 747 of file wallet.h.

◆ GetName()

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

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

Definition at line 751 of file wallet.h.

Here is the call graph for this function:

◆ GetVersion()

int CWallet::GetVersion ( )
inline

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

Definition at line 1045 of file wallet.h.

◆ GroupOutputs()

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

Definition at line 4287 of file wallet.cpp.

Here is the call graph for this function:

◆ GUARDED_BY() [1/11]

WalletBatch* encrypted_batch CWallet::GUARDED_BY ( cs_wallet  )
private

◆ GUARDED_BY() [2/11]

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() [3/11]

TxSpends mapTxSpends CWallet::GUARDED_BY ( cs_wallet  )
private

◆ GUARDED_BY() [4/11]

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

◆ GUARDED_BY() [5/11]

int64_t m_max_keypool_index CWallet::GUARDED_BY ( cs_wallet  )
privatepure virtual

◆ GUARDED_BY() [6/11]

int64_t nTimeFirstKey CWallet::GUARDED_BY ( cs_wallet  )
privatepure virtual

◆ GUARDED_BY() [7/11]

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

◆ GUARDED_BY() [8/11]

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

◆ GUARDED_BY() [9/11]

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

◆ GUARDED_BY() [10/11]

int64_t nOrderPosNext CWallet::GUARDED_BY ( cs_wallet  )
pure virtual

◆ GUARDED_BY() [11/11]

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

◆ IsAbortingRescan()

bool CWallet::IsAbortingRescan ( )
inline

Definition at line 834 of file wallet.h.

Here is the caller graph for this function:

◆ IsScanning()

bool CWallet::IsScanning ( )
inline

Definition at line 835 of file wallet.h.

Here is the caller graph for this function:

◆ LearnAllRelatedScripts()

void CWallet::LearnAllRelatedScripts ( const CPubKey key)

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

Definition at line 4281 of file wallet.cpp.

Here is the caller graph for this function:

◆ 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 CBasicKeyStore automatically does this implicitly for all keys now.

Definition at line 4270 of file wallet.cpp.

Here is the call graph for this function:

◆ 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.

Definition at line 3764 of file wallet.cpp.

◆ 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)

Definition at line 846 of file wallet.h.

Here is the call graph for this function:

◆ LoadMinVersion()

bool CWallet::LoadMinVersion ( int  nVersion)
inline

Definition at line 851 of file wallet.h.

Here is the caller graph for this function:

◆ MarkPreSplitKeys()

void CWallet::MarkPreSplitKeys ( )

Definition at line 3799 of file wallet.cpp.

Here is the call graph for this function:

◆ postInitProcess()

void CWallet::postInitProcess ( )

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

Definition at line 4183 of file wallet.cpp.

◆ SetBroadcastTransactions()

void CWallet::SetBroadcastTransactions ( bool  broadcast)
inline

Set whether this wallet broadcasts transactions.

Definition at line 1084 of file wallet.h.

◆ 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.

Definition at line 3817 of file wallet.cpp.

Here is the call graph for this function:

◆ 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.

Definition at line 1168 of file wallet.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ WalletRescanReserver

friend class WalletRescanReserver
friend

Definition at line 626 of file wallet.h.

Member Data Documentation

◆ cs_wallet [1/2]

CCriticalSection CWallet::cs_wallet
mutable

Definition at line 729 of file wallet.h.

◆ cs_wallet [2/2]

void CWallet::cs_wallet

Definition at line 1134 of file wallet.h.

◆ database

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

Internal database handle.

Definition at line 710 of file wallet.h.

◆ fAbortRescan

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

Definition at line 623 of file wallet.h.

◆ fBroadcastTransactions

bool CWallet::fBroadcastTransactions = false
private

Definition at line 638 of file wallet.h.

◆ fScanningWallet

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

Definition at line 624 of file wallet.h.

◆ hdChain

CHDChain CWallet::hdChain
private

Definition at line 678 of file wallet.h.

◆ m_allow_fallback_fee

bool CWallet::m_allow_fallback_fee {true}

will be defined via chainparams

Definition at line 953 of file wallet.h.

◆ m_chain

interfaces::Chain& CWallet::m_chain
private

Interface for accessing chain state.

Definition at line 704 of file wallet.h.

◆ m_confirm_target

unsigned int CWallet::m_confirm_target {DEFAULT_TX_CONFIRM_TARGET}

Definition at line 950 of file wallet.h.

◆ m_default_address_type

OutputType CWallet::m_default_address_type {DEFAULT_ADDRESS_TYPE}

Definition at line 962 of file wallet.h.

◆ m_default_change_type

OutputType CWallet::m_default_change_type {DEFAULT_CHANGE_TYPE}

Definition at line 963 of file wallet.h.

◆ m_discard_rate

CFeeRate CWallet::m_discard_rate {DEFAULT_DISCARD_FEE}

Definition at line 961 of file wallet.h.

◆ 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

Definition at line 960 of file wallet.h.

◆ m_last_block_processed

const CBlockIndex* CWallet::m_last_block_processed = nullptr
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.

Protected by cs_main (see BlockUntilSyncedToCurrentChain)

Definition at line 722 of file wallet.h.

◆ m_location

WalletLocation CWallet::m_location
private

Wallet location which includes wallet name (see WalletLocation).

Definition at line 707 of file wallet.h.

◆ m_min_fee

CFeeRate CWallet::m_min_fee {DEFAULT_TRANSACTION_MINFEE}

Override with -mintxfee.

Definition at line 954 of file wallet.h.

◆ m_pay_tx_fee

CFeeRate CWallet::m_pay_tx_fee {DEFAULT_PAY_TX_FEE}

Definition at line 949 of file wallet.h.

◆ m_pool_key_to_index

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

Definition at line 687 of file wallet.h.

◆ m_signal_rbf

bool CWallet::m_signal_rbf {DEFAULT_WALLET_RBF}

Definition at line 952 of file wallet.h.

◆ m_spend_zero_conf_change

bool CWallet::m_spend_zero_conf_change {DEFAULT_SPEND_ZEROCONF_CHANGE}

Definition at line 951 of file wallet.h.

◆ m_wallet_flags

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

Definition at line 688 of file wallet.h.

◆ mapAddressBook

std::map<CTxDestination, CAddressBookData> CWallet::mapAddressBook

Definition at line 785 of file wallet.h.

◆ mapMasterKeys

MasterKeyMap CWallet::mapMasterKeys

Definition at line 763 of file wallet.h.

◆ mutexScanning

std::mutex CWallet::mutexScanning
private

Definition at line 625 of file wallet.h.

◆ nAccountingEntryNumber

uint64_t CWallet::nAccountingEntryNumber = 0

Definition at line 783 of file wallet.h.

◆ nLastResend

int64_t CWallet::nLastResend = 0
private

Definition at line 637 of file wallet.h.

◆ nMasterKeyMaxID

unsigned int CWallet::nMasterKeyMaxID = 0

Definition at line 764 of file wallet.h.

◆ nNextResend

int64_t CWallet::nNextResend = 0
private

Definition at line 636 of file wallet.h.

◆ 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.

Definition at line 1066 of file wallet.h.

◆ 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.

Definition at line 1073 of file wallet.h.

◆ NotifyUnload

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

Wallet is about to be unloaded.

Definition at line 1057 of file wallet.h.

◆ NotifyWatchonlyChanged

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

Watch-only address added.

Definition at line 1079 of file wallet.h.

◆ 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().

Definition at line 879 of file wallet.h.

◆ nWalletVersion

int CWallet::nWalletVersion = FEATURE_BASE
private

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

Definition at line 631 of file wallet.h.

◆ set_pre_split_keypool

std::set<int64_t> CWallet::set_pre_split_keypool
private

Definition at line 685 of file wallet.h.

◆ setInternalKeyPool

std::set<int64_t> CWallet::setInternalKeyPool
private

Definition at line 683 of file wallet.h.

◆ ShowProgress

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

Show progress e.g.

for rescan

Definition at line 1076 of file wallet.h.

◆ wtxOrdered

TxItems CWallet::wtxOrdered

Definition at line 780 of file wallet.h.


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