Bitcoin ABC  0.26.3
P2P Digital Currency
wallet.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2018-2020 The Bitcoin developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef BITCOIN_WALLET_WALLET_H
8 #define BITCOIN_WALLET_WALLET_H
9 
10 #include <consensus/amount.h>
11 #include <interfaces/chain.h>
12 #include <interfaces/handler.h>
13 #include <outputtype.h>
14 #include <primitives/blockhash.h>
15 #include <psbt.h>
16 #include <tinyformat.h>
17 #include <util/message.h>
18 #include <util/strencodings.h>
19 #include <util/string.h>
20 #include <util/system.h>
21 #include <util/translation.h>
22 #include <util/ui_change_type.h>
23 #include <validationinterface.h>
24 #include <wallet/coinselection.h>
25 #include <wallet/crypter.h>
26 #include <wallet/rpcwallet.h>
27 #include <wallet/scriptpubkeyman.h>
28 #include <wallet/transaction.h>
29 #include <wallet/walletdb.h>
30 #include <wallet/walletutil.h>
31 
32 #include <algorithm>
33 #include <atomic>
34 #include <cstdint>
35 #include <map>
36 #include <memory>
37 #include <optional>
38 #include <set>
39 #include <stdexcept>
40 #include <string>
41 #include <utility>
42 #include <vector>
43 
44 #include <boost/signals2/signal.hpp>
45 
46 using LoadWalletFn =
47  std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
48 
49 struct bilingual_str;
50 
56 void UnloadWallet(std::shared_ptr<CWallet> &&wallet);
57 
58 bool AddWallet(const std::shared_ptr<CWallet> &wallet);
59 bool RemoveWallet(const std::shared_ptr<CWallet> &wallet,
60  std::optional<bool> load_on_start,
61  std::vector<bilingual_str> &warnings);
62 bool RemoveWallet(const std::shared_ptr<CWallet> &wallet,
63  std::optional<bool> load_on_start);
64 std::vector<std::shared_ptr<CWallet>> GetWallets();
65 std::shared_ptr<CWallet> GetWallet(const std::string &name);
66 std::shared_ptr<CWallet>
67 LoadWallet(interfaces::Chain &chain, const std::string &name,
68  std::optional<bool> load_on_start, const DatabaseOptions &options,
70  std::vector<bilingual_str> &warnings);
71 std::shared_ptr<CWallet>
72 CreateWallet(interfaces::Chain &chain, const std::string &name,
73  std::optional<bool> load_on_start, const DatabaseOptions &options,
75  std::vector<bilingual_str> &warnings);
76 std::unique_ptr<interfaces::Handler> HandleLoadWallet(LoadWalletFn load_wallet);
77 std::unique_ptr<WalletDatabase>
78 MakeWalletDatabase(const std::string &name, const DatabaseOptions &options,
80 
99 constexpr Amount HIGH_APS_FEE{COIN / 10000};
103 static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
104 static const bool DEFAULT_WALLETBROADCAST = true;
105 static const bool DEFAULT_DISABLE_WALLET = false;
109 constexpr Amount HIGH_TX_FEE_PER_KB{COIN / 100};
114 static constexpr size_t DUMMY_P2PKH_INPUT_SIZE = 148;
115 
116 class CChainParams;
117 class CCoinControl;
118 class COutput;
119 class CScript;
120 class CTxMemPool;
121 class CWalletTx;
122 class ReserveDestination;
123 
126 
127 static constexpr uint64_t KNOWN_WALLET_FLAGS =
131 
132 static constexpr uint64_t MUTABLE_WALLET_FLAGS = WALLET_FLAG_AVOID_REUSE;
133 
134 static const std::map<std::string, WalletFlags> WALLET_FLAG_MAP{
135  {"avoid_reuse", WALLET_FLAG_AVOID_REUSE},
136  {"blank", WALLET_FLAG_BLANK_WALLET},
137  {"key_origin_metadata", WALLET_FLAG_KEY_ORIGIN_METADATA},
138  {"disable_private_keys", WALLET_FLAG_DISABLE_PRIVATE_KEYS},
139  {"descriptor_wallet", WALLET_FLAG_DESCRIPTORS},
140 };
141 
142 extern const std::map<uint64_t, std::string> WALLET_FLAG_CAVEATS;
143 
161 protected:
163  const CWallet *const pwallet;
169  int64_t nIndex{-1};
173  bool fInternal{false};
174 
175 public:
178  explicit ReserveDestination(CWallet *_pwallet, OutputType _type)
179  : pwallet(_pwallet), type(_type) {}
180 
183 
187 
189  bool GetReservedDestination(CTxDestination &pubkey, bool internal);
191  void ReturnDestination();
194  void KeepDestination();
195 };
196 
199 private:
200  bool m_change{true};
201  std::string m_label;
202 
203 public:
204  std::string purpose;
205 
206  CAddressBookData() : purpose("unknown") {}
207 
208  typedef std::map<std::string, std::string> StringMap;
210 
211  bool IsChange() const { return m_change; }
212  const std::string &GetLabel() const { return m_label; }
213  void SetLabel(const std::string &label) {
214  m_change = false;
215  m_label = label;
216  }
217 };
218 
219 struct CRecipient {
223 };
224 
226  bool use_bnb = true;
227  size_t change_output_size = 0;
228  size_t change_spend_size = 0;
230  size_t tx_noinputs_size = 0;
234 
235  CoinSelectionParams(bool use_bnb_, size_t change_output_size_,
236  size_t change_spend_size_, CFeeRate effective_fee_,
237  size_t tx_noinputs_size_, bool avoid_partial)
238  : use_bnb(use_bnb_), change_output_size(change_output_size_),
239  change_spend_size(change_spend_size_), effective_fee(effective_fee_),
240  tx_noinputs_size(tx_noinputs_size_),
241  m_avoid_partial_spends(avoid_partial) {}
243 };
244 
245 // forward declarations for ScanForWalletTransactions/RescanFromTime
247 
252 class CWallet final : public WalletStorage,
254 private:
256 
257  bool Unlock(const CKeyingMaterial &vMasterKeyIn,
258  bool accept_no_keys = false);
259 
260  std::atomic<bool> fAbortRescan{false};
261  // controlled by WalletRescanReserver
262  std::atomic<bool> fScanningWallet{false};
263  std::atomic<int64_t> m_scanning_start{0};
264  std::atomic<double> m_scanning_progress{0};
265  friend class WalletRescanReserver;
266 
269  int nWalletVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
270 
273  int nWalletMaxVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
274 
275  int64_t nNextResend = 0;
277  // Local time that the tip block was received. Used to schedule wallet
278  // rebroadcasts.
279  std::atomic<int64_t> m_best_block_time{0};
280 
285  typedef std::multimap<COutPoint, TxId> TxSpends;
287  void AddToSpends(const COutPoint &outpoint, const TxId &wtxid)
290 
307  CWalletTx::Confirmation confirm, bool fUpdate)
309 
314  void MarkConflicted(const BlockHash &hashBlock, int conflicting_height,
315  const TxId &txid);
316 
321  void MarkInputsDirty(const CTransactionRef &tx)
323 
324  void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>)
326 
333  void SyncTransaction(const CTransactionRef &tx,
334  CWalletTx::Confirmation confirm, bool update_tx = true)
336 
337  std::atomic<uint64_t> m_wallet_flags{0};
338 
339  bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address,
340  const std::string &strName,
341  const std::string &strPurpose);
342 
344  void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag);
345 
347  void UnsetBlankWalletFlag(WalletBatch &batch) override;
348 
351 
353  std::string m_name;
354 
356  std::unique_ptr<WalletDatabase> database;
357 
365  BlockHash m_last_block_processed GUARDED_BY(cs_wallet);
366 
367  /* Height of last block processed is used by wallet to know depth of
368  * transactions without relying on Chain interface beyond asynchronous
369  * updates. For safety, we initialize it to -1. Height is a pointer on
370  * node's tip and doesn't imply that the wallet has scanned sequentially all
371  * blocks up to this one.
372  */
373  int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
374 
375  std::map<OutputType, ScriptPubKeyMan *> m_external_spk_managers;
376  std::map<OutputType, ScriptPubKeyMan *> m_internal_spk_managers;
377 
378  // Indexed by a unique identifier produced by each ScriptPubKeyMan using
379  // ScriptPubKeyMan::GetID. In many cases it will be the hash of an internal
380  // structure
381  std::map<uint256, std::unique_ptr<ScriptPubKeyMan>> m_spk_managers;
382 
383 public:
384  /*
385  * Main wallet lock.
386  * This lock protects all the fields added by CWallet.
387  */
389 
395  WalletDatabase &GetDatabase() override { return *database; }
396 
400  const std::string &GetName() const { return m_name; }
401 
402  typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
404  unsigned int nMasterKeyMaxID = 0;
405 
407  CWallet(interfaces::Chain *chain, const std::string &name,
408  std::unique_ptr<WalletDatabase> _database)
409  : m_chain(chain), m_name(name), database(std::move(_database)) {}
410 
412  // Should not have slots connected at this point.
413  assert(NotifyUnload.empty());
414  }
415 
416  /* Returns the chain params used by this wallet. */
417  const CChainParams &GetChainParams() const override;
418 
419  bool IsCrypted() const;
420  bool IsLocked() const override;
421  bool Lock();
422 
424  bool HaveChain() const { return m_chain ? true : false; }
425 
426  std::map<TxId, CWalletTx> mapWallet GUARDED_BY(cs_wallet);
427 
428  typedef std::multimap<int64_t, CWalletTx *> TxItems;
430 
431  int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
433 
434  std::map<CTxDestination, CAddressBookData>
435  m_address_book GUARDED_BY(cs_wallet);
436  const CAddressBookData *
438  bool allow_change = false) const
440 
441  std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
442 
445 
447  interfaces::Chain &chain() const {
448  assert(m_chain);
449  return *m_chain;
450  }
451 
452  const CWalletTx *GetWalletTx(const TxId &txid) const
454 
455  std::set<TxId> GetTxConflicts(const CWalletTx &wtx) const
457 
464  int GetTxDepthInMainChain(const CWalletTx &wtx) const
466  bool IsTxInMainChain(const CWalletTx &wtx) const
469 
470  return GetTxDepthInMainChain(wtx) > 0;
471  }
472 
478  int GetTxBlocksToMaturity(const CWalletTx &wtx) const
480  bool IsTxImmatureCoinBase(const CWalletTx &wtx) const
482 
485  bool CanSupportFeature(enum WalletFeature wf) const override
488  return nWalletMaxVersion >= wf;
489  }
490 
491  bool IsSpent(const COutPoint &outpoint) const
493 
494  // Whether this or any UTXO with the same CTxDestination has been spent.
495  bool IsSpentKey(const TxId &txid, unsigned int n) const
497  void SetSpentKeyState(WalletBatch &batch, const TxId &txid, unsigned int n,
498  bool used, std::set<CTxDestination> &tx_destinations)
500 
501  bool IsLockedCoin(const COutPoint &outpoint) const
504  void UnlockCoin(const COutPoint &output)
507  void ListLockedCoins(std::vector<COutPoint> &vOutpts) const
509 
510  /*
511  * Rescan abort properties
512  */
513  void AbortRescan() { fAbortRescan = true; }
514  bool IsAbortingRescan() const { return fAbortRescan; }
515  bool IsScanning() const { return fScanningWallet; }
516  int64_t ScanningDuration() const {
518  }
519  double ScanningProgress() const {
520  return fScanningWallet ? double(m_scanning_progress) : 0;
521  }
522 
526 
529  nWalletVersion = nVersion;
530  nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion);
531  return true;
532  }
533 
539  bool AddDestData(WalletBatch &batch, const CTxDestination &dest,
540  const std::string &key, const std::string &value)
543  bool EraseDestData(WalletBatch &batch, const CTxDestination &dest,
544  const std::string &key)
547  void LoadDestData(const CTxDestination &dest, const std::string &key,
548  const std::string &value)
552  bool GetDestData(const CTxDestination &dest, const std::string &key,
553  std::string *value) const
556  std::vector<std::string> GetDestValues(const std::string &prefix) const
558 
562  int64_t nRelockTime GUARDED_BY(cs_wallet){0};
563 
564  // Used to prevent concurrent calls to walletpassphrase RPC.
566  bool Unlock(const SecureString &strWalletPassphrase,
567  bool accept_no_keys = false);
568  bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase,
569  const SecureString &strNewWalletPassphrase);
570  bool EncryptWallet(const SecureString &strWalletPassphrase);
571 
572  void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const
574  unsigned int ComputeTimeSmart(const CWalletTx &wtx) const;
575 
580  int64_t IncOrderPosNext(WalletBatch *batch = nullptr)
583 
584  void MarkDirty();
585 
594  using UpdateWalletTxFn = std::function<bool(CWalletTx &wtx, bool new_tx)>;
595 
597  const CWalletTx::Confirmation &confirm,
598  const UpdateWalletTxFn &update_wtx = nullptr,
599  bool fFlushOnClose = true);
600  bool LoadToWallet(const TxId &txid, const UpdateWalletTxFn &fill_wtx)
603  uint64_t mempool_sequence) override;
604  void blockConnected(const CBlock &block, int height) override;
605  void blockDisconnected(const CBlock &block, int height) override;
606  void updatedBlockTip() override;
607  int64_t RescanFromTime(int64_t startTime,
608  const WalletRescanReserver &reserver, bool update);
609 
610  struct ScanResult {
611  enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS;
612 
617  std::optional<int> last_scanned_height;
618 
624  };
626  int start_height,
627  std::optional<int> max_height,
628  const WalletRescanReserver &reserver,
629  bool fUpdate);
631  MemPoolRemovalReason reason,
632  uint64_t mempool_sequence) override;
635 
636  OutputType
637  TransactionChangeType(const std::optional<OutputType> &change_type,
638  const std::vector<CRecipient> &vecSend) const;
639 
640  // Fetch the inputs and sign with SIGHASH_ALL.
641  bool SignTransaction(CMutableTransaction &tx) const
643  // Sign the tx given the input coins and sighash.
645  const std::map<COutPoint, Coin> &coins,
646  SigHashType sighash,
647  std::map<int, std::string> &input_errors) const;
648  SigningResult SignMessage(const std::string &message, const PKHash &pkhash,
649  std::string &str_sig) const;
650 
667  FillPSBT(PartiallySignedTransaction &psbtx, bool &complete,
668  SigHashType sighash_type = SigHashType().withForkId(),
669  bool sign = true, bool bip32derivs = true) const;
670 
682  void CommitTransaction(
683  CTransactionRef tx, mapValue_t mapValue,
684  std::vector<std::pair<std::string, std::string>> orderForm,
685  bool broadcast = true);
686 
691  bool SubmitTxMemoryPoolAndRelay(const CWalletTx &wtx,
692  std::string &err_string, bool relay) const
694 
695  bool DummySignTx(CMutableTransaction &txNew, const std::set<CTxOut> &txouts,
696  bool use_max_sig = false) const {
697  std::vector<CTxOut> v_txouts(txouts.size());
698  std::copy(txouts.begin(), txouts.end(), v_txouts.begin());
699  return DummySignTx(txNew, v_txouts, use_max_sig);
700  }
701  bool DummySignTx(CMutableTransaction &txNew,
702  const std::vector<CTxOut> &txouts,
703  bool use_max_sig = false) const;
704  bool DummySignInput(CTxIn &tx_in, const CTxOut &txout,
705  bool use_max_sig = false) const;
706 
707  bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp)
709  bool ImportPrivKeys(const std::map<CKeyID, CKey> &privkey_map,
710  const int64_t timestamp)
712  bool ImportPubKeys(
713  const std::vector<CKeyID> &ordered_pubkeys,
714  const std::map<CKeyID, CPubKey> &pubkey_map,
715  const std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> &key_origins,
716  const bool add_keypool, const bool internal, const int64_t timestamp)
718  bool ImportScriptPubKeys(const std::string &label,
719  const std::set<CScript> &script_pub_keys,
720  const bool have_solving_data,
721  const bool apply_label, const int64_t timestamp)
723 
728  // Override with -mintxfee
745  std::optional<OutputType> m_default_change_type{};
751 
753  bool TopUpKeyPool(unsigned int kpSize = 0);
754 
755  int64_t GetOldestKeyPoolTime() const;
756 
757  std::set<CTxDestination> GetLabelAddresses(const std::string &label) const
759 
764  void MarkDestinationsDirty(const std::set<CTxDestination> &destinations)
766 
767  bool GetNewDestination(const OutputType type, const std::string label,
768  CTxDestination &dest, std::string &error);
769  bool GetNewChangeDestination(const OutputType type, CTxDestination &dest,
770  std::string &error);
771 
772  isminetype IsMine(const CTxDestination &dest) const
774  isminetype IsMine(const CScript &script) const
780  Amount GetDebit(const CTxIn &txin, const isminefilter &filter) const;
781  isminetype IsMine(const CTxOut &txout) const
783  ;
784  bool IsMine(const CTransaction &tx) const
787  bool IsFromMe(const CTransaction &tx) const;
788  Amount GetDebit(const CTransaction &tx, const isminefilter &filter) const;
789  void chainStateFlushed(const CBlockLocator &loc) override;
790 
791  DBErrors LoadWallet(bool &fFirstRunRet);
792  DBErrors ZapSelectTx(std::vector<TxId> &txIdsIn,
793  std::vector<TxId> &txIdsOut)
795 
796  bool SetAddressBook(const CTxDestination &address,
797  const std::string &strName, const std::string &purpose);
798 
799  bool DelAddressBook(const CTxDestination &address);
800 
801  unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
802 
805  void SetMinVersion(enum WalletFeature, WalletBatch *batch_in = nullptr,
806  bool fExplicit = false) override;
807 
810  bool SetMaxVersion(int nVersion);
811 
814  int GetVersion() const {
815  LOCK(cs_wallet);
816  return nWalletVersion;
817  }
818 
821  std::set<TxId> GetConflicts(const TxId &txid) const
823 
826  bool HasWalletSpend(const TxId &txid) const
828 
830  void Flush();
831 
833  void Close();
834 
836  boost::signals2::signal<void()> NotifyUnload;
837 
842  boost::signals2::signal<void(CWallet *wallet, const CTxDestination &address,
843  const std::string &label, bool isMine,
844  const std::string &purpose, ChangeType status)>
846 
851  boost::signals2::signal<void(CWallet *wallet, const TxId &txid,
852  ChangeType status)>
854 
856  boost::signals2::signal<void(const std::string &title, int nProgress)>
858 
860  boost::signals2::signal<void(bool fHaveWatchOnly)> NotifyWatchonlyChanged;
861 
863  boost::signals2::signal<void()> NotifyCanGetAddressesChanged;
864 
869  boost::signals2::signal<void(CWallet *wallet)> NotifyStatusChanged;
870 
874  void SetBroadcastTransactions(bool broadcast) {
875  fBroadcastTransactions = broadcast;
876  }
877 
879  bool TransactionCanBeAbandoned(const TxId &txid) const;
880 
885  bool AbandonTransaction(const TxId &txid);
886 
891  static std::shared_ptr<CWallet>
892  Create(interfaces::Chain &chain, const std::string &name,
893  std::unique_ptr<WalletDatabase> database,
894  uint64_t wallet_creation_flags, bilingual_str &error,
895  std::vector<bilingual_str> &warnings);
896 
902  void postInitProcess();
903 
904  bool BackupWallet(const std::string &strDest) const;
905 
906  /* Returns true if HD is enabled */
907  bool IsHDEnabled() const;
908 
913  bool CanGetAddresses(bool internal = false) const;
914 
921  void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main)
923 
927  void SetWalletFlag(uint64_t flags);
928 
932  void UnsetWalletFlag(uint64_t flag);
933 
937  bool IsWalletFlagSet(uint64_t flag) const override;
938 
943  bool AddWalletFlags(uint64_t flags);
945  bool LoadWalletFlags(uint64_t flags);
946 
948  bool IsLegacy() const;
949 
954  const std::string GetDisplayName() const override {
955  std::string wallet_name =
956  GetName().length() == 0 ? "default wallet" : GetName();
957  return strprintf("[%s]", wallet_name);
958  };
959 
964  template <typename... Params>
965  void WalletLogPrintf(std::string fmt, Params... parameters) const {
966  LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
967  };
968 
969  template <typename... Params>
970  void WalletLogPrintfToBeContinued(std::string fmt,
971  Params... parameters) const {
972  LogPrintfToBeContinued(("%s " + fmt).c_str(), GetDisplayName(),
973  parameters...);
974  };
975 
977  bool UpgradeWallet(int version, bilingual_str &error);
978 
981  std::set<ScriptPubKeyMan *> GetActiveScriptPubKeyMans() const;
982 
984  std::set<ScriptPubKeyMan *> GetAllScriptPubKeyMans() const;
985 
989  bool internal) const;
990 
992  ScriptPubKeyMan *GetScriptPubKeyMan(const CScript &script) const;
994  ScriptPubKeyMan *GetScriptPubKeyMan(const uint256 &id) const;
995 
998  std::set<ScriptPubKeyMan *>
999  GetScriptPubKeyMans(const CScript &script, SignatureData &sigdata) const;
1000 
1002  std::unique_ptr<SigningProvider>
1003  GetSolvingProvider(const CScript &script) const;
1004  std::unique_ptr<SigningProvider>
1005  GetSolvingProvider(const CScript &script, SignatureData &sigdata) const;
1006 
1011 
1015 
1016  const CKeyingMaterial &GetEncryptionKey() const override;
1017  bool HasEncryptionKeys() const override;
1018 
1022  assert(m_last_block_processed_height >= 0);
1023  return m_last_block_processed_height;
1024  };
1027  assert(m_last_block_processed_height >= 0);
1028  return m_last_block_processed;
1029  }
1031  void SetLastBlockProcessed(int block_height, BlockHash block_hash)
1034  m_last_block_processed_height = block_height;
1035  m_last_block_processed = block_hash;
1036  };
1037 
1040 
1044 
1052  void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1053 
1061  void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1062 
1070  void DeactivateScriptPubKeyMan(const uint256 &id, OutputType type,
1071  bool internal);
1072 
1075 
1080 
1083  ScriptPubKeyMan *
1085  const FlatSigningProvider &signing_provider,
1086  const std::string &label, bool internal)
1088 };
1089 
1095 void MaybeResendWalletTxs();
1096 
1099 private:
1102 
1103 public:
1105  : m_wallet(w), m_could_reserve(false) {}
1106 
1107  bool reserve() {
1109  if (m_wallet.fScanningWallet.exchange(true)) {
1110  return false;
1111  }
1112  m_wallet.m_scanning_start = GetTimeMillis();
1113  m_wallet.m_scanning_progress = 0;
1114  m_could_reserve = true;
1115  return true;
1116  }
1117 
1118  bool isReserved() const {
1119  return (m_could_reserve && m_wallet.fScanningWallet);
1120  }
1121 
1123  if (m_could_reserve) {
1124  m_wallet.fScanningWallet = false;
1125  }
1126  }
1127 };
1128 
1130 bool AddWalletSetting(interfaces::Chain &chain, const std::string &wallet_name);
1131 
1135  const std::string &wallet_name);
1136 
1137 #endif // BITCOIN_WALLET_WALLET_H
static constexpr Amount SATOSHI
Definition: amount.h:143
static constexpr Amount COIN
Definition: amount.h:144
int flags
Definition: bitcoin-tx.cpp:533
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:119
const CChainParams & Params()
Return the currently selected parameters.
Address book data.
Definition: wallet.h:198
const std::string & GetLabel() const
Definition: wallet.h:212
StringMap destdata
Definition: wallet.h:209
std::map< std::string, std::string > StringMap
Definition: wallet.h:208
std::string m_label
Definition: wallet.h:201
std::string purpose
Definition: wallet.h:204
bool IsChange() const
Definition: wallet.h:211
void SetLabel(const std::string &label)
Definition: wallet.h:213
Definition: block.h:60
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:74
Coin Control Features.
Definition: coincontrol.h:21
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
A mutable version of CTransaction.
Definition: transaction.h:274
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:20
Definition: spend.h:19
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:431
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:192
An input of a transaction.
Definition: transaction.h:59
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:354
An output of a transaction.
Definition: transaction.h:128
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:253
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
Get the SigningProvider for a script.
Definition: wallet.cpp:3253
std::atomic< int64_t > m_best_block_time
Definition: wallet.h:279
bool Lock()
Definition: wallet.cpp:3153
BlockHash GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:1025
int64_t nRelockTime GUARDED_BY(cs_wallet)
Holds a timestamp at which point the wallet is scheduled (externally) to be relocked.
Definition: wallet.h:562
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:3224
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition: wallet.h:836
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:402
bool HaveChain() const
Interface to assert chain access.
Definition: wallet.h:424
int GetTxBlocksToMaturity(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3122
int nWalletVersion GUARDED_BY(cs_wallet)
the current wallet version: clients below this version are not able to load the wallet
double ScanningProgress() const
Definition: wallet.h:519
bool DummySignTx(CMutableTransaction &txNew, const std::set< CTxOut > &txouts, bool use_max_sig=false) const
Definition: wallet.h:695
uint64_t nAccountingEntryNumber
Definition: wallet.h:432
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
Definition: wallet.cpp:3311
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Adds the active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3364
void SetupLegacyScriptPubKeyMan()
Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
Definition: wallet.cpp:3288
Mutex m_unlock_mutex
Definition: wallet.h:562
bool AddDestData(WalletBatch &batch, const CTxDestination &dest, const std::string &key, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Adds a destination data tuple to the store, and saves it to disk When adding new fields,...
Definition: wallet.cpp:2617
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Definition: wallet.h:863
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:954
MasterKeyMap mapMasterKeys
Definition: wallet.h:403
std::string m_name
Wallet name: relative directory name or "" for default wallet.
Definition: wallet.h:353
TxItems wtxOrdered
Definition: wallet.h:429
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:400
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:3112
bool IsTxImmatureCoinBase(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3134
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:857
RecursiveMutex cs_wallet
Definition: wallet.h:388
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
Definition: wallet.cpp:3172
std::multimap< COutPoint, TxId > TxSpends
Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated tran...
Definition: wallet.h:285
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:872
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:965
bool IsAbortingRescan() const
Definition: wallet.h:514
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Create new DescriptorScriptPubKeyMans and add them to the wallet.
Definition: wallet.cpp:3326
std::atomic< int64_t > m_scanning_start
Definition: wallet.h:263
WalletDatabase & GetDBHandle()
Get database handle used by this wallet.
Definition: wallet.h:394
interfaces::Chain * m_chain
Interface for accessing chain state.
Definition: wallet.h:350
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
Definition: wallet.cpp:3283
std::map< TxId, CWalletTx > mapWallet GUARDED_BY(cs_wallet)
std::map< OutputType, ScriptPubKeyMan * > m_external_spk_managers
Definition: wallet.h:375
WalletDatabase & GetDatabase() override
Definition: wallet.h:395
void DeactivateScriptPubKeyMan(const uint256 &id, OutputType type, bool internal)
Remove specified ScriptPubKeyMan from set of active SPK managers.
Definition: wallet.cpp:3402
bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Look up a destination data tuple in the store, return true if found false otherwise.
Definition: wallet.cpp:2641
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:735
bool IsLegacy() const
Determine if we are a legacy wallet.
Definition: wallet.cpp:3425
interfaces::Chain & chain() const
Interface for accessing chain state.
Definition: wallet.h:447
std::atomic< bool > fAbortRescan
Definition: wallet.h:260
std::map< uint256, std::unique_ptr< ScriptPubKeyMan > > m_spk_managers
Definition: wallet.h:381
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Loads an active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3375
std::unique_ptr< interfaces::Handler > m_chain_notifications_handler
Registered interfaces::Chain::Notifications handler.
Definition: wallet.h:444
static std::shared_ptr< CWallet > Create(interfaces::Chain &chain, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bilingual_str &error, std::vector< bilingual_str > &warnings)
Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error.
Definition: wallet.cpp:2705
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:874
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
Definition: wallet.h:845
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
Definition: wallet.h:1020
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: wallet.h:869
OutputType m_default_address_type
Definition: wallet.h:738
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan(const WalletDescriptor &desc) const
Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.
Definition: wallet.cpp:3435
int64_t ScanningDuration() const
Definition: wallet.h:516
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor &desc)
Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
Definition: wallet.cpp:3319
LegacyScriptPubKeyMan * GetLegacyScriptPubKeyMan() const
Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
Definition: wallet.cpp:3269
std::atomic< uint64_t > m_wallet_flags
Definition: wallet.h:337
Amount m_max_aps_fee
note: this is absolute fee, not fee rate
Definition: wallet.h:737
std::map< CTxDestination, CAddressBookData > m_address_book GUARDED_BY(cs_wallet)
CFeeRate m_pay_tx_fee
Definition: wallet.h:724
int64_t nNextResend
Definition: wallet.h:275
bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
check whether we are allowed to upgrade (or already support) to the named feature
Definition: wallet.h:485
bool BackupWallet(const std::string &strDest) const
Definition: wallet.cpp:3095
int64_t nOrderPosNext GUARDED_BY(cs_wallet)=0
BlockHash 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 IsTxInMainChain(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:466
unsigned int ComputeTimeSmart(const CWalletTx &wtx) const
Compute smart timestamp for a transaction being added to the wallet.
Definition: wallet.cpp:2575
CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet)
bool IsScanning() const
Definition: wallet.h:515
TxSpends mapTxSpends GUARDED_BY(cs_wallet)
void WalletLogPrintfToBeContinued(std::string fmt, Params... parameters) const
Definition: wallet.h:970
std::unique_ptr< WalletDatabase > database
Internal database handle.
Definition: wallet.h:356
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:3451
int m_last_block_processed_height GUARDED_BY(cs_wallet)
std::set< ScriptPubKeyMan * > GetActiveScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers.
Definition: wallet.cpp:3187
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:527
CFeeRate m_min_fee
Definition: wallet.h:729
std::vector< std::string > GetDestValues(const std::string &prefix) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get all destination values matching a prefix.
Definition: wallet.cpp:2660
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:860
bool IsLocked() const override
Definition: wallet.cpp:3145
bool m_allow_fallback_fee
will be false if -fallbackfee=0
Definition: wallet.h:727
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
Definition: wallet.h:376
std::atomic< double > m_scanning_progress
Definition: wallet.h:264
~CWallet()
Definition: wallet.h:411
int GetVersion() const
get the current wallet format (the oldest client version guaranteed to understand this wallet)
Definition: wallet.h:814
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2483
bool EraseDestData(WalletBatch &batch, const CTxDestination &dest, const std::string &key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Erases a destination data tuple in the store and on disk.
Definition: wallet.cpp:2627
boost::signals2::signal< void(CWallet *wallet, const TxId &txid, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:853
bool HasEncryptionKeys() const override
Definition: wallet.cpp:3307
bool m_spend_zero_conf_change
Definition: wallet.h:725
CWallet(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > _database)
Construct wallet with specified name and database implementation.
Definition: wallet.h:407
Amount m_default_max_tx_fee
Absolute maximum transaction fee (in satoshis) used by default for the wallet.
Definition: wallet.h:750
bool UpgradeWallet(int version, bilingual_str &error)
Upgrade the wallet.
Definition: wallet.cpp:3041
bool fBroadcastTransactions
Definition: wallet.h:276
ScriptPubKeyMan * GetScriptPubKeyMan(const OutputType &type, bool internal) const
Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
Definition: wallet.cpp:3208
bool IsCrypted() const
Definition: wallet.cpp:3141
std::atomic< bool > fScanningWallet
Definition: wallet.h:262
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans.
Definition: wallet.cpp:3200
std::multimap< int64_t, CWalletTx * > TxItems
Definition: wallet.h:428
int nWalletMaxVersion GUARDED_BY(cs_wallet)
the maximum wallet format version: memory-only variable that specifies to what version this wallet ma...
std::optional< OutputType > m_default_change_type
Default output type for change outputs.
Definition: wallet.h:745
void AbortRescan()
Definition: wallet.h:513
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:2636
unsigned int nMasterKeyMaxID
Definition: wallet.h:404
std::function< bool(CWalletTx &wtx, bool new_tx)> UpdateWalletTxFn
Callback for updating transaction metadata in mapWallet.
Definition: wallet.h:594
void postInitProcess()
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
Definition: wallet.cpp:3084
void SetLastBlockProcessed(int block_height, BlockHash block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Set last block processed height, currently only use in unit test.
Definition: wallet.h:1031
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3029
const CKeyingMaterial & GetEncryptionKey() const override
Definition: wallet.cpp:3303
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:65
A UTXO entry.
Definition: coins.h:27
A wrapper to reserve an address from a wallet.
Definition: wallet.h:160
bool fInternal
Whether this is from the internal (change output) keypool.
Definition: wallet.h:173
OutputType const type
Definition: wallet.h:167
~ReserveDestination()
Destructor.
Definition: wallet.h:186
ReserveDestination(CWallet *_pwallet, OutputType _type)
Construct a ReserveDestination object.
Definition: wallet.h:178
ReserveDestination & operator=(const ReserveDestination &)=delete
ScriptPubKeyMan * m_spk_man
The ScriptPubKeyMan to reserve from.
Definition: wallet.h:166
int64_t nIndex
The index of the address's key in the keypool.
Definition: wallet.h:169
CTxDestination address
The destination.
Definition: wallet.h:171
ReserveDestination(const ReserveDestination &)=delete
const CWallet *const pwallet
The wallet to reserve from.
Definition: wallet.h:163
A class implementing ScriptPubKeyMan manages some (or all) scriptPubKeys used in a wallet.
Signature hash type wrapper class.
Definition: sighashtype.h:37
Access to the wallet database.
Definition: walletdb.h:175
An instance of this class represents one database.
Definition: db.h:100
Descriptor with some wallet metadata.
Definition: walletutil.h:80
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1098
bool isReserved() const
Definition: wallet.h:1118
CWallet & m_wallet
Definition: wallet.h:1100
WalletRescanReserver(CWallet &w)
Definition: wallet.h:1104
Chain notifications.
Definition: chain.h:241
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:123
256-bit opaque blob.
Definition: uint256.h:127
std::vector< uint8_t, secure_allocator< uint8_t > > CKeyingMaterial
Definition: crypter.h:57
TransactionError
Definition: error.h:22
void LockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2453
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:2376
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2299
void CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector< std::pair< std::string, std::string >> orderForm, bool broadcast=true)
Add the transaction to the wallet and maybe attempt to broadcast it.
Definition: wallet.cpp:2122
void KeepDestination()
Keep the address.
Definition: wallet.cpp:2436
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2474
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2310
std::set< CTxDestination > GetLabelAddresses(const std::string &label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2397
bool IsLockedCoin(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2468
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
Definition: wallet.cpp:2092
void UnlockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2458
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:2258
DBErrors LoadWallet(bool &fFirstRunRet)
Definition: wallet.cpp:2169
OutputType TransactionChangeType(const std::optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend) const
Definition: wallet.cpp:2106
bool SignTransaction(CMutableTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2001
void ReturnDestination()
Return reserved address.
Definition: wallet.cpp:2445
bool GetNewChangeDestination(const OutputType type, CTxDestination &dest, std::string &error)
Definition: wallet.cpp:2349
void UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2463
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:2320
bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::string &strPurpose)
Definition: wallet.cpp:2231
TransactionError FillPSBT(PartiallySignedTransaction &psbtx, bool &complete, SigHashType sighash_type=SigHashType().withForkId(), bool sign=true, bool bip32derivs=true) const
Fills out a PSBT with information from the wallet.
Definition: wallet.cpp:2048
bool GetReservedDestination(CTxDestination &pubkey, bool internal)
Reserve an address.
Definition: wallet.cpp:2415
int64_t GetOldestKeyPoolTime() const
Definition: wallet.cpp:2366
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:2265
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination &dest, std::string &error)
Definition: wallet.cpp:2329
DBErrors ZapSelectTx(std::vector< TxId > &txIdsIn, std::vector< TxId > &txIdsOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2199
bool AddWalletFlags(uint64_t flags)
Overwrite all flags by the given uint64_t.
Definition: wallet.cpp:1530
void blockConnected(const CBlock &block, int height) override
Definition: wallet.cpp:1352
bool LoadToWallet(const TxId &txid, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1044
void MarkConflicted(const BlockHash &hashBlock, int conflicting_height, const TxId &txid)
Mark a transaction (and its in-wallet descendants) as conflicting with a particular block.
Definition: wallet.cpp:1227
void Flush()
Flush wallet (bitdb flush)
Definition: wallet.cpp:602
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
Definition: wallet.cpp:400
bool SetMaxVersion(int nVersion)
change which version we're allowed to upgrade to (note that this does not immediately imply upgrading...
Definition: wallet.cpp:554
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:1605
std::set< TxId > GetConflicts(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get wallet transactions that conflict with given transaction (spend same outputs)
Definition: wallet.cpp:567
void MarkDirty()
Definition: wallet.cpp:892
bool SubmitTxMemoryPoolAndRelay(const 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:1879
void AddToSpends(const COutPoint &outpoint, const TxId &wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:680
void SyncTransaction(const CTransactionRef &tx, CWalletTx::Confirmation confirm, bool update_tx=true) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Used by TransactionAddedToMemorypool/BlockConnected/Disconnected/ScanForWalletTransactions.
Definition: wallet.cpp:1284
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1585
CWalletTx * AddToWallet(CTransactionRef tx, const CWalletTx::Confirmation &confirm, const UpdateWalletTxFn &update_wtx=nullptr, bool fFlushOnClose=true)
Definition: wallet.cpp:950
bool HasWalletSpend(const TxId &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:596
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:444
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
Definition: wallet.cpp:1447
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1595
isminetype IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1422
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
Definition: wallet.cpp:1519
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:1619
bool CanGetAddresses(bool internal=false) const
Returns true if the wallet can give out new addresses.
Definition: wallet.cpp:1474
ScanResult ScanForWalletTransactions(const BlockHash &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:1705
bool IsSpentKey(const TxId &txid, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:923
bool TransactionCanBeAbandoned(const TxId &txid) const
Return whether transaction can be abandoned.
Definition: wallet.cpp:1152
const CChainParams & GetChainParams() const override
Definition: wallet.cpp:384
Amount GetDebit(const CTxIn &txin, const isminefilter &filter) const
Returns amount of debit if the input matches the filter, otherwise returns 0.
Definition: wallet.cpp:1401
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:1159
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, CWalletTx::Confirmation confirm, bool fUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Add a transaction to the wallet, or update it.
Definition: wallet.cpp:1095
bool IsSpent(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction, spends it:
Definition: wallet.cpp:659
void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1846
bool IsHDEnabled() const
Definition: wallet.cpp:1465
void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag)
Unsets a wallet flag and saves it to disk.
Definition: wallet.cpp:1502
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:610
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:704
void updatedBlockTip() override
Definition: wallet.cpp:1384
void UnsetWalletFlag(uint64_t flag)
Unsets a single wallet flag.
Definition: wallet.cpp:1497
void transactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
Definition: wallet.cpp:1310
bool IsWalletFlagSet(uint64_t flag) const override
Check if a certain wallet flag is set.
Definition: wallet.cpp:1515
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
Definition: wallet.cpp:1654
bool AbandonTransaction(const TxId &txid)
Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent.
Definition: wallet.cpp:1168
void UnsetBlankWalletFlag(WalletBatch &batch) override
Unset the blank wallet flag and saves it to disk.
Definition: wallet.cpp:1511
void SetSpentKeyState(WalletBatch &batch, const TxId &txid, unsigned int n, bool used, std::set< CTxDestination > &tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:899
void transactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence) override
Definition: wallet.cpp:1297
DBErrors ReorderTransactions()
Definition: wallet.cpp:824
void blockDisconnected(const CBlock &block, int height) override
Definition: wallet.cpp:1367
void Close()
Close wallet database.
Definition: wallet.cpp:606
int64_t IncOrderPosNext(WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Increment the next transaction order id.
Definition: wallet.cpp:880
const CWalletTx * GetWalletTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:390
void ResendWalletTransactions()
Definition: wallet.cpp:1940
void SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr, bool fExplicit=false) override
signify that a particular wallet feature is now used.
Definition: wallet.cpp:526
std::set< TxId > GetTxConflicts(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1920
bool DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig=false) const
Definition: wallet.cpp:1544
void chainStateFlushed(const CBlockLocator &loc) override
Definition: wallet.cpp:521
uint8_t isminefilter
Definition: wallet.h:41
isminetype
IsMine() return codes.
Definition: ismine.h:18
#define LogPrintfToBeContinued
These are aliases used to explicitly state that the message should not end with a newline character.
Definition: logging.h:222
#define LogPrintf(...)
Definition: logging.h:206
SigningResult
Definition: message.h:47
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:257
OutputType
Definition: outputtype.h:16
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
const char * prefix
Definition: rest.cpp:819
const char * name
Definition: rest.cpp:48
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:55
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:92
Definition: amount.h:19
static constexpr Amount zero() noexcept
Definition: amount.h:32
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:105
CScript scriptPubKey
Definition: wallet.h:220
Amount nAmount
Definition: wallet.h:221
bool fSubtractFeeFromAmount
Definition: wallet.h:222
std::optional< int > last_scanned_height
Definition: wallet.h:617
BlockHash last_scanned_block
Hash and height of most recent block that was successfully scanned.
Definition: wallet.h:616
BlockHash last_failed_block
Hash of the most recent block that could not be scanned due to read errors or pruning.
Definition: wallet.h:623
Confirmation includes tx status and a triplet of {block height/block hash/tx index in block} at which...
Definition: transaction.h:181
bool m_subtract_fee_outputs
Indicate that we are subtracting the fee from outputs.
Definition: wallet.h:232
CoinSelectionParams(bool use_bnb_, size_t change_output_size_, size_t change_spend_size_, CFeeRate effective_fee_, size_t tx_noinputs_size_, bool avoid_partial)
Definition: wallet.h:235
size_t change_spend_size
Definition: wallet.h:228
size_t tx_noinputs_size
Definition: wallet.h:230
bool m_avoid_partial_spends
Definition: wallet.h:233
CFeeRate effective_fee
Definition: wallet.h:229
size_t change_output_size
Definition: wallet.h:227
A version of CTransaction with the PSBT format.
Definition: psbt.h:334
A TxId is the identifier of a transaction.
Definition: txid.h:14
Bilingual messages:
Definition: translation.h:17
#define LOCK(cs)
Definition: sync.h:306
bool error(const char *fmt, const Args &...args)
Definition: system.h:45
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:55
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:101
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
Definition: txmempool.h:293
ChangeType
General change type (added, updated, removed).
Definition: ui_change_type.h:9
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())
DatabaseStatus
Definition: db.h:229
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:475
std::map< std::string, std::string > mapValue_t
Definition: transaction.h:21
constexpr Amount HIGH_TX_FEE_PER_KB
Discourage users to set fees higher than this amount (in satoshis) per kB.
Definition: wallet.h:109
std::shared_ptr< CWallet > LoadWallet(interfaces::Chain &chain, 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:263
constexpr Amount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:82
std::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
Definition: wallet.cpp:165
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:105
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Definition: wallet.cpp:2673
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Definition: wallet.h:47
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:119
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:125
static constexpr uint64_t MUTABLE_WALLET_FLAGS
Definition: wallet.h:132
constexpr Amount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
Definition: wallet.h:112
const std::map< uint64_t, std::string > WALLET_FLAG_CAVEATS
Definition: wallet.cpp:42
static const std::map< std::string, WalletFlags > WALLET_FLAG_MAP
Definition: wallet.h:134
static constexpr size_t DUMMY_P2PKH_INPUT_SIZE
Pre-calculated constants for input size estimation.
Definition: wallet.h:114
void MaybeResendWalletTxs()
Called periodically by the schedule thread.
Definition: wallet.cpp:1989
static const Amount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:84
static const Amount DEFAULT_TRANSACTION_MINFEE_PER_KB
-mintxfee default
Definition: wallet.h:86
std::shared_ptr< CWallet > GetWallet(const std::string &name)
Definition: wallet.cpp:154
std::shared_ptr< CWallet > CreateWallet(interfaces::Chain &chain, 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:281
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
Definition: wallet.cpp:200
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:103
static constexpr uint64_t KNOWN_WALLET_FLAGS
Definition: wallet.h:127
constexpr Amount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:107
static const Amount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled...
Definition: wallet.h:97
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:53
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_WALLETBROADCAST
Definition: wallet.h:104
constexpr Amount HIGH_APS_FEE
discourage APS fee higher than this amount
Definition: wallet.h:99
static const Amount WALLET_INCREMENTAL_RELAY_FEE(5000 *SATOSHI)
minimum recommended increment for BIP 125 replacement txs
std::vector< std::shared_ptr< CWallet > > GetWallets()
Definition: wallet.cpp:149
bool AddWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:105
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:45
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:55
@ WALLET_FLAG_AVOID_REUSE
Definition: walletutil.h:47
@ WALLET_FLAG_KEY_ORIGIN_METADATA
Definition: walletutil.h:51
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:70
@ WALLET_FLAG_BLANK_WALLET
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
Definition: walletutil.h:67
WalletFeature
(client) version numbers for particular wallet features
Definition: walletutil.h:14
@ FEATURE_BASE
Definition: walletutil.h:17