Bitcoin Core  0.20.99
P2P Digital Currency
Classes | Typedefs | Functions | Variables
wallet.h File Reference
#include <amount.h>
#include <interfaces/chain.h>
#include <interfaces/handler.h>
#include <outputtype.h>
#include <policy/feerate.h>
#include <psbt.h>
#include <tinyformat.h>
#include <util/message.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/system.h>
#include <util/ui_change_type.h>
#include <validationinterface.h>
#include <wallet/coinselection.h>
#include <wallet/crypter.h>
#include <wallet/scriptpubkeyman.h>
#include <wallet/walletdb.h>
#include <wallet/walletutil.h>
#include <algorithm>
#include <atomic>
#include <map>
#include <memory>
#include <set>
#include <stdexcept>
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
#include <boost/signals2/signal.hpp>
Include dependency graph for wallet.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ReserveDestination
 A wrapper to reserve an address from a wallet. More...
 
class  CAddressBookData
 Address book data. More...
 
struct  CRecipient
 
struct  COutputEntry
 
class  CMerkleTx
 Legacy class used for deserializing vtxPrev for backwards compatibility. More...
 
class  CWalletTx
 A transaction with a bunch of additional info that only the owner cares about. More...
 
struct  CWalletTx::Confirmation
 
class  COutput
 
struct  CoinSelectionParams
 
class  CWallet
 A CWallet maintains a set of transactions and balances, and provides the ability to create new transactions. More...
 
struct  CWallet::ScanResult
 
struct  CWallet::Balance
 
class  WalletRescanReserver
 RAII object to check and reserve a wallet rescan. More...
 

Typedefs

using LoadWalletFn = std::function< void(std::unique_ptr< interfaces::Wallet > wallet)>
 
typedef std::map< std::string, std::string > mapValue_t
 

Functions

void UnloadWallet (std::shared_ptr< CWallet > &&wallet)
 Explicitly unload and delete the wallet. More...
 
bool AddWallet (const std::shared_ptr< CWallet > &wallet)
 
