Bitcoin Core 22.99.0
P2P Digital Currency
wallet.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2020 The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_WALLET_WALLET_H
7#define BITCOIN_WALLET_WALLET_H
8
9#include <consensus/amount.h>
10#include <interfaces/chain.h>
11#include <interfaces/handler.h>
12#include <outputtype.h>
13#include <policy/feerate.h>
14#include <psbt.h>
15#include <tinyformat.h>
16#include <util/message.h>
17#include <util/strencodings.h>
18#include <util/string.h>
19#include <util/system.h>
20#include <util/ui_change_type.h>
21#include <validationinterface.h>
23#include <wallet/crypter.h>
25#include <wallet/transaction.h>
26#include <wallet/walletdb.h>
27#include <wallet/walletutil.h>
28
29#include <algorithm>
30#include <atomic>
31#include <map>
32#include <memory>
33#include <optional>
34#include <set>
35#include <stdexcept>
36#include <stdint.h>
37#include <string>
38#include <utility>
39#include <vector>
40
41#include <boost/signals2/signal.hpp>
42
43struct WalletContext;
44
45using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
46
47struct bilingual_str;
48
54void UnloadWallet(std::shared_ptr<CWallet>&& wallet);
55
56bool AddWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
57bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start, std::vector<bilingual_str>& warnings);
58bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start);
59std::vector<std::shared_ptr<CWallet>> GetWallets(WalletContext& context);
60std::shared_ptr<CWallet> GetWallet(WalletContext& context, const std::string& name);
61std::shared_ptr<CWallet> LoadWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings);
62std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings);
63std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext& context, LoadWalletFn load_wallet);
64std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
65
71static const CAmount DEFAULT_DISCARD_FEE = 10000;
75static const CAmount DEFAULT_CONSOLIDATE_FEERATE{10000}; // 10 sat/vbyte
85constexpr CAmount HIGH_APS_FEE{COIN / 10000};
89static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
91static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false;
93static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
95static const bool DEFAULT_WALLET_RBF = false;
96static const bool DEFAULT_WALLETBROADCAST = true;
97static const bool DEFAULT_DISABLE_WALLET = false;
105static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE = 91;
106
107class CCoinControl;
108class COutput;
109class CScript;
110class CWalletTx;
111struct FeeCalculation;
112enum class FeeEstimateMode;
114
117
118static constexpr uint64_t KNOWN_WALLET_FLAGS =
126
127static constexpr uint64_t MUTABLE_WALLET_FLAGS =
129
130static const std::map<std::string,WalletFlags> WALLET_FLAG_MAP{
131 {"avoid_reuse", WALLET_FLAG_AVOID_REUSE},
132 {"blank", WALLET_FLAG_BLANK_WALLET},
133 {"key_origin_metadata", WALLET_FLAG_KEY_ORIGIN_METADATA},
134 {"last_hardened_xpub_cached", WALLET_FLAG_LAST_HARDENED_XPUB_CACHED},
135 {"disable_private_keys", WALLET_FLAG_DISABLE_PRIVATE_KEYS},
136 {"descriptor_wallet", WALLET_FLAG_DESCRIPTORS},
137 {"external_signer", WALLET_FLAG_EXTERNAL_SIGNER}
138};
139
140extern const std::map<uint64_t,std::string> WALLET_FLAG_CAVEATS;
141
158{
159protected:
161 const CWallet* const pwallet;
166 int64_t nIndex{-1};
170 bool fInternal{false};
171
172public:
176 , type(type) { }
177
180
183 {
185 }
186
188 bool GetReservedDestination(CTxDestination& pubkey, bool internal, bilingual_str& error);
190 void ReturnDestination();
192 void KeepDestination();
193};
194
197{
198private:
199 bool m_change{true};
200 std::string m_label;
201public:
202 std::string purpose;
203
204 CAddressBookData() : purpose("unknown") {}
205
206 typedef std::map<std::string, std::string> StringMap;
208
209 bool IsChange() const { return m_change; }
210 const std::string& GetLabel() const { return m_label; }
211 void SetLabel(const std::string& label) {
212 m_change = false;
213 m_label = label;
214 }
215};
216
218{
222};
223
224class WalletRescanReserver; //forward declarations for ScanForWalletTransactions/RescanFromTime
229{
230private:
232
233 bool Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys = false);
234
235 std::atomic<bool> fAbortRescan{false};
236 std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
237 std::atomic<int64_t> m_scanning_start{0};
238 std::atomic<double> m_scanning_progress{0};
240
242 int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE};
243
245 int64_t nNextResend = 0;
249 // Local time that the tip block was received. Used to schedule wallet rebroadcasts.
250 std::atomic<int64_t> m_best_block_time {0};
251
257 typedef std::multimap<COutPoint, uint256> TxSpends;
259 void AddToSpends(const COutPoint& outpoint, const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
260 void AddToSpends(const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
261
278 bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, CWalletTx::Confirmation confirm, bool fUpdate, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
279
281 void MarkConflicted(const uint256& hashBlock, int conflicting_height, const uint256& hashTx);
282
285
286 void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
287
288 void SyncTransaction(const CTransactionRef& tx, CWalletTx::Confirmation confirm, bool update_tx = true, bool rescanning_old_block = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
289
291 std::atomic<uint64_t> m_wallet_flags{0};
292
293 bool SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::string& strPurpose);
294
296 void UnsetWalletFlagWithDB(WalletBatch& batch, uint64_t flag);
297
299 void UnsetBlankWalletFlag(WalletBatch& batch) override;
300
303
305 std::string m_name;
306
308 std::unique_ptr<WalletDatabase> const m_database;
309
317 uint256 m_last_block_processed GUARDED_BY(cs_wallet);
318
324 int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
325
326 std::map<OutputType, ScriptPubKeyMan*> m_external_spk_managers;
327 std::map<OutputType, ScriptPubKeyMan*> m_internal_spk_managers;
328
329 // Indexed by a unique identifier produced by each ScriptPubKeyMan using
330 // ScriptPubKeyMan::GetID. In many cases it will be the hash of an internal structure
331 std::map<uint256, std::unique_ptr<ScriptPubKeyMan>> m_spk_managers;
332
338 static bool AttachChain(const std::shared_ptr<CWallet>& wallet, interfaces::Chain& chain, const bool rescan_required, bilingual_str& error, std::vector<bilingual_str>& warnings);
339
340public:
346
347 WalletDatabase& GetDatabase() const override
348 {
349 assert(static_cast<bool>(m_database));
350 return *m_database;
351 }
352
355 const std::string& GetName() const { return m_name; }
356
357 typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
359 unsigned int nMasterKeyMaxID = 0;
360
362 CWallet(interfaces::Chain* chain, const std::string& name, std::unique_ptr<WalletDatabase> database)
363 : m_chain(chain),
364 m_name(name),
365 m_database(std::move(database))
366 {
367 }
368
370 {
371 // Should not have slots connected at this point.
372 assert(NotifyUnload.empty());
373 }
374
375 bool IsCrypted() const;
376 bool IsLocked() const override;
377 bool Lock();
378
380 bool HaveChain() const { return m_chain ? true : false; }
381
384 std::map<uint256, CWalletTx> mapWallet GUARDED_BY(cs_wallet);
385
386 typedef std::multimap<int64_t, CWalletTx*> TxItems;
388
389 int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
391
392 std::map<CTxDestination, CAddressBookData> m_address_book GUARDED_BY(cs_wallet);
393 const CAddressBookData* FindAddressBookEntry(const CTxDestination&, bool allow_change = false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
394
399 std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
400
402 std::unique_ptr<interfaces::Handler> m_chain_notifications_handler;
403
405 interfaces::Chain& chain() const { assert(m_chain); return *m_chain; }
406
408
409 // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
410 // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation
411 // "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having to
412 // resolve the issue of member access into incomplete type CWallet. Note
413 // that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)"
414 // in place.
415 std::set<uint256> GetTxConflicts(const CWalletTx& wtx) const NO_THREAD_SAFETY_ANALYSIS;
416
423 // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
424 // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation
425 // "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having to
426 // resolve the issue of member access into incomplete type CWallet. Note
427 // that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)"
428 // in place.
430 bool IsTxInMainChain(const CWalletTx& wtx) const { return GetTxDepthInMainChain(wtx) > 0; }
431
437 int GetTxBlocksToMaturity(const CWalletTx& wtx) const;
438 bool IsTxImmatureCoinBase(const CWalletTx& wtx) const;
439
442
443 bool IsSpent(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
444
445 // Whether this or any known UTXO with the same single key has been spent.
446 bool IsSpentKey(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
447 void SetSpentKeyState(WalletBatch& batch, const uint256& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
448
451
452 bool IsLockedCoin(uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
453 bool LockCoin(const COutPoint& output, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
454 bool UnlockCoin(const COutPoint& output, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
456 void ListLockedCoins(std::vector<COutPoint>& vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
457
458 /*
459 * Rescan abort properties
460 */
461 void AbortRescan() { fAbortRescan = true; }
462 bool IsAbortingRescan() const { return fAbortRescan; }
463 bool IsScanning() const { return fScanningWallet; }
465 double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; }
466
469
472
473 bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; return true; }
474
476 void LoadDestData(const CTxDestination& dest, const std::string& key, const std::string& value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
477
479 int64_t nRelockTime GUARDED_BY(cs_wallet){0};
480
481 // Used to prevent concurrent calls to walletpassphrase RPC.
483 bool Unlock(const SecureString& strWalletPassphrase, bool accept_no_keys = false);
484 bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
485 bool EncryptWallet(const SecureString& strWalletPassphrase);
486
487 void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
488 unsigned int ComputeTimeSmart(const CWalletTx& wtx, bool rescanning_old_block) const;
489
496
497 void MarkDirty();
498
505 using UpdateWalletTxFn = std::function<bool(CWalletTx& wtx, bool new_tx)>;
506
507 CWalletTx* AddToWallet(CTransactionRef tx, const CWalletTx::Confirmation& confirm, const UpdateWalletTxFn& update_wtx=nullptr, bool fFlushOnClose=true, bool rescanning_old_block = false);
508 bool LoadToWallet(const uint256& hash, const UpdateWalletTxFn& fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
509 void transactionAddedToMempool(const CTransactionRef& tx, uint64_t mempool_sequence) override;
510 void blockConnected(const CBlock& block, int height) override;
511 void blockDisconnected(const CBlock& block, int height) override;
512 void updatedBlockTip() override;
513 int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver, bool update);
514
515 struct ScanResult {
516 enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS;
517
522 std::optional<int> last_scanned_height;
523
529 };
530 ScanResult ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate);
531 void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override;
534
535 OutputType TransactionChangeType(const std::optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend) const;
536
540 bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const;
541 SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const;
542
557 bool& complete,
558 int sighash_type = 1 /* SIGHASH_ALL */,
559 bool sign = true,
560 bool bip32derivs = true,
561 size_t* n_signed = nullptr) const;
562
572 void CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm);
573
575 bool SubmitTxMemoryPoolAndRelay(const CWalletTx& wtx, std::string& err_string, bool relay) const;
576
577 bool DummySignTx(CMutableTransaction &txNew, const std::set<CTxOut> &txouts, const CCoinControl* coin_control = nullptr) const
578 {
579 std::vector<CTxOut> v_txouts(txouts.size());
580 std::copy(txouts.begin(), txouts.end(), v_txouts.begin());
581 return DummySignTx(txNew, v_txouts, coin_control);
582 }
583 bool DummySignTx(CMutableTransaction &txNew, const std::vector<CTxOut> &txouts, const CCoinControl* coin_control = nullptr) const;
584
585 bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
586 bool ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
587 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);
588 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);
589
604
608
614
624 std::optional<OutputType> m_default_change_type{};
627
629 bool TopUpKeyPool(unsigned int kpSize = 0);
630
631 int64_t GetOldestKeyPoolTime() const;
632
633 std::set<CTxDestination> GetLabelAddresses(const std::string& label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
634
639 void MarkDestinationsDirty(const std::set<CTxDestination>& destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
640
641 bool GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, bilingual_str& error);
643
650 CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
654 bool IsFromMe(const CTransaction& tx) const;
655 CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
656 void chainStateFlushed(const CBlockLocator& loc) override;
657
659 DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
660
661 bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose);
662
663 bool DelAddressBook(const CTxDestination& address);
664
666 bool SetAddressUsed(WalletBatch& batch, const CTxDestination& dest, bool used) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
667
668 std::vector<std::string> GetAddressReceiveRequests() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
669 bool SetAddressReceiveRequest(WalletBatch& batch, const CTxDestination& dest, const std::string& id, const std::string& value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
670
672
674 void SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr) override;
675
677 int GetVersion() const { LOCK(cs_wallet); return nWalletVersion; }
678
680 std::set<uint256> GetConflicts(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
681
684
686 void Flush();
687
689 void Close();
690
692 boost::signals2::signal<void ()> NotifyUnload;
693
698 boost::signals2::signal<void(const CTxDestination& address,
699 const std::string& label, bool isMine,
700 const std::string& purpose, ChangeType status)>
702
707 boost::signals2::signal<void(const uint256& hashTx, ChangeType status)> NotifyTransactionChanged;
708
710 boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
711
713 boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
714
716 boost::signals2::signal<void ()> NotifyCanGetAddressesChanged;
717
722 boost::signals2::signal<void (CWallet* wallet)> NotifyStatusChanged;
723
727 void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
728
730 bool TransactionCanBeAbandoned(const uint256& hashTx) const;
731
732 /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
733 bool AbandonTransaction(const uint256& hashTx);
734
736 bool MarkReplaced(const uint256& originalHash, const uint256& newHash);
737
738 /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
739 static std::shared_ptr<CWallet> Create(WalletContext& context, const std::string& name, std::unique_ptr<WalletDatabase> database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector<bilingual_str>& warnings);
740
745 void postInitProcess();
746
747 bool BackupWallet(const std::string& strDest) const;
748
749 /* Returns true if HD is enabled */
750 bool IsHDEnabled() const;
751
752 /* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */
753 bool CanGetAddresses(bool internal = false) const;
754
761 void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main) EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet);
762
764 void SetWalletFlag(uint64_t flags);
765
767 void UnsetWalletFlag(uint64_t flag);
768
770 bool IsWalletFlagSet(uint64_t flag) const override;
771
774 bool AddWalletFlags(uint64_t flags);
776 bool LoadWalletFlags(uint64_t flags);
777
779 bool IsLegacy() const;
780
782 const std::string GetDisplayName() const override {
783 std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName();
784 return strprintf("[%s]", wallet_name);
785 };
786
788 template<typename... Params>
789 void WalletLogPrintf(std::string fmt, Params... parameters) const {
790 LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
791 };
792
794 bool UpgradeWallet(int version, bilingual_str& error);
795
797 std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;
798
800 std::set<ScriptPubKeyMan*> GetAllScriptPubKeyMans() const;
801
803 ScriptPubKeyMan* GetScriptPubKeyMan(const OutputType& type, bool internal) const;
804
806 ScriptPubKeyMan* GetScriptPubKeyMan(const CScript& script) const;
809
811 std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script, SignatureData& sigdata) const;
812
814 std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
815 std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;
816
820
823
824 const CKeyingMaterial& GetEncryptionKey() const override;
825 bool HasEncryptionKeys() const override;
826
829 {
831 assert(m_last_block_processed_height >= 0);
832 return m_last_block_processed_height;
833 };
835 {
837 assert(m_last_block_processed_height >= 0);
838 return m_last_block_processed;
839 }
842 {
844 m_last_block_processed_height = block_height;
845 m_last_block_processed = block_hash;
846 };
847
850
853
858 void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
859
864 void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
865
870 void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal);
871
874
877
879 ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
880};
881
887
890{
891private:
894public:
896
897 bool reserve()
898 {
900 if (m_wallet.fScanningWallet.exchange(true)) {
901 return false;
902 }
903 m_wallet.m_scanning_start = GetTimeMillis();
904 m_wallet.m_scanning_progress = 0;
905 m_could_reserve = true;
906 return true;
907 }
908
909 bool isReserved() const
910 {
911 return (m_could_reserve && m_wallet.fScanningWallet);
912 }
913
915 {
916 if (m_could_reserve) {
917 m_wallet.fScanningWallet = false;
918 }
919 }
920};
921
923bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
924
926bool RemoveWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
927
928bool DummySignInput(const SigningProvider& provider, CTxIn &tx_in, const CTxOut &txout, bool use_max_sig);
929
930#endif // BITCOIN_WALLET_WALLET_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition: amount.h:15
int flags
Definition: bitcoin-tx.cpp:525
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: validation.cpp:118
const CChainParams & Params()
Return the currently selected parameters.
Address book data.
Definition: wallet.h:197
StringMap destdata
Definition: wallet.h:207
std::map< std::string, std::string > StringMap
Definition: wallet.h:206
std::string m_label
Definition: wallet.h:200
const std::string & GetLabel() const
Definition: wallet.h:210
std::string purpose
Definition: wallet.h:202
bool IsChange() const
Definition: wallet.h:209
void SetLabel(const std::string &label)
Definition: wallet.h:211
Definition: block.h:63
Coin Control Features.
Definition: coincontrol.h:29
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:30
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:23
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:27
Definition: spend.h:17
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:406
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:260
An input of a transaction.
Definition: transaction.h:66
An output of a transaction.
Definition: transaction.h:129
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:229
std::unique_ptr< WalletDatabase > const m_database
Internal database handle.
Definition: wallet.h:308
bool SetAddressReceiveRequest(WalletBatch &batch, const CTxDestination &dest, const std::string &id, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2496
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
Get the SigningProvider for a script.
Definition: wallet.cpp:3073
std::atomic< int64_t > m_best_block_time
Definition: wallet.h:250
bool Lock()
Definition: wallet.cpp:2981
std::map< CTxDestination, CAddressBookData > m_address_book GUARDED_BY(cs_wallet)
int64_t nRelockTime GUARDED_BY(cs_wallet)
Holds a timestamp at which point the wallet is scheduled (externally) to be relocked....
Definition: wallet.h:479
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....
Definition: wallet.cpp:3043
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:357
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,...
bool HaveChain() const
Interface to assert chain access.
Definition: wallet.h:380
int nWalletVersion GUARDED_BY(cs_wallet)
the current wallet version: clients below this version are not able to load the wallet
Definition: wallet.h:242
double ScanningProgress() const
Definition: wallet.h:465
uint64_t nAccountingEntryNumber
Definition: wallet.h:390
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
Definition: wallet.cpp:3131
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Adds the active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3217
void SetupLegacyScriptPubKeyMan()
Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
Definition: wallet.cpp:3107
Mutex m_unlock_mutex
Definition: wallet.h:479
unsigned int ComputeTimeSmart(const CWalletTx &wtx, bool rescanning_old_block) const
Compute smart timestamp for a transaction being added to the wallet.
Definition: wallet.cpp:2402
const std::string GetDisplayName() const override
Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet ha...
Definition: wallet.h:782
MasterKeyMap mapMasterKeys
Definition: wallet.h:358
std::string m_name
Wallet name: relative directory name or "" for default wallet.
Definition: wallet.h:305
TxItems wtxOrdered
Definition: wallet.h:387
CFeeRate m_discard_rate
If the cost to spend a change output at this feerate is greater than the value of the output itself,...
Definition: wallet.h:607
std::map< OutputType, ScriptPubKeyMan * > m_external_spk_managers
Definition: wallet.h:326
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: wallet.h:722
void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Remove specified ScriptPubKeyMan from set of active SPK managers.
Definition: wallet.cpp:3246
RecursiveMutex cs_wallet
Main wallet lock.
Definition: wallet.h:345
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
Definition: wallet.cpp:2995
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:725
std::map< uint256, CWalletTx > mapWallet GUARDED_BY(cs_wallet)
Map from txid to CWalletTx for all transactions this wallet is interested in, including received and ...
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
Definition: wallet.h:789
bool IsAbortingRescan() const
Definition: wallet.h:462
interfaces::Chain & chain() const
Interface for accessing chain state.
Definition: wallet.h:405
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Create new DescriptorScriptPubKeyMans and add them to the wallet.
Definition: wallet.cpp:3150
std::atomic< int64_t > m_scanning_start
Definition: wallet.h:237
interfaces::Chain * m_chain
Interface for accessing chain state.
Definition: wallet.h:302
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
Definition: wallet.cpp:3101
boost::signals2::signal< void(const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:707
bool IsTxInMainChain(const CWalletTx &wtx) const
Definition: wallet.h:430
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:713
boost::signals2::signal< void(const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
Definition: wallet.h:701
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:603
bool IsLegacy() const
Determine if we are a legacy wallet.
Definition: wallet.cpp:3263
std::atomic< bool > fAbortRescan
Definition: wallet.h:235
std::map< uint256, std::unique_ptr< ScriptPubKeyMan > > m_spk_managers
Definition: wallet.h:331
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Loads an active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3226
std::unique_ptr< interfaces::Handler > m_chain_notifications_handler
Registered interfaces::Chain::Notifications handler.
Definition: wallet.h:402
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:727
int GetTxBlocksToMaturity(const CWalletTx &wtx) const
Definition: wallet.cpp:2952
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
Definition: wallet.h:828
OutputType m_default_address_type
Definition: wallet.h:617
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan(const WalletDescriptor &desc) const
Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.
Definition: wallet.cpp:3272
CWallet(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > database)
Construct wallet with specified name and database implementation.
Definition: wallet.h:362
bool IsTxImmatureCoinBase(const CWalletTx &wtx) const
Definition: wallet.cpp:2961
int64_t ScanningDuration() const
Definition: wallet.h:464
uint256 GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:834
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor &desc)
Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
Definition: wallet.cpp:3139
LegacyScriptPubKeyMan * GetLegacyScriptPubKeyMan() const
Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
Definition: wallet.cpp:3089
std::atomic< uint64_t > m_wallet_flags
WalletFlags set on this wallet.
Definition: wallet.h:291
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:710
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:355
CFeeRate m_pay_tx_fee
Definition: wallet.h:590
int64_t nNextResend
The next scheduled rebroadcast of wallet transactions.
Definition: wallet.h:245
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Definition: wallet.h:716
CFeeRate m_consolidate_feerate
When the actual feerate is less than the consolidate feerate, we will tend to make transactions which...
Definition: wallet.h:613
bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
check whether we support the named feature
Definition: wallet.h:441
bool BackupWallet(const std::string &strDest) const
Definition: wallet.cpp:2924
int64_t nOrderPosNext GUARDED_BY(cs_wallet)=0
static bool AttachChain(const std::shared_ptr< CWallet > &wallet, interfaces::Chain &chain, const 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_blo...
Definition: wallet.cpp:2782
CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet)
bool IsScanning() const
Definition: wallet.h:463
TxSpends mapTxSpends GUARDED_BY(cs_wallet)
ScriptPubKeyMan * 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.
Definition: wallet.cpp:3285
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 Cha...
std::set< ScriptPubKeyMan * > GetActiveScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers.
Definition: wallet.cpp:3010
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:473
bool m_signal_rbf
Definition: wallet.h:595
CFeeRate m_min_fee
Override with -mintxfee.
Definition: wallet.h:597
std::multimap< int64_t, CWalletTx * > TxItems
Definition: wallet.h:386
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition: wallet.h:692
bool IsLocked() const override
Definition: wallet.cpp:2972
bool m_allow_fallback_fee
will be false if -fallbackfee=0
Definition: wallet.h:596
WalletDatabase & GetDatabase() const override
Definition: wallet.h:347
std::vector< std::string > GetAddressReceiveRequests() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2482
std::atomic< double > m_scanning_progress
Definition: wallet.h:238
~CWallet()
Definition: wallet.h:369
bool SetAddressUsed(WalletBatch &batch, const CTxDestination &dest, bool used) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2446
int GetVersion() const
get the current wallet format (the oldest client version guaranteed to understand this wallet)
Definition: wallet.h:677
int GetTxDepthInMainChain(const CWalletTx &wtx) const NO_THREAD_SAFETY_ANALYSIS
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
Definition: wallet.cpp:2944
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2319
static std::shared_ptr< CWallet > Create(WalletContext &context, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:2534
bool HasEncryptionKeys() const override
Definition: wallet.cpp:3126
std::multimap< COutPoint, uint256 > TxSpends
Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated tran...
Definition: wallet.h:257
std::function< bool(CWalletTx &wtx, bool new_tx)> UpdateWalletTxFn
Callback for updating transaction metadata in mapWallet.
Definition: wallet.h:505
bool IsAddressUsed(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2467
CAmount m_default_max_tx_fee
Absolute maximum transaction fee (in satoshis) used by default for the wallet.
Definition: wallet.h:626
bool m_spend_zero_conf_change
Allow Coin Selection to pick unconfirmed UTXOs that were sent from our own wallet if it cannot fund t...
Definition: wallet.h:594
bool UpgradeWallet(int version, bilingual_str &error)
Upgrade the wallet.
Definition: wallet.cpp:2879
bool fBroadcastTransactions
Whether this wallet will submit newly created transactions to the node's mempool and prompt rebroadca...
Definition: wallet.h:248
ScriptPubKeyMan * GetScriptPubKeyMan(const OutputType &type, bool internal) const
Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
Definition: wallet.cpp:3033
bool IsCrypted() const
Definition: wallet.cpp:2967
std::atomic< bool > fScanningWallet
Definition: wallet.h:236
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans.
Definition: wallet.cpp:3024
void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Set last block processed height, currently only use in unit test.
Definition: wallet.h:841
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
Definition: wallet.h:327
CAmount m_max_aps_fee
The maximum fee amount we're willing to pay to prioritize partial spend avoidance.
Definition: wallet.h:616
std::optional< OutputType > m_default_change_type
Default output type for change outputs.
Definition: wallet.h:624
void AbortRescan()
Definition: wallet.h:461
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.
Definition: wallet.cpp:2462
unsigned int nMasterKeyMaxID
Definition: wallet.h:359
bool DummySignTx(CMutableTransaction &txNew, const std::set< CTxOut > &txouts, const CCoinControl *coin_control=nullptr) const
Definition: wallet.h:577
void postInitProcess()
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
Definition: wallet.cpp:2912
unsigned int m_confirm_target
Definition: wallet.h:591
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2869
const CKeyingMaterial & GetEncryptionKey() const override
Definition: wallet.cpp:3121
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:47
A UTXO entry.
Definition: coins.h:31
A wrapper to reserve an address from a wallet.
Definition: wallet.h:158
bool fInternal
Whether this is from the internal (change output) keypool.
Definition: wallet.h:170
ReserveDestination & operator=(const ReserveDestination &)=delete
OutputType const type
Definition: wallet.h:164
~ReserveDestination()
Destructor. If a key has been reserved and not KeepKey'ed, it will be returned to the keypool.
Definition: wallet.h:182
ScriptPubKeyMan * m_spk_man
The ScriptPubKeyMan to reserve from. Based on type when GetReservedDestination is called.
Definition: wallet.h:163
int64_t nIndex
The index of the address's key in the keypool.
Definition: wallet.h:166
CTxDestination address
The destination.
Definition: wallet.h:168
ReserveDestination(const ReserveDestination &)=delete
ReserveDestination(CWallet *pwallet, OutputType type)
Construct a ReserveDestination object. This does NOT reserve an address yet.
Definition: wallet.h:174
const CWallet *const pwallet
The wallet to reserve from.
Definition: wallet.h:161
An interface to be implemented by keystores that support signing.
Access to the wallet database.
Definition: walletdb.h:179
An instance of this class represents one database.
Definition: db.h:104
Descriptor with some wallet metadata.
Definition: walletutil.h:76
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:890
bool isReserved() const
Definition: wallet.h:909
CWallet & m_wallet
Definition: wallet.h:892
WalletRescanReserver(CWallet &w)
Definition: wallet.h:895
Chain notifications.
Definition: chain.h:237
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:93
256-bit opaque blob.
Definition: uint256.h:124
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
Definition: crypter.h:61
DatabaseStatus
Definition: db.h:212
TransactionError
Definition: error.h:22
FeeEstimateMode
Definition: feerate.h:18
DBErrors ZapSelectTx(std::vector< uint256 > &vHashIn, std::vector< uint256 > &vHashOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2015
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination &dest, bilingual_str &error)
Definition: wallet.cpp:2139
bool IsLockedCoin(uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2299
bool DisplayAddress(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Display address on an external signer.
Definition: wallet.cpp:2252
bool LockCoin(const COutPoint &output, WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2267
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 ...
Definition: wallet.cpp:2182
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2101
void KeepDestination()
Keep the address. Do not return it's key to the keypool when this object goes out of scope.
Definition: wallet.cpp:2234
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2307
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2118
std::set< CTxDestination > GetLabelAddresses(const std::string &label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2196
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
Definition: wallet.cpp:1906
bool GetReservedDestination(CTxDestination &pubkey, bool internal, bilingual_str &error)
Reserve an address.
Definition: wallet.cpp:2211
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:2066
DBErrors LoadWallet()
Definition: wallet.cpp:1992
OutputType TransactionChangeType(const std::optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend) const
Definition: wallet.cpp:1918
bool SignTransaction(CMutableTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Fetch the inputs and sign with SIGHASH_ALL.
Definition: wallet.cpp:1822
void ReturnDestination()
Return reserved address.
Definition: wallet.cpp:2243
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.
Definition: wallet.cpp:1855
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:2129
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.
Definition: wallet.cpp:1952
bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::string &strPurpose)
Definition: wallet.cpp:2046
int64_t GetOldestKeyPoolTime() const
Definition: wallet.cpp:2172
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:2072
bool GetNewChangeDestination(const OutputType type, CTxDestination &dest, bilingual_str &error)
Definition: wallet.cpp:2158
bool UnlockCoin(const COutPoint &output, WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2277
bool UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2287
void SyncTransaction(const CTransactionRef &tx, CWalletTx::Confirmation confirm, bool update_tx=true, bool rescanning_old_block=false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1202
bool AddWalletFlags(uint64_t flags)
overwrite all flags by the given uint64_t returns false if unknown, non-tolerable flags are present
Definition: wallet.cpp:1438
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)
Definition: wallet.cpp:1508
void blockConnected(const CBlock &block, int height) override
Definition: wallet.cpp:1260
void Flush()
Flush wallet (bitdb flush)
Definition: wallet.cpp:521
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
Definition: wallet.cpp:370
std::set< uint256 > GetTxConflicts(const CWalletTx &wtx) const NO_THREAD_SAFETY_ANALYSIS
Definition: wallet.cpp:1751
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.
Definition: wallet.cpp:514
bool MarkReplaced(const uint256 &originalHash, const uint256 &newHash)
Mark a transaction as replaced by another transaction (e.g., BIP 125).
Definition: wallet.cpp:802
void MarkDirty()
Definition: wallet.cpp:793
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1488
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:423
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...
Definition: wallet.cpp:1394
void SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr) override
signify that a particular wallet feature is now used.
Definition: wallet.cpp:475
const CWalletTx * GetWalletTx(const uint256 &hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:361
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
Definition: wallet.cpp:1353
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1498
CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const
Returns amount of debit if the input matches the filter, otherwise returns 0.
Definition: wallet.cpp:1306
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, CWalletTx::Confirmation confirm, bool fUpdate, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Add a transaction to the wallet, or update it.
Definition: wallet.cpp:1035
ScanResult ScanForWalletTransactions(const uint256 &start_block, int start_height, std::optional< int > max_height, const WalletRescanReserver &reserver, bool fUpdate)
Scan the block chain (starting in start_block) for transactions from or to us.
Definition: wallet.cpp:1592
bool DummySignInput(const SigningProvider &provider, CTxIn &tx_in, const CTxOut &txout, bool use_max_sig)
Definition: wallet.cpp:1452
isminetype IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1328
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
Definition: wallet.cpp:1426
bool IsSpent(const uint256 &hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction spends it:
Definition: wallet.cpp:574
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)
Definition: wallet.cpp:1518
bool CanGetAddresses(bool internal=false) const
Definition: wallet.cpp:1381
void MarkInputsDirty(const CTransactionRef &tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Mark a transaction's inputs dirty, thus forcing the outputs to be recomputed.
Definition: wallet.cpp:1086
bool AbandonTransaction(const uint256 &hashTx)
Definition: wallet.cpp:1096
void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1695
bool IsHDEnabled() const
Definition: wallet.cpp:1370
void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag)
Unsets a wallet flag and saves it to disk.
Definition: wallet.cpp:1408
void UpgradeDescriptorCache() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade DescriptorCaches.
Definition: wallet.cpp:385
CWalletTx * AddToWallet(CTransactionRef tx, const CWalletTx::Confirmation &confirm, const UpdateWalletTxFn &update_wtx=nullptr, bool fFlushOnClose=true, bool rescanning_old_block=false)
Definition: wallet.cpp:888
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:531
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:622
void SetSpentKeyState(WalletBatch &batch, const uint256 &hash, unsigned int n, bool used, std::set< CTxDestination > &tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:834
void updatedBlockTip() override
Definition: wallet.cpp:1288
bool SubmitTxMemoryPoolAndRelay(const CWalletTx &wtx, std::string &err_string, bool relay) const
Pass this transaction to node for mempool insertion and relay to peers if flag set to true.
Definition: wallet.cpp:1723
void UnsetWalletFlag(uint64_t flag)
Unsets a single wallet flag.
Definition: wallet.cpp:1402
bool LoadToWallet(const uint256 &hash, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:991
void transactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
Definition: wallet.cpp:1223
bool TransactionCanBeAbandoned(const uint256 &hashTx) const
Return whether transaction can be abandoned.
Definition: wallet.cpp:1079
bool IsWalletFlagSet(uint64_t flag) const override
check if a certain wallet flag is set
Definition: wallet.cpp:1421
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
Definition: wallet.cpp:1549
void UnsetBlankWalletFlag(WalletBatch &batch) override
Unset the blank wallet flag and saves it to disk.
Definition: wallet.cpp:1416
void transactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence) override
Definition: wallet.cpp:1213
void AddToSpends(const COutPoint &outpoint, const uint256 &wtxid, WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:593
DBErrors ReorderTransactions()
Definition: wallet.cpp:724
bool IsSpentKey(const uint256 &hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:853
void blockDisconnected(const CBlock &block, int height) override
Definition: wallet.cpp:1273
std::set< uint256 > GetConflicts(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get wallet transactions that conflict with given transaction (spend same outputs)
Definition: wallet.cpp:491
void Close()
Close wallet database.
Definition: wallet.cpp:526
int64_t IncOrderPosNext(WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Increment the next transaction order id.
Definition: wallet.cpp:781
void MarkConflicted(const uint256 &hashBlock, int conflicting_height, const uint256 &hashTx)
Mark a transaction (and its in-wallet descendants) as conflicting with a particular block.
Definition: wallet.cpp:1150
void ResendWalletTransactions()
Definition: wallet.cpp:1771
void chainStateFlushed(const CBlockLocator &loc) override
Definition: wallet.cpp:469
uint8_t isminefilter
Definition: wallet.h:36
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
Definition: ismine.h:39
#define LogPrintf(...)
Definition: logging.h:187
SigningResult
Definition: message.h:42
static unsigned const char sighash[]
Definition: sighash.json.h:2
OutputType
Definition: outputtype.h:18
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:386
const char * name
Definition: rest.cpp:43
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:59
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:157
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:115
A mutable version of CTransaction.
Definition: transaction.h:345
CScript scriptPubKey
Definition: wallet.h:219
CAmount nAmount
Definition: wallet.h:220
bool fSubtractFeeFromAmount
Definition: wallet.h:221
std::optional< int > last_scanned_height
Definition: wallet.h:522
uint256 last_failed_block
Height of the most recent block that could not be scanned due to read errors or pruning.
Definition: wallet.h:528
uint256 last_scanned_block
Hash and height of most recent block that was successfully scanned.
Definition: wallet.h:521
A version of CTransaction with the PSBT format.
Definition: psbt.h:392
WalletContext struct containing references to state shared between CWallet instances,...
Definition: context.h:34
Bilingual messages:
Definition: translation.h:16
#define LOCK(cs)
Definition: sync.h:226
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48
#define NO_THREAD_SAFETY_ANALYSIS
Definition: threadsafety.h:51
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:117
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
Definition: txmempool.h:341
ChangeType
General change type (added, updated, removed).
Definition: ui_change_type.h:9
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Definition: context.h:22
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:502
std::map< std::string, std::string > mapValue_t
Definition: transaction.h:20
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:97
constexpr CAmount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
Definition: wallet.h:103
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
Definition: wallet.cpp:158
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:116
static constexpr uint64_t MUTABLE_WALLET_FLAGS
Definition: wallet.h:127
static const unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
Definition: wallet.h:93
const std::map< uint64_t, std::string > WALLET_FLAG_CAVEATS
Definition: wallet.cpp:51
constexpr CAmount HIGH_APS_FEE
discourage APS fee higher than this amount
Definition: wallet.h:85
static const CAmount WALLET_INCREMENTAL_RELAY_FEE
minimum recommended increment for BIP 125 replacement txs
Definition: wallet.h:87
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:117
constexpr CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:99
constexpr CAmount HIGH_TX_FEE_PER_KB
Discourage users to set fees higher than this amount (in satoshis) per kB.
Definition: wallet.h:101
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Definition: wallet.cpp:2510
static const std::map< std::string, WalletFlags > WALLET_FLAG_MAP
Definition: wallet.h:130
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
Definition: wallet.cpp:189
static const CAmount DEFAULT_CONSOLIDATE_FEERATE
-consolidatefeerate default
Definition: wallet.h:75
void MaybeResendWalletTxs(WalletContext &context)
Called periodically by the schedule thread.
Definition: wallet.cpp:1809
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:105
static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE
Pre-calculated constants for input size estimation in virtual size
Definition: wallet.h:105
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:89
static const CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled...
Definition: wallet.h:83
static constexpr uint64_t KNOWN_WALLET_FLAGS
Definition: wallet.h:118
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Definition: wallet.cpp:143
bool AddWalletSetting(interfaces::Chain &chain, const std::string &wallet_name)
Add wallet name to persistent configuration so it will be loaded on startup.
Definition: wallet.cpp:59
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: wallet.cpp:70
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:96
std::shared_ptr< CWallet > GetWallet(WalletContext &context, const std::string &name)
Definition: wallet.cpp:149
static const CAmount DEFAULT_DISCARD_FEE
-discardfee default
Definition: wallet.h:71
std::shared_ptr< CWallet > CreateWallet(WalletContext &context, const std::string &name, std::optional< bool > load_on_start, DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:258
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Definition: wallet.h:91
std::shared_ptr< CWallet > LoadWallet(WalletContext &context, const std::string &name, std::optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:245
static const CAmount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:69
static const bool DEFAULT_WALLET_RBF
-walletrbf default
Definition: wallet.h:95
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:67
static const CAmount DEFAULT_TRANSACTION_MINFEE
-mintxfee default
Definition: wallet.h:73
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:44
bool IsFeatureSupported(int wallet_version, int feature_version)
Definition: walletutil.cpp:32
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
Definition: walletutil.h:68
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:50
@ WALLET_FLAG_AVOID_REUSE
Definition: walletutil.h:41
@ WALLET_FLAG_KEY_ORIGIN_METADATA
Definition: walletutil.h:44
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:65
@ WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
Definition: walletutil.h:47
@ WALLET_FLAG_BLANK_WALLET
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
Definition: walletutil.h:62
WalletFeature
(client) version numbers for particular wallet features
Definition: walletutil.h:15
@ FEATURE_BASE
Definition: walletutil.h:16