BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
wallet.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_WALLET_WALLET_H
7 #define BITCOIN_WALLET_WALLET_H
8 
9 #include <amount.h>
10 #include <outputtype.h>
11 #include <policy/feerate.h>
12 #include <streams.h>
13 #include <tinyformat.h>
14 #include <ui_interface.h>
15 #include <utilstrencodings.h>
16 #include <validationinterface.h>
17 #include <script/ismine.h>
18 #include <script/sign.h>
19 #include <util.h>
20 #include <wallet/crypter.h>
21 #include <wallet/coinselection.h>
22 #include <wallet/walletdb.h>
23 #include <wallet/rpcwallet.h>
24 
25 #include <algorithm>
26 #include <atomic>
27 #include <map>
28 #include <memory>
29 #include <set>
30 #include <stdexcept>
31 #include <stdint.h>
32 #include <string>
33 #include <utility>
34 #include <vector>
35 
36 bool AddWallet(const std::shared_ptr<CWallet>& wallet);
37 bool RemoveWallet(const std::shared_ptr<CWallet>& wallet);
38 bool HasWallets();
39 std::vector<std::shared_ptr<CWallet>> GetWallets();
40 std::shared_ptr<CWallet> GetWallet(const std::string& name);
41 
43 extern std::vector<std::shared_ptr<CWallet>> vpwallets GUARDED_BY(cs_wallets);
44 
46 static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
50 static const CAmount DEFAULT_FALLBACK_FEE = 20000;
52 static const CAmount DEFAULT_DISCARD_FEE = 10000;
54 static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
56 static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
58 static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
60 static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false;
62 static const bool DEFAULT_AVOIDPARTIALSPENDS = false;
64 static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
66 static const bool DEFAULT_WALLET_RBF = false;
67 static const bool DEFAULT_WALLETBROADCAST = true;
68 static const bool DEFAULT_DISABLE_WALLET = false;
69 
70 class CBlockIndex;
71 class CCoinControl;
72 class COutput;
73 class CReserveKey;
74 class CScript;
75 class CTxMemPool;
77 class CWalletTx;
78 struct FeeCalculation;
79 enum class FeeEstimateMode;
80 
83 {
84  FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getwalletinfo's clientversion output)
85 
86  FEATURE_WALLETCRYPT = 40000, // wallet encryption
87  FEATURE_COMPRPUBKEY = 60000, // compressed public keys
88 
89  FEATURE_HD = 130000, // Hierarchical key derivation after BIP32 (HD Wallet)
90 
91  FEATURE_HD_SPLIT = 139900, // Wallet with HD chain split (change outputs will use m/0'/1'/k)
92 
93  FEATURE_NO_DEFAULT_KEY = 159900, // Wallet without a default key written
94 
95  FEATURE_PRE_SPLIT_KEYPOOL = 169900, // Upgraded to HD SPLIT and can have a pre-split keypool
96 
98 };
99 
102 
105 
106 enum WalletFlags : uint64_t {
107  // wallet flags in the upper section (> 1 << 31) will lead to not opening the wallet if flag is unknown
108  // unknown wallet flags in the lower section <= (1 << 31) will be tolerated
109 
110  // will enforce the rule that the wallet can't contain any private keys (only watch-only/pubkeys)
112 };
113 
114 static constexpr uint64_t g_known_wallet_flags = WALLET_FLAG_DISABLE_PRIVATE_KEYS;
115 
117 class CKeyPool
118 {
119 public:
120  int64_t nTime;
122  bool fInternal; // for change outputs
123  bool m_pre_split; // For keys generated before keypool split upgrade
124 
125  CKeyPool();
126  CKeyPool(const CPubKey& vchPubKeyIn, bool internalIn);
127 
129 
130  template <typename Stream, typename Operation>
131  inline void SerializationOp(Stream& s, Operation ser_action) {
132  int nVersion = s.GetVersion();
133  if (!(s.GetType() & SER_GETHASH))
134  READWRITE(nVersion);
135  READWRITE(nTime);
137  if (ser_action.ForRead()) {
138  try {
140  }
141  catch (std::ios_base::failure&) {
142  /* flag as external address if we can't read the internal boolean
143  (this will be the case for any wallet before the HD chain split version) */
144  fInternal = false;
145  }
146  try {
148  }
149  catch (std::ios_base::failure&) {
150  /* flag as postsplit address if we can't read the m_pre_split boolean
151  (this will be the case for any wallet that upgrades to HD chain split)*/
152  m_pre_split = false;
153  }
154  }
155  else {
158  }
159  }
160 };
161 
164 {
165 public:
166  std::string name;
167  std::string purpose;
168 
169  CAddressBookData() : purpose("unknown") {}
170 
171  typedef std::map<std::string, std::string> StringMap;
173 };
174 
176 {
180 };
181 
182 typedef std::map<std::string, std::string> mapValue_t;
183 
184 
185 static inline void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
186 {
187  if (!mapValue.count("n"))
188  {
189  nOrderPos = -1; // TODO: calculate elsewhere
190  return;
191  }
192  nOrderPos = atoi64(mapValue["n"].c_str());
193 }
194 
195 
196 static inline void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
197 {
198  if (nOrderPos == -1)
199  return;
200  mapValue["n"] = i64tostr(nOrderPos);
201 }
202 
204 {
207  int vout;
208 };
209 
212 {
213 private:
215  static const uint256 ABANDON_HASH;
216 
217 public:
220 
221  /* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest
222  * block in the chain we know this or any in-wallet dependency conflicts
223  * with. Older clients interpret nIndex == -1 as unconfirmed for backward
224  * compatibility.
225  */
226  int nIndex;
227 
229  {
230  SetTx(MakeTransactionRef());
231  Init();
232  }
233 
235  {
236  SetTx(std::move(arg));
237  Init();
238  }
239 
240  void Init()
241  {
242  hashBlock = uint256();
243  nIndex = -1;
244  }
245 
247  {
248  tx = std::move(arg);
249  }
250 
252 
253  template <typename Stream, typename Operation>
254  inline void SerializationOp(Stream& s, Operation ser_action) {
255  std::vector<uint256> vMerkleBranch; // For compatibility with older versions.
256  READWRITE(tx);
258  READWRITE(vMerkleBranch);
259  READWRITE(nIndex);
260  }
261 
262  void SetMerkleBranch(const CBlockIndex* pIndex, int posInBlock);
263 
272 
279  bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
280  bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
282 
283  const uint256& GetHash() const { return tx->GetHash(); }
284  bool IsCoinBase() const { return tx->IsCoinBase(); }
286 };
287 
288 //Get the marginal bytes of spending the specified output
289 int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* pwallet, bool use_max_sig = false);
290 
295 class CWalletTx : public CMerkleTx
296 {
297 private:
298  const CWallet* pwallet;
299 
300 public:
327  std::vector<std::pair<std::string, std::string> > vOrderForm;
328  unsigned int fTimeReceivedIsTxTime;
329  unsigned int nTimeReceived;
330 
339  unsigned int nTimeSmart;
345  char fFromMe;
346  int64_t nOrderPos;
347  std::multimap<int64_t, CWalletTx*>::const_iterator m_it_wtxOrdered;
348 
349  // memory only
350  mutable bool fDebitCached;
351  mutable bool fCreditCached;
352  mutable bool fImmatureCreditCached;
354  mutable bool fWatchDebitCached;
355  mutable bool fWatchCreditCached;
358  mutable bool fChangeCached;
359  mutable bool fInMempool;
369 
370  CWalletTx(const CWallet* pwalletIn, CTransactionRef arg) : CMerkleTx(std::move(arg))
371  {
372  Init(pwalletIn);
373  }
374 
375  void Init(const CWallet* pwalletIn)
376  {
377  pwallet = pwalletIn;
378  mapValue.clear();
379  vOrderForm.clear();
380  fTimeReceivedIsTxTime = false;
381  nTimeReceived = 0;
382  nTimeSmart = 0;
383  fFromMe = false;
384  fDebitCached = false;
385  fCreditCached = false;
386  fImmatureCreditCached = false;
387  fAvailableCreditCached = false;
388  fWatchDebitCached = false;
389  fWatchCreditCached = false;
390  fImmatureWatchCreditCached = false;
391  fAvailableWatchCreditCached = false;
392  fChangeCached = false;
393  fInMempool = false;
394  nDebitCached = 0;
395  nCreditCached = 0;
396  nImmatureCreditCached = 0;
397  nAvailableCreditCached = 0;
398  nWatchDebitCached = 0;
399  nWatchCreditCached = 0;
400  nAvailableWatchCreditCached = 0;
401  nImmatureWatchCreditCached = 0;
402  nChangeCached = 0;
403  nOrderPos = -1;
404  }
405 
406  template<typename Stream>
407  void Serialize(Stream& s) const
408  {
409  char fSpent = false;
410  mapValue_t mapValueCopy = mapValue;
411 
412  mapValueCopy["fromaccount"] = "";
413  WriteOrderPos(nOrderPos, mapValueCopy);
414  if (nTimeSmart) {
415  mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);
416  }
417 
418  s << static_cast<const CMerkleTx&>(*this);
419  std::vector<CMerkleTx> vUnused;
420  s << vUnused << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime << nTimeReceived << fFromMe << fSpent;
421  }
422 
423  template<typename Stream>
424  void Unserialize(Stream& s)
425  {
426  Init(nullptr);
427  char fSpent;
428 
429  s >> static_cast<CMerkleTx&>(*this);
430  std::vector<CMerkleTx> vUnused;
431  s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >> nTimeReceived >> fFromMe >> fSpent;
432 
433  ReadOrderPos(nOrderPos, mapValue);
434  nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
435 
436  mapValue.erase("fromaccount");
437  mapValue.erase("spent");
438  mapValue.erase("n");
439  mapValue.erase("timesmart");
440  }
441 
443  void MarkDirty()
444  {
445  fCreditCached = false;
446  fAvailableCreditCached = false;
447  fImmatureCreditCached = false;
448  fWatchDebitCached = false;
449  fWatchCreditCached = false;
450  fAvailableWatchCreditCached = false;
451  fImmatureWatchCreditCached = false;
452  fDebitCached = false;
453  fChangeCached = false;
454  }
455 
456  void BindWallet(CWallet *pwalletIn)
457  {
458  pwallet = pwalletIn;
459  MarkDirty();
460  }
461 
463  CAmount GetDebit(const isminefilter& filter) const;
465  CAmount GetImmatureCredit(bool fUseCache=true) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
466  // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
467  // annotation "EXCLUSIVE_LOCKS_REQUIRED(cs_main, pwallet->cs_wallet)". The
468  // annotation "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid
469  // having to resolve the issue of member access into incomplete type CWallet.
470  CAmount GetAvailableCredit(bool fUseCache=true, const isminefilter& filter=ISMINE_SPENDABLE) const NO_THREAD_SAFETY_ANALYSIS;
471  CAmount GetImmatureWatchOnlyCredit(const bool fUseCache=true) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
472  CAmount GetChange() const;
473 
474  // Get the marginal bytes if spending the specified output from this transaction
475  int GetSpendSize(unsigned int out, bool use_max_sig = false) const
476  {
477  return CalculateMaximumSignedInputSize(tx->vout[out], pwallet, use_max_sig);
478  }
479 
480  void GetAmounts(std::list<COutputEntry>& listReceived,
481  std::list<COutputEntry>& listSent, CAmount& nFee, const isminefilter& filter) const;
482 
483  bool IsFromMe(const isminefilter& filter) const
484  {
485  return (GetDebit(filter) > 0);
486  }
487 
488  // True if only scriptSigs are different
489  bool IsEquivalentTo(const CWalletTx& tx) const;
490 
491  bool InMempool() const;
492  bool IsTrusted() const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
493 
494  int64_t GetTxTime() const;
495 
496  // RelayWalletTransaction may only be called if fBroadcastTransactions!
497  bool RelayWalletTransaction(CConnman* connman) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
498 
501 
502  // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
503  // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation
504  // "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having to
505  // resolve the issue of member access into incomplete type CWallet. Note
506  // that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)"
507  // in place.
508  std::set<uint256> GetConflicts() const NO_THREAD_SAFETY_ANALYSIS;
509 };
510 
511 class COutput
512 {
513 public:
514  const CWalletTx *tx;
515  int i;
516  int nDepth;
517 
520 
523 
525  bool fSolvable;
526 
529 
535  bool fSafe;
536 
537  COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn, bool use_max_sig_in = false)
538  {
539  tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; fSolvable = fSolvableIn; fSafe = fSafeIn; nInputBytes = -1; use_max_sig = use_max_sig_in;
540  // If known and signable by the given wallet, compute nInputBytes
541  // Failure will keep this value -1
542  if (fSpendable && tx) {
543  nInputBytes = tx->GetSpendSize(i, use_max_sig);
544  }
545  }
546 
547  std::string ToString() const;
548 
549  inline CInputCoin GetInputCoin() const
550  {
551  return CInputCoin(tx->tx, i, nInputBytes);
552  }
553 };
554 
557 {
558 public:
560  int64_t nTimeCreated;
561  int64_t nTimeExpires;
562  std::string strComment;
565 
566  explicit CWalletKey(int64_t nExpires=0);
567 
569 
570  template <typename Stream, typename Operation>
571  inline void SerializationOp(Stream& s, Operation ser_action) {
572  int nVersion = s.GetVersion();
573  if (!(s.GetType() & SER_GETHASH))
574  READWRITE(nVersion);
575  READWRITE(vchPrivKey);
576  READWRITE(nTimeCreated);
577  READWRITE(nTimeExpires);
578  READWRITE(LIMITED_STRING(strComment, 65536));
579  }
580 };
581 
583 {
584  bool use_bnb = true;
585  size_t change_output_size = 0;
586  size_t change_spend_size = 0;
587  CFeeRate effective_fee = CFeeRate(0);
588  size_t tx_noinputs_size = 0;
589 
590  CoinSelectionParams(bool use_bnb, size_t change_output_size, size_t change_spend_size, CFeeRate effective_fee, size_t tx_noinputs_size) : use_bnb(use_bnb), change_output_size(change_output_size), change_spend_size(change_spend_size), effective_fee(effective_fee), tx_noinputs_size(tx_noinputs_size) {}
592 };
593 
594 class WalletRescanReserver; //forward declarations for ScanForWalletTransactions/RescanFromTime
599 class CWallet final : public CCryptoKeyStore, public CValidationInterface
600 {
601 private:
602  std::atomic<bool> fAbortRescan{false};
603  std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
604  std::mutex mutexScanning;
605  friend class WalletRescanReserver;
606 
607  WalletBatch *encrypted_batch GUARDED_BY(cs_wallet) = nullptr;
608 
610  int nWalletVersion = FEATURE_BASE;
611 
613  int nWalletMaxVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
614 
615  int64_t nNextResend = 0;
616  int64_t nLastResend = 0;
617  bool fBroadcastTransactions = false;
618 
624  typedef std::multimap<COutPoint, uint256> TxSpends;
625  TxSpends mapTxSpends GUARDED_BY(cs_wallet);
626  void AddToSpends(const COutPoint& outpoint, const uint256& wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
627  void AddToSpends(const uint256& wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
628 
642  bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
643 
644  /* Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
645  void MarkConflicted(const uint256& hashBlock, const uint256& hashTx);
646 
647  /* Mark a transaction's inputs dirty, thus forcing the outputs to be recomputed */
648  void MarkInputsDirty(const CTransactionRef& tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
649 
650  void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
651 
652  /* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected/ScanForWalletTransactions.
653  * Should be called with pindexBlock and posInBlock if this is for a transaction that is included in a block. */
654  void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindex = nullptr, int posInBlock = 0, bool update_tx = true) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
655 
656  /* the HD chain data model (external chain counters) */
657  CHDChain hdChain;
658 
659  /* HD derive new child key (on internal or external chain) */
660  void DeriveNewChildKey(WalletBatch &batch, CKeyMetadata& metadata, CKey& secret, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
661 
662  std::set<int64_t> setInternalKeyPool;
663  std::set<int64_t> setExternalKeyPool GUARDED_BY(cs_wallet);
664  std::set<int64_t> set_pre_split_keypool;
665  int64_t m_max_keypool_index GUARDED_BY(cs_wallet) = 0;
666  std::map<CKeyID, int64_t> m_pool_key_to_index;
667  std::atomic<uint64_t> m_wallet_flags{0};
668 
669  int64_t nTimeFirstKey GUARDED_BY(cs_wallet) = 0;
670 
680  bool AddWatchOnly(const CScript& dest) override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
681 
687  std::string m_name;
688 
690  std::unique_ptr<WalletDatabase> database;
691 
702  const CBlockIndex* m_last_block_processed = nullptr;
703 
704 public:
705  /*
706  * Main wallet lock.
707  * This lock protects all the fields added by CWallet.
708  */
710 
715  {
716  return *database;
717  }
718 
724  bool SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet,
725  const CCoinControl& coin_control, CoinSelectionParams& coin_selection_params, bool& bnb_used) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
726 
729  const std::string& GetName() const { return m_name; }
730 
731  void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
732  void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
733 
734  // Map from Key ID to key metadata.
735  std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_wallet);
736 
737  // Map from Script ID to key metadata (for watch-only keys).
738  std::map<CScriptID, CKeyMetadata> m_script_metadata GUARDED_BY(cs_wallet);
739 
740  typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
741  MasterKeyMap mapMasterKeys;
742  unsigned int nMasterKeyMaxID = 0;
743 
745  CWallet(std::string name, std::unique_ptr<WalletDatabase> database) : m_name(std::move(name)), database(std::move(database))
746  {
747  }
748 
750  {
751  delete encrypted_batch;
752  encrypted_batch = nullptr;
753  }
754 
755  std::map<uint256, CWalletTx> mapWallet GUARDED_BY(cs_wallet);
756 
757  typedef std::multimap<int64_t, CWalletTx*> TxItems;
759 
760  int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
761  uint64_t nAccountingEntryNumber = 0;
762 
763  std::map<CTxDestination, CAddressBookData> mapAddressBook;
764 
765  std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
766 
767  const CWalletTx* GetWalletTx(const uint256& hash) const;
768 
770  bool CanSupportFeature(enum WalletFeature wf) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
771 
775  void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0, const int nMinDepth = 0, const int nMaxDepth = 9999999) const EXCLUSIVE_LOCKS_REQUIRED(cs_main, cs_wallet);
776 
781 
785  const CTxOut& FindNonChangeParentOutput(const CTransaction& tx, int output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
786 
793  bool SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibilityFilter& eligibility_filter, std::vector<OutputGroup> groups,
794  std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, const CoinSelectionParams& coin_selection_params, bool& bnb_used) const;
795 
796  bool IsSpent(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_main, cs_wallet);
797  std::vector<OutputGroup> GroupOutputs(const std::vector<COutput>& outputs, bool single_coin) const;
798 
799  bool IsLockedCoin(uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
800  void LockCoin(const COutPoint& output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
801  void UnlockCoin(const COutPoint& output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
802  void UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
803  void ListLockedCoins(std::vector<COutPoint>& vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
804 
805  /*
806  * Rescan abort properties
807  */
808  void AbortRescan() { fAbortRescan = true; }
809  bool IsAbortingRescan() { return fAbortRescan; }
810  bool IsScanning() { return fScanningWallet; }
811 
816  CPubKey GenerateNewKey(WalletBatch& batch, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
818  bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
819  bool AddKeyPubKeyWithDB(WalletBatch &batch,const CKey& key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
821  bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); }
823  void LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
824  void LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
825 
826  bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
827  void UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
828 
830  bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) override;
832  bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
833  bool AddCScript(const CScript& redeemScript) override;
834  bool LoadCScript(const CScript& redeemScript);
835 
837  bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
839  bool EraseDestData(const CTxDestination &dest, const std::string &key);
841  void LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
843  bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const;
845  std::vector<std::string> GetDestValues(const std::string& prefix) const;
846 
848  bool AddWatchOnly(const CScript& dest, int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
849  bool RemoveWatchOnly(const CScript &dest) override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
851  bool LoadWatchOnly(const CScript &dest);
852 
854  int64_t nRelockTime = 0;
855 
856  bool Unlock(const SecureString& strWalletPassphrase);
857  bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
858  bool EncryptWallet(const SecureString& strWalletPassphrase);
859 
860  void GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
861  unsigned int ComputeTimeSmart(const CWalletTx& wtx) const;
862 
867  int64_t IncOrderPosNext(WalletBatch *batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
868  DBErrors ReorderTransactions();
869 
870  void MarkDirty();
871  bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
872  void LoadToWallet(const CWalletTx& wtxIn) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
873  void TransactionAddedToMempool(const CTransactionRef& tx) override;
874  void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) override;
875  void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) override;
876  int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver, bool update);
877  CBlockIndex* ScanForWalletTransactions(CBlockIndex* pindexStart, CBlockIndex* pindexStop, const WalletRescanReserver& reserver, bool fUpdate = false);
878  void TransactionRemovedFromMempool(const CTransactionRef &ptx) override;
879  void ReacceptWalletTransactions();
880  void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) override EXCLUSIVE_LOCKS_REQUIRED(cs_main);
881  // ResendWalletTransactionsBefore may only be called if fBroadcastTransactions!
882  std::vector<uint256> ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
883  CAmount GetBalance(const isminefilter& filter=ISMINE_SPENDABLE, const int min_depth=0) const;
884  CAmount GetUnconfirmedBalance() const;
885  CAmount GetImmatureBalance() const;
886  CAmount GetUnconfirmedWatchOnlyBalance() const;
887  CAmount GetImmatureWatchOnlyBalance() const;
888  CAmount GetLegacyBalance(const isminefilter& filter, int minDepth) const;
889  CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const;
890 
891  OutputType TransactionChangeType(OutputType change_type, const std::vector<CRecipient>& vecSend);
892 
897  bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl);
899 
905  bool CreateTransaction(const std::vector<CRecipient>& vecSend, CTransactionRef& tx, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
906  std::string& strFailReason, const CCoinControl& coin_control, bool sign = true);
907  bool CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, CReserveKey& reservekey, CConnman* connman, CValidationState& state);
908 
909  bool DummySignTx(CMutableTransaction &txNew, const std::set<CTxOut> &txouts, bool use_max_sig = false) const
910  {
911  std::vector<CTxOut> v_txouts(txouts.size());
912  std::copy(txouts.begin(), txouts.end(), v_txouts.begin());
913  return DummySignTx(txNew, v_txouts, use_max_sig);
914  }
915  bool DummySignTx(CMutableTransaction &txNew, const std::vector<CTxOut> &txouts, bool use_max_sig = false) const;
916  bool DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig = false) const;
917 
919  unsigned int m_confirm_target{DEFAULT_TX_CONFIRM_TARGET};
920  bool m_spend_zero_conf_change{DEFAULT_SPEND_ZEROCONF_CHANGE};
921  bool m_signal_rbf{DEFAULT_WALLET_RBF};
922  bool m_allow_fallback_fee{true};
923  CFeeRate m_min_fee{DEFAULT_TRANSACTION_MINFEE};
924 
929  CFeeRate m_fallback_fee{DEFAULT_FALLBACK_FEE};
930  CFeeRate m_discard_rate{DEFAULT_DISCARD_FEE};
931  OutputType m_default_address_type{DEFAULT_ADDRESS_TYPE};
932  OutputType m_default_change_type{DEFAULT_CHANGE_TYPE};
933 
934  bool NewKeyPool();
935  size_t KeypoolCountExternalKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
936  bool TopUpKeyPool(unsigned int kpSize = 0);
937 
952  bool ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fRequestedInternal);
953  void KeepKey(int64_t nIndex);
954  void ReturnKey(int64_t nIndex, bool fInternal, const CPubKey& pubkey);
955  bool GetKeyFromPool(CPubKey &key, bool internal = false);
956  int64_t GetOldestKeyPoolTime();
960  void MarkReserveKeysAsUsed(int64_t keypool_id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
961  const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
962 
963  std::set<std::set<CTxDestination>> GetAddressGroupings() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
964  std::map<CTxDestination, CAmount> GetAddressBalances() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
965 
966  std::set<CTxDestination> GetLabelAddresses(const std::string& label) const;
967 
968  isminetype IsMine(const CTxIn& txin) const;
973  CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
974  isminetype IsMine(const CTxOut& txout) const;
975  CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
976  bool IsChange(const CTxOut& txout) const;
977  CAmount GetChange(const CTxOut& txout) const;
978  bool IsMine(const CTransaction& tx) const;
980  bool IsFromMe(const CTransaction& tx) const;
981  CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
983  bool IsAllFromMe(const CTransaction& tx, const isminefilter& filter) const;
984  CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
985  CAmount GetChange(const CTransaction& tx) const;
986  void ChainStateFlushed(const CBlockLocator& loc) override;
987 
988  DBErrors LoadWallet(bool& fFirstRunRet);
989  DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);
990  DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
991 
992  bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose);
993 
994  bool DelAddressBook(const CTxDestination& address);
995 
996  const std::string& GetLabelName(const CScript& scriptPubKey) const;
997 
998  void GetScriptForMining(std::shared_ptr<CReserveScript> &script);
999 
1000  unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
1001  {
1002  AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool
1003  return setInternalKeyPool.size() + setExternalKeyPool.size();
1004  }
1005 
1007  void SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr, bool fExplicit = false);
1008 
1010  bool SetMaxVersion(int nVersion);
1011 
1013  int GetVersion() { LOCK(cs_wallet); return nWalletVersion; }
1014 
1016  std::set<uint256> GetConflicts(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1017 
1019  bool HasWalletSpend(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1020 
1022  void Flush(bool shutdown=false);
1023 
1025  boost::signals2::signal<void ()> NotifyUnload;
1026 
1031  boost::signals2::signal<void (CWallet *wallet, const CTxDestination
1032  &address, const std::string &label, bool isMine,
1033  const std::string &purpose,
1035 
1040  boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx,
1042 
1044  boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
1045 
1047  boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
1048 
1050  bool GetBroadcastTransactions() const { return fBroadcastTransactions; }
1052  void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
1053 
1055  bool TransactionCanBeAbandoned(const uint256& hashTx) const;
1056 
1057  /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
1058  bool AbandonTransaction(const uint256& hashTx);
1059 
1061  bool MarkReplaced(const uint256& originalHash, const uint256& newHash);
1062 
1064  static bool Verify(std::string wallet_file, bool salvage_wallet, std::string& error_string, std::string& warning_string);
1065 
1066  /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
1067  static std::shared_ptr<CWallet> CreateWalletFromFile(const std::string& name, const fs::path& path, uint64_t wallet_creation_flags = 0);
1068 
1073  void postInitProcess();
1074 
1075  bool BackupWallet(const std::string& strDest);
1076 
1077  /* Set the HD chain model (chain child index counters) */
1078  void SetHDChain(const CHDChain& chain, bool memonly);
1079  const CHDChain& GetHDChain() const { return hdChain; }
1080 
1081  /* Returns true if HD is enabled */
1082  bool IsHDEnabled() const;
1083 
1084  /* Generates a new HD seed (will not be activated) */
1085  CPubKey GenerateNewSeed();
1086 
1087  /* Derives a new HD seed (will not be activated) */
1088  CPubKey DeriveNewSeed(const CKey& key);
1089 
1090  /* Set the current HD seed (will reset the chain child index counters)
1091  Sets the seed's version based on the current wallet version (so the
1092  caller must ensure the current wallet version is correct before calling
1093  this function). */
1094  void SetHDSeed(const CPubKey& key);
1095 
1102  void BlockUntilSyncedToCurrentChain() LOCKS_EXCLUDED(cs_main, cs_wallet);
1103 
1110  void LearnRelatedScripts(const CPubKey& key, OutputType);
1111 
1116  void LearnAllRelatedScripts(const CPubKey& key);
1117 
1119  void SetWalletFlag(uint64_t flags);
1120 
1122  bool IsWalletFlagSet(uint64_t flag);
1123 
1126  bool SetWalletFlags(uint64_t overwriteFlags, bool memOnly);
1127 
1129  const std::string GetDisplayName() const {
1130  std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName();
1131  return strprintf("[%s]", wallet_name);
1132  };
1133 
1135  template<typename... Params>
1136  void WalletLogPrintf(std::string fmt, Params... parameters) const {
1137  LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
1138  };
1139 
1141  bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
1142 };
1143 
1145 class CReserveKey final : public CReserveScript
1146 {
1147 protected:
1149  int64_t nIndex;
1152 public:
1153  explicit CReserveKey(CWallet* pwalletIn)
1154  {
1155  nIndex = -1;
1156  pwallet = pwalletIn;
1157  fInternal = false;
1158  }
1159 
1160  CReserveKey() = default;
1161  CReserveKey(const CReserveKey&) = delete;
1162  CReserveKey& operator=(const CReserveKey&) = delete;
1163 
1165  {
1166  ReturnKey();
1167  }
1168 
1169  void ReturnKey();
1170  bool GetReservedKey(CPubKey &pubkey, bool internal = false);
1171  void KeepKey();
1172  void KeepScript() override { KeepKey(); }
1173 };
1174 
1177 {
1178 private:
1181 public:
1182  explicit WalletRescanReserver(CWallet* w) : m_wallet(w), m_could_reserve(false) {}
1183 
1184  bool reserve()
1185  {
1186  assert(!m_could_reserve);
1187  std::lock_guard<std::mutex> lock(m_wallet->mutexScanning);
1188  if (m_wallet->fScanningWallet) {
1189  return false;
1190  }
1191  m_wallet->fScanningWallet = true;
1192  m_could_reserve = true;
1193  return true;
1194  }
1195 
1196  bool isReserved() const
1197  {
1198  return (m_could_reserve && m_wallet->fScanningWallet);
1199  }
1200 
1202  {
1203  std::lock_guard<std::mutex> lock(m_wallet->mutexScanning);
1204  if (m_could_reserve) {
1205  m_wallet->fScanningWallet = false;
1206  }
1207  }
1208 };
1209 
1210 // Calculate the size of the transaction assuming all signatures are max size
1211 // Use DummySignatureCreator, which inserts 71 byte signatures everywhere.
1212 // NOTE: this requires that all inputs must be in mapWallet (eg the tx should
1213 // be IsAllFromMe).
1214 int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig = false) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet);
1215 int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig = false);
1216 #endif // BITCOIN_WALLET_WALLET_H
int64_t nTimeCreated
Definition: wallet.h:560
bool fChangeCached
Definition: wallet.h:358
const CWallet * pwallet
Definition: wallet.h:298
std::atomic< bool > fScanningWallet
Definition: wallet.h:603
#define NO_THREAD_SAFETY_ANALYSIS
Definition: threadsafety.h:53
CWallet * pwallet
Definition: wallet.h:1148
void SetTx(CTransactionRef arg)
Definition: wallet.h:246
static const uint256 ABANDON_HASH
Constant used in hashBlock to indicate tx has been abandoned.
Definition: wallet.h:215
Result CreateTransaction(const CWallet *wallet, const uint256 &txid, const CCoinControl &coin_control, CAmount total_fee, std::vector< std::string > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)
Create bumpfee transaction.
Definition: feebumper.cpp:76
std::unique_ptr< WalletDatabase > database
Internal database handle.
Definition: wallet.h:690
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:571
int i
Definition: wallet.h:515
void SetMerkleBranch(const CBlockIndex *pIndex, int posInBlock)
Definition: wallet.cpp:4222
CAmount nImmatureWatchCreditCached
Definition: wallet.h:366
void BindWallet(CWallet *pwalletIn)
Definition: wallet.h:456
std::map< std::string, std::string > mapValue_t
Definition: wallet.h:182
bool CanSupportFeature(enum WalletFeature wf) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
check whether we are allowed to upgrade (or already support) to the named feature ...
Definition: wallet.h:770
bool fSolvable
Whether we know how to spend this output, ignoring the lack of keys.
Definition: wallet.h:525
CPrivKey vchPrivKey
Definition: wallet.h:559
int64_t nIndex
Definition: wallet.h:1149
Describes a place in the block chain to another node such that if the other node doesn&#39;t have the sam...
Definition: block.h:128
CAmount nCreditCached
Definition: wallet.h:361
char fFromMe
From me flag is set to 1 for transactions that were created by the wallet on this bitcoin node...
Definition: wallet.h:345
CAmount nChangeCached
Definition: wallet.h:368
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:48
Definition: block.h:74
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:763
#define strprintf
Definition: tinyformat.h:1066
const uint256 & GetHash() const
Definition: wallet.h:283
bool IsFromMe(const isminefilter &filter) const
Definition: wallet.h:483
int nIndex
Definition: wallet.h:226
constexpr OutputType DEFAULT_CHANGE_TYPE
Default for -changetype.
Definition: wallet.h:104
bool use_max_sig
Whether to use the maximum sized, 72 byte signature when calculating the size of the input spend...
Definition: wallet.h:528
bool fImmatureCreditCached
Definition: wallet.h:352
bool AddWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:43
FeeEstimateMode
Definition: fees.h:52
TxItems wtxOrdered
Definition: wallet.h:758
const char * prefix
Definition: rest.cpp:581
bool fInternal
Definition: wallet.h:1151
Private key encryption is done based on a CMasterKey, which holds a salt and random encryption key...
Definition: crypter.h:34
uint256 hashBlock
Definition: wallet.h:219
std::multimap< COutPoint, uint256 > TxSpends
Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated tran...
Definition: wallet.h:624
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:56
int64_t nOrderPos
position in ordered transaction list
Definition: wallet.h:346
std::multimap< int64_t, CWalletTx * >::const_iterator m_it_wtxOrdered
Definition: wallet.h:347
An instance of this class represents one database.
Definition: db.h:104
CMerkleTx(CTransactionRef arg)
Definition: wallet.h:234
uint8_t isminefilter
used for bitflags of isminetype
Definition: ismine.h:25
std::vector< std::shared_ptr< CWallet > > vpwallets GUARDED_BY(cs_wallets)
WalletFeature
(client) version numbers for particular wallet features
Definition: wallet.h:82
CPubKey vchPubKey
Definition: wallet.h:1150
void MarkDirty()
make sure balances are recalculated
Definition: wallet.h:443
bool fSubtractFeeFromAmount
Definition: wallet.h:179
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:740
std::string strComment
Definition: wallet.h:562
std::string name
Definition: wallet.h:166
int nInputBytes
Pre-computed estimated size of this output as a fully-signed input in a transaction.
Definition: wallet.h:519
~CReserveKey()
Definition: wallet.h:1164
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:47
CAmount nWatchDebitCached
Definition: wallet.h:364
Keystore which keeps the private keys encrypted.
Definition: crypter.h:115
CCriticalSection cs_wallets
Definition: wallet.cpp:40
bool fSpendable
Whether we have the private keys to spend this output.
Definition: wallet.h:522
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:402
int64_t nTimeExpires
Definition: wallet.h:561
bool fAvailableCreditCached
Definition: wallet.h:353
Implement this to subscribe to events generated in validation.
bool IsNull() const
Definition: uint256.h:32
std::string purpose
Definition: wallet.h:167
void Init()
Definition: wallet.h:240
OutputType
Definition: outputtype.h:15
Coin Control Features.
Definition: coincontrol.h:16
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced, bool bypass_limits, const CAmount nAbsurdFee, bool test_accept)
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions repla...
Definition: validation.cpp:986
Access to the wallet database.
Definition: walletdb.h:139
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: wallet.h:326
std::mutex mutexScanning
Definition: wallet.h:604
bool fDebitCached
Definition: wallet.h:350
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition: wallet.h:1025
bool fAvailableWatchCreditCached
Definition: wallet.h:357
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
Definition: crypter.cpp:216
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
secure_allocator is defined in allocators.h CPrivKey is a serialized private key, with all parameters...
Definition: key.h:24
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:1041
#define AssertLockHeld(cs)
Definition: sync.h:70
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:1052
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn, bool use_max_sig_in=false)
Definition: wallet.h:537
isminefilter filter
Definition: rpcwallet.cpp:1011
int64_t nTime
Definition: wallet.h:120
void Unserialize(Stream &s)
Definition: wallet.h:424
CScript scriptPubKey
Definition: wallet.h:177
CCriticalSection cs_main
Definition: validation.cpp:216
int GetDepthInMainChain() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
Definition: wallet.cpp:4231
int nDepth
Definition: wallet.h:516
ChangeType
General change type (added, updated, removed).
Definition: ui_interface.h:23
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:1136
CTransactionRef tx
Definition: wallet.h:218
isminetype
IsMine() return codes.
Definition: ismine.h:17
An input of a transaction.
Definition: transaction.h:61
boost::variant< CNoDestination, CKeyID, CScriptID, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:123
int CalculateMaximumSignedInputSize(const CTxOut &txout, const CWallet *pwallet, bool use_max_sig=false)
Definition: wallet.cpp:1517
#define LOCK(cs)
Definition: sync.h:181
const char * name
Definition: rest.cpp:37
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
Definition: fees.h:136
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet) ...
Definition: wallet.h:1013
CKeyPool()
Definition: wallet.cpp:4201
int GetBlocksToMaturity() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: wallet.cpp:4246
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:254
An encapsulated public key.
Definition: pubkey.h:30
bool fSafe
Whether this output is considered safe to spend.
Definition: wallet.h:535
CAmount amount
Definition: wallet.h:206
void KeepScript() override
Definition: wallet.h:1172
bool IsCoinBase() const
Definition: wallet.h:284
std::map< std::string, std::string > StringMap
Definition: wallet.h:171
WalletDatabase & GetDBHandle()
Get database handle used by this wallet.
Definition: wallet.h:714
bool m_pre_split
Definition: wallet.h:123
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:101
Definition: net.h:115
An output of a transaction.
Definition: transaction.h:131
std::shared_ptr< CWallet > GetWallet(const std::string &name)
Definition: wallet.cpp:75
ADD_SERIALIZE_METHODS
Definition: wallet.h:251
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:18
bool fWatchCreditCached
Definition: wallet.h:355
CCriticalSection cs_wallet
Definition: wallet.h:709
ADD_SERIALIZE_METHODS
Definition: wallet.h:128
unsigned int fTimeReceivedIsTxTime
Definition: wallet.h:328
Special output type for change outputs only.
bool fCreditCached
Definition: wallet.h:351
CAmount nAmount
Definition: wallet.h:178
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1176
bool HasWallets()
Definition: wallet.cpp:63
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:295
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:1050
CWallet * m_wallet
Definition: wallet.h:1179
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:53
void Serialize(Stream &s) const
Definition: wallet.h:407
bool fInMempool
Definition: wallet.h:359
bool IsInMainChain() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: wallet.h:271
Capture information about block/transaction validation.
Definition: validation.h:26
256-bit opaque blob.
Definition: uint256.h:122
void Init(const CWallet *pwalletIn)
Definition: wallet.h:375
CPubKey vchPubKey
Definition: wallet.h:121
static feebumper::Result wallet cs_wallet
Definition: feebumper.cpp:22
CAmount nWatchCreditCached
Definition: wallet.h:365
CWalletTx(const CWallet *pwalletIn, CTransactionRef arg)
Definition: wallet.h:370
void setAbandoned()
Definition: wallet.h:281
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
CAmount nAvailableCreditCached
Definition: wallet.h:363
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:441
CoinSelectionParams coin_selection_params(false, 0, 0, CFeeRate(0), 0)
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:50
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:1034
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:729
int vout
Definition: wallet.h:207
A key allocated from the key pool.
Definition: wallet.h:1145
Result CommitTransaction(CWallet *wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< std::string > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Definition: feebumper.cpp:219
Address book data.
Definition: wallet.h:163
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:384
StringMap destdata
Definition: wallet.h:172
CTxDestination destination
Definition: wallet.h:205
unsigned int nTimeSmart
Stable timestamp that never changes, and reflects the order a transaction was added to the wallet...
Definition: wallet.h:339
CInputCoin GetInputCoin() const
Definition: wallet.h:549
CWallet & m_wallet
Definition: wallet.cpp:54
ADD_SERIALIZE_METHODS
Definition: wallet.h:568
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey)
Definition: ismine.cpp:175
Private key that includes an expiration date in case it never gets used.
Definition: wallet.h:556
A reference to a CKey: the Hash360 of its serialized public key.
Definition: pubkey.h:20
const CWalletTx * tx
Definition: wallet.h:514
#define LIMITED_STRING(obj, n)
Definition: serialize.h:413
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:590
int64_t atoi64(const char *psz)
bool IsScanning()
Definition: wallet.h:810
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:599
UniValue SignTransaction(CMutableTransaction &mtx, const UniValue &prevTxsUnival, CBasicKeyStore *keystore, bool is_temp_keystore, const UniValue &hashType)
Sign a transaction with the given keystore and previous transactions.
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:19
std::string i64tostr(int64_t n)
CReserveKey(CWallet *pwalletIn)
Definition: wallet.h:1153
Definition: wallet.h:203
void FundTransaction(CWallet *const pwallet, CMutableTransaction &tx, CAmount &fee_out, int &change_position, UniValue options)
Definition: rpcwallet.cpp:2750
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:1044
A reference to a CScript: the Hash360 of its serialization (see script.h)
Definition: standard.h:22
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:131
A mutable version of CTransaction.
Definition: transaction.h:360
CAmount nAvailableWatchCreditCached
Definition: wallet.h:367
bool IsAbortingRescan()
Definition: wallet.h:809
WalletFlags
Definition: wallet.h:106
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:826
int flags
Definition: bsha3-tx.cpp:509
CMerkleTx()
Definition: wallet.h:228
unsigned int nTimeReceived
time received by this node
Definition: wallet.h:329
bool fWatchDebitCached
Definition: wallet.h:354
An encapsulated private key.
Definition: key.h:27
std::string m_name
Wallet filename from wallet=<path> command line or config option.
Definition: wallet.h:687
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:264
bool isReserved() const
Definition: wallet.h:1196
bool hashUnset() const
Definition: wallet.h:279
bool fImmatureWatchCreditCached
Definition: wallet.h:356
const CHDChain & GetHDChain() const
Definition: wallet.h:1079
WalletRescanReserver(CWallet *w)
Definition: wallet.h:1182
#define READWRITE(...)
Definition: serialize.h:173
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:1047
std::multimap< int64_t, CWalletTx * > TxItems
Definition: wallet.h:757
bool IsImmatureCoinBase() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: wallet.cpp:4255
bool fInternal
Definition: wallet.h:122
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig=false) EXCLUSIVE_LOCKS_REQUIRED(wallet -> cs_wallet)
Definition: wallet.cpp:1488
std::vector< std::shared_ptr< CWallet > > GetWallets()
Definition: dummywallet.cpp:47
CAmount nImmatureCreditCached
Definition: wallet.h:362
A transaction with a merkle branch linking it to the block chain.
Definition: wallet.h:211
~CWallet()
Definition: wallet.h:749
A key pool entry.
Definition: wallet.h:117
std::vector< std::pair< std::string, std::string > > vOrderForm
Definition: wallet.h:327
bool isAbandoned() const
Definition: wallet.h:280
CAmount nDebitCached
Definition: wallet.h:360