bool RemoveWallet (const std::shared_ptr< CWallet > &wallet, Optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
 
bool RemoveWallet (const std::shared_ptr< CWallet > &wallet, Optional< bool > load_on_start)
 
std::vector< std::shared_ptr< CWallet > > GetWallets ()
 
std::shared_ptr< CWalletGetWallet (const std::string &name)
 
std::shared_ptr< CWalletLoadWallet (interfaces::Chain &chain, const std::string &name, Optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
 
std::shared_ptr< CWalletCreateWallet (interfaces::Chain &chain, const std::string &name, Optional< bool > load_on_start, DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
 
std::unique_ptr< interfaces::HandlerHandleLoadWallet (LoadWalletFn load_wallet)
 
std::unique_ptr< WalletDatabaseMakeWalletDatabase (const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
 
static void ReadOrderPos (int64_t &nOrderPos, mapValue_t &mapValue)
 
static void WriteOrderPos (const int64_t &nOrderPos, mapValue_t &mapValue)
 
int CalculateMaximumSignedInputSize (const CTxOut &txout, const CWallet *pwallet, bool use_max_sig=false)
 
void MaybeResendWalletTxs ()
 Called periodically by the schedule thread. More...
 
int64_t CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, bool use_max_sig=false) EXCLUSIVE_LOCKS_REQUIRED(wallet -> cs_wallet)
 
int64_t CalculateMaximumSignedTxSize (const CTransaction &tx, const CWallet *wallet, const std::vector< CTxOut > &txouts, bool use_max_sig=false)
 
bool AddWalletSetting (interfaces::Chain &chain, const std::string &wallet_name)
 Add wallet name to persistent configuration so it will be loaded on startup. More...
 
bool RemoveWalletSetting (interfaces::Chain &chain, const std::string &wallet_name)
 Remove wallet name from persistent configuration so it will not be loaded on startup. More...
 

Variables

constexpr CAmount DEFAULT_PAY_TX_FEE = 0
 -paytxfee default More...
 
static const CAmount DEFAULT_FALLBACK_FEE = 0
 -fallbackfee default More...
 
static const CAmount DEFAULT_DISCARD_FEE = 10000
 -discardfee default More...
 
static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000
 -mintxfee default More...
 
static const CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE = 0
 maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled by default More...
 
constexpr CAmount HIGH_APS_FEE {COIN / 10000}
 discourage APS fee higher than this amount More...
 
static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000
 minimum recommended increment for BIP 125 replacement txs More...
 
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true
 Default for -spendzeroconfchange. More...
 
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false
 Default for -walletrejectlongchains. More...
 
static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6
 -txconfirmtarget default More...
 
static const bool DEFAULT_WALLET_RBF = false
 -walletrbf default More...
 
static const bool DEFAULT_WALLETBROADCAST = true
 
static const bool DEFAULT_DISABLE_WALLET = false
 
constexpr CAmount DEFAULT_TRANSACTION_MAXFEE {COIN / 10}
 -maxtxfee default More...
 
constexpr CAmount HIGH_TX_FEE_PER_KB {COIN / 100}
 Discourage users to set fees higher than this amount (in satoshis) per kB. More...
 
constexpr CAmount HIGH_MAX_TX_FEE {100 * HIGH_TX_FEE_PER_KB}
 -maxtxfee will warn if called with a higher fee than this amount (in satoshis) More...
 
static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE = 91
 Pre-calculated constants for input size estimation in virtual size More...
 
constexpr OutputType DEFAULT_ADDRESS_TYPE {OutputType::BECH32}
 Default for -addresstype. More...
 
static constexpr uint64_t KNOWN_WALLET_FLAGS
 
static constexpr uint64_t MUTABLE_WALLET_FLAGS
 
static const std::map< std::string, WalletFlagsWALLET_FLAG_MAP
 
const std::map< uint64_t, std::string > WALLET_FLAG_CAVEATS
 

Typedef Documentation

◆ LoadWalletFn

using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>

Definition at line 41 of file wallet.h.

◆ mapValue_t

typedef std::map<std::string, std::string> mapValue_t

Definition at line 215 of file wallet.h.

Function Documentation

◆ AddWallet()

bool AddWallet ( const std::shared_ptr< CWallet > &  wallet)

Definition at line 95 of file wallet.cpp.

Here is the caller graph for this function:

◆ AddWalletSetting()

bool AddWalletSetting ( interfaces::Chain chain,
const std::string &  wallet_name 
)

Add wallet name to persistent configuration so it will be loaded on startup.

Definition at line 59 of file wallet.cpp.

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

◆ CreateWallet()

std::shared_ptr<CWallet> CreateWallet ( interfaces::Chain chain,
const std::string &  name,
Optional< bool >  load_on_start,
DatabaseOptions options,
DatabaseStatus status,
bilingual_str error,
std::vector< bilingual_str > &  warnings 
)

Definition at line 246 of file wallet.cpp.

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

◆ GetWallet()

std::shared_ptr<CWallet> GetWallet ( const std::string &  name)

Definition at line 138 of file wallet.cpp.

Here is the caller graph for this function:

◆ GetWallets()

std::vector<std::shared_ptr<CWallet> > GetWallets ( )

Definition at line 132 of file wallet.cpp.

Here is the caller graph for this function:

◆ HandleLoadWallet()

std::unique_ptr<interfaces::Handler> HandleLoadWallet ( LoadWalletFn  load_wallet)

Definition at line 147 of file wallet.cpp.

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

◆ LoadWallet()

std::shared_ptr<CWallet> LoadWallet ( interfaces::Chain chain,
const std::string &  name,
Optional< bool >  load_on_start,
const DatabaseOptions options,
DatabaseStatus status,
bilingual_str error,
std::vector< bilingual_str > &  warnings 
)

Definition at line 233 of file wallet.cpp.

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

◆ MakeWalletDatabase()

std::unique_ptr<WalletDatabase> MakeWalletDatabase ( const std::string &  name,
const DatabaseOptions options,
DatabaseStatus status,
bilingual_str error 
)

Definition at line 3786 of file wallet.cpp.

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

◆ MaybeResendWalletTxs()

void MaybeResendWalletTxs ( )

Called periodically by the schedule thread.

Prompts individual wallets to resend their transactions. Actual rebroadcast schedule is managed by the wallets themselves.

Definition at line 2128 of file wallet.cpp.

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

◆ ReadOrderPos()

static void ReadOrderPos ( int64_t &  nOrderPos,
mapValue_t mapValue 
)
inlinestatic

Definition at line 218 of file wallet.h.

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

◆ RemoveWallet() [1/2]

bool RemoveWallet ( const std::shared_ptr< CWallet > &  wallet,
Optional< bool >  load_on_start,
std::vector< bilingual_str > &  warnings 
)

Definition at line 106 of file wallet.cpp.

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

◆ RemoveWallet() [2/2]

bool RemoveWallet ( const std::shared_ptr< CWallet > &  wallet,
Optional< bool >  load_on_start 
)

Definition at line 126 of file wallet.cpp.

Here is the call graph for this function:

◆ RemoveWalletSetting()

bool RemoveWalletSetting ( interfaces::Chain chain,
const std::string &  wallet_name 
)

Remove wallet name from persistent configuration so it will not be loaded on startup.

Definition at line 70 of file wallet.cpp.

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

◆ UnloadWallet()

void UnloadWallet ( std::shared_ptr< CWallet > &&  wallet)

Explicitly unload and delete the wallet.

Blocks the current thread after signaling the unload intent so that all wallet clients release the wallet. Note that, when blocking is not required, the wallet is implicitly unloaded by the shared pointer deleter.

Definition at line 178 of file wallet.cpp.

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

◆ WriteOrderPos()

static void WriteOrderPos ( const int64_t &  nOrderPos,
mapValue_t mapValue 
)
inlinestatic

Definition at line 229 of file wallet.h.

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

Variable Documentation

◆ DEFAULT_ADDRESS_TYPE

constexpr OutputType DEFAULT_ADDRESS_TYPE {OutputType::BECH32}

Default for -addresstype.

Definition at line 111 of file wallet.h.

◆ DEFAULT_DISABLE_WALLET

const bool DEFAULT_DISABLE_WALLET = false
static

Definition at line 91 of file wallet.h.

◆ DEFAULT_DISCARD_FEE

const CAmount DEFAULT_DISCARD_FEE = 10000
static

-discardfee default

Definition at line 67 of file wallet.h.

◆ DEFAULT_FALLBACK_FEE

const CAmount DEFAULT_FALLBACK_FEE = 0
static

-fallbackfee default

Definition at line 65 of file wallet.h.

◆ DEFAULT_MAX_AVOIDPARTIALSPEND_FEE

const CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE = 0
static

maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled by default

A value of -1 disables this feature completely. A value of 0 (current default) means to attempt to do partial spend avoidance, and use its results if the fees remain unchanged A value > 0 means to do partial spend avoidance if the fee difference against a regular coin selection instance is in the range [0..value].

Definition at line 77 of file wallet.h.

◆ DEFAULT_PAY_TX_FEE

constexpr CAmount DEFAULT_PAY_TX_FEE = 0

-paytxfee default

Definition at line 63 of file wallet.h.

◆ DEFAULT_SPEND_ZEROCONF_CHANGE

const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true
static

Default for -spendzeroconfchange.

Definition at line 83 of file wallet.h.

◆ DEFAULT_TRANSACTION_MAXFEE

constexpr CAmount DEFAULT_TRANSACTION_MAXFEE {COIN / 10}

-maxtxfee default

Definition at line 93 of file wallet.h.

◆ DEFAULT_TRANSACTION_MINFEE

const CAmount DEFAULT_TRANSACTION_MINFEE = 1000
static

-mintxfee default

Definition at line 69 of file wallet.h.

◆ DEFAULT_TX_CONFIRM_TARGET

const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6
static

-txconfirmtarget default

Definition at line 87 of file wallet.h.

◆ DEFAULT_WALLET_RBF

const bool DEFAULT_WALLET_RBF = false
static

-walletrbf default

Definition at line 89 of file wallet.h.

◆ DEFAULT_WALLET_REJECT_LONG_CHAINS

const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false
static

Default for -walletrejectlongchains.

Definition at line 85 of file wallet.h.

◆ DEFAULT_WALLETBROADCAST

const bool DEFAULT_WALLETBROADCAST = true
static

Definition at line 90 of file wallet.h.

◆ DUMMY_NESTED_P2WPKH_INPUT_SIZE

constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE = 91
static

Pre-calculated constants for input size estimation in virtual size

Definition at line 100 of file wallet.h.

◆ HIGH_APS_FEE

constexpr CAmount HIGH_APS_FEE {COIN / 10000}

discourage APS fee higher than this amount

Definition at line 79 of file wallet.h.

◆ HIGH_MAX_TX_FEE

constexpr CAmount HIGH_MAX_TX_FEE {100 * HIGH_TX_FEE_PER_KB}

-maxtxfee will warn if called with a higher fee than this amount (in satoshis)

Definition at line 97 of file wallet.h.

◆ HIGH_TX_FEE_PER_KB

constexpr CAmount HIGH_TX_FEE_PER_KB {COIN / 100}

Discourage users to set fees higher than this amount (in satoshis) per kB.

Definition at line 95 of file wallet.h.

◆ KNOWN_WALLET_FLAGS

constexpr uint64_t KNOWN_WALLET_FLAGS
static
Initial value:
=
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses, and other watch only things, and is therefore "blank.".
Definition: walletutil.h:58
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:61

Definition at line 113 of file wallet.h.

◆ MUTABLE_WALLET_FLAGS

constexpr uint64_t MUTABLE_WALLET_FLAGS
static
Initial value:

Definition at line 120 of file wallet.h.

◆ WALLET_FLAG_CAVEATS

const std::map<uint64_t,std::string> WALLET_FLAG_CAVEATS

Definition at line 45 of file wallet.cpp.

◆ WALLET_FLAG_MAP

const std::map<std::string,WalletFlags> WALLET_FLAG_MAP
static
Initial value:
{
{"avoid_reuse", WALLET_FLAG_AVOID_REUSE},
{"key_origin_metadata", WALLET_FLAG_KEY_ORIGIN_METADATA},
{"disable_private_keys", WALLET_FLAG_DISABLE_PRIVATE_KEYS},
{"descriptor_wallet", WALLET_FLAG_DESCRIPTORS},
}
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses, and other watch only things, and is therefore "blank.".
Definition: walletutil.h:58
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:61

Definition at line 123 of file wallet.h.

◆ WALLET_INCREMENTAL_RELAY_FEE

const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000
static

minimum recommended increment for BIP 125 replacement txs

Definition at line 81 of file wallet.h.