Bitcoin ABC  0.26.3
P2P Digital Currency
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
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>
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>
44 #include <boost/signals2/signal.hpp>
46 using LoadWalletFn =
47  std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
49 struct bilingual_str;
56 void UnloadWallet(std::shared_ptr<CWallet> &&wallet);
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,
99 constexpr Amount HIGH_APS_FEE{COIN / 10000};
103 static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
105 static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false;
106 static const bool DEFAULT_WALLETBROADCAST = true;
107 static const bool DEFAULT_DISABLE_WALLET = false;
111 constexpr Amount HIGH_TX_FEE_PER_KB{COIN / 100};
116 static constexpr size_t DUMMY_P2PKH_INPUT_SIZE = 148;
118 class CChainParams;
119 class CCoinControl;
120 class COutput;
121 class CScript;
122 class CTxMemPool;
123 class CWalletTx;
124 class ReserveDestination;
129 static constexpr uint64_t KNOWN_WALLET_FLAGS =
134 static constexpr uint64_t MUTABLE_WALLET_FLAGS = WALLET_FLAG_AVOID_REUSE;
136 static const std::map<std::string, WalletFlags> WALLET_FLAG_MAP{
137  {"avoid_reuse", WALLET_FLAG_AVOID_REUSE},
139  {"key_origin_metadata", WALLET_FLAG_KEY_ORIGIN_METADATA},
140  {"disable_private_keys", WALLET_FLAG_DISABLE_PRIVATE_KEYS},
141  {"descriptor_wallet", WALLET_FLAG_DESCRIPTORS},
142 };
144 extern const std::map<uint64_t, std::string> WALLET_FLAG_CAVEATS;
163 protected:
165  const CWallet *const pwallet;
171  int64_t nIndex{-1};
175  bool fInternal{false};
177 public:
180  explicit ReserveDestination(CWallet *_pwallet, OutputType _type)
181  : pwallet(_pwallet), type(_type) {}
191  bool GetReservedDestination(CTxDestination &pubkey, bool internal);
193  void ReturnDestination();
196  void KeepDestination();
197 };
201 private:
202  bool m_change{true};
203  std::string m_label;
205 public:
206  std::string purpose;
208  CAddressBookData() : purpose("unknown") {}
210  typedef std::map<std::string, std::string> StringMap;
213  bool IsChange() const { return m_change; }
214  const std::string &GetLabel() const { return m_label; }
215  void SetLabel(const std::string &label) {
216  m_change = false;
217  m_label = label;
218  }
219 };
221 struct CRecipient {
225 };
228  bool use_bnb = true;
229  size_t change_output_size = 0;
230  size_t change_spend_size = 0;
232  size_t tx_noinputs_size = 0;
236  CoinSelectionParams(bool use_bnb_, size_t change_output_size_,
237  size_t change_spend_size_, CFeeRate effective_fee_,
238  size_t tx_noinputs_size_)
239  : use_bnb(use_bnb_), change_output_size(change_output_size_),
240  change_spend_size(change_spend_size_), effective_fee(effective_fee_),
241  tx_noinputs_size(tx_noinputs_size_) {}
243 };
245 // forward declarations for ScanForWalletTransactions/RescanFromTime
252 class CWallet final : public WalletStorage,
254 private:
257  bool Unlock(const CKeyingMaterial &vMasterKeyIn,
258  bool accept_no_keys = false);
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;
269  int nWalletVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
273  int nWalletMaxVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
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};
285  typedef std::multimap<COutPoint, TxId> TxSpends;
287  void AddToSpends(const COutPoint &outpoint, const TxId &wtxid)
307  CWalletTx::Confirmation confirm, bool fUpdate)
314  void MarkConflicted(const BlockHash &hashBlock, int conflicting_height,
315  const TxId &txid);
321  void MarkInputsDirty(const CTransactionRef &tx)
324  void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>)
333  void SyncTransaction(const CTransactionRef &tx,
334  CWalletTx::Confirmation confirm, bool update_tx = true)
337  std::atomic<uint64_t> m_wallet_flags{0};
339  bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address,
340  const std::string &strName,
341  const std::string &strPurpose);
344  void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag);
347  void UnsetBlankWalletFlag(WalletBatch &batch) override;
353  std::string m_name;
356  std::unique_ptr<WalletDatabase> database;
365  BlockHash m_last_block_processed GUARDED_BY(cs_wallet);
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;
375  std::map<OutputType, ScriptPubKeyMan *> m_external_spk_managers;
376  std::map<OutputType, ScriptPubKeyMan *> m_internal_spk_managers;
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;
383 public:
384  /*
385  * Main wallet lock.
386  * This lock protects all the fields added by CWallet.
387  */
395  WalletDatabase &GetDatabase() override { return *database; }
400  const std::string &GetName() const { return m_name; }
402  typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
404  unsigned int nMasterKeyMaxID = 0;
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)) {}
412  // Should not have slots connected at this point.
413  assert(NotifyUnload.empty());
414  }
416  /* Returns the chain params used by this wallet. */
417  const CChainParams &GetChainParams() const override;
419  bool IsCrypted() const;
420  bool IsLocked() const override;
421  bool Lock();
424  bool HaveChain() const { return m_chain ? true : false; }
426  std::map<TxId, CWalletTx> mapWallet GUARDED_BY(cs_wallet);
428  typedef std::multimap<int64_t, CWalletTx *> TxItems;
431  int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
434  std::map<CTxDestination, CAddressBookData>
435  m_address_book GUARDED_BY(cs_wallet);
436  const CAddressBookData *
438  bool allow_change = false) const
441  std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
444  std::unique_ptr<interfaces::Handler> m_chain_notifications_handler;
447  interfaces::Chain &chain() const {
448  assert(m_chain);
449  return *m_chain;
450  }
452  const CWalletTx *GetWalletTx(const TxId &txid) const
455  std::set<TxId> GetTxConflicts(const CWalletTx &wtx) const
464  int GetTxDepthInMainChain(const CWalletTx &wtx) const
466  bool IsTxInMainChain(const CWalletTx &wtx) const
470  return GetTxDepthInMainChain(wtx) > 0;
471  }
478  int GetTxBlocksToMaturity(const CWalletTx &wtx) const
480  bool IsTxImmatureCoinBase(const CWalletTx &wtx) const
485  bool CanSupportFeature(enum WalletFeature wf) const override
488  return nWalletMaxVersion >= wf;
489  }
491  bool IsSpent(const COutPoint &outpoint) const
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)
501  bool IsLockedCoin(const COutPoint &outpoint) const
504  void UnlockCoin(const COutPoint &output)
507  void ListLockedCoins(std::vector<COutPoint> &vOutpts) const
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  }
529  nWalletVersion = nVersion;
530  nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion);
531  return true;
532  }
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
562  int64_t nRelockTime GUARDED_BY(cs_wallet){0};
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);
572  void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const
574  unsigned int ComputeTimeSmart(const CWalletTx &wtx) const;
580  int64_t IncOrderPosNext(WalletBatch *batch = nullptr)
584  void MarkDirty();
594  using UpdateWalletTxFn = std::function<bool(CWalletTx &wtx, bool new_tx)>;
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);
610  struct ScanResult {
611  enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS;
617  std::optional<int> last_scanned_height;
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;
636  OutputType
637  TransactionChangeType(const std::optional<OutputType> &change_type,
638  const std::vector<CRecipient> &vecSend) const;
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;
667  FillPSBT(PartiallySignedTransaction &psbtx, bool &complete,
668  SigHashType sighash_type = SigHashType().withForkId(),
669  bool sign = true, bool bip32derivs = true) const;
681  void CommitTransaction(
682  CTransactionRef tx, mapValue_t mapValue,
683  std::vector<std::pair<std::string, std::string>> orderForm);
689  bool SubmitTxMemoryPoolAndRelay(const CWalletTx &wtx,
690  std::string &err_string, bool relay) const
693  bool DummySignTx(CMutableTransaction &txNew, const std::set<CTxOut> &txouts,
694  bool use_max_sig = false) const {
695  std::vector<CTxOut> v_txouts(txouts.size());
696  std::copy(txouts.begin(), txouts.end(), v_txouts.begin());
697  return DummySignTx(txNew, v_txouts, use_max_sig);
698  }
699  bool DummySignTx(CMutableTransaction &txNew,
700  const std::vector<CTxOut> &txouts,
701  bool use_max_sig = false) const;
702  bool DummySignInput(CTxIn &tx_in, const CTxOut &txout,
703  bool use_max_sig = false) const;
705  bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp)
707  bool ImportPrivKeys(const std::map<CKeyID, CKey> &privkey_map,
708  const int64_t timestamp)
710  bool ImportPubKeys(
711  const std::vector<CKeyID> &ordered_pubkeys,
712  const std::map<CKeyID, CPubKey> &pubkey_map,
713  const std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> &key_origins,
714  const bool add_keypool, const bool internal, const int64_t timestamp)
716  bool ImportScriptPubKeys(const std::string &label,
717  const std::set<CScript> &script_pub_keys,
718  const bool have_solving_data,
719  const bool apply_label, const int64_t timestamp)
726  // Override with -mintxfee
743  std::optional<OutputType> m_default_change_type{};
751  bool TopUpKeyPool(unsigned int kpSize = 0);
753  int64_t GetOldestKeyPoolTime() const;
755  std::set<CTxDestination> GetLabelAddresses(const std::string &label) const;
761  void MarkDestinationsDirty(const std::set<CTxDestination> &destinations)
764  bool GetNewDestination(const OutputType type, const std::string label,
765  CTxDestination &dest, std::string &error);
766  bool GetNewChangeDestination(const OutputType type, CTxDestination &dest,
767  std::string &error);
769  isminetype IsMine(const CTxDestination &dest) const
771  isminetype IsMine(const CScript &script) const
777  Amount GetDebit(const CTxIn &txin, const isminefilter &filter) const;
778  isminetype IsMine(const CTxOut &txout) const
780  ;
781  bool IsMine(const CTransaction &tx) const
784  bool IsFromMe(const CTransaction &tx) const;
785  Amount GetDebit(const CTransaction &tx, const isminefilter &filter) const;
786  void chainStateFlushed(const CBlockLocator &loc) override;
788  DBErrors LoadWallet(bool &fFirstRunRet);
789  DBErrors ZapSelectTx(std::vector<TxId> &txIdsIn,
790  std::vector<TxId> &txIdsOut)
793  bool SetAddressBook(const CTxDestination &address,
794  const std::string &strName, const std::string &purpose);
796  bool DelAddressBook(const CTxDestination &address);
798  unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
802  void SetMinVersion(enum WalletFeature, WalletBatch *batch_in = nullptr,
803  bool fExplicit = false) override;
807  bool SetMaxVersion(int nVersion);
811  int GetVersion() const {
812  LOCK(cs_wallet);
813  return nWalletVersion;
814  }
818  std::set<TxId> GetConflicts(const TxId &txid) const
823  bool HasWalletSpend(const TxId &txid) const
827  void Flush();
830  void Close();
833  boost::signals2::signal<void()> NotifyUnload;
839  boost::signals2::signal<void(CWallet *wallet, const CTxDestination &address,
840  const std::string &label, bool isMine,
841  const std::string &purpose, ChangeType status)>
848  boost::signals2::signal<void(CWallet *wallet, const TxId &txid,
849  ChangeType status)>
853  boost::signals2::signal<void(const std::string &title, int nProgress)>
857  boost::signals2::signal<void(bool fHaveWatchOnly)> NotifyWatchonlyChanged;
860  boost::signals2::signal<void()> NotifyCanGetAddressesChanged;
866  boost::signals2::signal<void(CWallet *wallet)> NotifyStatusChanged;
871  void SetBroadcastTransactions(bool broadcast) {
872  fBroadcastTransactions = broadcast;
873  }
876  bool TransactionCanBeAbandoned(const TxId &txid) const;
882  bool AbandonTransaction(const TxId &txid);
888  static std::shared_ptr<CWallet>
889  Create(interfaces::Chain &chain, const std::string &name,
890  std::unique_ptr<WalletDatabase> database,
891  uint64_t wallet_creation_flags, bilingual_str &error,
892  std::vector<bilingual_str> &warnings);
899  void postInitProcess();
901  bool BackupWallet(const std::string &strDest) const;
903  /* Returns true if HD is enabled */
904  bool IsHDEnabled() const;
910  bool CanGetAddresses(bool internal = false) const;
918  void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main)
924  void SetWalletFlag(uint64_t flags);
929  void UnsetWalletFlag(uint64_t flag);
934  bool IsWalletFlagSet(uint64_t flag) const override;
940  bool AddWalletFlags(uint64_t flags);
942  bool LoadWalletFlags(uint64_t flags);
945  bool IsLegacy() const;
951  const std::string GetDisplayName() const override {
952  std::string wallet_name =
953  GetName().length() == 0 ? "default wallet" : GetName();
954  return strprintf("[%s]", wallet_name);
955  };
961  template <typename... Params>
962  void WalletLogPrintf(std::string fmt, Params... parameters) const {
963  LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
964  };
966  template <typename... Params>
967  void WalletLogPrintfToBeContinued(std::string fmt,
968  Params... parameters) const {
969  LogPrintfToBeContinued(("%s " + fmt).c_str(), GetDisplayName(),
970  parameters...);
971  };
974  bool UpgradeWallet(int version, bilingual_str &error);
978  std::set<ScriptPubKeyMan *> GetActiveScriptPubKeyMans() const;
981  std::set<ScriptPubKeyMan *> GetAllScriptPubKeyMans() const;
986  bool internal) const;
989  ScriptPubKeyMan *GetScriptPubKeyMan(const CScript &script) const;
991  ScriptPubKeyMan *GetScriptPubKeyMan(const uint256 &id) const;
995  std::set<ScriptPubKeyMan *>
996  GetScriptPubKeyMans(const CScript &script, SignatureData &sigdata) const;
999  std::unique_ptr<SigningProvider>
1000  GetSolvingProvider(const CScript &script) const;
1001  std::unique_ptr<SigningProvider>
1002  GetSolvingProvider(const CScript &script, SignatureData &sigdata) const;
1013  const CKeyingMaterial &GetEncryptionKey() const override;
1014  bool HasEncryptionKeys() const override;
1019  assert(m_last_block_processed_height >= 0);
1020  return m_last_block_processed_height;
1021  };
1024  assert(m_last_block_processed_height >= 0);
1025  return m_last_block_processed;
1026  }
1028  void SetLastBlockProcessed(int block_height, BlockHash block_hash)
1031  m_last_block_processed_height = block_height;
1032  m_last_block_processed = block_hash;
1033  };
1049  void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1058  void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1070  ScriptPubKeyMan *
1072  const FlatSigningProvider &signing_provider,
1073  const std::string &label, bool internal);
1074 };
1081 void MaybeResendWalletTxs();
1085 private:
1089 public:
1091  : m_wallet(w), m_could_reserve(false) {}
1093  bool reserve() {
1095  if ( {
1096  return false;
1097  }
1098  m_wallet.m_scanning_start = GetTimeMillis();
1099  m_wallet.m_scanning_progress = 0;
1100  m_could_reserve = true;
1101  return true;
1102  }
1104  bool isReserved() const {
1105  return (m_could_reserve && m_wallet.fScanningWallet);
1106  }
1109  if (m_could_reserve) {
1110  m_wallet.fScanningWallet = false;
1111  }
1112  }
1113 };
1116 bool AddWalletSetting(interfaces::Chain &chain, const std::string &wallet_name);
1121  const std::string &wallet_name);
static constexpr Amount SATOSHI
Definition: amount.h:143
static constexpr Amount COIN
Definition: amount.h:144
int flags
Definition: bitcoin-tx.cpp:538
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:113
const CChainParams & Params()
Return the currently selected parameters.
Address book data.
Definition: wallet.h:200
const std::string & GetLabel() const
Definition: wallet.h:214
StringMap destdata
Definition: wallet.h:211
std::map< std::string, std::string > StringMap
Definition: wallet.h:210
std::string m_label
Definition: wallet.h:203
std::string purpose
Definition: wallet.h:206
bool IsChange() const
Definition: wallet.h:213
void SetLabel(const std::string &label)
Definition: wallet.h:215
Definition: block.h:55
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:280
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
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:194
An input of a transaction.
Definition: transaction.h:61
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:355
An output of a transaction.
Definition: transaction.h:130
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:3248
std::atomic< int64_t > m_best_block_time
Definition: wallet.h:279
bool Lock()
Definition: wallet.cpp:3148
BlockHash GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:1022
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:3219
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition: wallet.h:833
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:3117
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:693
uint64_t nAccountingEntryNumber
Definition: wallet.h:432
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
Definition: wallet.cpp:3306
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Adds the active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3359
void SetupLegacyScriptPubKeyMan()
Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
Definition: wallet.cpp:3283
Mutex m_unlock_mutex
Definition: wallet.h:562
ScriptPubKeyMan * AddWalletDescriptor(WalletDescriptor &desc, const FlatSigningProvider &signing_provider, const std::string &label, bool internal)
Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type.
Definition: wallet.cpp:3410
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:2614
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Definition: wallet.h:860
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:951
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:3107
bool IsTxImmatureCoinBase(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3129
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:854
RecursiveMutex cs_wallet
Definition: wallet.h:388
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
Definition: wallet.cpp:3167
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:869
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:962
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:3321
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:3278
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
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:2638
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:733
bool IsLegacy() const
Determine if we are a legacy wallet.
Definition: wallet.cpp:3384
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:3370
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:2700
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:871
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:842
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
Definition: wallet.h:1017
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: wallet.h:866
OutputType m_default_address_type
Definition: wallet.h:736
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan(const WalletDescriptor &desc) const
Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.
Definition: wallet.cpp:3394
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:3314
LegacyScriptPubKeyMan * GetLegacyScriptPubKeyMan() const
Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
Definition: wallet.cpp:3264
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:735
std::map< CTxDestination, CAddressBookData > m_address_book GUARDED_BY(cs_wallet)
CFeeRate m_pay_tx_fee
Definition: wallet.h:722
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:3090
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:2572
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:967
std::unique_ptr< WalletDatabase > database
Internal database handle.
Definition: wallet.h:356
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:3182
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:527
CFeeRate m_min_fee
Definition: wallet.h:727
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:2657
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:857
bool IsLocked() const override
Definition: wallet.cpp:3140
bool m_allow_fallback_fee
will be false if -fallbackfee=0
Definition: wallet.h:725
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
Definition: wallet.h:376
std::atomic< double > m_scanning_progress
Definition: wallet.h:264
Definition: wallet.h:411
int GetVersion() const
get the current wallet format (the oldest client version guaranteed to understand this wallet)
Definition: wallet.h:811
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2480
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:2624
boost::signals2::signal< void(CWallet *wallet, const TxId &txid, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:850
bool HasEncryptionKeys() const override
Definition: wallet.cpp:3302
bool m_spend_zero_conf_change
Definition: wallet.h:723
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:748
bool UpgradeWallet(int version, bilingual_str &error)
Upgrade the wallet.
Definition: wallet.cpp:3036
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:3203
bool IsCrypted() const
Definition: wallet.cpp:3136
std::atomic< bool > fScanningWallet
Definition: wallet.h:262
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans.
Definition: wallet.cpp:3195
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:743
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:2633
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:3079
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:1028
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3024
const CKeyingMaterial & GetEncryptionKey() const override
Definition: wallet.cpp:3298
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:162
bool fInternal
Whether this is from the internal (change output) keypool.
Definition: wallet.h:175
OutputType const type
Definition: wallet.h:169
Definition: wallet.h:188
ReserveDestination(CWallet *_pwallet, OutputType _type)
Construct a ReserveDestination object.
Definition: wallet.h:180
ReserveDestination & operator=(const ReserveDestination &)=delete
ScriptPubKeyMan * m_spk_man
The ScriptPubKeyMan to reserve from.
Definition: wallet.h:168
int64_t nIndex
The index of the address's key in the keypool.
Definition: wallet.h:171
CTxDestination address
The destination.
Definition: wallet.h:173
ReserveDestination(const ReserveDestination &)=delete
const CWallet *const pwallet
The wallet to reserve from.
Definition: wallet.h:165
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:1084
bool isReserved() const
Definition: wallet.h:1104
CWallet & m_wallet
Definition: wallet.h:1086
WalletRescanReserver(CWallet &w)
Definition: wallet.h:1090
Chain notifications.
Definition: chain.h:263
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
Definition: error.h:22
void LockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2450
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:2373
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2296
void KeepDestination()
Keep the address.
Definition: wallet.cpp:2433
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2471
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2307
bool IsLockedCoin(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2465
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
Definition: wallet.cpp:2091
void UnlockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2455
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:2255
DBErrors LoadWallet(bool &fFirstRunRet)
Definition: wallet.cpp:2166
OutputType TransactionChangeType(const std::optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend) const
Definition: wallet.cpp:2105
bool SignTransaction(CMutableTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2000
void ReturnDestination()
Return reserved address.
Definition: wallet.cpp:2442
bool GetNewChangeDestination(const OutputType type, CTxDestination &dest, std::string &error)
Definition: wallet.cpp:2346
void UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2460
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:2121
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:2317
bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::string &strPurpose)
Definition: wallet.cpp:2228
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:2047
bool GetReservedDestination(CTxDestination &pubkey, bool internal)
Reserve an address.
Definition: wallet.cpp:2412
int64_t GetOldestKeyPoolTime() const
Definition: wallet.cpp:2363
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:2262
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination &dest, std::string &error)
Definition: wallet.cpp:2326
DBErrors ZapSelectTx(std::vector< TxId > &txIdsIn, std::vector< TxId > &txIdsOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2196
std::set< CTxDestination > GetLabelAddresses(const std::string &label) const
Definition: wallet.cpp:2394
bool AddWalletFlags(uint64_t flags)
Overwrite all flags by the given uint64_t.
Definition: wallet.cpp:1529
void blockConnected(const CBlock &block, int height) override
Definition: wallet.cpp:1351
bool LoadToWallet(const TxId &txid, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1043
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:1226
void Flush()
Flush wallet (bitdb flush)
Definition: wallet.cpp:601
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
Definition: wallet.cpp:399
bool SetMaxVersion(int nVersion)
change which version we're allowed to upgrade to (note that this does not immediately imply upgrading...
Definition: wallet.cpp:553
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:1604
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:566
void MarkDirty()
Definition: wallet.cpp:891
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:1878
void AddToSpends(const COutPoint &outpoint, const TxId &wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:679
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:1283
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1584
CWalletTx * AddToWallet(CTransactionRef tx, const CWalletTx::Confirmation &confirm, const UpdateWalletTxFn &update_wtx=nullptr, bool fFlushOnClose=true)
Definition: wallet.cpp:949
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:595
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:443
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
Definition: wallet.cpp:1446
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1594
isminetype IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1421
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
Definition: wallet.cpp:1518
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:1618
bool CanGetAddresses(bool internal=false) const
Returns true if the wallet can give out new addresses.
Definition: wallet.cpp:1473
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:1704
bool IsSpentKey(const TxId &txid, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:922
bool TransactionCanBeAbandoned(const TxId &txid) const
Return whether transaction can be abandoned.
Definition: wallet.cpp:1151
const CChainParams & GetChainParams() const override
Definition: wallet.cpp:383
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:1400
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:1158
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:1094
bool IsSpent(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction, spends it:
Definition: wallet.cpp:658
void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1845
bool IsHDEnabled() const
Definition: wallet.cpp:1464
void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag)
Unsets a wallet flag and saves it to disk.
Definition: wallet.cpp:1501
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:609
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:703
void updatedBlockTip() override
Definition: wallet.cpp:1383
void UnsetWalletFlag(uint64_t flag)
Unsets a single wallet flag.
Definition: wallet.cpp:1496
void transactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
Definition: wallet.cpp:1309
bool IsWalletFlagSet(uint64_t flag) const override
Check if a certain wallet flag is set.
Definition: wallet.cpp:1514
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
Definition: wallet.cpp:1653
bool AbandonTransaction(const TxId &txid)
Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent.
Definition: wallet.cpp:1167
void UnsetBlankWalletFlag(WalletBatch &batch) override
Unset the blank wallet flag and saves it to disk.
Definition: wallet.cpp:1510
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:898
void transactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence) override
Definition: wallet.cpp:1296
DBErrors ReorderTransactions()
Definition: wallet.cpp:823
void blockDisconnected(const CBlock &block, int height) override
Definition: wallet.cpp:1366
void Close()
Close wallet database.
Definition: wallet.cpp:605
int64_t IncOrderPosNext(WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Increment the next transaction order id.
Definition: wallet.cpp:879
const CWalletTx * GetWalletTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:389
void ResendWalletTransactions()
Definition: wallet.cpp:1939
void SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr, bool fExplicit=false) override
signify that a particular wallet feature is now used.
Definition: wallet.cpp:525
std::set< TxId > GetTxConflicts(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1919
bool DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig=false) const
Definition: wallet.cpp:1543
void chainStateFlushed(const CBlockLocator &loc) override
Definition: wallet.cpp:520
uint8_t isminefilter
Definition: wallet.h:41
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:220
#define LogPrintf(...)
Definition: logging.h:204
Definition: message.h:47
Definition: outputtype.h:16
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:321
const char * prefix
Definition: rest.cpp:821
const char * name
Definition: rest.cpp:49
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:56
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:93
Definition: amount.h:19
static constexpr Amount zero()
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:100
CScript scriptPubKey
Definition: wallet.h:222
Amount nAmount
Definition: wallet.h:223
bool fSubtractFeeFromAmount
Definition: wallet.h:224
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:234
size_t change_spend_size
Definition: wallet.h:230
size_t tx_noinputs_size
Definition: wallet.h:232
CFeeRate effective_fee
Definition: wallet.h:231
size_t change_output_size
Definition: wallet.h:229
CoinSelectionParams(bool use_bnb_, size_t change_output_size_, size_t change_spend_size_, CFeeRate effective_fee_, size_t tx_noinputs_size_)
Definition: wallet.h:236
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:243
bool error(const char *fmt, const Args &...args)
Definition: system.h:45
Definition: threadsafety.h:56
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:55
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:106
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
Definition: txmempool.h:290
General change type (added, updated, removed).
Definition: ui_change_type.h:9
Definition: db.h:229
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:479
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:111
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:262
constexpr Amount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:82
std::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
Definition: wallet.cpp:164
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:107
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Definition: wallet.cpp:2670
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:118
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:127
static constexpr uint64_t MUTABLE_WALLET_FLAGS
Definition: wallet.h:134
constexpr Amount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
Definition: wallet.h:114
const std::map< uint64_t, std::string > WALLET_FLAG_CAVEATS
Definition: wallet.cpp:41
static const std::map< std::string, WalletFlags > WALLET_FLAG_MAP
Definition: wallet.h:136
static constexpr size_t DUMMY_P2PKH_INPUT_SIZE
Pre-calculated constants for input size estimation.
Definition: wallet.h:116
void MaybeResendWalletTxs()
Called periodically by the schedule thread.
Definition: wallet.cpp:1988
static const Amount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:84
-mintxfee default
Definition: wallet.h:86
std::shared_ptr< CWallet > GetWallet(const std::string &name)
Definition: wallet.cpp:153
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:280
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
Definition: wallet.cpp:199
Default for -spendzeroconfchange.
Definition: wallet.h:103
static constexpr uint64_t KNOWN_WALLET_FLAGS
Definition: wallet.h:129
-maxtxfee default
Definition: wallet.h:109
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:52
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:67
Definition: wallet.h:106
constexpr Amount HIGH_APS_FEE
discourage APS fee higher than this amount
Definition: wallet.h:99
Default for -walletrejectlongchains.
Definition: wallet.h:105
minimum recommended increment for BIP 125 replacement txs
std::vector< std::shared_ptr< CWallet > > GetWallets()
Definition: wallet.cpp:148
bool AddWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:104
Error statuses for the wallet database.
Definition: walletdb.h:45
Definition: walletutil.h:55
Definition: walletutil.h:47
Definition: walletutil.h:51
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:70
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
Definition: walletutil.h:67
(client) version numbers for particular wallet features
Definition: walletutil.h:14
Definition: walletutil.h:17