Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
CWallet Class Referencefinalabstract

A CWallet 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]

Classes

struct  ScanResult
struct  AddrBookFilter

Public Types

typedef std::map< unsigned int, CMasterKey > MasterKeyMap
typedef std::multimap< int64_t, CWalletTx * > TxItems
using UpdateWalletTxFn = std::function<bool(CWalletTx& wtx, bool new_tx)>
using ListAddrBookFunc = std::function<void(const CTxDestination& dest, const std::string& label, bool is_change, const std::optional<AddressPurpose> purpose)>
 Walk-through the address book entries.

Public Member Functions

std::unordered_map< Txid, CWalletTx, SaltedTxidHasher > mapWallet GUARDED_BY (cs_wallet)
 Map from txid to CWalletTx for all transactions this wallet is interested in, including received and sent transactions.
int64_t nOrderPosNext GUARDED_BY (cs_wallet)=0
std::map< CTxDestination, CAddressBookData > m_address_book GUARDED_BY (cs_wallet)
std::map< COutPoint, bool > m_locked_coins GUARDED_BY (cs_wallet)
 Set of Coins owned by this wallet that we won't try to spend from.
int64_t nRelockTime GUARDED_BY (cs_wallet)
 Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock().
bool Unlock (const SecureString &strWalletPassphrase)
WalletDatabase & GetDatabase () const override
const std::string & GetName () const
 Get a name for this wallet for logging/debugging purposes.
 CWallet (interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > database)
 Construct wallet with specified name and database implementation.
 ~CWallet ()
bool IsLocked () const override
bool Lock ()
bool HaveChain () const
 Interface to assert chain access.
