Bitcoin Core  25.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-2022 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 <interfaces/wallet.h>
13 #include <logging.h>
14 #include <outputtype.h>
15 #include <policy/feerate.h>
16 #include <psbt.h>
17 #include <tinyformat.h>
18 #include <util/fs.h>
19 #include <util/hasher.h>
20 #include <util/message.h>
21 #include <util/result.h>
22 #include <util/strencodings.h>
23 #include <util/string.h>
24 #include <util/time.h>
25 #include <util/ui_change_type.h>
26 #include <validationinterface.h>
27 #include <wallet/crypter.h>
28 #include <wallet/scriptpubkeyman.h>
29 #include <wallet/transaction.h>
30 #include <wallet/walletdb.h>
31 #include <wallet/walletutil.h>
32 
33 #include <algorithm>
34 #include <atomic>
35 #include <map>
36 #include <memory>
37 #include <optional>
38 #include <set>
39 #include <stdexcept>
40 #include <stdint.h>
41 #include <string>
42 #include <utility>
43 #include <unordered_map>
44 #include <vector>
45 
46 #include <boost/signals2/signal.hpp>
47 
48 
49 using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
50 
51 class CScript;
52 enum class FeeEstimateMode;
53 struct bilingual_str;
54 
55 namespace wallet {
56 struct WalletContext;
57 
63 void UnloadWallet(std::shared_ptr<CWallet>&& wallet);
64 
65 bool AddWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
66 bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start, std::vector<bilingual_str>& warnings);
67 bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start);
68 std::vector<std::shared_ptr<CWallet>> GetWallets(WalletContext& context);
69 std::shared_ptr<CWallet> GetDefaultWallet(WalletContext& context, size_t& count);
70 std::shared_ptr<CWallet> GetWallet(WalletContext& context, const std::string& name);
71 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);
72 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);
73 std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings);
74 std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext& context, LoadWalletFn load_wallet);
75 void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
76 std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
77 
81 static const CAmount DEFAULT_FALLBACK_FEE = 0;
83 static const CAmount DEFAULT_DISCARD_FEE = 10000;
85 static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
87 static const CAmount DEFAULT_CONSOLIDATE_FEERATE{10000}; // 10 sat/vbyte
97 constexpr CAmount HIGH_APS_FEE{COIN / 10000};
101 static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
103 static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS{true};
105 static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
107 static const bool DEFAULT_WALLET_RBF = true;
108 static const bool DEFAULT_WALLETBROADCAST = true;
109 static const bool DEFAULT_DISABLE_WALLET = false;
110 static const bool DEFAULT_WALLETCROSSCHAIN = false;
114 constexpr CAmount HIGH_TX_FEE_PER_KB{COIN / 100};
118 static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE = 91;
119 
120 class CCoinControl;
121 class CWalletTx;
122 class ReserveDestination;
123 
126 
127 static constexpr uint64_t KNOWN_WALLET_FLAGS =
135 
136 static constexpr uint64_t MUTABLE_WALLET_FLAGS =
138 
139 static const std::map<std::string,WalletFlags> WALLET_FLAG_MAP{
140  {"avoid_reuse", WALLET_FLAG_AVOID_REUSE},
141  {"blank", WALLET_FLAG_BLANK_WALLET},
142  {"key_origin_metadata", WALLET_FLAG_KEY_ORIGIN_METADATA},
143  {"last_hardened_xpub_cached", WALLET_FLAG_LAST_HARDENED_XPUB_CACHED},
144  {"disable_private_keys", WALLET_FLAG_DISABLE_PRIVATE_KEYS},
145  {"descriptor_wallet", WALLET_FLAG_DESCRIPTORS},
146  {"external_signer", WALLET_FLAG_EXTERNAL_SIGNER}
147 };
148 
165 {
166 protected:
168  const CWallet* const pwallet;
173  int64_t nIndex{-1};
177  bool fInternal{false};
178 
179 public:
182  : pwallet(pwallet)
183  , type(type) { }
184 
187 
190  {
192  }
193 
197  void ReturnDestination();
199  void KeepDestination();
200 };
201 
206 {
214  std::optional<std::string> label;
215 
221  std::optional<AddressPurpose> purpose;
222 
230  bool previously_spent{false};
231 
239  std::map<std::string, std::string> receive_requests{};
240 
242  bool IsChange() const { return !label.has_value(); }
243  std::string GetLabel() const { return label ? *label : std::string{}; }
244  void SetLabel(std::string name) { label = std::move(name); }
245 };
246 
247 inline std::string PurposeToString(AddressPurpose p)
248 {
249  switch(p) {
250  case AddressPurpose::RECEIVE: return "receive";
251  case AddressPurpose::SEND: return "send";
252  case AddressPurpose::REFUND: return "refund";
253  } // no default case so the compiler will warn when a new enum as added
254  assert(false);
255 }
256 
257 inline std::optional<AddressPurpose> PurposeFromString(std::string_view s)
258 {
259  if (s == "receive") return AddressPurpose::RECEIVE;
260  else if (s == "send") return AddressPurpose::SEND;
261  else if (s == "refund") return AddressPurpose::REFUND;
262  return {};
263 }
264 
266 {
270 };
271 
272 class WalletRescanReserver; //forward declarations for ScanForWalletTransactions/RescanFromTime
277 {
278 private:
280 
281  bool Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys = false);
282 
283  std::atomic<bool> fAbortRescan{false};
284  std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
285  std::atomic<bool> m_attaching_chain{false};
286  std::atomic<bool> m_scanning_with_passphrase{false};
287  std::atomic<SteadyClock::time_point> m_scanning_start{SteadyClock::time_point{}};
288  std::atomic<double> m_scanning_progress{0};
289  friend class WalletRescanReserver;
290 
292  int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE};
293 
299  // Local time that the tip block was received. Used to schedule wallet rebroadcasts.
300  std::atomic<int64_t> m_best_block_time {0};
301 
302  // First created key time. Used to skip blocks prior to this time.
303  // 'std::numeric_limits<int64_t>::max()' if wallet is blank.
304  std::atomic<int64_t> m_birth_time{std::numeric_limits<int64_t>::max()};
305 
311  typedef std::unordered_multimap<COutPoint, uint256, SaltedOutpointHasher> TxSpends;
313  void AddToSpends(const COutPoint& outpoint, const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
314  void AddToSpends(const CWalletTx& wtx, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
315 
332  bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const SyncTxState& state, bool fUpdate, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
333 
335  void MarkConflicted(const uint256& hashBlock, int conflicting_height, const uint256& hashTx);
336 
337  enum class TxUpdate { UNCHANGED, CHANGED, NOTIFY_CHANGED };
338 
339  using TryUpdatingStateFn = std::function<TxUpdate(CWalletTx& wtx)>;
340 
342  void RecursiveUpdateTxState(const uint256& tx_hash, const TryUpdatingStateFn& try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
343 
346 
347  void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
348 
349  void SyncTransaction(const CTransactionRef& tx, const SyncTxState& state, bool update_tx = true, bool rescanning_old_block = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
350 
352  std::atomic<uint64_t> m_wallet_flags{0};
353 
354  bool SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::optional<AddressPurpose>& strPurpose);
355 
357  void UnsetWalletFlagWithDB(WalletBatch& batch, uint64_t flag);
358 
360  void UnsetBlankWalletFlag(WalletBatch& batch) override;
361 
364 
366  std::string m_name;
367 
369  std::unique_ptr<WalletDatabase> m_database;
370 
378  uint256 m_last_block_processed GUARDED_BY(cs_wallet);
379 
385  int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
386 
387  std::map<OutputType, ScriptPubKeyMan*> m_external_spk_managers;
388  std::map<OutputType, ScriptPubKeyMan*> m_internal_spk_managers;
389 
390  // Indexed by a unique identifier produced by each ScriptPubKeyMan using
391  // ScriptPubKeyMan::GetID. In many cases it will be the hash of an internal structure
392  std::map<uint256, std::unique_ptr<ScriptPubKeyMan>> m_spk_managers;
393 
394  // Appends spk managers into the main 'm_spk_managers'.
395  // Must be the only method adding data to it.
396  void AddScriptPubKeyMan(const uint256& id, std::unique_ptr<ScriptPubKeyMan> spkm_man);
397 
403  static bool AttachChain(const std::shared_ptr<CWallet>& wallet, interfaces::Chain& chain, const bool rescan_required, bilingual_str& error, std::vector<bilingual_str>& warnings);
404 
406 
407 public:
413 
414  WalletDatabase& GetDatabase() const override
415  {
416  assert(static_cast<bool>(m_database));
417  return *m_database;
418  }
419 
422  const std::string& GetName() const { return m_name; }
423 
424  typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
426  unsigned int nMasterKeyMaxID = 0;
427 
429  CWallet(interfaces::Chain* chain, const std::string& name, std::unique_ptr<WalletDatabase> database)
430  : m_chain(chain),
431  m_name(name),
432  m_database(std::move(database))
433  {
434  }
435 
437  {
438  // Should not have slots connected at this point.
439  assert(NotifyUnload.empty());
440  }
441 
442  bool IsCrypted() const;
443  bool IsLocked() const override;
444  bool Lock();
445 
447  bool HaveChain() const { return m_chain ? true : false; }
448 
451  std::unordered_map<uint256, CWalletTx, SaltedTxidHasher> mapWallet GUARDED_BY(cs_wallet);
452 
453  typedef std::multimap<int64_t, CWalletTx*> TxItems;
455 
456  int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
457 
458  std::map<CTxDestination, CAddressBookData> m_address_book GUARDED_BY(cs_wallet);
459  const CAddressBookData* FindAddressBookEntry(const CTxDestination&, bool allow_change = false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
460 
465  std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
466 
469 
471  interfaces::Chain& chain() const { assert(m_chain); return *m_chain; }
472 
474 
475  std::set<uint256> GetTxConflicts(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
476 
485  {
487  return GetTxDepthInMainChain(wtx) > 0;
488  }
489 
497 
499  bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); return IsFeatureSupported(nWalletVersion, wf); }
500 
501  bool IsSpent(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
502 
503  // Whether this or any known scriptPubKey with the same single key has been spent.
504  bool IsSpentKey(const CScript& scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
505  void SetSpentKeyState(WalletBatch& batch, const uint256& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
506 
509 
510  bool IsLockedCoin(const COutPoint& output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
511  bool LockCoin(const COutPoint& output, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
512  bool UnlockCoin(const COutPoint& output, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
514  void ListLockedCoins(std::vector<COutPoint>& vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
515 
516  /*
517  * Rescan abort properties
518  */
519  void AbortRescan() { fAbortRescan = true; }
520  bool IsAbortingRescan() const { return fAbortRescan; }
521  bool IsScanning() const { return fScanningWallet; }
523  SteadyClock::duration ScanningDuration() const { return fScanningWallet ? SteadyClock::now() - m_scanning_start.load() : SteadyClock::duration{}; }
524  double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; }
525 
528 
531 
532  bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; return true; }
533 
537  void LoadAddressReceiveRequest(const CTxDestination& dest, const std::string& id, const std::string& request) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
538 
540  int64_t nRelockTime GUARDED_BY(cs_wallet){0};
541 
542  // Used to prevent concurrent calls to walletpassphrase RPC.
544  // Used to prevent deleting the passphrase from memory when it is still in use.
546 
547  bool Unlock(const SecureString& strWalletPassphrase, bool accept_no_keys = false);
548  bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
549  bool EncryptWallet(const SecureString& strWalletPassphrase);
550 
551  void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
552  unsigned int ComputeTimeSmart(const CWalletTx& wtx, bool rescanning_old_block) const;
553 
560 
561  void MarkDirty();
562 
569  using UpdateWalletTxFn = std::function<bool(CWalletTx& wtx, bool new_tx)>;
570 
575  CWalletTx* AddToWallet(CTransactionRef tx, const TxState& state, const UpdateWalletTxFn& update_wtx=nullptr, bool fFlushOnClose=true, bool rescanning_old_block = false);
576  bool LoadToWallet(const uint256& hash, const UpdateWalletTxFn& fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
577  void transactionAddedToMempool(const CTransactionRef& tx) override;
578  void blockConnected(const interfaces::BlockInfo& block) override;
579  void blockDisconnected(const interfaces::BlockInfo& block) override;
580  void updatedBlockTip() override;
581  int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver, bool update);
582 
583  struct ScanResult {
584  enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS;
585 
590  std::optional<int> last_scanned_height;
591 
597  };
598  ScanResult ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate, const bool save_progress);
599  void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) override;
603  bool ShouldResend() const;
604  void ResubmitWalletTransactions(bool relay, bool force);
605 
606  OutputType TransactionChangeType(const std::optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend) const;
607 
611  bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const;
612  SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const;
613 
630  bool& complete,
631  int sighash_type = SIGHASH_DEFAULT,
632  bool sign = true,
633  bool bip32derivs = true,
634  size_t* n_signed = nullptr,
635  bool finalize = true) const;
636 
646  void CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm);
647 
649  bool SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string, bool relay) const
651 
652  bool DummySignTx(CMutableTransaction &txNew, const std::vector<CTxOut> &txouts, const CCoinControl* coin_control = nullptr) const;
653 
654  bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
655  bool ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
656  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);
657  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);
658 
660  void FirstKeyTimeChanged(const ScriptPubKeyMan* spkm, int64_t new_birth_time);
661 
668  bool m_allow_fallback_fee{true};
676 
680 
686 
696  std::optional<OutputType> m_default_change_type{};
699 
702 
705 
707  bool TopUpKeyPool(unsigned int kpSize = 0);
708 
709  std::optional<int64_t> GetOldestKeyPoolTime() const;
710 
711  // Filter struct for 'ListAddrBookAddresses'
712  struct AddrBookFilter {
713  // Fetch addresses with the provided label
714  std::optional<std::string> m_op_label{std::nullopt};
715  // Don't include change addresses by default
716  bool ignore_change{true};
717  };
718 
722  std::vector<CTxDestination> ListAddrBookAddresses(const std::optional<AddrBookFilter>& filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
723 
727  std::set<std::string> ListAddrBookLabels(const std::optional<AddressPurpose> purpose) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
728 
733  using ListAddrBookFunc = std::function<void(const CTxDestination& dest, const std::string& label, bool is_change, const std::optional<AddressPurpose> purpose)>;
735 
740  void MarkDestinationsDirty(const std::set<CTxDestination>& destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
741 
742  util::Result<CTxDestination> GetNewDestination(const OutputType type, const std::string label);
744 
751  CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
753  bool IsMine(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
756  bool IsFromMe(const CTransaction& tx) const;
757  CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
758  void chainStateFlushed(const CBlockLocator& loc) override;
759 
761  DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
762 
763  bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::optional<AddressPurpose>& purpose);
764 
765  bool DelAddressBook(const CTxDestination& address);
766 
769 
770  std::vector<std::string> GetAddressReceiveRequests() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
771  bool SetAddressReceiveRequest(WalletBatch& batch, const CTxDestination& dest, const std::string& id, const std::string& value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
772  bool EraseAddressReceiveRequest(WalletBatch& batch, const CTxDestination& dest, const std::string& id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
773 
774  unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
775 
777  void SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr) override;
778 
780  int GetVersion() const { LOCK(cs_wallet); return nWalletVersion; }
781 
783  std::set<uint256> GetConflicts(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
784 
787 
789  void Flush();
790 
792  void Close();
793 
795  boost::signals2::signal<void ()> NotifyUnload;
796 
801  boost::signals2::signal<void(const CTxDestination& address,
802  const std::string& label, bool isMine,
803  AddressPurpose purpose, ChangeType status)>
805 
810  boost::signals2::signal<void(const uint256& hashTx, ChangeType status)> NotifyTransactionChanged;
811 
813  boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
814 
816  boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
817 
819  boost::signals2::signal<void ()> NotifyCanGetAddressesChanged;
820 
825  boost::signals2::signal<void (CWallet* wallet)> NotifyStatusChanged;
826 
830  void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
831 
833  bool TransactionCanBeAbandoned(const uint256& hashTx) const;
834 
835  /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
836  bool AbandonTransaction(const uint256& hashTx);
837 
839  bool MarkReplaced(const uint256& originalHash, const uint256& newHash);
840 
841  /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
842  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);
843 
848  void postInitProcess();
849 
850  bool BackupWallet(const std::string& strDest) const;
851 
852  /* Returns true if HD is enabled */
853  bool IsHDEnabled() const;
854 
855  /* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */
856  bool CanGetAddresses(bool internal = false) const;
857 
864  void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main) EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet);
865 
867  void SetWalletFlag(uint64_t flags);
868 
870  void UnsetWalletFlag(uint64_t flag);
871 
873  bool IsWalletFlagSet(uint64_t flag) const override;
874 
878  void InitWalletFlags(uint64_t flags);
880  bool LoadWalletFlags(uint64_t flags);
881 
883  bool IsLegacy() const;
884 
886  std::string GetDisplayName() const override
887  {
888  std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName();
889  return strprintf("[%s]", wallet_name);
890  };
891 
893  template<typename... Params>
894  void WalletLogPrintf(std::string fmt, Params... parameters) const {
895  LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
896  };
897 
899  bool UpgradeWallet(int version, bilingual_str& error);
900 
902  std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;
903 
905  std::set<ScriptPubKeyMan*> GetAllScriptPubKeyMans() const;
906 
908  ScriptPubKeyMan* GetScriptPubKeyMan(const OutputType& type, bool internal) const;
909 
911  std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script) const;
913  ScriptPubKeyMan* GetScriptPubKeyMan(const uint256& id) const;
914 
916  std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
917  std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;
918 
920  std::vector<WalletDescriptor> GetWalletDescriptors(const CScript& script) const;
921 
925 
928 
929  const CKeyingMaterial& GetEncryptionKey() const override;
930  bool HasEncryptionKeys() const override;
931 
934  {
936  assert(m_last_block_processed_height >= 0);
937  return m_last_block_processed_height;
938  };
940  {
942  assert(m_last_block_processed_height >= 0);
943  return m_last_block_processed;
944  }
947  {
949  m_last_block_processed_height = block_height;
950  m_last_block_processed = block_hash;
951  };
952 
955 
958 
963  void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
964 
969  void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
970 
975  void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal);
976 
980 
983 
987  std::optional<bool> IsInternalScriptPubKeyMan(ScriptPubKeyMan* spk_man) const;
988 
990  ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
991 
998 
1001 
1005 
1007  bool CanGrindR() const;
1008 };
1009 
1015 
1018 {
1019 private:
1020  using Clock = std::chrono::steady_clock;
1021  using NowFn = std::function<Clock::time_point()>;
1023  bool m_could_reserve{false};
1025 public:
1027 
1028  bool reserve(bool with_passphrase = false)
1029  {
1030  assert(!m_could_reserve);
1031  if (m_wallet.fScanningWallet.exchange(true)) {
1032  return false;
1033  }
1034  m_wallet.m_scanning_with_passphrase.exchange(with_passphrase);
1035  m_wallet.m_scanning_start = SteadyClock::now();
1036  m_wallet.m_scanning_progress = 0;
1037  m_could_reserve = true;
1038  return true;
1039  }
1040 
1041  bool isReserved() const
1042  {
1043  return (m_could_reserve && m_wallet.fScanningWallet);
1044  }
1045 
1046  Clock::time_point now() const { return m_now ? m_now() : Clock::now(); };
1047 
1048  void setNow(NowFn now) { m_now = std::move(now); }
1049 
1051  {
1052  if (m_could_reserve) {
1053  m_wallet.fScanningWallet = false;
1054  m_wallet.m_scanning_with_passphrase = false;
1055  }
1056  }
1057 };
1058 
1060 bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
1061 
1063 bool RemoveWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
1064 
1065 bool DummySignInput(const SigningProvider& provider, CTxIn &tx_in, const CTxOut &txout, bool can_grind_r, const CCoinControl* coin_control);
1066 
1067 bool FillInputToWeight(CTxIn& txin, int64_t target_weight);
1068 
1070  std::string wallet_name;
1071  std::shared_ptr<CWallet> watchonly_wallet;
1072  std::shared_ptr<CWallet> solvables_wallet;
1074 };
1075 
1077 [[nodiscard]] util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& wallet_name, const SecureString& passphrase, WalletContext& context);
1078 } // namespace wallet
1079 
1080 #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:528
const CChainParams & Params()
Return the currently selected parameters.
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:33
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:24
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:36
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:411
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:295
An input of a transaction.
Definition: transaction.h:75
An output of a transaction.
Definition: transaction.h:158
An interface to be implemented by keystores that support signing.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:31
Chain notifications.
Definition: chain.h:271
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:122
256-bit opaque blob.
Definition: uint256.h:105
Coin Control Features.
Definition: coincontrol.h:30
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:277
std::atomic< bool > fAbortRescan
Definition: wallet.h:283
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:422
bool HaveChain() const
Interface to assert chain access.
Definition: wallet.h:447
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:828
bool m_signal_rbf
Definition: wallet.h:667
bool IsCrypted() const
Definition: wallet.cpp:3398
std::atomic< SteadyClock::time_point > m_scanning_start
Definition: wallet.h:287
std::function< bool(CWalletTx &wtx, bool new_tx)> UpdateWalletTxFn
Callback for updating transaction metadata in mapWallet.
Definition: wallet.h:569
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition: wallet.h:795
CAmount m_default_max_tx_fee
Absolute maximum transaction fee (in satoshis) used by default for the wallet.
Definition: wallet.h:698
OutputType m_default_address_type
Definition: wallet.h:689
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...
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:679
LegacyScriptPubKeyMan * GetLegacyScriptPubKeyMan() const
Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
Definition: wallet.cpp:3525
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Adds the active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3668
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Loads an active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3677
std::unique_ptr< WalletDatabase > m_database
Internal database handle.
Definition: wallet.h:369
CWallet(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > database)
Construct wallet with specified name and database implementation.
Definition: wallet.h:429
std::function< void(const CTxDestination &dest, const std::string &label, bool is_change, const std::optional< AddressPurpose > purpose)> ListAddrBookFunc
Walk-through the address book entries.
Definition: wallet.h:733
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
Get the SigningProvider for a script.
Definition: wallet.cpp:3497
bool IsTxImmatureCoinBase(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3390
const CKeyingMaterial & GetEncryptionKey() const override
Definition: wallet.cpp:3566
std::set< ScriptPubKeyMan * > GetActiveScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers.
Definition: wallet.cpp:3444
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3293
CFeeRate m_pay_tx_fee
Definition: wallet.h:662
void postInitProcess()
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
Definition: wallet.cpp:3336
int GetTxDepthInMainChain(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
Definition: wallet.cpp:3366
unsigned int nMasterKeyMaxID
Definition: wallet.h:426
bool IsScanning() const
Definition: wallet.h:521
std::map< CTxDestination, CAddressBookData > m_address_book GUARDED_BY(cs_wallet)
bool SetAddressReceiveRequest(WalletBatch &batch, const CTxDestination &dest, const std::string &id, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2870
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
Definition: wallet.h:933
std::atomic< double > m_scanning_progress
Definition: wallet.h:288
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:816
CAmount m_max_aps_fee
The maximum fee amount we're willing to pay to prioritize partial spend avoidance.
Definition: wallet.h:688
WalletDatabase & GetDatabase() const override
Definition: wallet.h:414
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan(const WalletDescriptor &desc) const
Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.
Definition: wallet.cpp:3723
std::map< OutputType, ScriptPubKeyMan * > m_external_spk_managers
Definition: wallet.h:387
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor &desc)
Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
Definition: wallet.cpp:3585
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 IsLegacy() const
Determine if we are a legacy wallet.
Definition: wallet.cpp:3714
CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet)
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:830
std::optional< MigrationData > GetDescriptorsForLegacy(bilingual_str &error) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get all of the descriptors from a legacy wallet.
Definition: wallet.cpp:3890
std::optional< OutputType > m_default_change_type
Default output type for change outputs.
Definition: wallet.h:696
int64_t nOrderPosNext GUARDED_BY(cs_wallet)=0
bool MigrateToSQLite(bilingual_str &error) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Move all records from the BDB database to a new SQLite database for storage.
Definition: wallet.cpp:3819
bool BackupWallet(const std::string &strDest) const
Definition: wallet.cpp:3346
std::unique_ptr< interfaces::Handler > m_chain_notifications_handler
Registered interfaces::Chain::Notifications handler.
Definition: wallet.h:468
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
Definition: wallet.h:388
std::string m_name
Wallet name: relative directory name or "" for default wallet.
Definition: wallet.h:366
bool SetAddressPreviouslySpent(WalletBatch &batch, const CTxDestination &dest, bool used) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2829
double ScanningProgress() const
Definition: wallet.h:524
SteadyClock::duration ScanningDuration() const
Definition: wallet.h:523
RecursiveMutex m_relock_mutex
Definition: wallet.h:545
std::string m_notify_tx_changed_script
Notify external script when a wallet transaction comes in or is updated (handled by -walletnotify)
Definition: wallet.h:704
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:886
std::vector< std::string > GetAddressReceiveRequests() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2859
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:532
std::vector< WalletDescriptor > GetWalletDescriptors(const CScript &script) const
Get the wallet descriptors for a script.
Definition: wallet.cpp:3513
std::atomic< bool > m_attaching_chain
Definition: wallet.h:285
bool fBroadcastTransactions
Whether this wallet will submit newly created transactions to the node's mempool and prompt rebroadca...
Definition: wallet.h:298
int GetTxBlocksToMaturity(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3378
bool HasEncryptionKeys() const override
Definition: wallet.cpp:3571
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:2908
int GetVersion() const
get the current wallet format (the oldest client version guaranteed to understand this wallet)
Definition: wallet.h:780
bool CanGrindR() const
Whether the (external) signer performs R-value signature grinding.
Definition: wallet.cpp:4084
std::optional< bool > IsInternalScriptPubKeyMan(ScriptPubKeyMan *spk_man) const
Returns whether the provided ScriptPubKeyMan is internal.
Definition: wallet.cpp:3736
void SetNextResend()
Set the next time this wallet should resend transactions to 12-36 hours from now, ~1 day on average.
Definition: wallet.h:601
TxItems wtxOrdered
Definition: wallet.h:454
std::atomic< bool > m_scanning_with_passphrase
Definition: wallet.h:286
bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
check whether we support the named feature
Definition: wallet.h:499
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:666
MasterKeyMap mapMasterKeys
Definition: wallet.h:425
unsigned int m_confirm_target
Definition: wallet.h:663
CFeeRate m_consolidate_feerate
When the actual feerate is less than the consolidate feerate, we will tend to make transactions which...
Definition: wallet.h:685
NodeClock::time_point m_next_resend
The next scheduled rebroadcast of wallet transactions.
Definition: wallet.h:295
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:894
int64_t nRelockTime GUARDED_BY(cs_wallet)
Holds a timestamp at which point the wallet is scheduled (externally) to be relocked....
Definition: wallet.h:540
bool EraseAddressReceiveRequest(WalletBatch &batch, const CTxDestination &dest, const std::string &id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2877
std::unordered_multimap< COutPoint, uint256, SaltedOutpointHasher > TxSpends
Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated tran...
Definition: wallet.h:311
void AbortRescan()
Definition: wallet.h:519
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:813
void LoadAddressReceiveRequest(const CTxDestination &dest, const std::string &id, const std::string &request) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Appends payment request to destination.
Definition: wallet.cpp:2848
Mutex m_unlock_mutex
Definition: wallet.h:540
void AddScriptPubKeyMan(const uint256 &id, std::unique_ptr< ScriptPubKeyMan > spkm_man)
Definition: wallet.cpp:3543
void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Remove specified ScriptPubKeyMan from set of active SPK managers.
Definition: wallet.cpp:3697
bool UpgradeWallet(int version, bilingual_str &error)
Upgrade the wallet.
Definition: wallet.cpp:3303
std::atomic< uint64_t > m_wallet_flags
WalletFlags set on this wallet.
Definition: wallet.h:352
interfaces::Chain * m_chain
Interface for accessing chain state.
Definition: wallet.h:363
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:675
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
Definition: wallet.cpp:3429
bool IsLocked() const override
Definition: wallet.cpp:3403
boost::signals2::signal< void(const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:810
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:424
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Definition: wallet.h:819
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans.
Definition: wallet.cpp:3458
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:2778
TxSpends mapTxSpends GUARDED_BY(cs_wallet)
bool IsTxInMainChain(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:484
int nWalletVersion GUARDED_BY(cs_wallet)
the current wallet version: clients below this version are not able to load the wallet
Definition: wallet.h:292
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:3760
bool IsAbortingRescan() const
Definition: wallet.h:520
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:946
ScriptPubKeyMan * GetScriptPubKeyMan(const OutputType &type, bool internal) const
Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
Definition: wallet.cpp:3467
bool IsAddressPreviouslySpent(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2853
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2695
uint256 GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:939
bool m_allow_fallback_fee
will be false if -fallbackfee=0
Definition: wallet.h:668
int64_t m_keypool_size
Number of pre-generated keys/scripts by each spkm (part of the look-ahead process,...
Definition: wallet.h:701
RecursiveMutex cs_wallet
Main wallet lock.
Definition: wallet.h:412
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
Definition: wallet.cpp:3576
CFeeRate m_min_fee
Override with -mintxfee.
Definition: wallet.h:669
std::atomic< int64_t > m_best_block_time
Definition: wallet.h:300
void SetupLegacyScriptPubKeyMan()
Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
Definition: wallet.cpp:3551
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:3171
boost::signals2::signal< void(const CTxDestination &address, const std::string &label, bool isMine, AddressPurpose purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
Definition: wallet.h:804
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
Definition: wallet.cpp:3537
std::multimap< int64_t, CWalletTx * > TxItems
Definition: wallet.h:453
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: wallet.h:825
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3619
bool ApplyMigrationData(MigrationData &data, bilingual_str &error) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Adds the ScriptPubKeyMans given in MigrationData to this wallet, removes LegacyScriptPubKeyMan,...
Definition: wallet.cpp:3905
std::map< uint256, std::unique_ptr< ScriptPubKeyMan > > m_spk_managers
Definition: wallet.h:392
std::function< TxUpdate(CWalletTx &wtx)> TryUpdatingStateFn
Definition: wallet.h:339
std::atomic< int64_t > m_birth_time
Definition: wallet.h:304
void LoadAddressPreviouslySpent(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Marks destination as previously spent.
Definition: wallet.cpp:2843
std::unordered_map< uint256, CWalletTx, SaltedTxidHasher > mapWallet GUARDED_BY(cs_wallet)
Map from txid to CWalletTx for all transactions this wallet is interested in, including received and ...
std::atomic< bool > fScanningWallet
Definition: wallet.h:284
std::set< ScriptPubKeyMan * > GetScriptPubKeyMans(const CScript &script) const
Get all the ScriptPubKeyMans for a script.
Definition: wallet.cpp:3477
interfaces::Chain & chain() const
Interface for accessing chain state.
Definition: wallet.h:471
bool IsScanningWithPassphrase() const
Definition: wallet.h:522
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:161
A wrapper to reserve an address from a wallet.
Definition: wallet.h:165
const CWallet *const pwallet
The wallet to reserve from.
Definition: wallet.h:168
CTxDestination address
The destination.
Definition: wallet.h:175
ReserveDestination & operator=(const ReserveDestination &)=delete
bool fInternal
Whether this is from the internal (change output) keypool.
Definition: wallet.h:177
~ReserveDestination()
Destructor. If a key has been reserved and not KeepKey'ed, it will be returned to the keypool.
Definition: wallet.h:189
ReserveDestination(CWallet *pwallet, OutputType type)
Construct a ReserveDestination object. This does NOT reserve an address yet.
Definition: wallet.h:181
ScriptPubKeyMan * m_spk_man
The ScriptPubKeyMan to reserve from. Based on type when GetReservedDestination is called.
Definition: wallet.h:170
int64_t nIndex
The index of the address's key in the keypool.
Definition: wallet.h:173
OutputType const type
Definition: wallet.h:171
ReserveDestination(const ReserveDestination &)=delete
Access to the wallet database.
Definition: walletdb.h:190
An instance of this class represents one database.
Definition: db.h:125
Descriptor with some wallet metadata.
Definition: walletutil.h:77
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1018
std::function< Clock::time_point()> NowFn
Definition: wallet.h:1021
std::chrono::steady_clock Clock
Definition: wallet.h:1020
WalletRescanReserver(CWallet &w)
Definition: wallet.h:1026
Clock::time_point now() const
Definition: wallet.h:1046
void setNow(NowFn now)
Definition: wallet.h:1048
bool reserve(bool with_passphrase=false)
Definition: wallet.h:1028
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
TransactionError
Definition: error.h:22
FeeEstimateMode
Definition: feerate.h:21
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:2543
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::optional< AddressPurpose > &purpose)
Definition: wallet.cpp:2435
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:2492
bool UnlockCoin(const COutPoint &output, WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2655
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2481
void KeepDestination()
Keep the address. Do not return its key to the keypool when this object goes out of scope.
Definition: wallet.cpp:2613
bool IsLockedCoin(const COutPoint &output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2677
bool SignTransaction(CMutableTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Fetch the inputs and sign with SIGHASH_ALL.
Definition: wallet.cpp:2150
DBErrors LoadWallet()
Definition: wallet.cpp:2355
std::vector< CTxDestination > ListAddrBookAddresses(const std::optional< AddrBookFilter > &filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Filter and retrieve destinations stored in the addressbook.
Definition: wallet.cpp:2566
void ReturnDestination()
Return reserved address.
Definition: wallet.cpp:2622
util::Result< CTxDestination > GetNewDestination(const OutputType type, const std::string label)
Definition: wallet.cpp:2502
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2464
bool LockCoin(const COutPoint &output, WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2645
std::optional< int64_t > GetOldestKeyPoolTime() const
Definition: wallet.cpp:2529
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
Definition: wallet.cpp:2238
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:2314
bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::optional< AddressPurpose > &strPurpose)
Definition: wallet.cpp:2409
bool DisplayAddress(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Display address on an external signer.
Definition: wallet.cpp:2631
DBErrors ZapSelectTx(std::vector< uint256 > &vHashIn, std::vector< uint256 > &vHashOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2378
std::set< std::string > ListAddrBookLabels(const std::optional< AddressPurpose > purpose) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Retrieve all the known labels in the address book.
Definition: wallet.cpp:2582
OutputType TransactionChangeType(const std::optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend) const
Definition: wallet.cpp:2251
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2683
bool UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2665
util::Result< CTxDestination > GetNewChangeDestination(const OutputType type)
Definition: wallet.cpp:2518
void ForEachAddrBookEntry(const ListAddrBookFunc &func) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2557
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:2441
util::Result< CTxDestination > GetReservedDestination(bool internal)
Reserve an address.
Definition: wallet.cpp:2596
TransactionError FillPSBT(PartiallySignedTransaction &psbtx, bool &complete, int sighash_type=SIGHASH_DEFAULT, bool sign=true, bool bip32derivs=true, size_t *n_signed=nullptr, bool finalize=true) const
Fills out a PSBT with information from the wallet.
Definition: wallet.cpp:2184
bool IsSpentKey(const CScript &scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:983
void SyncTransaction(const CTransactionRef &tx, const SyncTxState &state, bool update_tx=true, bool rescanning_old_block=false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1370
bool LoadToWallet(const uint256 &hash, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1139
int64_t IncOrderPosNext(WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Increment the next transaction order id.
Definition: wallet.cpp:911
bool DummySignInput(const SigningProvider &provider, CTxIn &tx_in, const CTxOut &txout, bool can_grind_r, const CCoinControl *coin_control)
Definition: wallet.cpp:1671
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:1256
bool HasWalletSpend(const CTransactionRef &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Check if a given transaction has any of its outputs spent by another transaction in the wallet.
Definition: wallet.cpp:643
void SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr) override
signify that a particular wallet feature is now used.
Definition: wallet.cpp:603
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:545
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:665
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:1789
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:1301
void updatedBlockTip() override
Definition: wallet.cpp:1491
bool TransactionCanBeAbandoned(const uint256 &hashTx) const
Return whether transaction can be abandoned.
Definition: wallet.cpp:1249
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1759
void Flush()
Flush wallet (bitdb flush)
Definition: wallet.cpp:655
void blockDisconnected(const interfaces::BlockInfo &block) override
Definition: wallet.cpp:1447
bool IsWalletFlagSet(uint64_t flag) const override
check if a certain wallet flag is set
Definition: wallet.cpp:1636
bool DummySignTx(CMutableTransaction &txNew, const std::vector< CTxOut > &txouts, const CCoinControl *coin_control=nullptr) const
Definition: wallet.cpp:1731
void blockConnected(const interfaces::BlockInfo &block) override
Definition: wallet.cpp:1428
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:620
void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag)
Unsets a wallet flag and saves it to disk.
Definition: wallet.cpp:1623
void FirstKeyTimeChanged(const ScriptPubKeyMan *spkm, int64_t new_birth_time)
Updates wallet birth time if 'new_birth_time' is below it.
Definition: wallet.cpp:1812
bool IsSpent(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction spends it:
Definition: wallet.cpp:708
void UnsetBlankWalletFlag(WalletBatch &batch) override
Unset the blank wallet flag and saves it to disk.
Definition: wallet.cpp:1631
void ResubmitWalletTransactions(bool relay, bool force)
Definition: wallet.cpp:2098
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:964
void RecursiveUpdateTxState(const uint256 &tx_hash, const TryUpdatingStateFn &try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Mark a transaction (and its in-wallet descendants) as a particular tx state.
Definition: wallet.cpp:1328
bool CanGetAddresses(bool internal=false) const
Definition: wallet.cpp:1596
void MarkDirty()
Definition: wallet.cpp:923
ScanResult ScanForWalletTransactions(const uint256 &start_block, int start_height, std::optional< int > max_height, const WalletRescanReserver &reserver, bool fUpdate, const bool save_progress)
Scan the block chain (starting in start_block) for transactions from or to us.
Definition: wallet.cpp:1872
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
Definition: wallet.cpp:1641
std::set< uint256 > GetTxConflicts(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2045
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
Definition: wallet.cpp:492
bool IsHDEnabled() const
Definition: wallet.cpp:1585
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:1779
void transactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason) override
Definition: wallet.cpp:1391
static NodeClock::time_point GetDefaultNextResend()
Definition: wallet.cpp:2072
bool ShouldResend() const
Return true if all conditions for periodically resending transactions are met.
Definition: wallet.cpp:2055
void InitWalletFlags(uint64_t flags)
overwrite all flags by the given uint64_t flags must be uninitialised (or 0) only known flags may be ...
Definition: wallet.cpp:1653
void UnsetWalletFlag(uint64_t flag)
Unsets a single wallet flag.
Definition: wallet.cpp:1617
bool AbandonTransaction(const uint256 &hashTx)
Definition: wallet.cpp:1266
void chainStateFlushed(const CBlockLocator &loc) override
Definition: wallet.cpp:592
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:1508
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:751
CWalletTx * AddToWallet(CTransactionRef tx, const TxState &state, const UpdateWalletTxFn &update_wtx=nullptr, bool fFlushOnClose=true, bool rescanning_old_block=false)
Add the transaction to the wallet, wrapping it up inside a CWalletTx.
Definition: wallet.cpp:1014
void AddToSpends(const COutPoint &outpoint, const uint256 &wtxid, WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:725
bool MarkReplaced(const uint256 &originalHash, const uint256 &newHash)
Mark a transaction as replaced by another transaction.
Definition: wallet.cpp:932
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1769
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
Definition: wallet.cpp:1828
isminetype IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1530
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
Definition: wallet.cpp:1568
DBErrors ReorderTransactions()
Definition: wallet.cpp:854
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, const SyncTxState &state, bool fUpdate, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Add a transaction to the wallet, or update it.
Definition: wallet.cpp:1183
void UpgradeDescriptorCache() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade DescriptorCaches.
Definition: wallet.cpp:507
const CWalletTx * GetWalletTx(const uint256 &hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:483
void transactionAddedToMempool(const CTransactionRef &tx) override
Definition: wallet.cpp:1381
void Close()
Close wallet database.
Definition: wallet.cpp:660
bool FillInputToWeight(CTxIn &txin, int64_t target_weight)
Definition: wallet.cpp:1687
bool SubmitTxMemoryPoolAndRelay(CWalletTx &wtx, std::string &err_string, bool relay) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Pass this transaction to node for mempool insertion and relay to peers if flag set to true.
Definition: wallet.cpp:2015
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
Definition: interpreter.h:33
bool error(const char *fmt, const Args &... args)
Definition: logging.h:261
#define LogPrintf(...)
Definition: logging.h:236
SigningResult
Definition: message.h:43
static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE
Pre-calculated constants for input size estimation in virtual size
Definition: wallet.h:118
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
Definition: wallet.cpp:206
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:47
constexpr CAmount HIGH_APS_FEE
discourage APS fee higher than this amount
Definition: wallet.h:97
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:322
static const CAmount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:81
void MaybeResendWalletTxs(WalletContext &context)
Called periodically by the schedule thread.
Definition: wallet.cpp:2135
std::variant< TxStateConfirmed, TxStateInMempool, TxStateInactive > SyncTxState
Subset of states transaction sync logic is implemented to handle.
Definition: transaction.h:71
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Definition: wallet.cpp:145
constexpr CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:112
std::map< std::string, std::string > mapValue_t
Definition: transaction.h:133
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
Definition: crypter.h:62
static const CAmount DEFAULT_DISCARD_FEE
-discardfee default
Definition: wallet.h:83
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:57
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:68
static const bool DEFAULT_WALLETCROSSCHAIN
Definition: wallet.h:110
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
Definition: wallet.cpp:167
std::underlying_type< isminetype >::type isminefilter
used for bitflags of isminetype
Definition: wallet.h:42
static const CAmount DEFAULT_TRANSACTION_MINFEE
-mintxfee default
Definition: wallet.h:85
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
util::Result< MigrationResult > MigrateLegacyToDescriptor(const std::string &wallet_name, const SecureString &passphrase, WalletContext &context)
Do all steps to migrate a legacy wallet to a descriptor wallet.
Definition: wallet.cpp:4182
static const bool DEFAULT_WALLET_RBF
-walletrbf default
Definition: wallet.h:107
constexpr CAmount HIGH_TX_FEE_PER_KB
Discourage users to set fees higher than this amount (in satoshis) per kB.
Definition: wallet.h:114
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:125
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
Definition: wallet.cpp:2884
void NotifyWalletLoaded(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:174
constexpr CAmount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
Definition: wallet.h:116
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:79
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:109
static const std::map< std::string, WalletFlags > WALLET_FLAG_MAP
Definition: wallet.h:139
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:95
static const unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
Definition: wallet.h:105
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
Definition: types.h:40
std::string PurposeToString(AddressPurpose p)
Definition: wallet.h:247
AddressPurpose
Address purpose field that has been been stored with wallet sending and receiving addresses since BIP...
Definition: types.h:60
@ REFUND
Never set in current code may be present in older wallet databases.
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:108
std::shared_ptr< CWallet > RestoreWallet(WalletContext &context, const fs::path &backup_file, const std::string &wallet_name, std::optional< bool > load_on_start, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:440
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:107
static const CAmount WALLET_INCREMENTAL_RELAY_FEE
minimum recommended increment for replacement txs
Definition: wallet.h:99
WalletFeature
(client) version numbers for particular wallet features
Definition: walletutil.h:16
@ FEATURE_BASE
Definition: walletutil.h:17
static constexpr uint64_t KNOWN_WALLET_FLAGS
Definition: wallet.h:127
static const CAmount DEFAULT_CONSOLIDATE_FEERATE
-consolidatefeerate default
Definition: wallet.h:87
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:335
bool IsFeatureSupported(int wallet_version, int feature_version)
Definition: walletutil.cpp:33
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
Definition: walletutil.h:69
@ WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
Definition: walletutil.h:48
@ WALLET_FLAG_KEY_ORIGIN_METADATA
Definition: walletutil.h:45
@ WALLET_FLAG_AVOID_REUSE
Definition: walletutil.h:42
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:66
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:51
@ WALLET_FLAG_BLANK_WALLET
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
Definition: walletutil.h:63
static constexpr uint64_t MUTABLE_WALLET_FLAGS
Definition: wallet.h:136
std::shared_ptr< CWallet > GetWallet(WalletContext &context, const std::string &name)
Definition: wallet.cpp:158
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:101
std::variant< TxStateConfirmed, TxStateInMempool, TxStateConflicted, TxStateInactive, TxStateUnrecognized > TxState
All possible CWalletTx states.
Definition: transaction.h:68
std::optional< AddressPurpose > PurposeFromString(std::string_view s)
Definition: wallet.h:257
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Definition: wallet.h:103
DatabaseStatus
Definition: db.h:197
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:119
std::shared_ptr< CWallet > GetDefaultWallet(WalletContext &context, size_t &count)
Definition: wallet.cpp:151
WalletContext context
OutputType
Definition: outputtype.h:17
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:421
const char * name
Definition: rest.cpp:45
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:60
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:149
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:121
Definition: key.h:161
A mutable version of CTransaction.
Definition: transaction.h:380
std::chrono::time_point< NodeClock > time_point
Definition: time.h:19
A version of CTransaction with the PSBT format.
Definition: psbt.h:947
Bilingual messages:
Definition: translation.h:18
Address book data.
Definition: wallet.h:206
std::optional< AddressPurpose > purpose
Address purpose which was originally recorded for payment protocol support but now serves as a cached...
Definition: wallet.h:221
void SetLabel(std::string name)
Definition: wallet.h:244
std::string GetLabel() const
Definition: wallet.h:243
bool previously_spent
Whether coins with this address have previously been spent.
Definition: wallet.h:230
std::map< std::string, std::string > receive_requests
Map containing data about previously generated receive requests requesting funds to be sent to this a...
Definition: wallet.h:239
std::optional< std::string > label
Address label which is always nullopt for change addresses.
Definition: wallet.h:214
bool IsChange() const
Accessor methods.
Definition: wallet.h:242
CAmount nAmount
Definition: wallet.h:268
bool fSubtractFeeFromAmount
Definition: wallet.h:269
CScript scriptPubKey
Definition: wallet.h:267
std::optional< int > last_scanned_height
Definition: wallet.h:590
uint256 last_scanned_block
Hash and height of most recent block that was successfully scanned.
Definition: wallet.h:589
uint256 last_failed_block
Height of the most recent block that could not be scanned due to read errors or pruning.
Definition: wallet.h:596
struct containing information needed for migrating legacy wallets to descriptor wallets
std::shared_ptr< CWallet > watchonly_wallet
Definition: wallet.h:1071
std::string wallet_name
Definition: wallet.h:1070
std::shared_ptr< CWallet > solvables_wallet
Definition: wallet.h:1072
WalletContext struct containing references to state shared between CWallet instances,...
Definition: context.h:35
#define LOCK(cs)
Definition: sync.h:258
static int count
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
Definition: txmempool.h:231
ChangeType
General change type (added, updated, removed).
Definition: ui_change_type.h:9
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:560
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Definition: wallet.h:49