Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

wallet.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Copyright (c) 2014-2019 The Dash Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef BITCOIN_WALLET_WALLET_H
8 #define BITCOIN_WALLET_WALLET_H
9 
10 #include <amount.h>
11 #include <base58.h>
12 #include <policy/feerate.h>
13 #include <saltedhasher.h>
14 #include <streams.h>
15 #include <tinyformat.h>
16 #include <ui_interface.h>
17 #include <util.h>
18 #include <utilstrencodings.h>
19 #include <validationinterface.h>
20 #include <script/ismine.h>
21 #include <util.h>
22 #include <wallet/coincontrol.h>
23 #include <wallet/crypter.h>
24 #include <wallet/walletdb.h>
25 #include <wallet/rpcwallet.h>
26 
28 
29 #include <algorithm>
30 #include <atomic>
31 #include <deque>
32 #include <map>
33 #include <memory>
34 #include <set>
35 #include <stdexcept>
36 #include <stdint.h>
37 #include <string>
38 #include <utility>
39 #include <vector>
40 
41 bool AddWallet(CWallet* wallet);
42 bool RemoveWallet(CWallet* wallet);
43 bool HasWallets();
44 std::vector<CWallet*> GetWallets();
45 CWallet* GetWallet(const std::string& name);
46 
50 extern CFeeRate payTxFee;
51 extern unsigned int nTxConfirmTarget;
52 extern bool bSpendZeroConfChange;
53 
54 static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
58 static const CAmount DEFAULT_FALLBACK_FEE = 1000;
60 static const CAmount DEFAULT_DISCARD_FEE = 10000;
62 static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
66 static const CAmount MIN_CHANGE = CENT;
70 static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
72 static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false;
74 static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
75 static const bool DEFAULT_WALLETBROADCAST = true;
76 static const bool DEFAULT_DISABLE_WALLET = false;
77 
78 static const int64_t TIMESTAMP_MIN = 0;
79 
81 static const bool DEFAULT_USE_HD_WALLET = false;
82 
83 class CBlockIndex;
84 class CCoinControl;
85 class COutput;
86 class CReserveKey;
87 class CScript;
88 class CTxMemPool;
90 class CWalletTx;
91 struct FeeCalculation;
92 enum class FeeEstimateMode;
93 
96 {
97  FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getwalletinfo's clientversion output)
98 
99  FEATURE_WALLETCRYPT = 40000, // wallet encryption
100  FEATURE_COMPRPUBKEY = 60000, // compressed public keys
101  FEATURE_HD = 120200, // Hierarchical key derivation after BIP32 (HD Wallet), BIP44 (multi-coin), BIP39 (mnemonic)
102  // which uses on-the-fly private key derivation
103 
105 };
106 
108 {
111  std::vector<COutPoint> vecOutPoints;
113  {
114  nAmount = 0;
115  }
116 };
117 
119 class CKeyPool
120 {
121 public:
122  int64_t nTime;
124  bool fInternal; // for change outputs
125 
126  CKeyPool();
127  CKeyPool(const CPubKey& vchPubKeyIn, bool fInternalIn);
128 
130 
131  template <typename Stream, typename Operation>
132  inline void SerializationOp(Stream& s, Operation ser_action) {
133  int nVersion = s.GetVersion();
134  if (!(s.GetType() & SER_GETHASH))
135  READWRITE(nVersion);
136  READWRITE(nTime);
138  if (ser_action.ForRead()) {
139  try {
141  }
142  catch (std::ios_base::failure&) {
143  /* flag as external address if we can't read the internal boolean
144  (this will be the case for any wallet before the HD chain split version) */
145  fInternal = false;
146  }
147  }
148  else {
150  }
151  }
152 };
153 
156 {
157 public:
158  std::string name;
159  std::string purpose;
160 
161  CAddressBookData() : purpose("unknown") {}
162 
163  typedef std::map<std::string, std::string> StringMap;
165 };
166 
168 {
172 };
173 
174 typedef std::map<std::string, std::string> mapValue_t;
175 
176 
177 static inline void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
178 {
179  if (!mapValue.count("n"))
180  {
181  nOrderPos = -1; // TODO: calculate elsewhere
182  return;
183  }
184  nOrderPos = atoi64(mapValue["n"].c_str());
185 }
186 
187 
188 static inline void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
189 {
190  if (nOrderPos == -1)
191  return;
192  mapValue["n"] = i64tostr(nOrderPos);
193 }
194 
196 {
199  int vout;
200 };
201 
204 {
205 private:
207  static const uint256 ABANDON_HASH;
208 
209 public:
212 
213  /* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest
214  * block in the chain we know this or any in-wallet dependency conflicts
215  * with. Older clients interpret nIndex == -1 as unconfirmed for backward
216  * compatibility.
217  */
218  int nIndex;
219 
221  {
223  Init();
224  }
225 
227  {
228  SetTx(std::move(arg));
229  Init();
230  }
231 
232  void Init()
233  {
234  hashBlock = uint256();
235  nIndex = -1;
236  }
237 
239  {
240  tx = std::move(arg);
241  }
242 
244 
245  template <typename Stream, typename Operation>
246  inline void SerializationOp(Stream& s, Operation ser_action) {
247  std::vector<uint256> vMerkleBranch; // For compatibility with older versions.
248  READWRITE(tx);
250  READWRITE(vMerkleBranch);
251  READWRITE(nIndex);
252  }
253 
254  void SetMerkleBranch(const CBlockIndex* pIndex, int posInBlock);
255 
262  int GetDepthInMainChain(const CBlockIndex* &pindexRet) const;
263  int GetDepthInMainChain() const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); }
264  bool IsInMainChain() const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet) > 0; }
265  bool IsLockedByInstantSend() const;
266  bool IsChainLocked() const;
267  int GetBlocksToMaturity() const;
268  bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
269  bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
271 
272  const uint256& GetHash() const { return tx->GetHash(); }
273  bool IsCoinBase() const { return tx->IsCoinBase(); }
274 };
275 
280 class CWalletTx : public CMerkleTx
281 {
282 private:
283  const CWallet* pwallet;
284 
285 public:
312  std::vector<std::pair<std::string, std::string> > vOrderForm;
313  unsigned int fTimeReceivedIsTxTime;
314  unsigned int nTimeReceived;
315 
324  unsigned int nTimeSmart;
330  char fFromMe;
331  std::string strFromAccount;
332  int64_t nOrderPos;
333  std::multimap<int64_t, std::pair<CWalletTx*, CAccountingEntry*>>::const_iterator m_it_wtxOrdered;
334 
335  // memory only
336  mutable bool fDebitCached;
337  mutable bool fCreditCached;
338  mutable bool fImmatureCreditCached;
343  mutable bool fWatchDebitCached;
344  mutable bool fWatchCreditCached;
347  mutable bool fChangeCached;
348  mutable bool fInMempool;
361 
363  {
364  Init(nullptr);
365  }
366 
367  CWalletTx(const CWallet* pwalletIn, CTransactionRef arg) : CMerkleTx(std::move(arg))
368  {
369  Init(pwalletIn);
370  }
371 
372  void Init(const CWallet* pwalletIn)
373  {
374  pwallet = pwalletIn;
375  mapValue.clear();
376  vOrderForm.clear();
377  fTimeReceivedIsTxTime = false;
378  nTimeReceived = 0;
379  nTimeSmart = 0;
380  fFromMe = false;
381  strFromAccount.clear();
382  fDebitCached = false;
383  fCreditCached = false;
384  fImmatureCreditCached = false;
385  fAvailableCreditCached = false;
386  fAnonymizedCreditCached = false;
387  fDenomUnconfCreditCached = false;
388  fDenomConfCreditCached = false;
389  fWatchDebitCached = false;
390  fWatchCreditCached = false;
393  fChangeCached = false;
394  fInMempool = false;
395  nDebitCached = 0;
396  nCreditCached = 0;
402  nWatchDebitCached = 0;
403  nWatchCreditCached = 0;
406  nChangeCached = 0;
407  nOrderPos = -1;
408  }
409 
411 
412  template <typename Stream, typename Operation>
413  inline void SerializationOp(Stream& s, Operation ser_action) {
414  if (ser_action.ForRead())
415  Init(nullptr);
416  char fSpent = false;
417 
418  if (!ser_action.ForRead())
419  {
420  mapValue["fromaccount"] = strFromAccount;
421 
423 
424  if (nTimeSmart)
425  mapValue["timesmart"] = strprintf("%u", nTimeSmart);
426  }
427 
428  READWRITE(*(CMerkleTx*)this);
429  std::vector<CMerkleTx> vUnused;
430  READWRITE(vUnused);
436  READWRITE(fSpent);
437 
438  if (ser_action.ForRead())
439  {
440  strFromAccount = mapValue["fromaccount"];
441 
443 
444  nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
445  }
446 
447  mapValue.erase("fromaccount");
448  mapValue.erase("spent");
449  mapValue.erase("n");
450  mapValue.erase("timesmart");
451  }
452 
454  void MarkDirty()
455  {
456  fCreditCached = false;
457  fAvailableCreditCached = false;
458  fImmatureCreditCached = false;
459  fAnonymizedCreditCached = false;
460  fDenomUnconfCreditCached = false;
461  fDenomConfCreditCached = false;
462  fWatchDebitCached = false;
463  fWatchCreditCached = false;
466  fDebitCached = false;
467  fChangeCached = false;
468  }
469 
470  void BindWallet(CWallet *pwalletIn)
471  {
472  pwallet = pwalletIn;
473  MarkDirty();
474  }
475 
476  const CWallet* GetWallet() const
477  {
478  return pwallet;
479  }
480 
482  CAmount GetDebit(const isminefilter& filter) const;
483  CAmount GetCredit(const isminefilter& filter) const;
484  CAmount GetImmatureCredit(bool fUseCache=true) const;
485  CAmount GetAvailableCredit(bool fUseCache=true) const;
486  CAmount GetImmatureWatchOnlyCredit(const bool fUseCache=true) const;
487  CAmount GetAvailableWatchOnlyCredit(const bool fUseCache=true) const;
488  CAmount GetChange() const;
489 
490  CAmount GetAnonymizedCredit(const CCoinControl* coinControl = nullptr) const;
491  CAmount GetDenominatedCredit(bool unconfirmed, bool fUseCache=true) const;
492 
493  void GetAmounts(std::list<COutputEntry>& listReceived,
494  std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
495 
496  bool IsFromMe(const isminefilter& filter) const
497  {
498  return (GetDebit(filter) > 0);
499  }
500 
501  // True if only scriptSigs are different
502  bool IsEquivalentTo(const CWalletTx& tx) const;
503 
504  bool InMempool() const;
505  bool IsTrusted() const;
506 
507  int64_t GetTxTime() const;
508 
509  // RelayWalletTransaction may only be called if fBroadcastTransactions!
510  bool RelayWalletTransaction(CConnman* connman);
511 
513  bool AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state);
514 
515  std::set<uint256> GetConflicts() const;
516 };
517 
519 {
521  size_t operator()(const CWalletTx* a) const
522  {
523  return h(a->GetHash());
524  }
525 };
526 
527 class CInputCoin {
528 public:
529  CInputCoin(const CWalletTx* walletTx, unsigned int i)
530  {
531  if (!walletTx)
532  throw std::invalid_argument("walletTx should not be null");
533  if (i >= walletTx->tx->vout.size())
534  throw std::out_of_range("The output index is out of range");
535 
536  outpoint = COutPoint(walletTx->GetHash(), i);
537  txout = walletTx->tx->vout[i];
538  }
539 
542 
543  bool operator<(const CInputCoin& rhs) const {
544  return outpoint < rhs.outpoint;
545  }
546 
547  bool operator!=(const CInputCoin& rhs) const {
548  return outpoint != rhs.outpoint;
549  }
550 
551  bool operator==(const CInputCoin& rhs) const {
552  return outpoint == rhs.outpoint;
553  }
554 };
555 
557 {
558  inline bool operator()(const CInputCoin& a, const CInputCoin& b) const
559  {
560  // Note: CInputCoin-s are essentially inputs, their txouts are used for informational purposes only
561  // that's why we use CompareInputBIP69 to sort them in a BIP69 compliant way.
562  return CompareInputBIP69()(CTxIn(a.outpoint), CTxIn(b.outpoint));
563  }
564 };
565 
566 class COutput
567 {
568 public:
569  const CWalletTx *tx;
570  int i;
571  int nDepth;
572 
575 
577  bool fSolvable;
578 
584  bool fSafe;
585 
586  COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn)
587  {
588  tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; fSolvable = fSolvableIn; fSafe = fSafeIn;
589  }
590 
591  //Used with Darksend. Will return largest nondenom, then denominations, then very small inputs
592  int Priority() const;
593 
594  std::string ToString() const;
595 };
596 
597 
598 
599 
602 {
603 public:
605  int64_t nTimeCreated;
606  int64_t nTimeExpires;
607  std::string strComment;
610 
611  explicit CWalletKey(int64_t nExpires=0);
612 
614 
615  template <typename Stream, typename Operation>
616  inline void SerializationOp(Stream& s, Operation ser_action) {
617  int nVersion = s.GetVersion();
618  if (!(s.GetType() & SER_GETHASH))
619  READWRITE(nVersion);
624  }
625 };
626 
632 {
633 public:
634  std::string strAccount;
636  int64_t nTime;
637  std::string strOtherAccount;
638  std::string strComment;
640  int64_t nOrderPos;
641  uint64_t nEntryNo;
642 
644  {
645  SetNull();
646  }
647 
648  void SetNull()
649  {
650  nCreditDebit = 0;
651  nTime = 0;
652  strAccount.clear();
653  strOtherAccount.clear();
654  strComment.clear();
655  nOrderPos = -1;
656  nEntryNo = 0;
657  }
658 
660 
661  template <typename Stream, typename Operation>
662  inline void SerializationOp(Stream& s, Operation ser_action) {
663  int nVersion = s.GetVersion();
664  if (!(s.GetType() & SER_GETHASH))
665  READWRITE(nVersion);
668  READWRITE(nTime);
670 
671  if (!ser_action.ForRead())
672  {
674 
675  if (!(mapValue.empty() && _ssExtra.empty()))
676  {
677  CDataStream ss(s.GetType(), s.GetVersion());
678  ss.insert(ss.begin(), '\0');
679  ss << mapValue;
680  ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
681  strComment.append(ss.str());
682  }
683  }
684 
686 
687  size_t nSepPos = strComment.find("\0", 0, 1);
688  if (ser_action.ForRead())
689  {
690  mapValue.clear();
691  if (std::string::npos != nSepPos)
692  {
693  CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
694  ss >> mapValue;
695  _ssExtra = std::vector<char>(ss.begin(), ss.end());
696  }
698  }
699  if (std::string::npos != nSepPos)
700  strComment.erase(nSepPos);
701 
702  mapValue.erase("n");
703  }
704 
705 private:
706  std::vector<char> _ssExtra;
707 };
708 
709 
710 class WalletRescanReserver; //forward declarations for ScanForWalletTransactions/RescanFromTime
715 class CWallet final : public CCryptoKeyStore, public CValidationInterface
716 {
717 private:
718  std::atomic<bool> fAbortRescan;
719  std::atomic<bool> fScanningWallet; //controlled by WalletRescanReserver
720  std::mutex mutexScanning;
721  friend class WalletRescanReserver;
722 
723 
729  bool SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = nullptr) const;
730 
732 
735 
738 
739  int64_t nNextResend;
740  int64_t nLastResend;
742 
744  mutable std::vector<CompactTallyItem> vecAnonymizableTallyCached;
746  mutable std::vector<CompactTallyItem> vecAnonymizableTallyCachedNonDenom;
747 
753  typedef std::multimap<COutPoint, uint256> TxSpends;
755  void AddToSpends(const COutPoint& outpoint, const uint256& wtxid);
756  void AddToSpends(const uint256& wtxid);
757 
758  std::set<COutPoint> setWalletUTXO;
759  mutable std::map<COutPoint, int> mapOutpointRoundsCache;
760 
761  /* Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
762  void MarkConflicted(const uint256& hashBlock, const uint256& hashTx);
763 
764  void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
765 
766  /* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected.
767  * Should be called with pindexBlock and posInBlock if this is for a transaction that is included in a block. */
768  void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindex = nullptr, int posInBlock = 0);
769 
770  /* HD derive new child key (on internal or external chain) */
771  void DeriveNewChildKey(WalletBatch &batch, const CKeyMetadata& metadata, CKey& secretRet, uint32_t nAccountIndex, bool fInternal /*= false*/);
772 
773  std::set<int64_t> setInternalKeyPool;
774  std::set<int64_t> setExternalKeyPool;
776  std::map<CKeyID, int64_t> m_pool_key_to_index;
777 
778  int64_t nTimeFirstKey;
779 
789  bool AddWatchOnly(const CScript& dest) override;
790 
796  std::string m_name;
797 
799  std::unique_ptr<WalletDatabase> database;
800 
801  // Used to NotifyTransactionChanged of the previous block's coinbase when
802  // the next block comes in
804 
805  // A helper function which loops through wallet UTXOs
806  std::unordered_set<const CWalletTx*, WalletTxHasher> GetSpendableTXs() const;
807 
819 
825 
829  void InitPrivateSendSalt();
830 
831 public:
832  /*
833  * Main wallet lock.
834  * This lock protects all the fields added by CWallet.
835  */
837 
842  {
843  return *database;
844  }
845 
848  const std::string& GetName() const { return m_name; }
849 
850  void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool);
851 
852  // Map from Key ID to key metadata.
853  std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
854 
855  // Map from Script ID to key metadata (for watch-only keys).
856  std::map<CScriptID, CKeyMetadata> m_script_metadata;
857 
858  typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
860  unsigned int nMasterKeyMaxID;
861 
863  CWallet(std::string name, std::unique_ptr<WalletDatabase> database) : m_name(std::move(name)), database(std::move(database))
864  {
865  SetNull();
866  }
867 
869  {
870  delete encrypted_batch;
871  encrypted_batch = nullptr;
872  }
873 
874  void SetNull()
875  {
878  nMasterKeyMaxID = 0;
879  encrypted_batch = nullptr;
880  nOrderPosNext = 0;
882  nNextResend = 0;
883  nLastResend = 0;
885  nTimeFirstKey = 0;
886  fBroadcastTransactions = false;
887  nRelockTime = 0;
888  fAbortRescan = false;
889  fScanningWallet = false;
890  fAnonymizableTallyCached = false;
894  }
895 
896  std::map<uint256, CWalletTx> mapWallet;
897  std::list<CAccountingEntry> laccentries;
898 
899  typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
900  typedef std::multimap<int64_t, TxPair > TxItems;
902 
903  int64_t nOrderPosNext;
905 
906  std::map<CTxDestination, CAddressBookData> mapAddressBook;
907 
908  std::set<COutPoint> setLockedCoins;
909 
911 
912  std::map<CKeyID, CHDPubKey> mapHdPubKeys; //<! memory map of HD extended pubkeys
913 
914  const CWalletTx* GetWalletTx(const uint256& hash) const;
915 
918 
922  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;
923 
927  std::map<CTxDestination, std::vector<COutput>> ListCoins() const;
928 
932  const CTxOut& FindNonChangeParentOutput(const CTransaction& tx, int output) const;
933 
940  bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, uint64_t nMaxAncestors, std::vector<COutput> vCoins, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, CoinType nCoinType = CoinType::ALL_COINS) const;
941 
942  // Coin selection
943  bool SelectPSInOutPairsByDenominations(int nDenom, CAmount nValueMax, std::vector< std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet);
944  bool GetCollateralTxDSIn(CTxDSIn& txdsinRet, CAmount& nValueRet) const;
945  bool SelectDenominatedAmounts(CAmount nValueMax, std::set<CAmount>& setAmountsRet) const;
946 
947  bool SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated = true, bool fAnonymizable = true, bool fSkipUnconfirmed = true, int nMaxOupointsPerAddress = -1) const;
948 
950  bool GetMasternodeOutpointAndKeys(COutPoint& outpointRet, CPubKey& pubKeyRet, CKey& keyRet, const std::string& strTxHash = "", const std::string& strOutputIndex = "");
952  bool GetOutpointAndKeysFromOutput(const COutput& out, COutPoint& outpointRet, CPubKey& pubKeyRet, CKey& keyRet);
953 
954  bool HasCollateralInputs(bool fOnlyConfirmed = true) const;
955  int CountInputsWithAmount(CAmount nInputAmount) const;
956 
957  // get the PrivateSend chain depth for a given input
958  int GetRealOutpointPrivateSendRounds(const COutPoint& outpoint, int nRounds = 0) const;
959  // respect current settings
960  int GetCappedOutpointPrivateSendRounds(const COutPoint& outpoint) const;
961 
962  bool IsDenominated(const COutPoint& outpoint) const;
963  bool IsFullyMixed(const COutPoint& outpoint) const;
964 
965  bool IsSpent(const uint256& hash, unsigned int n) const;
966 
967  bool IsLockedCoin(uint256 hash, unsigned int n) const;
968  void LockCoin(const COutPoint& output);
969  void UnlockCoin(const COutPoint& output);
970  void UnlockAllCoins();
971  void ListLockedCoins(std::vector<COutPoint>& vOutpts) const;
972  void ListProTxCoins(std::vector<COutPoint>& vOutpts);
973 
974  /*
975  * Rescan abort properties
976  */
977  void AbortRescan() { fAbortRescan = true; }
978  bool IsAbortingRescan() { return fAbortRescan; }
979  bool IsScanning() { return fScanningWallet; }
980 
985  CPubKey GenerateNewKey(WalletBatch& batch, uint32_t nAccountIndex, bool fInternal /*= false*/);
987  bool HaveKey(const CKeyID &address) const override;
989  bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
991  bool GetKey(const CKeyID &address, CKey& keyOut) const override;
993  bool AddHDPubKey(WalletBatch &batch, const CExtPubKey &extPubKey, bool fInternal);
995  bool LoadHDPubKey(const CHDPubKey &hdPubKey);
997  bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override;
998  bool AddKeyPubKeyWithDB(WalletBatch &batch, const CKey& key, const CPubKey &pubkey);
1000  bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); }
1002  bool LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &metadata);
1003  bool LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata);
1004 
1005  bool LoadMinVersion(int nVersion) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
1006  void UpdateTimeFirstKey(int64_t nCreateTime);
1007 
1009  bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) override;
1011  bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
1012  bool AddCScript(const CScript& redeemScript) override;
1013  bool LoadCScript(const CScript& redeemScript);
1014 
1016  bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
1018  bool EraseDestData(const CTxDestination &dest, const std::string &key);
1020  bool LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
1022  bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const;
1024  std::vector<std::string> GetDestValues(const std::string& prefix) const;
1025 
1027  bool AddWatchOnly(const CScript& dest, int64_t nCreateTime);
1028 
1029  bool RemoveWatchOnly(const CScript &dest) override;
1031  bool LoadWatchOnly(const CScript &dest);
1032 
1034  int64_t nRelockTime;
1035 
1036  bool Unlock(const SecureString& strWalletPassphrase, bool fForMixingOnly = false);
1037  bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
1038  bool EncryptWallet(const SecureString& strWalletPassphrase);
1039 
1040  void GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) const;
1041  unsigned int ComputeTimeSmart(const CWalletTx& wtx) const;
1042 
1047  int64_t IncOrderPosNext(WalletBatch *batch = nullptr);
1049  bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "");
1050  bool GetAccountDestination(CTxDestination &dest, std::string strAccount, bool bForceNew = false);
1051 
1052  void MarkDirty();
1053  bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
1054  bool LoadToWallet(const CWalletTx& wtxIn);
1055  void TransactionAddedToMempool(const CTransactionRef& tx, int64_t nAcceptTime) override;
1056  void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) override;
1057  void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) override;
1058  bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate);
1059  int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver, bool update);
1060  CBlockIndex* ScanForWalletTransactions(CBlockIndex* pindexStart, CBlockIndex* pindexStop, const WalletRescanReserver& reserver, bool fUpdate = false);
1061  void TransactionRemovedFromMempool(const CTransactionRef &ptx) override;
1063  void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) override;
1064  // ResendWalletTransactionsBefore may only be called if fBroadcastTransactions!
1065  std::vector<uint256> ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman);
1066  CAmount GetBalance() const;
1068  CAmount GetImmatureBalance() const;
1069  CAmount GetWatchOnlyBalance() const;
1072  CAmount GetLegacyBalance(const isminefilter& filter, int minDepth, const std::string* account, const bool fAddLocked) const;
1073 
1074  CAmount GetAnonymizableBalance(bool fSkipDenominated = false, bool fSkipUnconfirmed = true) const;
1075  CAmount GetAnonymizedBalance(const CCoinControl* coinControl = nullptr) const;
1076  float GetAverageAnonymizedRounds() const;
1078  CAmount GetDenominatedBalance(bool unconfirmed=false) const;
1079 
1080  bool GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount amount, const COutPoint& outpoint=COutPoint()/*defaults null*/);
1081  CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const;
1082 
1087  bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl);
1089 
1095  bool CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
1096  std::string& strFailReason, const CCoinControl& coin_control, bool sign = true, int nExtraPayloadSize = 0);
1097  bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state);
1098 
1099  bool CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason);
1100 
1101  void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
1102  bool AddAccountingEntry(const CAccountingEntry&);
1103  bool AddAccountingEntry(const CAccountingEntry&, WalletBatch *batch);
1104 
1108 
1109  bool NewKeyPool();
1110  size_t KeypoolCountExternalKeys();
1111  size_t KeypoolCountInternalKeys();
1112  bool TopUpKeyPool(unsigned int kpSize = 0);
1113  void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fInternal);
1114  void KeepKey(int64_t nIndex);
1115  void ReturnKey(int64_t nIndex, bool fInternal, const CPubKey& pubkey);
1116  bool GetKeyFromPool(CPubKey &key, bool fInternal /*= false*/);
1117  int64_t GetOldestKeyPoolTime();
1121  void MarkReserveKeysAsUsed(int64_t keypool_id);
1122  const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
1123 
1124  std::set< std::set<CTxDestination> > GetAddressGroupings();
1125  std::map<CTxDestination, CAmount> GetAddressBalances();
1126 
1127  std::set<CTxDestination> GetAccountAddresses(const std::string& strAccount) const;
1128 
1129  isminetype IsMine(const CTxIn& txin) const;
1134  CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
1135  isminetype IsMine(const CTxOut& txout) const;
1136  CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
1137  bool IsChange(const CTxOut& txout) const;
1138  CAmount GetChange(const CTxOut& txout) const;
1139  bool IsMine(const CTransaction& tx) const;
1141  bool IsFromMe(const CTransaction& tx) const;
1142  CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
1144  bool IsAllFromMe(const CTransaction& tx, const isminefilter& filter) const;
1145  CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
1146  CAmount GetChange(const CTransaction& tx) const;
1147  void SetBestChain(const CBlockLocator& loc) override;
1148 
1149  DBErrors LoadWallet(bool& fFirstRunRet);
1151  DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);
1152  DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut);
1153 
1154  bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose);
1155 
1156  bool DelAddressBook(const CTxDestination& address);
1157 
1158  const std::string& GetAccountName(const CScript& scriptPubKey) const;
1159 
1160  void GetScriptForMining(std::shared_ptr<CReserveScript> &script);
1161 
1162  unsigned int GetKeyPoolSize()
1163  {
1164  AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool
1165  return setInternalKeyPool.size() + setExternalKeyPool.size();
1166  }
1167 
1169  bool SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr, bool fExplicit = false);
1170 
1172  bool SetMaxVersion(int nVersion);
1173 
1176 
1178  std::set<uint256> GetConflicts(const uint256& txid) const;
1179 
1181  void Flush(bool shutdown=false);
1182 
1187  boost::signals2::signal<void (CWallet *wallet, const CTxDestination
1188  &address, const std::string &label, bool isMine,
1189  const std::string &purpose,
1191 
1196  boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx,
1198 
1200  boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
1201 
1203  boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
1204 
1206  boost::signals2::signal<void ()> NotifyISLockReceived;
1207 
1209  boost::signals2::signal<void (int height)> NotifyChainLockReceived;
1210 
1214  void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
1215 
1217  bool TransactionCanBeAbandoned(const uint256& hashTx) const;
1218 
1219  /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
1220  bool AbandonTransaction(const uint256& hashTx);
1221 
1223  static bool Verify(std::string wallet_file, bool salvage_wallet, std::string& error_string, std::string& warning_string);
1224 
1225  /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
1226  static CWallet* CreateWalletFromFile(const std::string& name, const fs::path& path);
1227 
1232  void postInitProcess();
1233 
1234  /* AutoBackup functionality */
1235  static bool InitAutoBackup();
1236  bool AutoBackupWallet(const fs::path& wallet_path, std::string& strBackupWarningRet, std::string& strBackupErrorRet);
1237 
1238  bool BackupWallet(const std::string& strDest);
1239 
1244  /* Returns true if HD is enabled */
1245  bool IsHDEnabled() const;
1246  /* Generates a new HD chain */
1247  void GenerateNewHDChain();
1248  /* Set the HD chain model (chain child index counters) */
1249  bool SetHDChain(WalletBatch &batch, const CHDChain& chain, bool memonly);
1250  bool SetCryptedHDChain(WalletBatch &batch, const CHDChain& chain, bool memonly);
1255  bool SetHDChainSingle(const CHDChain& chain, bool memonly);
1256  bool SetCryptedHDChainSingle(const CHDChain& chain, bool memonly);
1257 
1258  bool GetDecryptedHDChain(CHDChain& hdChainRet);
1259 
1260  void NotifyTransactionLock(const CTransaction &tx, const llmq::CInstantSendLock& islock) override;
1261  void NotifyChainLock(const CBlockIndex* pindexChainLock, const llmq::CChainLockSig& clsig) override;
1262 
1270 };
1271 
1273 class CReserveKey final : public CReserveScript
1274 {
1275 protected:
1277  int64_t nIndex;
1280 public:
1281  explicit CReserveKey(CWallet* pwalletIn)
1282  {
1283  nIndex = -1;
1284  pwallet = pwalletIn;
1285  fInternal = false;
1286  }
1287 
1288  CReserveKey() = default;
1289  CReserveKey(const CReserveKey&) = delete;
1290  CReserveKey& operator=(const CReserveKey&) = delete;
1291 
1293  {
1294  ReturnKey();
1295  }
1296 
1297  void ReturnKey();
1298  bool GetReservedKey(CPubKey &pubkey, bool fInternalIn /*= false*/);
1299  void KeepKey();
1300  void KeepScript() override { KeepKey(); }
1301 };
1302 
1303 
1309 {
1310 public:
1312 
1314  {
1315  SetNull();
1316  }
1317 
1318  void SetNull()
1319  {
1320  vchPubKey = CPubKey();
1321  }
1322 
1324 
1325  template <typename Stream, typename Operation>
1326  inline void SerializationOp(Stream& s, Operation ser_action) {
1327  int nVersion = s.GetVersion();
1328  if (!(s.GetType() & SER_GETHASH))
1329  READWRITE(nVersion);
1331  }
1332 };
1333 
1334 
1337 {
1338 private:
1341 public:
1343 
1344  bool reserve()
1345  {
1346  assert(!m_could_reserve);
1347  std::lock_guard<std::mutex> lock(m_wallet->mutexScanning);
1348  if (m_wallet->fScanningWallet) {
1349  return false;
1350  }
1351  m_wallet->fScanningWallet = true;
1352  m_could_reserve = true;
1353  return true;
1354  }
1355 
1356  bool isReserved() const
1357  {
1359  }
1360 
1362  {
1363  std::lock_guard<std::mutex> lock(m_wallet->mutexScanning);
1364  if (m_could_reserve) {
1365  m_wallet->fScanningWallet = false;
1366  }
1367  }
1368 };
1369 
1370 #endif // BITCOIN_WALLET_WALLET_H
bool IsEquivalentTo(const CWalletTx &tx) const
Definition: wallet.cpp:2452
int64_t nTimeCreated
Definition: wallet.h:605
std::unordered_set< const CWalletTx *, WalletTxHasher > GetSpendableTXs() const
Definition: wallet.cpp:2520
bool fChangeCached
Definition: wallet.h:347
bool RemoveWallet(CWallet *wallet)
Definition: wallet.cpp:63
const CWallet * pwallet
Definition: wallet.h:283
std::atomic< bool > fScanningWallet
Definition: wallet.h:719
bool SelectCoinsMinConf(const CAmount &nTargetValue, int nConfMine, int nConfTheirs, uint64_t nMaxAncestors, std::vector< COutput > vCoins, std::set< CInputCoin > &setCoinsRet, CAmount &nValueRet, CoinType nCoinType=CoinType::ALL_COINS) const
Shuffle and select coins until nTargetValue is reached while avoiding small change; This method is st...
Definition: wallet.cpp:3025
std::set< std::set< CTxDestination > > GetAddressGroupings()
Definition: wallet.cpp:4614
bool GetAccountDestination(CTxDestination &dest, std::string strAccount, bool bForceNew=false)
Definition: wallet.cpp:1043
CWallet * pwallet
Definition: wallet.h:1276
void SetTx(CTransactionRef arg)
Definition: wallet.h:238
static const uint256 ABANDON_HASH
Constant used in hashBlock to indicate tx has been abandoned.
Definition: wallet.h:207
bool CanSupportFeature(enum WalletFeature wf) const
check whether we are allowed to upgrade (or already support) to the named feature ...
Definition: wallet.h:917
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:662
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:70
int64_t nNextResend
Definition: wallet.h:739
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:413
Account information.
Definition: wallet.h:1308
std::unique_ptr< WalletDatabase > database
Internal database handle.
Definition: wallet.h:799
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:616
int i
Definition: wallet.h:570
int64_t nOrderPos
position in ordered transaction list
Definition: wallet.h:640
void SetMerkleBranch(const CBlockIndex *pIndex, int posInBlock)
Definition: wallet.cpp:5492
CAmount nImmatureWatchCreditCached
Definition: wallet.h:358
void UnlockAllCoins()
Definition: wallet.cpp:4814
void BindWallet(CWallet *pwalletIn)
Definition: wallet.h:470
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:80
int64_t IncOrderPosNext(WalletBatch *batch=nullptr)
Increment the next transaction order id.
Definition: wallet.cpp:997
static const unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
Definition: wallet.h:74
static const CAmount DEFAULT_DISCARD_FEE
-m_discard_rate default
Definition: wallet.h:60
bool LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
Adds a destination data tuple to the store, without saving it to disk.
Definition: wallet.cpp:4988
CAmount GetDenominatedCredit(bool unconfirmed, bool fUseCache=true) const
Definition: wallet.cpp:2360
const CWalletTx * GetWalletTx(const uint256 &hash) const
Definition: wallet.cpp:178
CAmount GetImmatureBalance() const
Definition: wallet.cpp:2666
bool IsLockedByInstantSend() const
Definition: wallet.cpp:5531
int64_t GetOldestKeyPoolTime()
Definition: wallet.cpp:4553
static bool Verify(std::string wallet_file, bool salvage_wallet, std::string &error_string, std::string &warning_string)
Verify wallet naming and perform salvage on the wallet if required.
Definition: wallet.cpp:5024
bool fSolvable
Whether we know how to spend this output, ignoring the lack of keys.
Definition: wallet.h:577
void GetKeyBirthTimes(std::map< CTxDestination, int64_t > &mapKeyBirth) const
Definition: wallet.cpp:4856
CPrivKey vchPrivKey
Definition: wallet.h:604
bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment="")
Definition: wallet.cpp:1009
int64_t nIndex
Definition: wallet.h:1277
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:127
void TransactionAddedToMempool(const CTransactionRef &tx, int64_t nAcceptTime) override
Notifies listeners of a transaction having been added to mempool.
Definition: wallet.cpp:1431
#define READWRITE(obj)
Definition: serialize.h:165
CAmount nCreditCached
Definition: wallet.h:350
void postInitProcess()
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
Definition: wallet.cpp:5302
uint64_t nAccountingEntryNumber
Definition: wallet.h:904
CAmount GetAvailableBalance(const CCoinControl *coinControl=nullptr) const
Definition: wallet.cpp:2760
const std::map< CKeyID, int64_t > & GetAllReserveKeys() const
Definition: wallet.h:1122
char fFromMe
From me flag is set to 1 for transactions that were created by the wallet on this bitcoin node...
Definition: wallet.h:330
CAmount nChangeCached
Definition: wallet.h:360
COutPoint outpoint
Definition: wallet.h:540
int Priority() const
Definition: wallet.cpp:166
static const CAmount WALLET_INCREMENTAL_RELAY_FEE
minimum recommended increment for BIP 125 replacement txs
Definition: wallet.h:64
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:906
std::vector< std::string > GetDestValues(const std::string &prefix) const
Get all destination values matching a prefix.
Definition: wallet.cpp:5010
std::set< uint256 > GetConflicts() const
Definition: wallet.cpp:2157
CCriticalSection cs_wallet
Definition: wallet.h:836
static const CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
Definition: amount.h:26
CAmount GetLegacyBalance(const isminefilter &filter, int minDepth, const std::string *account, const bool fAddLocked) const
Definition: wallet.cpp:2723
#define strprintf
Definition: tinyformat.h:1066
const uint256 & GetHash() const
Definition: wallet.h:272
bool IsFromMe(const isminefilter &filter) const
Definition: wallet.h:496
std::vector< char > _ssExtra
Definition: wallet.h:706
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
Definition: wallet.cpp:1861
int nIndex
Definition: wallet.h:218
uint256 nPrivateSendSalt
Pulled from wallet DB ("ps_salt") and used when mixing a random number of rounds. ...
Definition: wallet.h:824
bool fImmatureCreditCached
Definition: wallet.h:338
std::string strFromAccount
Definition: wallet.h:331
WalletFeature
(client) version numbers for particular wallet features
Definition: wallet.h:95
bool IsChainLocked() const
Definition: wallet.cpp:5536
bool SelectDenominatedAmounts(CAmount nValueMax, std::set< CAmount > &setAmountsRet) const
Definition: wallet.cpp:3458
FeeEstimateMode
Definition: fees.h:97
TxItems wtxOrdered
Definition: wallet.h:901
const char * prefix
Definition: rest.cpp:574
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Adds a key to the store, and saves it to disk.
Definition: wallet.cpp:405
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
Definition: wallet.cpp:2169
bool fInternal
Definition: wallet.h:1279
Implementation of BIP69 https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki.
Definition: transaction.h:352
void ReacceptWalletTransactions()
Definition: wallet.cpp:2106
bool FundTransaction(CMutableTransaction &tx, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, bool lockUnspents, const std::set< int > &setSubtractFeeFromOutputs, CCoinControl)
Insert additional inputs into the transaction by calling CreateTransaction();.
Definition: wallet.cpp:3252
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:75
uint256 hashBlock
Definition: wallet.h:211
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:76
const std::string & GetAccountName(const CScript &scriptPubKey) const
Definition: wallet.cpp:4315
std::vector< COutPoint > vecOutPoints
Definition: wallet.h:111
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:753
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:57
bool fAnonymizableTallyCachedNonDenom
Definition: wallet.h:745
int64_t nOrderPos
position in ordered transaction list
Definition: wallet.h:332
static const CAmount DEFAULT_TRANSACTION_MINFEE
-mintxfee default
Definition: wallet.h:62
std::set< int64_t > setInternalKeyPool
Definition: wallet.h:773
bool SelectPSInOutPairsByDenominations(int nDenom, CAmount nValueMax, std::vector< std::pair< CTxDSIn, CTxOut > > &vecPSInOutPairsRet)
Definition: wallet.cpp:3311
An instance of this class represents one database.
Definition: db.h:95
void AddToSpends(const COutPoint &outpoint, const uint256 &wtxid)
Definition: wallet.cpp:774
bool AutoBackupWallet(const fs::path &wallet_path, std::string &strBackupWarningRet, std::string &strBackupErrorRet)
Definition: wallet.cpp:5327
bool SetMaxVersion(int nVersion)
change which version we&#39;re allowed to upgrade to (note that this does not immediately imply upgrading...
Definition: wallet.cpp:673
CMerkleTx(CTransactionRef arg)
Definition: wallet.h:226
uint8_t isminefilter
used for bitflags of isminetype
Definition: ismine.h:29
int64_t nTimeFirstKey
Definition: wallet.h:778
Definition: box.hpp:161
mapValue_t mapValue
Definition: wallet.h:639
bool fAnonymizedCreditCached
Definition: wallet.h:340
std::map< CKeyID, int64_t > m_pool_key_to_index
Definition: wallet.h:776
void SetNull()
Definition: wallet.h:1318
CPubKey vchPubKey
Definition: wallet.h:1278
void MarkDirty()
make sure balances are recalculated
Definition: wallet.h:454
bool fSubtractFeeFromAmount
Definition: wallet.h:171
unsigned int GetKeyPoolSize()
Definition: wallet.h:1162
bool SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr, bool fExplicit=false)
signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVe...
Definition: wallet.cpp:647
void BlockDisconnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindexDisconnected) override
Notifies listeners of a block being disconnected.
Definition: wallet.cpp:1502
static void ReadOrderPos(int64_t &nOrderPos, mapValue_t &mapValue)
Definition: wallet.h:177
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:858
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
CFeeRate payTxFee
Settings.
std::string strComment
Definition: wallet.h:607
std::string name
Definition: wallet.h:158
bool AddKeyPubKeyWithDB(WalletBatch &batch, const CKey &key, const CPubKey &pubkey)
Definition: wallet.cpp:369
~CReserveKey()
Definition: wallet.h:1292
bool GetKeyFromPool(CPubKey &key, bool fInternal)
Definition: wallet.cpp:4521
CWalletKey(int64_t nExpires=0)
todo: add something to note what created it (user, getnewaddress, change) maybe should have a map<str...
Definition: wallet.cpp:5486
CoinType
Definition: coincontrol.h:14
static CWallet * CreateWalletFromFile(const std::string &name, const fs::path &path)
Definition: wallet.cpp:5075
std::atomic< bool > fAbortRescan
Definition: wallet.h:718
void ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, bool fInternal)
Definition: wallet.cpp:4458
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:49
CAmount nWatchDebitCached
Definition: wallet.h:356
CAmount GetUnconfirmedWatchOnlyBalance() const
Definition: wallet.cpp:2692
Keystore which keeps the private keys encrypted.
Definition: crypter.h:119
int64_t m_max_keypool_index
Definition: wallet.h:775
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
Definition: wallet.cpp:4366
bool LoadHDPubKey(const CHDPubKey &hdPubKey)
loads a HDPubKey into the wallets memory
Definition: wallet.cpp:336
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:797
const CBlockIndex * m_last_block_processed
The following is used to keep track of how far behind the wallet is from the chain sync...
Definition: wallet.h:818
bool fSpendable
Whether we have the private keys to spend this output.
Definition: wallet.h:574
bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const
Look up a destination data tuple in the store, return true if found false otherwise.
Definition: wallet.cpp:4994
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:345
std::map< COutPoint, int > mapOutpointRoundsCache
Definition: wallet.h:759
int64_t nTimeExpires
Definition: wallet.h:606
StaticSaltedHasher h
Definition: wallet.h:520
static const unsigned int DEFAULT_KEYPOOL_SIZE
Definition: wallet.h:54
std::set< uint256 > GetConflicts(const uint256 &txid) const
Get wallet transactions that conflict with given transaction (spend same outputs) ...
Definition: wallet.cpp:685
void BlockUntilSyncedToCurrentChain()
Blocks until the wallet state is up-to-date to /at least/ the current chain at the time this function...
Definition: wallet.cpp:1517
bool fAvailableCreditCached
Definition: wallet.h:339
bool IsSpent(const uint256 &hash, unsigned int n) const
Outpoint is spent if any non-conflicted transaction spends it:
Definition: wallet.cpp:755
bool IsChange(const CTxOut &txout) const
Definition: wallet.cpp:1715
bool IsNull() const
Definition: uint256.h:33
std::string purpose
Definition: wallet.h:159
CAmount GetImmatureCredit(bool fUseCache=true) const
Definition: wallet.cpp:2233
void Init()
Definition: wallet.h:232
bool SetHDChain(WalletBatch &batch, const CHDChain &chain, bool memonly)
Definition: wallet.cpp:1781
std::vector< CompactTallyItem > vecAnonymizableTallyCachedNonDenom
Definition: wallet.h:746
void SyncTransaction(const CTransactionRef &tx, const CBlockIndex *pindex=nullptr, int posInBlock=0)
Definition: wallet.cpp:1411
bool AddWatchOnly(const CScript &dest) override
Private version of AddWatchOnly method which does not accept a timestamp, and which will reset the wa...
Definition: wallet.cpp:490
Coin Control Features.
Definition: coincontrol.h:28
CAmount GetBalance() const
Definition: wallet.cpp:2541
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) ...
Definition: wallet.cpp:446
std::map< CScriptID, CKeyMetadata > m_script_metadata
Definition: wallet.h:856
std::map< CTxDestination, CAmount > GetAddressBalances()
Definition: wallet.cpp:4574
WalletBatch * encrypted_batch
Definition: wallet.h:731
CAccount()
Definition: wallet.h:1313
iterator insert(iterator it, const char x=char())
Definition: streams.h:201
bool operator()(const CInputCoin &a, const CInputCoin &b) const
Definition: wallet.h:558
std::string ToString() const
Definition: wallet.cpp:129
unsigned int nTxConfirmTarget
Definition: wallet.cpp:96
Access to the wallet database.
Definition: walletdb.h:96
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: wallet.h:311
std::mutex mutexScanning
Definition: wallet.h:720
CAmount GetImmatureWatchOnlyCredit(const bool fUseCache=true) const
Definition: wallet.cpp:2277
bool fDebitCached
Definition: wallet.h:336
static const CAmount MIN_CHANGE
target minimum change amount
Definition: wallet.h:66
std::list< CAccountingEntry > laccentries
Definition: wallet.h:897
void KeepKey(int64_t nIndex)
Definition: wallet.cpp:4495
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
std::multimap< int64_t, TxPair > TxItems
Definition: wallet.h:900
bool fAvailableWatchCreditCached
Definition: wallet.h:346
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
Definition: crypter.cpp:299
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
void MarkReserveKeysAsUsed(int64_t keypool_id)
Marks all keys in the keypool up to and including reserve_key as used.
Definition: wallet.cpp:4758
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:1197
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Definition: wallet.h:72
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:1214
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:4277
void MarkConflicted(const uint256 &hashBlock, const uint256 &hashTx)
Definition: wallet.cpp:1347
bool HasWallets()
Definition: wallet.cpp:73
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:346
void MarkDirty()
Definition: wallet.cpp:1082
std::string strComment
Definition: wallet.h:638
false
Definition: bls_dkg.cpp:168
DBErrors ReorderTransactions()
Definition: wallet.cpp:920
ADD_SERIALIZE_METHODS
Definition: wallet.h:410
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:4295
size_t KeypoolCountExternalKeys()
Definition: wallet.cpp:4360
int64_t nTime
Definition: wallet.h:122
CScript scriptPubKey
Definition: wallet.h:169
boost::signals2::signal< void(int height)> NotifyChainLockReceived
ChainLock received.
Definition: wallet.h:1209
CAmount GetAnonymizableBalance(bool fSkipDenominated=false, bool fSkipUnconfirmed=true) const
Definition: wallet.cpp:2555
unsigned int nMasterKeyMaxID
Definition: wallet.h:860
static CFeeRate m_discard_rate
Definition: wallet.h:1107
unsigned int ComputeTimeSmart(const CWalletTx &wtx) const
Compute smart timestamp for a transaction being added to the wallet.
Definition: wallet.cpp:4928
ADD_SERIALIZE_METHODS
Definition: wallet.h:1323
int GetDepthInMainChain() const
Definition: wallet.h:263
bool AbandonTransaction(const uint256 &hashTx)
Definition: wallet.cpp:1283
DBErrors LoadWallet(bool &fFirstRunRet)
Definition: wallet.cpp:4160
void UnlockCoin(const COutPoint &output)
Definition: wallet.cpp:4803
int nDepth
Definition: wallet.h:571
uint64_t nEntryNo
Definition: wallet.h:641
bool LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
Definition: wallet.cpp:430
ChangeType
General change type (added, updated, removed).
Definition: ui_interface.h:20
bool fDenomUnconfCreditCached
Definition: wallet.h:341
bool HasCollateralInputs(bool fOnlyConfirmed=true) const
Definition: wallet.cpp:3577
CTransactionRef tx
Definition: wallet.h:210
bool NewKeyPool()
Mark old keypool keys as used, and generate all new keys.
Definition: wallet.cpp:4334
bool SignTransaction(CMutableTransaction &tx)
isminetype
IsMine() return codes.
Definition: ismine.h:17
An input of a transaction.
Definition: transaction.h:70
CInputCoin(const CWalletTx *walletTx, unsigned int i)
Definition: wallet.h:529
bool AddCScript(const CScript &redeemScript) override
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
Definition: wallet.cpp:467
bool IsHDEnabled() const
HD Wallet Functions.
Definition: wallet.cpp:1847
#define LOCK(cs)
Definition: sync.h:178
const char * name
Definition: rest.cpp:36
We want to be able to estimate feerates that are needed on tx&#39;s to be included in a certain number of...
Definition: fees.h:138
bool InMempool() const
Definition: wallet.cpp:2414
void NotifyChainLock(const CBlockIndex *pindexChainLock, const llmq::CChainLockSig &clsig) override
Definition: wallet.cpp:5468
CReserveKey & operator=(const CReserveKey &)=delete
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet) ...
Definition: wallet.h:1175
bool GetKey(const CKeyID &address, CKey &keyOut) const override
GetKey implementation that can derive a HD private key on the fly.
Definition: wallet.cpp:300
static const CAmount MIN_FINAL_CHANGE
final minimum change amount after paying for fees
Definition: wallet.h:68
CKeyPool()
Definition: wallet.cpp:5473
std::set< COutPoint > setWalletUTXO
Definition: wallet.h:758
void ListProTxCoins(std::vector< COutPoint > &vOutpts)
Definition: wallet.cpp:4838
void SetBestChain(const CBlockLocator &loc) override
Notifies listeners of the new active block chain on-disk.
Definition: wallet.cpp:641
bool IsDenominated(const COutPoint &outpoint) const
Definition: wallet.cpp:1664
bool AddWallet(CWallet *wallet)
Definition: wallet.cpp:53
bool SelectCoins(const std::vector< COutput > &vAvailableCoins, const CAmount &nTargetValue, std::set< CInputCoin > &setCoinsRet, CAmount &nValueRet, const CCoinControl *coinControl=nullptr) const
Select a set of coins such that nValueRet >= nTargetValue and at least all coins from coinControl are...
Definition: wallet.cpp:3168
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:246
int64_t nKeysLeftSinceAutoBackup
Definition: wallet.h:910
An encapsulated public key.
Definition: pubkey.h:30
bool SelectCoinsGroupedByAddresses(std::vector< CompactTallyItem > &vecTallyRet, bool fSkipDenominated=true, bool fAnonymizable=true, bool fSkipUnconfirmed=true, int nMaxOupointsPerAddress=-1) const
Definition: wallet.cpp:3355
bool TransactionCanBeAbandoned(const uint256 &hashTx) const
Return whether transaction can be abandoned.
Definition: wallet.cpp:1276
bool fSafe
Whether this output is considered safe to spend.
Definition: wallet.h:584
std::set< COutPoint > setLockedCoins
Definition: wallet.h:908
TxSpends mapTxSpends
Definition: wallet.h:754
CAmount amount
Definition: wallet.h:198
bool IsLockedCoin(uint256 hash, unsigned int n) const
Definition: wallet.cpp:4820
void KeepScript() override
Definition: wallet.h:1300
bool IsCoinBase() const
Definition: wallet.h:273
std::map< std::string, std::string > StringMap
Definition: wallet.h:163
CAmount GetUnconfirmedBalance() const
Definition: wallet.cpp:2653
WalletDatabase & GetDBHandle()
Get database handle used by this wallet.
Definition: wallet.h:841
bool LoadKey(const CKey &key, const CPubKey &pubkey)
Adds a key to the store, without saving it to disk (used by LoadWallet)
Definition: wallet.h:1000
int GetBlocksToMaturity() const
Definition: wallet.cpp:5546
CAmount GetImmatureWatchOnlyBalance() const
Definition: wallet.cpp:2705
void Flush(bool shutdown=false)
Flush wallet (bitdb flush)
Definition: wallet.cpp:708
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
Definition: wallet.cpp:4981
void UpdateTimeFirstKey(int64_t nCreateTime)
Update wallet first key creation time.
Definition: wallet.cpp:455
void InitPrivateSendSalt()
Fetches PrivateSend salt from database or generates and saves a new one if no salt was found in the d...
Definition: wallet.cpp:2934
size_t KeypoolCountInternalKeys()
Definition: wallet.cpp:4385
bool IsTrusted() const
Definition: wallet.cpp:2419
CWallet(std::string name, std::unique_ptr< WalletDatabase > database)
Construct wallet with specified name and database implementation.
Definition: wallet.h:863
void ResendWalletTransactions(int64_t nBestBlockTime, CConnman *connman) override
Tells listeners to broadcast their data.
Definition: wallet.cpp:2486
bool bSpendZeroConfChange
Definition: wallet.cpp:97
static const bool DEFAULT_USE_HD_WALLET
if set, all keys will be derived by using BIP39/BIP44
Definition: wallet.h:81
DBErrors ZapSelectTx(std::vector< uint256 > &vHashIn, std::vector< uint256 > &vHashOut)
Definition: wallet.cpp:4220
Definition: net.h:136
static const CAmount CENT
Definition: amount.h:15
An output of a transaction.
Definition: transaction.h:144
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, const CBlockIndex *pIndex, int posInBlock, bool fUpdate)
Add a transaction to the wallet, or update it.
Definition: wallet.cpp:1217
ADD_SERIALIZE_METHODS
Definition: wallet.h:243
CAmount GetDenominatedBalance(bool unconfirmed=false) const
Definition: wallet.cpp:2638
bool LoadToWallet(const CWalletTx &wtxIn)
Definition: wallet.cpp:1181
void SetNull()
Definition: wallet.h:874
std::set< int64_t > setExternalKeyPool
Definition: wallet.h:774
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
CTxDestination txdest
Definition: wallet.h:109
bool fWatchCreditCached
Definition: wallet.h:344
ADD_SERIALIZE_METHODS
Definition: wallet.h:129
void TransactionRemovedFromMempool(const CTransactionRef &ptx) override
Notifies listeners of a transaction leaving mempool.
Definition: wallet.cpp:1441
unsigned int fTimeReceivedIsTxTime
Definition: wallet.h:313
bool AddHDPubKey(WalletBatch &batch, const CExtPubKey &extPubKey, bool fInternal)
Adds a HDPubKey into the wallet(database)
Definition: wallet.cpp:344
bool IsAllFromMe(const CTransaction &tx, const isminefilter &filter) const
Returns whether all of the inputs match the filter.
Definition: wallet.cpp:1878
CAmount GetAnonymizedBalance(const CCoinControl *coinControl=nullptr) const
Definition: wallet.cpp:2577
bool LoadMinVersion(int nVersion)
Definition: wallet.h:1005
void LockCoin(const COutPoint &output)
Definition: wallet.cpp:4792
bool Unlock(const SecureString &strWalletPassphrase, bool fForMixingOnly=false)
Definition: wallet.cpp:524
bool AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose=true)
Definition: wallet.cpp:1094
const CTxOut & FindNonChangeParentOutput(const CTransaction &tx, int output) const
Find non-change parent output.
Definition: wallet.cpp:2917
bool fCreditCached
Definition: wallet.h:337
bool LoadScriptMetadata(const CScriptID &script_id, const CKeyMetadata &metadata)
Definition: wallet.cpp:438
int nWalletMaxVersion
the maximum wallet format version: memory-only variable that specifies to what version this wallet ma...
Definition: wallet.h:737
CAmount nAmount
Definition: wallet.h:170
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1336
bool GetCollateralTxDSIn(CTxDSIn &txdsinRet, CAmount &nValueRet) const
Definition: wallet.cpp:3481
static std::vector< COutput > vCoins
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
populate vCoins with vector of available COutputs.
Definition: wallet.cpp:2775
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:280
bool AcceptToMemoryPool(const CAmount &nAbsurdFee, CValidationState &state)
Pass this transaction to the mempool.
Definition: wallet.cpp:5554
CAmount GetNormalizedAnonymizedBalance() const
Definition: wallet.cpp:2616
CAmount GetWatchOnlyBalance() const
Definition: wallet.cpp:2678
bool SetCryptedHDChain(WalletBatch &batch, const CHDChain &chain, bool memonly)
Definition: wallet.cpp:1794
bool operator<(const CInputCoin &rhs) const
Definition: wallet.h:543
std::vector< CWallet * > GetWallets()
Definition: wallet.cpp:79
bool IsInMainChain() const
Definition: wallet.h:264
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:1212
CWallet * m_wallet
Definition: wallet.h:1339
CAmount nAnonymizedCreditCached
Definition: wallet.h:353
bool operator!=(const CInputCoin &rhs) const
Definition: wallet.h:547
bool fBroadcastTransactions
Definition: wallet.h:741
CPubKey vchPubKey
Definition: wallet.h:1311
void KeepKey()
Definition: wallet.cpp:4740
static const int64_t TIMESTAMP_MIN
Definition: wallet.h:78
CBlockIndex * ScanForWalletTransactions(CBlockIndex *pindexStart, CBlockIndex *pindexStop, const WalletRescanReserver &reserver, bool fUpdate=false)
Scan the block chain (starting in pindexStart) for transactions from or to us.
Definition: wallet.cpp:2030
bool fInMempool
Definition: wallet.h:348
int GetCappedOutpointPrivateSendRounds(const COutPoint &outpoint) const
Definition: wallet.cpp:1657
static void WriteOrderPos(const int64_t &nOrderPos, mapValue_t &mapValue)
Definition: wallet.h:188
CAmount GetAvailableCredit(bool fUseCache=true) const
Definition: wallet.cpp:2247
Capture information about block/transaction validation.
Definition: validation.h:22
std::vector< uint256 > ResendWalletTransactionsBefore(int64_t nTime, CConnman *connman)
Definition: wallet.cpp:2461
256-bit opaque blob.
Definition: uint256.h:123
void Init(const CWallet *pwalletIn)
Definition: wallet.h:372
CPubKey vchPubKey
Definition: wallet.h:123
std::set< CTxDestination > GetAccountAddresses(const std::string &strAccount) const
Definition: wallet.cpp:4707
CAmount nWatchCreditCached
Definition: wallet.h:357
bool GetOutpointAndKeysFromOutput(const COutput &out, COutPoint &outpointRet, CPubKey &pubKeyRet, CKey &keyRet)
Extract txin information and keys from output.
Definition: wallet.cpp:3531
CWalletTx(const CWallet *pwalletIn, CTransactionRef arg)
Definition: wallet.h:367
void GetScriptForMining(std::shared_ptr< CReserveScript > &script)
Definition: wallet.cpp:4781
void setAbandoned()
Definition: wallet.h:270
bool IsFullyMixed(const COutPoint &outpoint) const
Definition: wallet.cpp:1680
static bool InitAutoBackup()
Definition: wallet.cpp:5309
CAmount nDenomUnconfCreditCached
Definition: wallet.h:354
CAmount nAvailableCreditCached
Definition: wallet.h:352
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:442
std::map< CTxDestination, std::vector< COutput > > ListCoins() const
Return list of available coins and locked coins grouped by non-change output address.
Definition: wallet.cpp:2871
CAmount nAmount
Definition: wallet.h:110
ADD_SERIALIZE_METHODS
Definition: wallet.h:659
DBErrors ZapWalletTx(std::vector< CWalletTx > &vWtx)
Definition: wallet.cpp:4252
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:1190
static CFeeRate fallbackFee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:1106
CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const
Returns amount of debit if the input matches the filter, otherwise returns 0.
Definition: wallet.cpp:1559
bool SetCryptedHDChainSingle(const CHDChain &chain, bool memonly)
Definition: wallet.cpp:1820
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:567
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:848
MasterKeyMap mapMasterKeys
Definition: wallet.h:859
int vout
Definition: wallet.h:199
void NotifyTransactionLock(const CTransaction &tx, const llmq::CInstantSendLock &islock) override
Definition: wallet.cpp:5450
CAmount GetCredit(const isminefilter &filter) const
Definition: wallet.cpp:2200
int64_t GetTxTime() const
Definition: wallet.cpp:1923
A key allocated from the key pool.
Definition: wallet.h:1273
CWalletTx()
Definition: wallet.h:362
Address book data.
Definition: wallet.h:155
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >)
Definition: wallet.cpp:713
const CWallet * GetWallet() const
Definition: wallet.h:476
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
StringMap destdata
Definition: wallet.h:164
int64_t nOrderPosNext
Definition: wallet.h:903
std::map< CKeyID, CHDPubKey > mapHdPubKeys
Definition: wallet.h:912
CTxDestination destination
Definition: wallet.h:197
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:4391
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret) override
Adds an encrypted key to the store, and saves it to disk.
Definition: wallet.cpp:412
unsigned int nTimeSmart
Stable timestamp that never changes, and reflects the order a transaction was added to the wallet...
Definition: wallet.h:324
void BlockConnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindex, const std::vector< CTransactionRef > &vtxConflicted) override
Notifies listeners of a block being connected.
Definition: wallet.cpp:1449
void SetNull()
Definition: wallet.h:648
void ListAccountCreditDebit(const std::string &strAccount, std::list< CAccountingEntry > &entries)
Definition: wallet.cpp:4135
bool SetHDChainSingle(const CHDChain &chain, bool memonly)
Set the HD chain model (chain child index counters) using temporary wallet db object which causes db ...
Definition: wallet.cpp:1814
boost::signals2::signal< void()> NotifyISLockReceived
IS-lock received.
Definition: wallet.h:1206
bool RelayWalletTransaction(CConnman *connman)
Definition: wallet.cpp:2137
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:1326
void GenerateNewHDChain()
Definition: wallet.cpp:1744
ADD_SERIALIZE_METHODS
Definition: wallet.h:613
Private key that includes an expiration date in case it never gets used.
Definition: wallet.h:601
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
Internal transfers.
Definition: wallet.h:631
const CWalletTx * tx
Definition: wallet.h:569
#define LIMITED_STRING(obj, n)
Definition: serialize.h:377
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coin_control, bool sign=true, int nExtraPayloadSize=0)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Definition: wallet.cpp:3658
static CFeeRate minTxFee
Fees smaller than this (in duffs) are considered zero fee (for transaction creation) Override with -m...
Definition: wallet.h:1105
int64_t atoi64(const char *psz)
int nWalletVersion
the current wallet version: clients below this version are not able to load the wallet ...
Definition: wallet.h:734
bool IsScanning()
Definition: wallet.h:979
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:715
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:19
bool fAnonymizableTallyCached
Definition: wallet.h:743
size_t operator()(const CWalletTx *a) const
Definition: wallet.h:521
std::string i64tostr(int64_t n)
bool LoadCScript(const CScript &redeemScript)
Definition: wallet.cpp:474
CPubKey GenerateNewKey(WalletBatch &batch, uint32_t nAccountIndex, bool fInternal)
keystore implementation Generate a new key
Definition: wallet.cpp:187
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn)
Definition: wallet.h:586
std::map< CKeyID, CKeyMetadata > mapKeyMetadata
Definition: wallet.h:853
CAccountingEntry()
Definition: wallet.h:643
int GetRealOutpointPrivateSendRounds(const COutPoint &outpoint, int nRounds=0) const
Definition: wallet.cpp:1576
CReserveKey(CWallet *pwalletIn)
Definition: wallet.h:1281
void AbortRescan()
Definition: wallet.h:977
Definition: wallet.h:195
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:896
std::vector< CompactTallyItem > vecAnonymizableTallyCached
Definition: wallet.h:744
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:1200
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:22
bool CreateCollateralTransaction(CMutableTransaction &txCollateral, std::string &strReason)
Definition: wallet.cpp:3587
CAmount GetAnonymizedCredit(const CCoinControl *coinControl=nullptr) const
Definition: wallet.cpp:2320
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:132
A mutable version of CTransaction.
Definition: transaction.h:291
CAmount GetAvailableWatchOnlyCredit(const bool fUseCache=true) const
Definition: wallet.cpp:2291
CAmount nAvailableWatchCreditCached
Definition: wallet.h:359
bool GetReservedKey(CPubKey &pubkey, bool fInternalIn)
Definition: wallet.cpp:4721
bool IsAbortingRescan()
Definition: wallet.h:978
std::multimap< int64_t, std::pair< CWalletTx *, CAccountingEntry * > >::const_iterator m_it_wtxOrdered
Definition: wallet.h:333
static const CAmount DEFAULT_TRANSACTION_FEE
-paytxfee default
Definition: wallet.h:56
void ReturnKey()
Definition: wallet.cpp:4749
int64_t nLastResend
Definition: wallet.h:740
CMerkleTx()
Definition: wallet.h:220
unsigned int nTimeReceived
time received by this node
Definition: wallet.h:314
bool fWatchDebitCached
Definition: wallet.h:343
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:796
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
bool GetMasternodeOutpointAndKeys(COutPoint &outpointRet, CPubKey &pubKeyRet, CKey &keyRet, const std::string &strTxHash="", const std::string &strOutputIndex="")
Get 1000DASH output and keys which can be used for the Masternode.
Definition: wallet.cpp:3501
bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
Adds a destination data tuple to the store, and saves it to disk.
Definition: wallet.cpp:4972
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const
Definition: wallet.cpp:4828
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
GetPubKey implementation that also checks the mapHdPubKeys.
Definition: wallet.cpp:286
bool isReserved() const
Definition: wallet.h:1356
CAmount GetCredit(const CTxOut &txout, const isminefilter &filter) const
Definition: wallet.cpp:1708
bool fDenomConfCreditCached
Definition: wallet.h:342
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
Definition: wallet.cpp:1993
isminetype IsMine(const CTxIn &txin) const
Definition: wallet.cpp:1542
bool hashUnset() const
Definition: wallet.h:268
uint256 hashPrevBestCoinbase
Definition: wallet.h:803
bool fImmatureWatchCreditCached
Definition: wallet.h:345
std::pair< CWalletTx *, CAccountingEntry * > TxPair
Definition: wallet.h:899
AssertLockHeld(g_cs_orphans)
bool BackupWallet(const std::string &strDest)
Definition: wallet.cpp:5320
WalletRescanReserver(CWallet *w)
Definition: wallet.h:1342
CWallet * GetWallet(const std::string &name)
Definition: wallet.cpp:85
bool AddAccountingEntry(const CAccountingEntry &)
Definition: wallet.cpp:4140
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:1203
float GetAverageAnonymizedRounds() const
Definition: wallet.cpp:2594
bool GetDecryptedHDChain(CHDChain &hdChainRet)
Definition: wallet.cpp:1826
Holds a mixing input.
Definition: privatesend.h:121
std::string strOtherAccount
Definition: wallet.h:637
void ReturnKey(int64_t nIndex, bool fInternal, const CPubKey &pubkey)
Definition: wallet.cpp:4506
void AutoLockMasternodeCollaterals()
Definition: wallet.cpp:4204
static const CAmount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:58
bool fInternal
Definition: wallet.h:124
int64_t nRelockTime
Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock().
Definition: wallet.h:1034
bool HaveKey(const CKeyID &address) const override
HaveKey implementation that also checks the mapHdPubKeys.
Definition: wallet.cpp:328
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet) ...
Definition: wallet.cpp:519
CAmount nCreditDebit
Definition: wallet.h:635
void DeriveNewChildKey(WalletBatch &batch, const CKeyMetadata &metadata, CKey &secretRet, uint32_t nAccountIndex, bool fInternal)
Definition: wallet.cpp:225
int64_t nTime
Definition: wallet.h:636
CAmount GetChange(const CTxOut &txout) const
Definition: wallet.cpp:1737
CTxOut txout
Definition: wallet.h:541
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
CAmount nImmatureCreditCached
Definition: wallet.h:351
CAmount GetChange() const
Definition: wallet.cpp:2405
bool RemoveWatchOnly(const CScript &dest) override
Definition: wallet.cpp:506
A transaction with a merkle branch linking it to the block chain.
Definition: wallet.h:203
std::map< std::string, std::string > mapValue_t
Definition: wallet.h:174
int CountInputsWithAmount(CAmount nInputAmount) const
Definition: wallet.cpp:3559
~CWallet()
Definition: wallet.h:868
bool GetBudgetSystemCollateralTX(CWalletTx &tx, uint256 hash, CAmount amount, const COutPoint &outpoint=COutPoint())
Definition: wallet.cpp:3631
A key pool entry.
Definition: wallet.h:119
bool operator==(const CInputCoin &rhs) const
Definition: wallet.h:551
CAmount nDenomConfCreditCached
Definition: wallet.h:355
std::vector< std::pair< std::string, std::string > > vOrderForm
Definition: wallet.h:312
bool isAbandoned() const
Definition: wallet.h:269
CReserveKey()=default
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, CConnman *connman, CValidationState &state)
Call after CreateTransaction unless you want to abort.
Definition: wallet.cpp:4089
CAmount nDebitCached
Definition: wallet.h:349
void GetAmounts(std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, std::string &strSentAccount, const isminefilter &filter) const
Definition: wallet.cpp:1929
std::string strAccount
Definition: wallet.h:634
Released under the MIT license