const CAddressBookData * FindAddressBookEntry (const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
interfaces::Chainchain () const
 Interface for accessing chain state.
const CWalletTxGetWalletTx (const Txid &hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
std::set< TxidGetTxConflicts (const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
const std::unordered_map< COutPoint, WalletTXO, SaltedOutpointHasher > & GetTXOs () const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
std::optional< WalletTXO > GetTXO (const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void RefreshTXOsFromTx (const CWalletTx &wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Cache outputs that belong to the wallet from a single transaction.
void RefreshAllTXOs () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Cache outputs that belong to the wallet for all transactions in the wallet.
int GetTxDepthInMainChain (const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockchain 0 : in memory pool, waiting to be included in a block >=1 : this many blocks deep in the main chain.
int GetTxBlocksToMaturity (const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool IsTxImmatureCoinBase (const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool IsSpent (const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Outpoint is spent if any non-conflicted transaction spends it:
bool IsSpentKey (const CScript &scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void SetSpentKeyState (WalletBatch &batch, const Txid &hash, unsigned int n, bool used, std::set< CTxDestination > &tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
util::Result< void > DisplayAddress (const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Display address on an external signer.
bool IsLockedCoin (const COutPoint &output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void LoadLockedCoin (const COutPoint &coin, bool persistent) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool LockCoin (const COutPoint &output, bool persist) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool UnlockCoin (const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool UnlockAllCoins () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void ListLockedCoins (std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void AbortRescan ()
bool IsAbortingRescan () const
bool IsScanning () const
bool IsScanningWithPassphrase () const
SteadyClock::duration ScanningDuration () const
double ScanningProgress () const
void UpgradeDescriptorCache () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Upgrade DescriptorCaches.
void LoadAddressPreviouslySpent (const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Marks destination as previously spent.
void LoadAddressReceiveRequest (const CTxDestination &dest, const std::string &id, const std::string &request) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Appends payment request to destination.
bool ChangeWalletPassphrase (const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
bool EncryptWallet (const SecureString &strWalletPassphrase)
unsigned int ComputeTimeSmart (const CWalletTx &wtx, bool rescanning_old_block) const
 Compute smart timestamp for a transaction being added to the wallet.
int64_t IncOrderPosNext (WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Increment the next transaction order id.
DBErrors ReorderTransactions ()
void MarkDirty ()
CWalletTxAddToWallet (CTransactionRef tx, const TxState &state, const UpdateWalletTxFn &update_wtx=nullptr, bool rescanning_old_block=false)
 Add the transaction to the wallet, wrapping it up inside a CWalletTx.
bool LoadToWallet (const Txid &hash, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void transactionAddedToMempool (const CTransactionRef &tx) override
void blockConnected (const kernel::ChainstateRole &role, const interfaces::BlockInfo &block) override
void blockDisconnected (const interfaces::BlockInfo &block) override
void updatedBlockTip () override
int64_t RescanFromTime (int64_t startTime, const WalletRescanReserver &reserver, bool update)
 Scan active chain for relevant transactions after importing keys.
ScanResult ScanForWalletTransactions (const uint256 &start_block, int start_height, std::optional< int > max_height, const WalletRescanReserver &reserver, bool fUpdate, bool save_progress)
 Scan the block chain (starting in start_block) for transactions from or to us.
void transactionRemovedFromMempool (const CTransactionRef &tx, MemPoolRemovalReason reason) override
void SetNextResend ()
 Set the next time this wallet should resend transactions to 12-36 hours from now, ~1 day on average.
bool ShouldResend () const
 Return true if all conditions for periodically resending transactions are met.
void ResubmitWalletTransactions (node::TxBroadcast broadcast_method, bool force)
OutputType TransactionChangeType (const std::optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend) const
bool SignTransaction (CMutableTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Fetch the inputs and sign with SIGHASH_ALL.
bool SignTransaction (CMutableTransaction &tx, const std::map< COutPoint, Coin > &coins, int sighash, std::map< int, bilingual_str > &input_errors) const
 Sign the tx given the input coins and sighash.
SigningResult SignMessage (const std::string &message, const PKHash &pkhash, std::string &str_sig) const
std::optional< common::PSBTErrorFillPSBT (PartiallySignedTransaction &psbtx, bool &complete, std::optional< int > sighash_type=std::nullopt, bool sign=true, bool bip32derivs=true, size_t *n_signed=nullptr, bool finalize=true) const
 Fills out a PSBT with information from the wallet.
void CommitTransaction (CTransactionRef tx, mapValue_t mapValue, std::vector< std::pair< std::string, std::string > > orderForm)
 Submit the transaction to the node's mempool and then relay to peers.
bool SubmitTxMemoryPoolAndRelay (CWalletTx &wtx, std::string &err_string, node::TxBroadcast broadcast_method) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Pass this transaction to node for optional mempool insertion and relay to peers.
void MaybeUpdateBirthTime (int64_t time)
 Updates wallet birth time if 'time' is below it.
size_t KeypoolCountExternalKeys () const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool TopUpKeyPool (unsigned int kpSize=0)
std::vector< CTxDestinationListAddrBookAddresses (const std::optional< AddrBookFilter > &filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Filter and retrieve destinations stored in the addressbook.
std::set< std::string > ListAddrBookLabels (std::optional< AddressPurpose > purpose) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Retrieve all the known labels in the address book.
void ForEachAddrBookEntry (const ListAddrBookFunc &func) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void MarkDestinationsDirty (const std::set< CTxDestination > &destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Marks all outputs in each one of the destinations dirty, so their cache is reset and does not return outdated information.
util::Result< CTxDestinationGetNewDestination (OutputType type, const std::string &label)
util::Result< CTxDestinationGetNewChangeDestination (OutputType type)
bool IsMine (const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool IsMine (const CScript &script) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool IsMine (const CTxOut &txout) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool IsMine (const CTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool IsMine (const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
CAmount GetDebit (const CTxIn &txin) const
 Returns amount of debit, i.e.
CAmount GetDebit (const CTransaction &tx) const
bool IsFromMe (const CTransaction &tx) const
 should probably be renamed to IsRelevantToMe
DBErrors PopulateWalletFromDB (bilingual_str &error, std::vector< bilingual_str > &warnings)
util::Result< void > RemoveTxs (std::vector< Txid > &txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Erases the provided transactions from the wallet.
util::Result< void > RemoveTxs (WalletBatch &batch, std::vector< Txid > &txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool SetAddressBook (const CTxDestination &address, const std::string &strName, const std::optional< AddressPurpose > &purpose)
bool DelAddressBook (const CTxDestination &address)
bool DelAddressBookWithDB (WalletBatch &batch, const CTxDestination &address)
bool IsAddressPreviouslySpent (const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool SetAddressPreviouslySpent (WalletBatch &batch, const CTxDestination &dest, bool used) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
std::vector< std::string > GetAddressReceiveRequests () const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool SetAddressReceiveRequest (WalletBatch &batch, const CTxDestination &dest, const std::string &id, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool EraseAddressReceiveRequest (WalletBatch &batch, const CTxDestination &dest, const std::string &id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
unsigned int GetKeyPoolSize () const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
std::set< TxidGetConflicts (const Txid &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Get wallet transactions that conflict with given transaction (spend same outputs).
bool HasWalletSpend (const CTransactionRef &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Check if a given transaction has any of its outputs spent by another transaction in the wallet.
void Close ()
 Close wallet database.
bool GetBroadcastTransactions () const
 Inquire whether this wallet broadcasts transactions.
void SetBroadcastTransactions (bool broadcast)
 Set whether this wallet broadcasts transactions.
bool TransactionCanBeAbandoned (const Txid &hashTx) const
 Return whether transaction can be abandoned.
bool AbandonTransaction (const Txid &hashTx)
bool AbandonTransaction (CWalletTx &tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool MarkReplaced (const Txid &originalHash, const Txid &newHash)
 Mark a transaction as replaced by another transaction.
void postInitProcess ()
 Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init tasks.
bool BackupWallet (const std::string &strDest) const
bool IsHDEnabled () const
bool CanGetAddresses (bool internal=false) const
int64_t GetBirthTime () const
void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(void SetWalletFlag (uint64_t flags)
 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.
void UnsetWalletFlag (uint64_t flag)
 Unsets a single wallet flag.
bool IsWalletFlagSet (uint64_t flag) const override
 check if a certain wallet flag is set
void InitWalletFlags (uint64_t flags)
 overwrite all flags by the given uint64_t flags must be uninitialised (or 0) only known flags may be present
bool LoadWalletFlags (uint64_t flags)
 Loads the flags into the wallet.
uint64_t GetWalletFlags () const
 Retrieve all of the wallet's flags.
std::string LogName () const override
 Return wallet name for use in logs, will return "default wallet" if the wallet has no name.
std::string DisplayName () const
 Return wallet name for display, like LogName() but translates "default wallet" string.
template<typename... Params>
void WalletLogPrintf (util::ConstevalFormatString< sizeof...(Params)> wallet_fmt, const Params &... params) const
 Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
void LogStats () const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
std::set< ScriptPubKeyMan * > GetActiveScriptPubKeyMans () const
 Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers.
bool IsActiveScriptPubKeyMan (const ScriptPubKeyMan &spkm) const
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans () const
 Returns all unique ScriptPubKeyMans.
ScriptPubKeyMan * GetScriptPubKeyMan (const OutputType &type, bool internal) const
 Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
ScriptPubKeyMan * GetScriptPubKeyMan (const uint256 &id) const
 Get the ScriptPubKeyMan by id.
std::set< ScriptPubKeyMan * > GetScriptPubKeyMans (const CScript &script) const
 Get all the ScriptPubKeyMans for a script.
std::unique_ptr< SigningProviderGetSolvingProvider (const CScript &script) const
 Get the SigningProvider for a script.
std::unique_ptr< SigningProviderGetSolvingProvider (const CScript &script, SignatureData &sigdata) const
std::vector< WalletDescriptorGetWalletDescriptors (const CScript &script) const
 Get the wallet descriptors for a script.
LegacyDataSPKM * GetLegacyDataSPKM () const
 Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
LegacyDataSPKM * GetOrCreateLegacyDataSPKM ()
void SetupLegacyScriptPubKeyMan ()
 Make a Legacy(Data)SPKM and set it for all types, internal, and external.
bool WithEncryptionKey (std::function< bool(const CKeyingMaterial &)> cb) const override
bool HasEncryptionKeys () const override
bool HaveCryptedKeys () const
int GetLastBlockHeight () const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Get last block processed height.
uint256 GetLastBlockHash () const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void SetLastBlockProcessed (int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Set last block processed height, and write to database.
void WriteBestBlock () const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Write the current best block to database.
void ConnectScriptPubKeyManNotifiers ()
 Connect the signals from ScriptPubKeyMans to the signals in CWallet.
DescriptorScriptPubKeyMan & LoadDescriptorScriptPubKeyMan (uint256 id, WalletDescriptor &desc)
 Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
void AddActiveScriptPubKeyMan (uint256 id, OutputType type, bool internal)
void LoadActiveScriptPubKeyMan (uint256 id, OutputType type, bool internal)
void DeactivateScriptPubKeyMan (uint256 id, OutputType type, bool internal)
DescriptorScriptPubKeyMan & SetupDescriptorScriptPubKeyMan (WalletBatch &batch, const CExtKey &master_key, const OutputType &output_type, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Create new DescriptorScriptPubKeyMan and add it to the wallet.
void SetupDescriptorScriptPubKeyMans (WalletBatch &batch, const CExtKey &master_key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Create new DescriptorScriptPubKeyMans and add them to the wallet.
void SetupDescriptorScriptPubKeyMans () EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void SetupOwnDescriptorScriptPubKeyMans (WalletBatch &batch) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Create new seed and default DescriptorScriptPubKeyMans for this wallet.
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan (const WalletDescriptor &desc) const
 Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.
std::optional< bool > IsInternalScriptPubKeyMan (ScriptPubKeyMan *spk_man) const
util::Result< std::reference_wrapper< DescriptorScriptPubKeyMan > > AddWalletDescriptor (WalletDescriptor &desc, const FlatSigningProvider &signing_provider, const std::string &label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type.
bool MigrateToSQLite (bilingual_str &error) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Move all records from the BDB database to a new SQLite database for storage.
std::optional< MigrationData > GetDescriptorsForLegacy (bilingual_str &error) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Get all of the descriptors from a legacy wallet.
util::Result< void > ApplyMigrationData (WalletBatch &local_wallet_batch, MigrationData &data) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool CanGrindR () const
 Whether the (external) signer performs R-value signature grinding.
void CacheNewScriptPubKeys (const std::set< CScript > &spks, ScriptPubKeyMan *spkm)
 Add scriptPubKeys for this ScriptPubKeyMan into the scriptPubKey cache.
void TopUpCallback (const std::set< CScript > &spks, ScriptPubKeyMan *spkm) override
std::set< CExtPubKeyGetActiveHDPubKeys () const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Retrieve the xpubs in use by the active descriptors.
std::optional< CKeyGetKey (const CKeyID &keyid) const
void DisconnectChainNotifications ()
 Disconnect chain notifications and wait for all notifications to be processed.
Public Member Functions inherited from wallet::WalletStorage
virtual ~WalletStorage ()=default
virtual void UnsetBlankWalletFlag (WalletBatch &)=0
virtual bool WithEncryptionKey (std::function< bool(const CKeyingMaterial &)> cb) const =0
 Pass the encryption key to cb().
virtual void TopUpCallback (const std::set< CScript > &, ScriptPubKeyMan *)=0
 Callback function for after TopUp completes containing any scripts that were added by a SPKMan.
Public Member Functions inherited from interfaces::Chain::Notifications
virtual ~Notifications ()=default
virtual void chainStateFlushed (const kernel::ChainstateRole &role, const CBlockLocator &locator)

Static Public Member Functions

static bool LoadWalletArgs (std::shared_ptr< CWallet > wallet, const WalletContext &context, bilingual_str &error, std::vector< bilingual_str > &warnings)
static std::shared_ptr< CWalletCreateNew (WalletContext &context, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bilingual_str &error, std::vector< bilingual_str > &warnings)
static std::shared_ptr< CWalletLoadExisting (WalletContext &context, const std::string &name, std::unique_ptr< WalletDatabase > database, bilingual_str &error, std::vector< bilingual_str > &warnings)

Public Attributes

RecursiveMutex cs_wallet
 Main wallet lock.
MasterKeyMap mapMasterKeys
unsigned int nMasterKeyMaxID = 0
TxItems wtxOrdered
std::unique_ptr< interfaces::Handlerm_chain_notifications_handler
 Registered interfaces::Chain::Notifications handler.
Mutex m_unlock_mutex
RecursiveMutex m_relock_mutex
unsigned int m_confirm_target {DEFAULT_TX_CONFIRM_TARGET}
bool m_spend_zero_conf_change {DEFAULT_SPEND_ZEROCONF_CHANGE}
 Allow Coin Selection to pick unconfirmed UTXOs that were sent from our own wallet if it cannot fund the transaction otherwise.
bool m_signal_rbf {DEFAULT_WALLET_RBF}
bool m_allow_fallback_fee {true}
 will be false if -fallbackfee=0
CFeeRate m_min_fee {DEFAULT_TRANSACTION_MINFEE}
CFeeRate m_fallback_fee {DEFAULT_FALLBACK_FEE}
 If fee estimation does not have enough data to provide estimates, use this fee instead.
CFeeRate m_discard_rate {DEFAULT_DISCARD_FEE}
 If the cost to spend a change output at this feerate is greater than the value of the output itself, just drop it to fees.
CFeeRate m_consolidate_feerate {DEFAULT_CONSOLIDATE_FEERATE}
 When the actual feerate is less than the consolidate feerate, we will tend to make transactions which consolidate inputs.
CAmount m_max_aps_fee {DEFAULT_MAX_AVOIDPARTIALSPEND_FEE}
 The maximum fee amount we're willing to pay to prioritize partial spend avoidance.
OutputType m_default_address_type {DEFAULT_ADDRESS_TYPE}
std::optional< OutputTypem_default_change_type {}
 Default output type for change outputs.
CAmount m_default_max_tx_fee {DEFAULT_TRANSACTION_MAXFEE}
 Absolute maximum transaction fee (in satoshis) used by default for the wallet.
int64_t m_keypool_size {DEFAULT_KEYPOOL_SIZE}
 Number of pre-generated keys/scripts by each spkm (part of the look-ahead process, used to detect payments).
std::string m_notify_tx_changed_script
 Notify external script when a wallet transaction comes in or is updated (handled by -walletnotify).
boost::signals2::signal< void()> NotifyUnload
 Wallet is about to be unloaded.
boost::signals2::signal< void(const CTxDestination &address, const std::string &label, bool isMine, AddressPurpose purpose, ChangeType status)> NotifyAddressBookChanged
 Address book entry changed.
boost::signals2::signal< void(const Txid &hashTx, ChangeType status)> NotifyTransactionChanged
 Wallet transaction added, removed or updated.
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
 Show progress e.g.
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
 Keypool has new keys.
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
 Wallet status (encrypted, locked) changed.

Private Types

enum class  TxUpdate { UNCHANGED , CHANGED , NOTIFY_CHANGED }
typedef std::unordered_multimap< COutPoint, Txid, SaltedOutpointHasherTxSpends
 Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated transactions where the mutant gets mined).
using TryUpdatingStateFn = std::function<TxUpdate(CWalletTx& wtx)>

Private Member Functions

CKeyingMaterial vMasterKey GUARDED_BY (cs_wallet)
TxSpends mapTxSpends GUARDED_BY (cs_wallet)
uint256 m_last_block_processed GUARDED_BY (cs_wallet)
 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.
int m_last_block_processed_height GUARDED_BY (cs_wallet)
 Height of last block processed is used by wallet to know depth of transactions without relying on Chain interface beyond asynchronous updates.
std::unordered_map< COutPoint, WalletTXO, SaltedOutpointHasher > m_txos GUARDED_BY (cs_wallet)
 Set of both spent and unspent transaction outputs owned by this wallet.
bool Unlock (const CKeyingMaterial &vMasterKeyIn)
void AddToSpends (const COutPoint &outpoint, const Txid &txid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void AddToSpends (const CWalletTx &wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool AddToWalletIfInvolvingMe (const CTransactionRef &tx, const SyncTxState &state, bool fUpdate, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Add a transaction to the wallet, or update it.
void MarkConflicted (const uint256 &hashBlock, int conflicting_height, const Txid &hashTx)
 Mark a transaction (and its in-wallet descendants) as conflicting with a particular block.
void RecursiveUpdateTxState (const Txid &tx_hash, const TryUpdatingStateFn &try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Mark a transaction (and its in-wallet descendants) as a particular tx state.
void RecursiveUpdateTxState (WalletBatch *batch, const Txid &tx_hash, const TryUpdatingStateFn &try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void MarkInputsDirty (const CTransactionRef &tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Mark a transaction's inputs dirty, thus forcing the outputs to be recomputed.
void SyncMetaData (std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool SyncTransaction (const CTransactionRef &tx, const SyncTxState &state, bool update_tx=true, bool rescanning_old_block=false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool SetAddressBookWithDB (WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::optional< AddressPurpose > &strPurpose)
void UnsetWalletFlagWithDB (WalletBatch &batch, uint64_t flag)
 Unsets a wallet flag and saves it to disk.
void UnsetBlankWalletFlag (WalletBatch &batch) override
 Unset the blank wallet flag and saves it to disk.
void AddScriptPubKeyMan (const uint256 &id, std::unique_ptr< ScriptPubKeyMan > spkm_man)
void AddActiveScriptPubKeyManWithDb (WalletBatch &batch, uint256 id, OutputType type, bool internal)
void SetWalletFlagWithDB (WalletBatch &batch, uint64_t flags)
 Store wallet flags.
void SetLastBlockProcessedInMem (int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void UpdateTrucSiblingConflicts (const CWalletTx &parent_wtx, const Txid &child_txid, bool add_conflict) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
 Update mempool conflicts for TRUC sibling transactions.

Static Private Member Functions

static bool AttachChain (const std::shared_ptr< CWallet > &wallet, interfaces::Chain &chain, bool rescan_required, bilingual_str &error, std::vector< bilingual_str > &warnings)
 Catch wallet up to current chain, scanning new blocks, updating the best block locator and m_last_block_processed, and registering for notifications about new blocks and transactions.
static NodeClock::time_point GetDefaultNextResend ()

Private Attributes

std::atomic< bool > fAbortRescan {false}
std::atomic< bool > fScanningWallet {false}
std::atomic< bool > m_scanning_with_passphrase {false}
std::atomic< SteadyClock::time_point > m_scanning_start {SteadyClock::time_point{}}
std::atomic< double > m_scanning_progress {0}
NodeClock::time_point m_next_resend {GetDefaultNextResend()}
 The next scheduled rebroadcast of wallet transactions.
bool fBroadcastTransactions = false
 Whether this wallet will submit newly created transactions to the node's mempool and prompt rebroadcasts (see ResendWalletTransactions()).
std::atomic< int64_t > m_best_block_time {0}
std::atomic< int64_t > m_birth_time {std::numeric_limits<int64_t>::max()}
std::atomic< uint64_t > m_wallet_flags {0}
 WalletFlags set on this wallet.
interfaces::Chainm_chain
 Interface for accessing chain state.
std::string m_name
 Wallet name: relative directory name or "" for default wallet.
std::unique_ptr< WalletDatabase > m_database
 Internal database handle.
std::map< OutputType, ScriptPubKeyMan * > m_external_spk_managers
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
std::map< uint256, std::unique_ptr< ScriptPubKeyMan > > m_spk_managers
std::unordered_map< CScript, std::vector< ScriptPubKeyMan * >, SaltedSipHasherm_cached_spks
 Cache of descriptor ScriptPubKeys used for IsMine. Maps ScriptPubKey to set of spkms.

Friends

class WalletRescanReserver

Detailed Description

A CWallet maintains a set of transactions and balances, and provides the ability to create new transactions.

Definition at line 309 of file wallet.h.

Member Typedef Documentation

◆ ListAddrBookFunc

using wallet::CWallet::ListAddrBookFunc = std::function<void(const CTxDestination& dest, const std::string& label, bool is_change, const std::optional<AddressPurpose> purpose)>

Walk-through the address book entries.

Stops when the provided 'ListAddrBookFunc' returns false.

Definition at line 774 of file wallet.h.

◆ MasterKeyMap

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

Definition at line 472 of file wallet.h.

◆ TryUpdatingStateFn

using wallet::CWallet::TryUpdatingStateFn = std::function<TxUpdate(CWalletTx& wtx)>
private

Definition at line 368 of file wallet.h.

◆ TxItems

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

Definition at line 500 of file wallet.h.

◆ TxSpends

typedef std::unordered_multimap<COutPoint, Txid, SaltedOutpointHasher> wallet::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 340 of file wallet.h.

◆ UpdateWalletTxFn

using wallet::CWallet::UpdateWalletTxFn = std::function<bool(CWalletTx& wtx, bool new_tx)>

Callback for updating transaction metadata in mapWallet.

Parameters
wtx- reference to mapWallet transaction to update
new_tx- true if wtx is newly inserted, false if it previously existed
Returns
true if wtx is changed and needs to be saved to disk, otherwise false

Definition at line 620 of file wallet.h.

Member Enumeration Documentation

◆ TxUpdate

enum class wallet::CWallet::TxUpdate
strongprivate
Enumerator
UNCHANGED 
CHANGED 
NOTIFY_CHANGED 

Definition at line 366 of file wallet.h.

Constructor & Destructor Documentation

◆ CWallet()

wallet::CWallet::CWallet ( interfaces::Chain * chain,
const std::string & name,
std::unique_ptr< WalletDatabase > database )
inline

Construct wallet with specified name and database implementation.

Definition at line 477 of file wallet.h.

Here is the caller graph for this function:

◆ ~CWallet()

Definition at line 484 of file wallet.h.

Member Function Documentation

◆ AbortRescan()

Definition at line 576 of file wallet.h.

◆ AddActiveScriptPubKeyMan()

Adds the active ScriptPubKeyMan for the specified type and internal. Writes it to the wallet file

Parameters
[in]idThe unique id for the ScriptPubKeyMan
[in]typeThe OutputType this ScriptPubKeyMan provides addresses for
[in]internalWhether this ScriptPubKeyMan provides change addresses

Definition at line 3671 of file wallet.cpp.

◆ AddActiveScriptPubKeyManWithDb()

void wallet::CWallet::AddActiveScriptPubKeyManWithDb ( WalletBatch & batch,
uint256 id,
OutputType type,
bool internal )
private

Definition at line 3677 of file wallet.cpp.

Here is the caller graph for this function:

◆ AddScriptPubKeyMan()

void wallet::CWallet::AddScriptPubKeyMan ( const uint256 & id,
std::unique_ptr< ScriptPubKeyMan > spkm_man )
private

Definition at line 3500 of file wallet.cpp.

Here is the caller graph for this function:

◆ AddWalletDescriptor()

util::Result< std::reference_wrapper< DescriptorScriptPubKeyMan > > wallet::CWallet::AddWalletDescriptor ( WalletDescriptor & desc,
const FlatSigningProvider & signing_provider,
const std::string & label,
bool internal )

Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type.

Definition at line 3756 of file wallet.cpp.

◆ ApplyMigrationData()

util::Result< void > wallet::CWallet::ApplyMigrationData ( WalletBatch & local_wallet_batch,
MigrationData & data )

Adds the ScriptPubKeyMans given in MigrationData to this wallet, removes LegacyScriptPubKeyMan, and where needed, moves tx and address book entries to watchonly_wallet or solvable_wallet

Definition at line 3908 of file wallet.cpp.

◆ AttachChain()

bool wallet::CWallet::AttachChain ( const std::shared_ptr< CWallet > & wallet,
interfaces::Chain & chain,
bool rescan_required,
bilingual_str & error,
std::vector< bilingual_str > & warnings )
staticprivate

Catch wallet up to current chain, scanning new blocks, updating the best block locator and m_last_block_processed, and registering for notifications about new blocks and transactions.

Definition at line 3171 of file wallet.cpp.

Here is the caller graph for this function:

◆ BackupWallet()

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

Definition at line 3311 of file wallet.cpp.

◆ CacheNewScriptPubKeys()

void wallet::CWallet::CacheNewScriptPubKeys ( const std::set< CScript > & spks,
ScriptPubKeyMan * spkm )

Add scriptPubKeys for this ScriptPubKeyMan into the scriptPubKey cache.

Definition at line 4485 of file wallet.cpp.

Here is the caller graph for this function:

◆ CanGrindR()

Whether the (external) signer performs R-value signature grinding.

Definition at line 4119 of file wallet.cpp.

◆ chain()

Interface for accessing chain state.

Definition at line 520 of file wallet.h.

Here is the caller graph for this function:

◆ CommitTransaction()

void wallet::CWallet::CommitTransaction ( CTransactionRef tx,
mapValue_t mapValue,
std::vector< std::pair< std::string, std::string > > orderForm )

Submit the transaction to the node's mempool and then relay to peers.

Should be called after CreateTransaction unless you want to abort broadcasting the transaction.

Parameters
[in]txThe transaction to be broadcast.
[in]mapValuekey-values to be set on the transaction.
[in]orderFormBIP 70 / BIP 21 order form details to be set on the transaction.

Definition at line 2314 of file wallet.cpp.

◆ ComputeTimeSmart()

unsigned int wallet::CWallet::ComputeTimeSmart ( const CWalletTx & wtx,
bool rescanning_old_block ) 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 transaction during a rescanning process, assign all its (not already known) transactions' timestamps to the block 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 2812 of file wallet.cpp.

Here is the caller graph for this function:

◆ ConnectScriptPubKeyManNotifiers()

Connect the signals from ScriptPubKeyMans to the signals in CWallet.

Definition at line 3552 of file wallet.cpp.

◆ CreateNew()

std::shared_ptr< CWallet > wallet::CWallet::CreateNew ( WalletContext & context,
const std::string & name,
std::unique_ptr< WalletDatabase > database,
uint64_t wallet_creation_flags,
bilingual_str & error,
std::vector< bilingual_str > & warnings )
static

Definition at line 3073 of file wallet.cpp.

Here is the caller graph for this function:

◆ DeactivateScriptPubKeyMan()

Remove specified ScriptPubKeyMan from set of active SPK managers. Writes the change to the wallet file.

Parameters
[in]idThe unique id for the ScriptPubKeyMan
[in]typeThe OutputType this ScriptPubKeyMan provides addresses for
[in]internalWhether this ScriptPubKeyMan provides change addresses

Definition at line 3705 of file wallet.cpp.

◆ DelAddressBook()

Definition at line 2522 of file wallet.cpp.

◆ DelAddressBookWithDB()

bool wallet::CWallet::DelAddressBookWithDB ( WalletBatch & batch,
const CTxDestination & address )

Definition at line 2529 of file wallet.cpp.

Here is the caller graph for this function:

◆ DisconnectChainNotifications()

Disconnect chain notifications and wait for all notifications to be processed.

Definition at line 4581 of file wallet.cpp.

◆ DisplayAddress()

Display address on an external signer.

Definition at line 2716 of file wallet.cpp.

◆ DisplayName()

std::string wallet::CWallet::DisplayName ( ) const
inline

Return wallet name for display, like LogName() but translates "default wallet" string.

Definition at line 930 of file wallet.h.

Here is the caller graph for this function:

◆ EraseAddressReceiveRequest()

bool wallet::CWallet::EraseAddressReceiveRequest ( WalletBatch & batch,
const CTxDestination & dest,
const std::string & id )

Definition at line 2911 of file wallet.cpp.

◆ FillPSBT()

std::optional< PSBTError > wallet::CWallet::FillPSBT ( PartiallySignedTransaction & psbtx,
bool & complete,
std::optional< int > sighash_type = std::nullopt,
bool sign = true,
bool bip32derivs = true,
size_t * n_signed = nullptr,
bool finalize = true ) const

Fills out a PSBT with information from the wallet.

Fills in UTXOs if we have them. Tries to sign if sign=true. Sets complete if the PSBT is now complete (i.e. has all required signatures or signature-parts, and is ready to finalize.) Sets error and returns false if something goes wrong.

Parameters
[in]psbtxPartiallySignedTransaction to fill in
[out]completeindicates whether the PSBT is now complete
[in]sighash_typethe sighash type to use when signing (if PSBT does not specify)
[in]signwhether to sign or not
[in]bip32derivswhether to fill in bip32 derivation information if available
[out]n_signedthe number of inputs signed by this wallet
[in]finalizewhether to create the final scriptSig or scriptWitness if possible return error

Definition at line 2186 of file wallet.cpp.

◆ FindAddressBookEntry()

const CAddressBookData * wallet::CWallet::FindAddressBookEntry ( const CTxDestination & dest,
bool allow_change = false ) const

Definition at line 3291 of file wallet.cpp.

◆ ForEachAddrBookEntry()

Definition at line 2642 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetActiveHDPubKeys()

Retrieve the xpubs in use by the active descriptors.

Definition at line 4498 of file wallet.cpp.

◆ GetActiveScriptPubKeyMans()

std::set< ScriptPubKeyMan * > wallet::CWallet::GetActiveScriptPubKeyMans ( ) const

Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers.

Definition at line 3392 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetAddressReceiveRequests()

std::vector< std::string > wallet::CWallet::GetAddressReceiveRequests ( ) const

Definition at line 2893 of file wallet.cpp.

◆ GetAllScriptPubKeyMans()

std::set< ScriptPubKeyMan * > wallet::CWallet::GetAllScriptPubKeyMans ( ) const

Returns all unique ScriptPubKeyMans.

Definition at line 3417 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetBirthTime()

int64_t wallet::CWallet::GetBirthTime ( ) const
inline

Definition at line 894 of file wallet.h.

◆ GetBroadcastTransactions()

Inquire whether this wallet broadcasts transactions.

Definition at line 857 of file wallet.h.

Here is the caller graph for this function:

◆ GetDatabase()

WalletDatabase & wallet::CWallet::GetDatabase ( ) const
inlineoverridevirtual

Implements wallet::WalletStorage.

Definition at line 462 of file wallet.h.

Here is the caller graph for this function:

◆ GetDescriptorScriptPubKeyMan()

DescriptorScriptPubKeyMan * wallet::CWallet::GetDescriptorScriptPubKeyMan ( const WalletDescriptor & desc) const

Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.

Definition at line 3722 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetDescriptorsForLegacy()

std::optional< MigrationData > wallet::CWallet::GetDescriptorsForLegacy ( bilingual_str & error) const

Get all of the descriptors from a legacy wallet.

Definition at line 3889 of file wallet.cpp.

◆ GetKey()

std::optional< CKey > wallet::CWallet::GetKey ( const CKeyID & keyid) const

Find the private key for the given key id from the wallet's descriptors, if available Returns nullopt when no descriptor has the key or if the wallet is locked.

Definition at line 4519 of file wallet.cpp.

◆ GetKeyPoolSize()

unsigned int wallet::CWallet::GetKeyPoolSize ( ) const

Definition at line 2580 of file wallet.cpp.

◆ GetLastBlockHash()

Definition at line 992 of file wallet.h.

Here is the caller graph for this function:

◆ GetLastBlockHeight()

Get last block processed height.

Definition at line 986 of file wallet.h.

Here is the caller graph for this function:

◆ GetLegacyDataSPKM()

LegacyDataSPKM * wallet::CWallet::GetLegacyDataSPKM ( ) const

Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.

Definition at line 3490 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetName()

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

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

Definition at line 470 of file wallet.h.

Here is the caller graph for this function:

◆ GetNewChangeDestination()

◆ GetNewDestination()

Definition at line 2601 of file wallet.cpp.

◆ GetOrCreateLegacyDataSPKM()

Definition at line 3510 of file wallet.cpp.

◆ GetScriptPubKeyMan() [1/2]

ScriptPubKeyMan * wallet::CWallet::GetScriptPubKeyMan ( const OutputType & type,
bool internal ) const

Get the ScriptPubKeyMan for the given OutputType and internal/external chain.

Definition at line 3426 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetScriptPubKeyMan() [2/2]

ScriptPubKeyMan * wallet::CWallet::GetScriptPubKeyMan ( const uint256 & id) const

Get the ScriptPubKeyMan by id.

Definition at line 3451 of file wallet.cpp.

◆ GetScriptPubKeyMans()

std::set< ScriptPubKeyMan * > wallet::CWallet::GetScriptPubKeyMans ( const CScript & script) const

Get all the ScriptPubKeyMans for a script.

Definition at line 3436 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetSolvingProvider() [1/2]

std::unique_ptr< SigningProvider > wallet::CWallet::GetSolvingProvider ( const CScript & script) const

Get the SigningProvider for a script.

Definition at line 3459 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetSolvingProvider() [2/2]

std::unique_ptr< SigningProvider > wallet::CWallet::GetSolvingProvider ( const CScript & script,
SignatureData & sigdata ) const

Definition at line 3465 of file wallet.cpp.

◆ GetTxBlocksToMaturity()

Returns
number of blocks to maturity for this transaction: 0 : is not a coinbase transaction, or is a mature coinbase transaction >0 : is a coinbase transaction which matures in this many blocks

Definition at line 3331 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetTxDepthInMainChain()

Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockchain 0 : in memory pool, waiting to be included in a block >=1 : this many blocks deep in the main chain.

Preconditions: it is only valid to call this function when the wallet is online and the block index is loaded. So this cannot be called by bitcoin-wallet tool code or by wallet migration code. If this is called without the wallet being online, it won't be able able to determine the the height of the last block processed, or the heights of blocks referenced in transaction, and might cause assert failures.

Definition at line 3317 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetTXO()

std::optional< WalletTXO > wallet::CWallet::GetTXO ( const COutPoint & outpoint) const

Definition at line 4571 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetTXOs()

const std::unordered_map< COutPoint, WalletTXO, SaltedOutpointHasher > & wallet::CWallet::GetTXOs ( ) const
inline

Definition at line 526 of file wallet.h.

◆ GetWalletDescriptors()

std::vector< WalletDescriptor > wallet::CWallet::GetWalletDescriptors ( const CScript & script) const

Get the wallet descriptors for a script.

Definition at line 3478 of file wallet.cpp.

◆ GUARDED_BY() [1/10]

int64_t nRelockTime wallet::CWallet::GUARDED_BY ( cs_wallet )
inline

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 592 of file wallet.h.

◆ GUARDED_BY() [2/10]

std::map< COutPoint, bool > m_locked_coins wallet::CWallet::GUARDED_BY ( cs_wallet )

Set of Coins owned by this wallet that we won't try to spend from.

A Coin may be locked if it has already been used to fund a transaction that hasn't confirmed yet. We wouldn't consider the Coin spent already, but also shouldn't try to use it again. bool to track whether this locked coin is persisted to disk.

◆ GUARDED_BY() [3/10]

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

◆ GUARDED_BY() [4/10]

std::unordered_map< Txid, CWalletTx, SaltedTxidHasher > mapWallet wallet::CWallet::GUARDED_BY ( cs_wallet )

Map from txid to CWalletTx for all transactions this wallet is interested in, including received and sent transactions.

◆ GUARDED_BY() [5/10]

std::unordered_map< COutPoint, WalletTXO, SaltedOutpointHasher > m_txos wallet::CWallet::GUARDED_BY ( cs_wallet )
private

Set of both spent and unspent transaction outputs owned by this wallet.

◆ GUARDED_BY() [6/10]

int m_last_block_processed_height wallet::CWallet::GUARDED_BY ( cs_wallet )
private

Height of last block processed is used by wallet to know depth of transactions without relying on Chain interface beyond asynchronous updates.

For safety, we initialize it to -1. Height is a pointer on node's tip and doesn't imply that the wallet has scanned sequentially all blocks up to this one.

◆ GUARDED_BY() [7/10]

uint256 m_last_block_processed wallet::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.

Processed hash is a pointer on node's tip and doesn't imply that the wallet has scanned sequentially all blocks up to this one.

◆ GUARDED_BY() [8/10]

◆ GUARDED_BY() [9/10]

CKeyingMaterial vMasterKey wallet::CWallet::GUARDED_BY ( cs_wallet )
private

◆ GUARDED_BY() [10/10]

int64_t nOrderPosNext wallet::CWallet::GUARDED_BY ( cs_wallet )
pure virtual

◆ HasEncryptionKeys()

bool wallet::CWallet::HasEncryptionKeys ( ) const
overridevirtual

Implements wallet::WalletStorage.

Definition at line 3539 of file wallet.cpp.

Here is the caller graph for this function:

◆ HaveChain()

bool wallet::CWallet::HaveChain ( ) const
inline

Interface to assert chain access.

Definition at line 494 of file wallet.h.

Here is the caller graph for this function:

◆ HaveCryptedKeys()

Definition at line 3544 of file wallet.cpp.

◆ IsAbortingRescan()

bool wallet::CWallet::IsAbortingRescan ( ) const
inline

Definition at line 577 of file wallet.h.

◆ IsActiveScriptPubKeyMan()

bool wallet::CWallet::IsActiveScriptPubKeyMan ( const ScriptPubKeyMan & spkm) const

Definition at line 3406 of file wallet.cpp.

◆ IsAddressPreviouslySpent()

Definition at line 2887 of file wallet.cpp.

Here is the caller graph for this function:

◆ IsInternalScriptPubKeyMan()

std::optional< bool > wallet::CWallet::IsInternalScriptPubKeyMan ( ScriptPubKeyMan * spk_man) const

Returns whether the provided ScriptPubKeyMan is internal

Parameters
[in]spk_manThe ScriptPubKeyMan to test
Returns
contains value only for active DescriptorScriptPubKeyMan, otherwise undefined

Definition at line 3737 of file wallet.cpp.

Here is the caller graph for this function:

◆ IsLocked()

bool wallet::CWallet::IsLocked ( ) const
overridevirtual

Implements wallet::WalletStorage.

Definition at line 3351 of file wallet.cpp.

Here is the caller graph for this function:

◆ IsLockedCoin()

bool wallet::CWallet::IsLockedCoin ( const COutPoint & output) const

Definition at line 2775 of file wallet.cpp.

◆ IsScanning()

bool wallet::CWallet::IsScanning ( ) const
inline

Definition at line 578 of file wallet.h.

◆ IsScanningWithPassphrase()

Definition at line 579 of file wallet.h.

◆ IsTxImmatureCoinBase()

Definition at line 3343 of file wallet.cpp.

◆ KeypoolCountExternalKeys()

Definition at line 2568 of file wallet.cpp.

◆ ListAddrBookAddresses()

std::vector< CTxDestination > wallet::CWallet::ListAddrBookAddresses ( const std::optional< AddrBookFilter > & filter) const

Filter and retrieve destinations stored in the addressbook.

Definition at line 2651 of file wallet.cpp.

◆ ListAddrBookLabels()

std::set< std::string > wallet::CWallet::ListAddrBookLabels ( std::optional< AddressPurpose > purpose) const

Retrieve all the known labels in the address book.

Definition at line 2667 of file wallet.cpp.

◆ ListLockedCoins()

void wallet::CWallet::ListLockedCoins ( std::vector< COutPoint > & vOutpts) const

Definition at line 2781 of file wallet.cpp.

◆ LoadActiveScriptPubKeyMan()

Loads an active ScriptPubKeyMan for the specified type and internal. (used by LoadWallet)

Parameters
[in]idThe unique id for the ScriptPubKeyMan
[in]typeThe OutputType this ScriptPubKeyMan provides addresses for
[in]internalWhether this ScriptPubKeyMan provides change addresses

Definition at line 3685 of file wallet.cpp.

Here is the caller graph for this function:

◆ LoadAddressPreviouslySpent()

Marks destination as previously spent.

Definition at line 2877 of file wallet.cpp.

Here is the caller graph for this function:

◆ LoadAddressReceiveRequest()

void wallet::CWallet::LoadAddressReceiveRequest ( const CTxDestination & dest,
const std::string & id,
const std::string & request )

Appends payment request to destination.

Definition at line 2882 of file wallet.cpp.

◆ LoadDescriptorScriptPubKeyMan()

DescriptorScriptPubKeyMan & wallet::CWallet::LoadDescriptorScriptPubKeyMan ( uint256 id,
WalletDescriptor & desc )

Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.

Definition at line 3562 of file wallet.cpp.

◆ LoadExisting()

std::shared_ptr< CWallet > wallet::CWallet::LoadExisting ( WalletContext & context,
const std::string & name,
std::unique_ptr< WalletDatabase > database,
bilingual_str & error,
std::vector< bilingual_str > & warnings )
static

Definition at line 3127 of file wallet.cpp.

Here is the caller graph for this function:

◆ LoadLockedCoin()

void wallet::CWallet::LoadLockedCoin ( const COutPoint & coin,
bool persistent )

Definition at line 2731 of file wallet.cpp.

Here is the caller graph for this function:

◆ LoadWalletArgs()

bool wallet::CWallet::LoadWalletArgs ( std::shared_ptr< CWallet > wallet,
const WalletContext & context,
bilingual_str & error,
std::vector< bilingual_str > & warnings )
static

Definition at line 2951 of file wallet.cpp.

Here is the caller graph for this function:

◆ Lock()

Definition at line 3360 of file wallet.cpp.

Here is the caller graph for this function:

◆ LockCoin()

bool wallet::CWallet::LockCoin ( const COutPoint & output,
bool persist )

Definition at line 2737 of file wallet.cpp.

◆ LogName()

std::string wallet::CWallet::LogName ( ) const
inlineoverridevirtual

Return wallet name for use in logs, will return "default wallet" if the wallet has no name.

Implements wallet::WalletStorage.

Definition at line 923 of file wallet.h.

◆ LogStats()

void wallet::CWallet::LogStats ( ) const
inline

Definition at line 943 of file wallet.h.

◆ MarkDestinationsDirty()

void wallet::CWallet::MarkDestinationsDirty ( const std::set< CTxDestination > & destinations)

Marks all outputs in each one of the destinations dirty, so their cache is reset and does not return outdated information.

Definition at line 2628 of file wallet.cpp.

Here is the caller graph for this function:

◆ MigrateToSQLite()

Move all records from the BDB database to a new SQLite database for storage.

The original BDB file will be deleted and replaced with a new SQLite file. A backup is not created. May crash if something unexpected happens in the filesystem.

Definition at line 3815 of file wallet.cpp.

◆ PopulateWalletFromDB()

DBErrors wallet::CWallet::PopulateWalletFromDB ( bilingual_str & error,
std::vector< bilingual_str > & warnings )

Definition at line 2353 of file wallet.cpp.

◆ postInitProcess()

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

Definition at line 3301 of file wallet.cpp.

◆ RefreshAllTXOs()

Cache outputs that belong to the wallet for all transactions in the wallet.

Definition at line 4563 of file wallet.cpp.

Here is the caller graph for this function:

◆ RefreshTXOsFromTx()

Cache outputs that belong to the wallet from a single transaction.

Definition at line 4549 of file wallet.cpp.

Here is the caller graph for this function:

◆ RemoveTxs() [1/2]

util::Result< void > wallet::CWallet::RemoveTxs ( std::vector< Txid > & txs_to_remove)

Erases the provided transactions from the wallet.

Definition at line 2419 of file wallet.cpp.

Here is the caller graph for this function:

◆ RemoveTxs() [2/2]

util::Result< void > wallet::CWallet::RemoveTxs ( WalletBatch & batch,
std::vector< Txid > & txs_to_remove )

Definition at line 2433 of file wallet.cpp.

◆ ScanningDuration()

SteadyClock::duration wallet::CWallet::ScanningDuration ( ) const
inline

Definition at line 580 of file wallet.h.

◆ ScanningProgress()

double wallet::CWallet::ScanningProgress ( ) const
inline

Definition at line 581 of file wallet.h.

◆ SetAddressBook()

bool wallet::CWallet::SetAddressBook ( const CTxDestination & address,
const std::string & strName,
const std::optional< AddressPurpose > & purpose )

Definition at line 2516 of file wallet.cpp.

Here is the caller graph for this function:

◆ SetAddressBookWithDB()

bool wallet::CWallet::SetAddressBookWithDB ( WalletBatch & batch,
const CTxDestination & address,
const std::string & strName,
const std::optional< AddressPurpose > & strPurpose )
private

Definition at line 2480 of file wallet.cpp.

Here is the caller graph for this function:

◆ SetAddressPreviouslySpent()

bool wallet::CWallet::SetAddressPreviouslySpent ( WalletBatch & batch,
const CTxDestination & dest,
bool used )

Definition at line 2863 of file wallet.cpp.

Here is the caller graph for this function:

◆ SetAddressReceiveRequest()

bool wallet::CWallet::SetAddressReceiveRequest ( WalletBatch & batch,
const CTxDestination & dest,
const std::string & id,
const std::string & value )

Definition at line 2904 of file wallet.cpp.

◆ SetBroadcastTransactions()

void wallet::CWallet::SetBroadcastTransactions ( bool broadcast)
inline

Set whether this wallet broadcasts transactions.

Definition at line 859 of file wallet.h.

◆ SetNextResend()

Set the next time this wallet should resend transactions to 12-36 hours from now, ~1 day on average.

Definition at line 652 of file wallet.h.

◆ SetupDescriptorScriptPubKeyMan()

DescriptorScriptPubKeyMan & wallet::CWallet::SetupDescriptorScriptPubKeyMan ( WalletBatch & batch,
const CExtKey & master_key,
const OutputType & output_type,
bool internal )

Create new DescriptorScriptPubKeyMan and add it to the wallet.

Definition at line 3574 of file wallet.cpp.

Here is the caller graph for this function:

◆ SetupDescriptorScriptPubKeyMans() [1/2]

Definition at line 3620 of file wallet.cpp.

Here is the caller graph for this function:

◆ SetupDescriptorScriptPubKeyMans() [2/2]

void wallet::CWallet::SetupDescriptorScriptPubKeyMans ( WalletBatch & batch,
const CExtKey & master_key )

Create new DescriptorScriptPubKeyMans and add them to the wallet.

Definition at line 3594 of file wallet.cpp.

◆ SetupLegacyScriptPubKeyMan()

Make a Legacy(Data)SPKM and set it for all types, internal, and external.

Definition at line 3516 of file wallet.cpp.

Here is the caller graph for this function:

◆ SetupOwnDescriptorScriptPubKeyMans()

Create new seed and default DescriptorScriptPubKeyMans for this wallet.

Definition at line 3604 of file wallet.cpp.

Here is the caller graph for this function:

◆ SignMessage()

SigningResult wallet::CWallet::SignMessage ( const std::string & message,
const PKHash & pkhash,
std::string & str_sig ) const

Definition at line 2240 of file wallet.cpp.

◆ SignTransaction() [1/2]

Fetch the inputs and sign with SIGHASH_ALL.

Definition at line 2152 of file wallet.cpp.

Here is the caller graph for this function:

◆ SignTransaction() [2/2]

bool wallet::CWallet::SignTransaction ( CMutableTransaction & tx,
const std::map< COutPoint, Coin > & coins,
int sighash,
std::map< int, bilingual_str > & input_errors ) const

Sign the tx given the input coins and sighash.

Definition at line 2171 of file wallet.cpp.

◆ TopUpCallback()

void wallet::CWallet::TopUpCallback ( const std::set< CScript > & spks,
ScriptPubKeyMan * spkm )
override

Definition at line 4492 of file wallet.cpp.

◆ TopUpKeyPool()

bool wallet::CWallet::TopUpKeyPool ( unsigned int kpSize = 0)

Definition at line 2591 of file wallet.cpp.

◆ TransactionChangeType()

OutputType wallet::CWallet::TransactionChangeType ( const std::optional< OutputType > & change_type,
const std::vector< CRecipient > & vecSend ) const

Definition at line 2253 of file wallet.cpp.

◆ Unlock()

bool wallet::CWallet::Unlock ( const CKeyingMaterial & vMasterKeyIn)
private

Definition at line 3377 of file wallet.cpp.

Here is the caller graph for this function:

◆ UnlockAllCoins()

Definition at line 2763 of file wallet.cpp.

◆ UnlockCoin()

bool wallet::CWallet::UnlockCoin ( const COutPoint & output)

Definition at line 2748 of file wallet.cpp.

Here is the caller graph for this function:

◆ WalletLogPrintf()

template<typename... Params>
void wallet::CWallet::WalletLogPrintf ( util::ConstevalFormatString< sizeof...(Params)> wallet_fmt,
const Params &... params ) const
inline

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

Definition at line 938 of file wallet.h.

Here is the caller graph for this function:

◆ WithEncryptionKey()

bool wallet::CWallet::WithEncryptionKey ( std::function< bool(const CKeyingMaterial &)> cb) const
override

Definition at line 3533 of file wallet.cpp.

◆ WriteBestBlock()

Write the current best block to database.

Definition at line 4534 of file wallet.cpp.

Here is the caller graph for this function:

◆ WalletRescanReserver

friend class WalletRescanReserver
friend

Definition at line 321 of file wallet.h.

Member Data Documentation

◆ cs_wallet

Main wallet lock.

This lock protects all the fields added by CWallet.

Definition at line 460 of file wallet.h.

◆ fAbortRescan

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

Definition at line 316 of file wallet.h.

◆ fBroadcastTransactions

Whether this wallet will submit newly created transactions to the node's mempool and prompt rebroadcasts (see ResendWalletTransactions()).

Definition at line 327 of file wallet.h.

◆ fScanningWallet

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

Definition at line 317 of file wallet.h.

◆ m_allow_fallback_fee

will be false if -fallbackfee=0

Definition at line 711 of file wallet.h.

◆ m_best_block_time

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

Definition at line 329 of file wallet.h.

◆ m_birth_time

std::atomic<int64_t> wallet::CWallet::m_birth_time {std::numeric_limits<int64_t>::max()}
private

Definition at line 333 of file wallet.h.

◆ m_cached_spks

std::unordered_map<CScript, std::vector<ScriptPubKeyMan*>, SaltedSipHasher> wallet::CWallet::m_cached_spks
private

Cache of descriptor ScriptPubKeys used for IsMine. Maps ScriptPubKey to set of spkms.

Definition at line 435 of file wallet.h.

◆ m_chain

Interface for accessing chain state.

Definition at line 393 of file wallet.h.

◆ m_chain_notifications_handler

◆ m_confirm_target

unsigned int wallet::CWallet::m_confirm_target {DEFAULT_TX_CONFIRM_TARGET}

Definition at line 706 of file wallet.h.

◆ m_consolidate_feerate

CFeeRate wallet::CWallet::m_consolidate_feerate {DEFAULT_CONSOLIDATE_FEERATE}

When the actual feerate is less than the consolidate feerate, we will tend to make transactions which consolidate inputs.

When the actual feerate is greater than the consolidate feerate, we will tend to make transactions which have the lowest fees.

Definition at line 728 of file wallet.h.

◆ m_database

std::unique_ptr<WalletDatabase> wallet::CWallet::m_database
private

Internal database handle.

Definition at line 399 of file wallet.h.

◆ m_default_address_type

Definition at line 732 of file wallet.h.

◆ m_default_change_type

Default output type for change outputs.

When unset, automatically choose type based on address type setting and the types other of non-change outputs (see -changetype option documentation and implementation in CWallet::TransactionChangeType for details).

Definition at line 739 of file wallet.h.

◆ m_default_max_tx_fee

CAmount wallet::CWallet::m_default_max_tx_fee {DEFAULT_TRANSACTION_MAXFEE}

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

Definition at line 741 of file wallet.h.

◆ m_discard_rate

If the cost to spend a change output at this feerate is greater than the value of the output itself, just drop it to fees.

Definition at line 722 of file wallet.h.

◆ m_external_spk_managers

std::map<OutputType, ScriptPubKeyMan*> wallet::CWallet::m_external_spk_managers
private

Definition at line 417 of file wallet.h.

◆ m_fallback_fee

CFeeRate wallet::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 718 of file wallet.h.

◆ m_internal_spk_managers

std::map<OutputType, ScriptPubKeyMan*> wallet::CWallet::m_internal_spk_managers
private

Definition at line 418 of file wallet.h.

◆ m_keypool_size

int64_t wallet::CWallet::m_keypool_size {DEFAULT_KEYPOOL_SIZE}

Number of pre-generated keys/scripts by each spkm (part of the look-ahead process, used to detect payments).

Definition at line 744 of file wallet.h.

◆ m_max_aps_fee

CAmount wallet::CWallet::m_max_aps_fee {DEFAULT_MAX_AVOIDPARTIALSPEND_FEE}

The maximum fee amount we're willing to pay to prioritize partial spend avoidance.

note: this is absolute fee, not fee rate

Definition at line 731 of file wallet.h.

◆ m_min_fee

CFeeRate wallet::CWallet::m_min_fee {DEFAULT_TRANSACTION_MINFEE}

Definition at line 712 of file wallet.h.

◆ m_name

std::string wallet::CWallet::m_name
private

Wallet name: relative directory name or "" for default wallet.

Definition at line 396 of file wallet.h.

◆ m_next_resend

The next scheduled rebroadcast of wallet transactions.

Definition at line 324 of file wallet.h.

◆ m_notify_tx_changed_script

Notify external script when a wallet transaction comes in or is updated (handled by -walletnotify).

Definition at line 747 of file wallet.h.

◆ m_relock_mutex

◆ m_scanning_progress

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

Definition at line 320 of file wallet.h.

◆ m_scanning_start

std::atomic<SteadyClock::time_point> wallet::CWallet::m_scanning_start {SteadyClock::time_point{}}
private

Definition at line 319 of file wallet.h.

◆ m_scanning_with_passphrase

std::atomic<bool> wallet::CWallet::m_scanning_with_passphrase {false}
private

Definition at line 318 of file wallet.h.

◆ m_signal_rbf

bool wallet::CWallet::m_signal_rbf {DEFAULT_WALLET_RBF}

Definition at line 710 of file wallet.h.

◆ m_spend_zero_conf_change

bool wallet::CWallet::m_spend_zero_conf_change {DEFAULT_SPEND_ZEROCONF_CHANGE}

Allow Coin Selection to pick unconfirmed UTXOs that were sent from our own wallet if it cannot fund the transaction otherwise.

Definition at line 709 of file wallet.h.

◆ m_spk_managers

std::map<uint256, std::unique_ptr<ScriptPubKeyMan> > wallet::CWallet::m_spk_managers
private

Definition at line 422 of file wallet.h.

◆ m_unlock_mutex

Definition at line 595 of file wallet.h.

◆ m_wallet_flags

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

WalletFlags set on this wallet.

Definition at line 382 of file wallet.h.

◆ mapMasterKeys

◆ nMasterKeyMaxID

Definition at line 474 of file wallet.h.

◆ NotifyAddressBookChanged

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

Address book entry changed.

Note
called without lock cs_wallet held.

Definition at line 836 of file wallet.h.

◆ NotifyCanGetAddressesChanged

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

Keypool has new keys.

Definition at line 848 of file wallet.h.

◆ NotifyStatusChanged

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

Wallet status (encrypted, locked) changed.

Note: Called without locks held.

Definition at line 854 of file wallet.h.

◆ NotifyTransactionChanged

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

Wallet transaction added, removed or updated.

Note
called with lock cs_wallet held.

Definition at line 842 of file wallet.h.

◆ NotifyUnload

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

Wallet is about to be unloaded.

Definition at line 827 of file wallet.h.

◆ ShowProgress

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

Show progress e.g.

for rescan

Definition at line 845 of file wallet.h.

◆ wtxOrdered

Definition at line 501 of file wallet.h.


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