6 #ifndef BITCOIN_WALLET_WALLET_H
7 #define BITCOIN_WALLET_WALLET_H
39 #include <boost/signals2/signal.hpp>
41 using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
52 bool AddWallet(
const std::shared_ptr<CWallet>& wallet);
55 std::vector<std::shared_ptr<CWallet>>
GetWallets();
220 if (!mapValue.count(
"n"))
225 nOrderPos =
atoi64(mapValue[
"n"]);
233 mapValue[
"n"] =
ToString(nOrderPos);
251 template<
typename Stream>
256 std::vector<uint256> vMerkleBranch;
259 s >> tx >> hashBlock >> vMerkleBranch >> nIndex;
307 std::vector<std::pair<std::string, std::string> >
vOrderForm;
398 template<
typename Stream>
403 mapValueCopy[
"fromaccount"] =
"";
409 std::vector<char> dummy_vector1;
410 std::vector<char> dummy_vector2;
411 bool dummy_bool =
false;
417 template<
typename Stream>
422 std::vector<uint256> dummy_vector1;
423 std::vector<CMerkleTx> dummy_vector2;
437 }
else if (serializedIndex == -1) {
487 void GetAmounts(std::list<COutputEntry>& listReceived,
586 COutput(
const CWalletTx *txIn,
int iIn,
int nDepthIn,
bool fSpendableIn,
bool fSolvableIn,
bool fSafeIn,
bool use_max_sig_in =
false)
619 change_output_size(change_output_size),
620 change_spend_size(change_spend_size),
624 tx_noinputs_size(tx_noinputs_size)
660 typedef std::multimap<COutPoint, uint256>
TxSpends;
757 bool SelectCoins(
const std::vector<COutput>& vAvailableCoins,
const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet,
CAmount& nValueRet,
772 database(std::move(database))
791 typedef std::multimap<int64_t, CWalletTx*>
TxItems;
800 std::set<
COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
944 Balance
GetBalance(
int min_depth = 0,
bool avoid_reuse =
true)
const;
975 int sighash_type = 1 ,
977 bool bip32derivs =
true,
978 size_t* n_signed =
nullptr)
const;
999 std::vector<CTxOut> v_txouts(txouts.size());
1000 std::copy(txouts.begin(), txouts.end(), v_txouts.begin());
1008 bool ImportPubKeys(
const std::vector<CKeyID>& ordered_pubkeys,
const std::map<CKeyID, CPubKey>& pubkey_map,
const std::map<
CKeyID, std::pair<CPubKey, KeyOriginInfo>>& key_origins,
const bool add_keypool,
const bool internal,
const int64_t timestamp)
EXCLUSIVE_LOCKS_REQUIRED(
cs_wallet);
1081 bool SetAddressBook(const CTxDestination& address, const std::
string& strName, const std::
string& purpose);
1113 &address,
const std::string &label,
bool isMine,
1114 const std::string &purpose,
1121 boost::signals2::signal<void (
CWallet *wallet,
const uint256 &hashTx,
1125 boost::signals2::signal<void (const std::string &title, int nProgress)>
ShowProgress;
1198 std::string wallet_name =
GetName().length() == 0 ?
"default wallet" :
GetName();
1203 template<
typename...
Params>
1246 assert(m_last_block_processed_height >= 0);
1247 return m_last_block_processed_height;
1252 assert(m_last_block_processed_height >= 0);
1253 return m_last_block_processed;
1259 m_last_block_processed_height = block_height;
1260 m_last_block_processed = block_hash;
1308 assert(!m_could_reserve);
1314 m_could_reserve =
true;
1325 if (m_could_reserve) {
1344 #endif // BITCOIN_WALLET_WALLET_H
std::shared_ptr< const CTransaction > CTransactionRef
constexpr CAmount HIGH_APS_FEE
discourage APS fee higher than this amount
bool AddDestData(WalletBatch &batch, const CTxDestination &dest, const std::string &key, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Adds a destination data tuple to the store, and saves it to disk When adding new fields, take care to consider how DelAddressBook should handle it!
std::function< bool(CWalletTx &wtx, bool new_tx)> UpdateWalletTxFn
Callback for updating transaction metadata in mapWallet.
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
Get the SigningProvider for a script.
void SetupLegacyScriptPubKeyMan()
Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
void GetAmounts(std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, const isminefilter &filter) const
std::atomic< bool > fScanningWallet
#define NO_THREAD_SAFETY_ANALYSIS
void Close()
Close wallet database.
const uint256 & GetHash() const
bool IsWalletFlagSet(uint64_t flag) const override
check if a certain wallet flag is set
const std::map< uint64_t, std::string > WALLET_FLAG_CAVEATS
std::unique_ptr< WalletDatabase > database
Internal database handle.
void SetSpentKeyState(WalletBatch &batch, const uint256 &hash, unsigned int n, bool used, std::set< CTxDestination > &tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void blockConnected(const CBlock &block, int height) override
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool IsLegacy() const
Determine if we are a legacy wallet.
std::unique_ptr< interfaces::Handler > m_chain_notifications_handler
Registered interfaces::Chain::Notifications handler.
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
CAmount GetAvailableCredit(bool fUseCache=true, const isminefilter &filter=ISMINE_SPENDABLE) const NO_THREAD_SAFETY_ANALYSIS
bool IsFeatureSupported(int wallet_version, int feature_version)
bool m_is_cache_empty
This flag is true if all m_amounts caches are empty.
CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet)
static const CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled...
void WalletLogPrintf(std::string fmt, Params...parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
CAmount GetCredit(const CTxOut &txout, const isminefilter &filter) const
bool DummySignTx(CMutableTransaction &txNew, const std::set< CTxOut > &txouts, bool use_max_sig=false) const
std::map< std::string, std::string > mapValue_t
bool IsAllFromMe(const CTransaction &tx, const isminefilter &filter) const
Returns whether all of the inputs match the filter.
bool fSolvable
Whether we know how to spend this output, ignoring the lack of keys.
CAmount GetImmatureWatchOnlyCredit(const bool fUseCache=true) const
CFeeRate m_effective_feerate
constexpr CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
CAmount GetAvailableBalance(const CCoinControl *coinControl=nullptr) const
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
constexpr CAmount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
void UnlockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
void SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr) override
signify that a particular wallet feature is now used.
std::shared_ptr< CWallet > GetWallet(const std::string &name)
void postInitProcess()
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
isminetype IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
uint64_t nAccountingEntryNumber
CTxDestination address
The destination.
TransactionError FillPSBT(PartiallySignedTransaction &psbtx, bool &complete, int sighash_type=1, bool sign=true, bool bip32derivs=true, size_t *n_signed=nullptr) const
Fills out a PSBT with information from the wallet.
std::map< CTxDestination, std::vector< COutput > > ListCoins() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Return list of available coins and locked coins grouped by non-change output address.
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
ScriptPubKeyMan * GetScriptPubKeyMan(const OutputType &type, bool internal) const
Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
size_t change_output_size
std::atomic< int64_t > m_best_block_time
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
int64_t GetTimeMillis()
Returns the system time (not mockable)
static const CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
bool AddWallet(const std::shared_ptr< CWallet > &wallet)
const CTxOut & FindNonChangeParentOutput(const CTransaction &tx, int output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Find non-change parent output.
static void LogPrintf(const char *fmt, const Args &...args)
uint256 last_scanned_block
Hash and height of most recent block that was successfully scanned.
bool use_max_sig
Whether to use the maximum sized, 72 byte signature when calculating the size of the input spend...
bool AddWalletSetting(interfaces::Chain &chain, const std::string &wallet_name)
Add wallet name to persistent configuration so it will be loaded on startup.
static const CAmount COIN
void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void AvailableCoins(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 EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
populate vCoins with vector of available COutputs.
bool IsChange(const CTxOut &txout) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
std::multimap< COutPoint, uint256 > TxSpends
Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated tran...
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
bool m_spend_zero_conf_change
int64_t nOrderPos
position in ordered transaction list
std::multimap< int64_t, CWalletTx * >::const_iterator m_it_wtxOrdered
void blockDisconnected(const CBlock &block, int height) override
const CKeyingMaterial & GetEncryptionKey() const override
bool CanGetAddresses(bool internal=false) const
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
static void ReadOrderPos(int64_t &nOrderPos, mapValue_t &mapValue)
double ScanningProgress() const
int nWalletVersion GUARDED_BY(cs_wallet)
the current wallet version: clients below this version are not able to load the wallet ...
static const bool DEFAULT_DISABLE_WALLET
void MarkDirty()
make sure balances are recalculated
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
bool fSubtractFeeFromAmount
std::vector< std::shared_ptr< CWallet > > GetWallets()
bool IsLocked() const override
void MaybeResendWalletTxs()
Called periodically by the schedule thread.
int64_t GetTxTime() const
A version of CTransaction with the PSBT format.
std::map< unsigned int, CMasterKey > MasterKeyMap
CAmount m_default_max_tx_fee
Absolute maximum transaction fee (in satoshis) used by default for the wallet.
int nInputBytes
Pre-computed estimated size of this output as a fully-signed input in a transaction.
void LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Adds a destination data tuple to the store, without saving it to disk.
const CWalletTx * GetWalletTx(const uint256 &hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
CAmount GetImmatureCredit(bool fUseCache=true) const
CAmount GetCredit(const isminefilter &filter) const
void chainStateFlushed(const CBlockLocator &loc) override
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
std::atomic< bool > fAbortRescan
bool MarkReplaced(const uint256 &originalHash, const uint256 &newHash)
Mark a transaction as replaced by another transaction (e.g., BIP 125).
DBErrors
Error statuses for the wallet database.
std::vector< OutputGroup > GroupOutputs(const std::vector< COutput > &outputs, bool single_coin, const size_t max_ancestors) const
bool EncryptWallet(const SecureString &strWalletPassphrase)
std::map< OutputType, ScriptPubKeyMan * > m_external_spk_managers
bool fSpendable
Whether we have the private keys to spend this output.
void operator=(CWalletTx const &x)=delete
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
int GetSpendSize(unsigned int out, bool use_max_sig=false) const
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
CAmount m_max_aps_fee
note: this is absolute fee, not fee rate
bool fFromMe
From me flag is set to 1 for transactions that were created by the wallet on this bitcoin node...
static const bool DEFAULT_WALLET_RBF
-walletrbf default
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Loads an active ScriptPubKeyMan for the specified type and internal.
WalletFeature
(client) version numbers for particular wallet features
const std::string & GetLabel() const
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
CFeeRate m_min_fee
Override with -mintxfee.
std::set< ScriptPubKeyMan * > GetScriptPubKeyMans(const CScript &script, SignatureData &sigdata) const
Get all of the ScriptPubKeyMans for a script given additional information in sigdata (populated by e...
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
bool IsEquivalentTo(const CWalletTx &tx) const
interfaces::Chain & chain() const
Interface for accessing chain state.
CWalletTx(const CWallet *wallet, CTransactionRef arg)
Access to the wallet database.
mapValue_t mapValue
Key/value map with information about the transaction.
DBErrors ZapSelectTx(std::vector< uint256 > &vHashIn, std::vector< uint256 > &vHashOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
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)
bool GetNewChangeDestination(const OutputType type, CTxDestination &dest, std::string &error)
int64_t CAmount
Amount in satoshis (Can be negative)
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
static const CAmount DEFAULT_FALLBACK_FEE
-fallbackfee default
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
bool HasEncryptionKeys() const override
std::string ToString(const T &t)
Locale-independent version of std::to_string.
DBErrors ReorderTransactions()
int64_t ScanningDuration() const
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans.
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn, bool use_max_sig_in=false)
CInputCoin GetInputCoin() const
bool IsLockedCoin(uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void UnsetWalletFlag(uint64_t flag)
Unsets a single wallet flag.
bool DelAddressBook(const CTxDestination &address)
CoinSelectionParams coin_selection_params(false, 0, 0, CFeeRate(0), CFeeRate(0), CFeeRate(0), 0)
bool error(const char *fmt, const Args &...args)
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...
static const std::map< std::string, WalletFlags > WALLET_FLAG_MAP
void Unserialize(Stream &s)
int GetVersion() const
get the current wallet format (the oldest client version guaranteed to understand this wallet) ...
void Serialize(Stream &s) const
unsigned int nMasterKeyMaxID
void UnsetBlankWalletFlag(WalletBatch &batch) override
Unset the blank wallet flag and saves it to disk.
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 AbandonTransaction(const uint256 &hashTx)
DBErrors LoadWallet(bool &fFirstRunRet)
CWallet(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > database)
Construct wallet with specified name and database implementation.
ScriptPubKeyMan * 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.
bool IsImmatureCoinBase() const
int GetBlocksToMaturity() const
int64_t GetOldestKeyPoolTime() const
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, CWalletTx::Confirmation confirm, bool fUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Add a transaction to the wallet, or update it.
An input of a transaction.
bool FundTransaction(CMutableTransaction &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, bool lockUnspents, const std::set< int > &setSubtractFeeFromOutputs, CCoinControl)
Insert additional inputs into the transaction by calling CreateTransaction();.
OutputType m_default_address_type
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *wallet, bool use_max_sig)
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Create new DescriptorScriptPubKeyMans and add them to the wallet.
void SetTx(CTransactionRef arg)
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...
std::set< ScriptPubKeyMan * > GetActiveScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers.
AssertLockHeld(mempool.cs)
bool TransactionCanBeAbandoned(const uint256 &hashTx) const
Return whether transaction can be abandoned.
std::set< uint256 > GetConflicts() const NO_THREAD_SAFETY_ANALYSIS
bool fSafe
Whether this output is considered safe to spend.
bool HaveChain() const
Interface to assert chain access.
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan(const WalletDescriptor &desc) const
Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet...
int64_t nIndex
The index of the address's key in the keypool.
bool m_subtract_fee_outputs
Indicate that we are subtracting the fee from outputs.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
interfaces::Chain * m_chain
Interface for accessing chain state.
void UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
static const bool DEFAULT_WALLETBROADCAST
CAmount GetCachableAmount(AmountType type, const isminefilter &filter, bool recalculate=false) const
std::map< std::string, std::string > StringMap
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses, and other watch only things, and is therefore "blank.".
WalletDatabase & GetDBHandle()
Get database handle used by this wallet.
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
ReserveDestination(CWallet *pwallet, OutputType type)
Construct a ReserveDestination object. This does NOT reserve an address yet.
uint256 GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
std::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
bool EraseDestData(WalletBatch &batch, const CTxDestination &dest, const std::string &key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Erases a destination data tuple in the store and on disk.
bool ImportScriptPubKeys(const std::string &label, const std::set< CScript > &script_pub_keys, const bool have_solving_data, const bool apply_label, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
ReserveDestination & operator=(const ReserveDestination &)=delete
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
unsigned int ComputeTimeSmart(const CWalletTx &wtx) const
Compute smart timestamp for a transaction being added to the wallet.
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const
Returns amount of debit if the input matches the filter, otherwise returns 0.
isminetype
IsMine() return codes.
void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Set last block processed height, currently only use in unit test.
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor &desc)
Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
An output of a transaction.
bool ImportPubKeys(const std::vector< CKeyID > &ordered_pubkeys, const std::map< CKeyID, CPubKey > &pubkey_map, const std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo >> &key_origins, const bool add_keypool, const bool internal, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet, Optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
CWalletTx * AddToWallet(CTransactionRef tx, const CWalletTx::Confirmation &confirm, const UpdateWalletTxFn &update_wtx=nullptr, bool fFlushOnClose=true)
Descriptor with some wallet metadata.
static const unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
bool IsFromMe(const isminefilter &filter) const
An outpoint - a combination of a transaction hash and an index n into its vout.
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 st...
unsigned int fTimeReceivedIsTxTime
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
static constexpr const uint256 & ABANDON_HASH
Constant used in hashBlock to indicate tx has been abandoned, only used at serialization/deserializat...
std::map< CTxDestination, CAmount > GetAddressBalances() const
~ReserveDestination()
Destructor. If a key has been reserved and not KeepKey'ed, it will be returned to the keypool...
void updatedBlockTip() override
void AddToSpends(const COutPoint &outpoint, const uint256 &wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
RAII object to check and reserve a wallet rescan.
A transaction with a bunch of additional info that only the owner cares about.
int64_t atoi64(const std::string &str)
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void MarkConflicted(const uint256 &hashBlock, int conflicting_height, const uint256 &hashTx)
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
std::map< uint256, std::unique_ptr< ScriptPubKeyMan > > m_spk_managers
bool isConflicted() const
bool IsAbortingRescan() const
bool fBroadcastTransactions
static std::shared_ptr< CWallet > Create(interfaces::Chain &chain, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bilingual_str &error, std::vector< bilingual_str > &warnings)
static constexpr uint64_t MUTABLE_WALLET_FLAGS
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 ...
CachableAmount m_amounts[AMOUNTTYPE_ENUM_ELEMENTS]
void SyncTransaction(const CTransactionRef &tx, CWalletTx::Confirmation confirm, bool update_tx=true) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
int64_t IncOrderPosNext(WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Increment the next transaction order id.
void LockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Cachable amount subdivided into watchonly and spendable parts.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
bool UpgradeWallet(int version, bilingual_str &error)
Upgrade the wallet.
static const CAmount DEFAULT_TRANSACTION_MINFEE
-mintxfee default
static void WriteOrderPos(const int64_t &nOrderPos, mapValue_t &mapValue)
std::set< CTxDestination > GetLabelAddresses(const std::string &label) const
void transactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence) override
CoinSelectionParams(bool use_bnb, size_t change_output_size, size_t change_spend_size, CFeeRate effective_feerate, CFeeRate long_term_feerate, CFeeRate discard_feerate, size_t tx_noinputs_size)
unsigned int m_confirm_target
WalletDatabase & GetDatabase() const override
Optional< OutputType > m_default_change_type
Default output type for change outputs.
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.
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
void BlockUntilSyncedToCurrentChain() const EXCLUSIVE_LOCKS_REQUIRED(!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...
std::atomic< uint64_t > m_wallet_flags
MasterKeyMap mapMasterKeys
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, FeeCalculation &fee_calc_out, bool sign=true)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
CFeeRate m_discard_feerate
void ResendWalletTransactions()
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
CTxDestination destination
bool TopUpKeyPool(unsigned int kpSize=0)
bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::string &strPurpose)
OutputType TransactionChangeType(const Optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend)
unsigned int nTimeSmart
Stable timestamp that never changes, and reflects the order a transaction was added to the wallet...
bool IsInMainChain() const
LegacyScriptPubKeyMan * GetLegacyScriptPubKeyMan() const
Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
bool RemoveWalletSetting(interfaces::Chain &chain, const std::string &wallet_name)
Remove wallet name from persistent configuration so it will not be loaded on startup.
A reference to a CKey: the Hash160 of its serialized public key.
void Unserialize(Stream &s)
std::string ToString() const
int GetDepthInMainChain() const NO_THREAD_SAFETY_ANALYSIS
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
void SetLabel(const std::string &label)
bool GetReservedDestination(CTxDestination &pubkey, bool internal)
Reserve an address.
std::set< uint256 > GetConflicts(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get wallet transactions that conflict with given transaction (spend same outputs) ...
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Fee rate in satoshis per kilobyte: CAmount / kB.
void MarkInputsDirty(const CTransactionRef &tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
const std::string GetDisplayName() const override
Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet ha...
A wrapper to reserve an address from a wallet.
bool LoadToWallet(const uint256 &hash, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
bool DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig=false) const
bool fInternal
Whether this is from the internal (change output) keypool.
Optional< int > last_scanned_height
A mutable version of CTransaction.
uint256 last_failed_block
Height of the most recent block that could not be scanned due to read errors or pruning.
bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
check whether we support the named feature
static const CAmount WALLET_INCREMENTAL_RELAY_FEE
minimum recommended increment for BIP 125 replacement txs
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
static std::vector< COutput > vCoins
bool IsSpent(const uint256 &hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction spends it:
void Flush()
Flush wallet (bitdb flush)
std::atomic< int64_t > m_scanning_start
unsigned int nTimeReceived
time received by this node
std::string m_name
Wallet name: relative directory name or "" for default wallet.
The basic transaction that is broadcasted on the network and contained in blocks. ...
boost::optional< T > Optional
Substitute for C++17 std::optional.
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)
std::vector< std::string > GetDestValues(const std::string &prefix) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get all destination values matching a prefix.
Confirmation(Status s=UNCONFIRMED, int b=0, uint256 h=uint256(), int i=0)
ScanResult ScanForWalletTransactions(const uint256 &start_block, int start_height, Optional< int > max_height, const WalletRescanReserver &reserver, bool fUpdate)
Scan the block chain (starting in start_block) for transactions from or to us.
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
std::atomic< double > m_scanning_progress
ChangeType
General change type (added, updated, removed).
bool m_allow_fallback_fee
will be false if -fallbackfee=0
bool BackupWallet(const std::string &strDest) const
Indicate that this wallet supports DescriptorScriptPubKeyMan.
bool IsSpentKey(const uint256 &hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
CFeeRate m_long_term_feerate
CAmount GetChange(const CTxOut &txout) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
std::multimap< int64_t, CWalletTx * > TxItems
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Balance GetBalance(int min_depth=0, bool avoid_reuse=true) const
void transactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
const CWallet *const pwallet
The wallet to reserve from.
bool SignTransaction(CMutableTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
WalletRescanReserver(CWallet &w)
static const CAmount DEFAULT_DISCARD_FEE
-discardfee default
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig)
bool AddWalletFlags(uint64_t flags)
overwrite all flags by the given uint64_t returns false if unknown, non-tolerable flags are present ...
bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Look up a destination data tuple in the store, return true if found false otherwise.
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Adds the active ScriptPubKeyMan for the specified type and internal.
void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag)
Unsets a wallet flag and saves it to disk.
Legacy class used for deserializing vtxPrev for backwards compatibility.
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination &dest, std::string &error)
const CWallet *const pwallet
static constexpr uint64_t KNOWN_WALLET_FLAGS
CAmount GetChange() const
void KeepDestination()
Keep the address. Do not return it's key to the keypool when this object goes out of scope...
bool CreateTransactionInternal(const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, FeeCalculation &fee_calc_out, bool sign)
constexpr CAmount HIGH_TX_FEE_PER_KB
Discourage users to set fees higher than this amount (in satoshis) per kB.
bool SubmitMemoryPoolAndRelay(std::string &err_string, bool relay)
bool IsTrusted(const CWalletTx &wtx, std::set< uint256 > &trusted_parents) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
std::vector< std::pair< std::string, std::string > > vOrderForm
void ReturnDestination()
Return reserved address.
ScriptPubKeyMan * m_spk_man
The ScriptPubKeyMan to reserve from. Based on type when GetReservedDestination is called...
An instance of this class represents one database.
bool isUnconfirmed() const
std::set< std::set< CTxDestination > > GetAddressGroupings() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE
Pre-calculated constants for input size estimation in virtual size