PIVX Core  5.6.99
P2P Digital Currency
wallet.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2021 The Bitcoin developers
3 // Copyright (c) 2014-2015 The Dash developers
4 // Copyright (c) 2015-2022 The PIVX Core developers
5 // Distributed under the MIT software license, see the accompanying
6 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 
8 #ifndef PIVX_WALLET_WALLET_H
9 #define PIVX_WALLET_WALLET_H
10 
11 #include "addressbook.h"
12 #include "amount.h"
13 #include "consensus/tx_verify.h"
14 #include "consensus/validation.h"
15 #include "crypter.h"
16 #include "destination_io.h"
17 #include "kernel.h"
18 #include "key.h"
19 #include "key_io.h"
20 #include "keystore.h"
21 #include "operationresult.h"
22 #include "policy/feerate.h"
23 #include "primitives/block.h"
24 #include "primitives/transaction.h"
25 #include "sapling/address.h"
26 #include "guiinterface.h"
27 #include "util/system.h"
28 #include "utilstrencodings.h"
29 #include "validationinterface.h"
30 #include "script/ismine.h"
31 #include "wallet/scriptpubkeyman.h"
33 #include "validation.h"
34 #include "wallet/walletdb.h"
35 
36 #include <algorithm>
37 #include <atomic>
38 #include <map>
39 #include <set>
40 #include <stdexcept>
41 #include <stdint.h>
42 #include <string>
43 #include <utility>
44 #include <vector>
45 
47 extern std::vector<CWalletRef> vpwallets;
48 
52 extern CFeeRate payTxFee;
53 extern CAmount maxTxFee;
54 extern unsigned int nTxConfirmTarget;
55 extern bool bSpendZeroConfChange;
56 extern bool bdisableSystemnotifications;
57 extern bool fPayAtLeastCustomFee;
58 
60 static const CAmount DEFAULT_TRANSACTION_FEE = 0;
62 static const CAmount nHighTransactionFeeWarning = 0.1 * COIN;
64 static const CAmount DEFAULT_TRANSACTION_MINFEE = 10000;
66 static const CAmount DEFAULT_TRANSACTION_MAXFEE = 1 * COIN;
68 static const CAmount MIN_CHANGE = CENT;
70 static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 1;
72 static const CAmount nHighTransactionMaxFeeWarning = 100 * nHighTransactionFeeWarning;
74 static const CAmount DEFAULT_MIN_STAKE_SPLIT_THRESHOLD = 100 * COIN;
76 static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
78 static const bool DEFAULT_STAKING = true;
80 static const bool DEFAULT_COLDSTAKING = true;
82 static const bool DEFAULT_GENERATE = false;
83 static const unsigned int DEFAULT_GENERATE_PROCLIMIT = 1;
85 static const unsigned int DEFAULT_CREATEWALLETBACKUPS = 10;
87 static const bool DEFAULT_DISABLE_WALLET = false;
88 
89 static const int64_t TIMESTAMP_MIN = 0;
90 
92 class CCoinControl;
93 class COutput;
94 class CStakeableOutput;
95 class CReserveKey;
96 class CScript;
97 class CScheduler;
98 class ScriptPubKeyMan;
100 class SaplingNoteData;
101 struct SaplingNoteEntry;
102 
105  FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output)
106 
107  FEATURE_WALLETCRYPT = 40000, // wallet encryption
108  FEATURE_COMPRPUBKEY = 60000, // compressed public keys
109 
110  FEATURE_PRE_PIVX = 61000, // inherited version..
111 
112  // The following features were implemented in BTC but not in our wallet, we can simply skip them.
113  // FEATURE_HD = 130000, Hierarchical key derivation after BIP32 (HD Wallet)
114  // FEATURE_HD_SPLIT = 139900, // Wallet with HD chain split (change outputs will use m/0'/1'/k)
115 
116  FEATURE_PRE_SPLIT_KEYPOOL = 169900, // Upgraded to HD SPLIT and can have a pre-split keypool
117 
118  FEATURE_SAPLING = 170000, // Upgraded to Saplings key manager.
119 
121 };
122 
124 class CKeyPool
125 {
126 public:
128  int64_t nTime;
132  uint8_t type;
135 
136  CKeyPool();
137  CKeyPool(const CPubKey& vchPubKeyIn, const uint8_t& type);
138 
139  bool IsInternal() const { return type == HDChain::ChangeType::INTERNAL; }
140  bool IsExternal() const { return type == HDChain::ChangeType::EXTERNAL; }
141  bool IsStaking() const { return type == HDChain::ChangeType::STAKING; }
142 
143  template<typename Stream>
144  void Serialize(Stream& s) const
145  {
146  int nVersion = s.GetVersion();
147  if (!(s.GetType() & SER_GETHASH)) {
148  s << nVersion;
149  }
150  s << nTime << vchPubKey << Span<unsigned char>((unsigned char*)&type, 1) << m_pre_split;
151  }
152 
153  template<typename Stream>
154  void Unserialize(Stream& s)
155  {
156  int nVersion = s.GetVersion();
157  if (!(s.GetType() & SER_GETHASH)) {
158  s >> nVersion;
159  }
160  s >> nTime >> vchPubKey;
161  try {
162  s >> Span<unsigned char>((unsigned char*)&type, 1);
163  } catch (std::ios_base::failure&) {
164  /* flag as external address if we can't read the internal boolean
165  (this will be the case for any wallet before the HD chain split version) */
166  type = HDChain::ChangeType::EXTERNAL;
167  }
168  try {
169  s >> m_pre_split;
170  } catch (std::ios_base::failure&) {
171  /* flag as pre-split address if we can't read the m_pre_split boolean
172  (this will be the case for any wallet prior to the HD chain upgrade) */
173  m_pre_split = true;
174  }
175  }
176 };
177 
185 {
186 private:
187  const CBlockIndex* tipBlock{nullptr};
188  int64_t nTime{0};
189  int nTries{0};
190  int nCoins{0};
191 
192 public:
193  // Get
194  const CBlockIndex* GetLastTip() const { return tipBlock; }
195  uint256 GetLastHash() const { return (GetLastTip() == nullptr ? UINT256_ZERO : GetLastTip()->GetBlockHash()); }
196  int GetLastHeight() const { return (GetLastTip() == nullptr ? 0 : GetLastTip()->nHeight); }
197  int GetLastCoins() const { return nCoins; }
198  int GetLastTries() const { return nTries; }
199  int64_t GetLastTime() const { return nTime; }
200  // Set
201  void SetLastCoins(const int coins) { nCoins = coins; }
202  void SetLastTries(const int tries) { nTries = tries; }
203  void SetLastTip(const CBlockIndex* lastTip) { tipBlock = lastTip; }
204  void SetLastTime(const uint64_t lastTime) { nTime = lastTime; }
205  void SetNull()
206  {
207  SetLastCoins(0);
208  SetLastTries(0);
209  SetLastTip(nullptr);
210  SetLastTime(0);
211  }
212  // Check whether staking status is active (last attempt earlier than 30 seconds ago)
213  bool IsActive() const { return (nTime + 30) >= GetTime(); }
214 };
215 
217 public:
220  CRecipientBase(const CAmount& _nAmount, bool _fSubtractFeeFromAmount) :
221  nAmount(_nAmount), fSubtractFeeFromAmount(_fSubtractFeeFromAmount) {}
222  virtual bool isTransparent() const { return true; };
223  virtual Optional<CScript> getScript() const { return nullopt; }
225  virtual std::string getMemo() const { return ""; }
226 };
227 
228 class CRecipient final : public CRecipientBase
229 {
230 public:
232  CRecipient(const CScript& _scriptPubKey, const CAmount& _nAmount, bool _fSubtractFeeFromAmount) :
233  CRecipientBase(_nAmount, _fSubtractFeeFromAmount), scriptPubKey(_scriptPubKey) {}
234  bool isTransparent() const override { return true; }
235  Optional<CScript> getScript() const override { return {scriptPubKey}; }
236 };
237 
239 {
240 public:
241  explicit CAddressBookIterator(std::map<CWDestination, AddressBook::CAddressBookData>& _map) : map(_map), it(_map.begin()), itEnd(_map.end()) {}
242  const CWDestination* GetDestKey();
243  const CTxDestination* GetCTxDestKey();
246 
247  bool IsValid() { return it != itEnd; }
248 
249  bool Next() {
250  if (!IsValid()) return false;
251  it++;
252  return IsValid();
253  }
254 
255  void SetFilter(CTxDestination& filter)
256  {
257  it = map.find(filter);
258  if (it != itEnd) {
259  itEnd = std::next(it);
260  }
261  }
262 
263 private:
264  std::map<CWDestination, AddressBook::CAddressBookData>& map;
265  std::map<CWDestination, AddressBook::CAddressBookData>::iterator it;
266  std::map<CWDestination, AddressBook::CAddressBookData>::iterator itEnd;
267 };
268 
269 template <class T>
270 using TxSpendMap = std::multimap<T, uint256>;
271 typedef std::map<SaplingOutPoint, SaplingNoteData> mapSaplingNoteData_t;
272 
273 typedef std::map<std::string, std::string> mapValue_t;
274 
275 static inline void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
276 {
277  if (!mapValue.count("n")) {
278  nOrderPos = -1; // TODO: calculate elsewhere
279  return;
280  }
281  nOrderPos = atoi64(mapValue["n"].c_str());
282 }
283 
284 
285 static inline void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
286 {
287  if (nOrderPos == -1)
288  return;
289  mapValue["n"] = i64tostr(nOrderPos);
290 }
291 
292 struct COutputEntry {
295  int vout;
296 };
297 
304 {
305 private:
306 
307 public:
308  template<typename Stream>
309  void Unserialize(Stream& s)
310  {
311  CTransactionRef tx;
312  uint256 hashBlock;
313  std::vector<uint256> vMerkleBranch;
314  int nIndex;
315 
316  s >> tx >> hashBlock >> vMerkleBranch >> nIndex;
317  }
318 };
319 
325 {
326 private:
327  const CWallet* pwallet;
328 
332  static const uint256 ABANDON_HASH;
333 
334 public:
337  std::vector<std::pair<std::string, std::string> > vOrderForm;
338  unsigned int fTimeReceivedIsTxTime;
339  unsigned int nTimeReceived;
344  unsigned int nTimeSmart;
345  char fFromMe;
346  int64_t nOrderPos;
347 
348  // memory only
350  CAmount GetCachableAmount(AmountType type, const isminefilter& filter, bool recalculate = false) const;
351  bool IsAmountCached(AmountType type, const isminefilter& filter) const; // Only used in unit tests
353 
355  mutable bool fChangeCached;
356  mutable bool fInMempool;
358  mutable bool fShieldedChangeCached;
360 
361  CWalletTx(const CWallet* pwalletIn, CTransactionRef arg);
362  void Init(const CWallet* pwalletIn);
363 
365 
366  /* New transactions start as UNCONFIRMED. At BlockConnected,
367  * they will transition to CONFIRMED. In case of reorg, at BlockDisconnected,
368  * they roll back to UNCONFIRMED. If we detect a conflicting transaction at
369  * block connection, we update conflicted tx and its dependencies as CONFLICTED.
370  * If tx isn't confirmed and outside of mempool, the user may switch it to ABANDONED
371  * by using the abandontransaction call. This last status may be override by a CONFLICTED
372  * or CONFIRMED transition.
373  */
374  enum Status {
378  ABANDONED
379  };
380 
381  /* Confirmation includes tx status and a triplet of {block height/block hash/tx index in block}
382  * at which tx has been confirmed. All three are set to 0 if tx is unconfirmed or abandoned.
383  * Meaning of these fields changes with CONFLICTED state where they instead point to block hash
384  * and block height of the deepest conflicting tx.
385  */
386  struct Confirmation {
390  int nIndex;
391  Confirmation(Status s = UNCONFIRMED, int b = 0, const uint256& h = UINT256_ZERO, int i = 0) : status(s), block_height(b), hashBlock(h), nIndex(i) {}
392  };
393 
395 
396  template<typename Stream>
397  void Serialize(Stream& s) const
398  {
399  mapValue_t mapValueCopy = mapValue;
400 
401  mapValueCopy["fromaccount"] = "";
402  WriteOrderPos(nOrderPos, mapValueCopy);
403  if (nTimeSmart) {
404  mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);
405  }
406 
407  std::vector<char> dummy_vector1;
408  std::vector<char> dummy_vector2;
409  char dummy_char = false;
410  uint256 serializedHash = isAbandoned() ? ABANDON_HASH : m_confirm.hashBlock;
411  int serializedIndex = isAbandoned() || isConflicted() ? -1 : m_confirm.nIndex;
412  s << tx << serializedHash << dummy_vector1 << serializedIndex << dummy_vector2 << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime << nTimeReceived << fFromMe << dummy_char;
413 
414  if (this->tx->isSaplingVersion()) {
415  s << mapSaplingNoteData;
416  }
417  }
418 
419  template<typename Stream>
420  void Unserialize(Stream& s)
421  {
422  Init(nullptr);
423 
424  std::vector<uint256> dummy_vector1;
425  std::vector<CMerkleTx> dummy_vector2;
426  char dummy_char;
427  int serializedIndex;
428  s >> tx >> m_confirm.hashBlock >> dummy_vector1 >> serializedIndex >> dummy_vector2 >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >> nTimeReceived >> fFromMe >> dummy_char;
429 
430  if (this->tx->isSaplingVersion()) {
431  s >> mapSaplingNoteData;
432  }
433 
434  /* At serialization/deserialization, an nIndex == -1 means that hashBlock refers to
435  * the earliest block in the chain we know this or any in-wallet ancestor conflicts
436  * with. If nIndex == -1 and hashBlock is ABANDON_HASH, it means transaction is abandoned.
437  * In same context, an nIndex >= 0 refers to a confirmed transaction (if hashBlock set) or
438  * unconfirmed one. Older clients interpret nIndex == -1 as unconfirmed for backward
439  * compatibility (pre-commit 9ac63d6).
440  */
441  if (serializedIndex == -1 && m_confirm.hashBlock == ABANDON_HASH) {
442  setAbandoned();
443  } else if (serializedIndex == -1) {
444  setConflicted();
445  } else if (!m_confirm.hashBlock.IsNull()) {
446  m_confirm.nIndex = serializedIndex;
447  setConfirmed();
448  }
449 
450  ReadOrderPos(nOrderPos, mapValue);
451  nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
452 
453  mapValue.erase("fromaccount");
454  mapValue.erase("version");
455  mapValue.erase("spent");
456  mapValue.erase("n");
457  mapValue.erase("timesmart");
458  }
459 
460  void SetTx(CTransactionRef arg) { tx = std::move(arg); }
461 
463  void MarkDirty();
464 
465  void BindWallet(CWallet* pwalletIn);
466 
468 
469  Optional<std::pair<
472 
473  Optional<std::pair<
475  libzcash::SaplingPaymentAddress>> RecoverSaplingNote(const SaplingOutPoint& op, const std::set<uint256>& ovks) const;
476 
478  bool HasP2CSInputs() const;
479 
481  void SetComment(const std::string& comment) { mapValue["comment"] = comment; }
482  std::string GetComment() const {
483  const auto& it = mapValue.find("comment");
484  return it != mapValue.end() ? it->second : "";
485  }
486 
487  int GetDepthAndMempool(bool& fConflicted) const;
488 
490  CAmount GetDebit(const isminefilter& filter) const;
491  CAmount GetCredit(const isminefilter& filter, bool recalculate = false) const;
492  CAmount GetImmatureCredit(bool fUseCache = true, const isminefilter& filter = ISMINE_SPENDABLE_ALL) const;
493  CAmount GetAvailableCredit(bool fUseCache = true, const isminefilter& filter=ISMINE_SPENDABLE) const;
494  // Return sum of locked coins
495  CAmount GetLockedCredit() const;
496  CAmount GetImmatureWatchOnlyCredit(const bool fUseCache = true) const;
497  CAmount GetAvailableWatchOnlyCredit(const bool fUseCache = true) const;
498  CAmount GetChange() const;
499 
500  // Shielded credit/debit/change
501  CAmount GetShieldedChange() const;
502  CAmount GetShieldedAvailableCredit(bool fUseCache = true) const;
503 
504  // Cold staking contracts credit/debit
505  CAmount GetColdStakingCredit(bool fUseCache = true) const;
506  CAmount GetColdStakingDebit(bool fUseCache = true) const;
507  CAmount GetStakeDelegationCredit(bool fUseCache = true) const;
508  CAmount GetStakeDelegationDebit(bool fUseCache = true) const;
509 
510  void GetAmounts(std::list<COutputEntry>& listReceived,
511  std::list<COutputEntry>& listSent,
512  CAmount& nFee,
513  const isminefilter& filter) const;
514 
515  bool IsFromMe(const isminefilter& filter) const;
516 
517  bool InMempool() const;
518 
519  // True if only scriptSigs are different
520  bool IsEquivalentTo(const CWalletTx& tx) const;
521 
522  bool IsTrusted() const;
523  bool IsTrusted(int& nDepth, bool& fConflicted) const;
524 
525  int64_t GetTxTime() const;
526  void UpdateTimeSmart();
527  void RelayWalletTransaction(CConnman* connman);
528  std::set<uint256> GetConflicts() const;
529 
536  // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
537  // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation
538  // "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having to
539  // resolve the issue of member access into incomplete type CWallet. Note
540  // that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)"
541  // in place.
543  bool IsInMainChainImmature() const;
544  int GetBlocksToMaturity() const;
545 
546  bool isAbandoned() const { return m_confirm.status == CWalletTx::ABANDONED; }
548  {
552  m_confirm.nIndex = 0;
553  }
558  bool isConfirmed() const { return m_confirm.status == CWalletTx::CONFIRMED; }
560 
561  const uint256& GetHash() const { return tx->GetHash(); }
562  bool IsCoinBase() const { return tx->IsCoinBase(); }
563  bool IsCoinStake() const { return tx->IsCoinStake(); }
564 
567 };
568 
569 
570 class WalletRescanReserver; //forward declarations for ScanForWalletTransactions/RescanFromTime
571 
577 {
578 private:
579  static std::atomic<bool> fFlushScheduled;
580  std::atomic<bool> fAbortRescan;
581  std::atomic<bool> fScanningWallet; //controlled by WalletRescanReserver
582  std::mutex mutexScanning;
583  friend class WalletRescanReserver;
584 
585 
588 
590  std::unique_ptr<ScriptPubKeyMan> m_spk_man = std::make_unique<ScriptPubKeyMan>(this);
591  std::unique_ptr<SaplingScriptPubKeyMan> m_sspk_man = std::make_unique<SaplingScriptPubKeyMan>(this);
592 
595 
598 
604  std::string m_name;
605 
607  std::unique_ptr<WalletDatabase> database;
608 
619  uint256 m_last_block_processed GUARDED_BY(cs_wallet) = UINT256_ZERO;
620 
621  /* Height of last block processed is used by wallet to know depth of transactions
622  * without relying on Chain interface beyond asynchronous updates. For safety, we
623  * initialize it to -1. Height is a pointer on node's tip and doesn't imply
624  * that the wallet has scanned sequentially all blocks up to this one.
625  */
626  int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
627  int64_t m_last_block_processed_time GUARDED_BY(cs_wallet) = 0;
628 
629  int64_t nNextResend;
630  int64_t nLastResend;
631  std::atomic<int64_t> nTimeBestReceived{0}; // Used only to inform the wallet of when we last received a block
632 
640  void AddToSpends(const COutPoint& outpoint, const uint256& wtxid);
641  void AddToSpends(const uint256& wtxid);
642 
643  /* Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
644  void MarkConflicted(const uint256& hashBlock, int conflicting_height, const uint256& hashTx);
645 
646  template <class T>
647  void SyncMetaData(std::pair<typename TxSpendMap<T>::iterator, typename TxSpendMap<T>::iterator> range);
648  void ChainTipAdded(const CBlockIndex *pindex, const CBlock *pblock, SaplingMerkleTree saplingTree);
649 
650  /* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected */
651  void SyncTransaction(const CTransactionRef& tx, const CWalletTx::Confirmation& confirm);
652 
653  bool IsKeyUsed(const CPubKey& vchPubKey) const;
654 
656  {
657  bool available{false};
658  bool solvable{false};
659  bool spendable{false};
660  };
661 
662  OutputAvailabilityResult CheckOutputAvailability(const CTxOut& output,
663  const unsigned int outIndex,
664  const uint256& wtxid,
665  const CCoinControl* coinControl,
666  const bool fCoinsSelected,
667  const bool fIncludeColdStaking,
668  const bool fIncludeDelegated,
669  const bool fIncludeLocked) const;
670 
672  std::vector<COutput> GetOutputsFromCoinControl(const CCoinControl* coinControl);
673 
675  std::map<CWDestination, AddressBook::CAddressBookData> mapAddressBook;
676 
677 public:
678 
679  static const CAmount DEFAULT_STAKE_SPLIT_THRESHOLD = 500 * COIN;
680 
682  bool SetupSPKM(bool newKeypool = true, bool memOnly = false);
684  bool IsHDEnabled() const;
686  bool IsSaplingUpgradeEnabled() const;
687 
690  {
692  assert(m_last_block_processed_height >= 0);
693  return m_last_block_processed_height;
694  };
696  int GetLastBlockHeightLockWallet() const;
699  {
701  m_last_block_processed_height = pindex->nHeight;
702  m_last_block_processed = pindex->GetBlockHash();
703  m_last_block_processed_time = pindex->GetBlockTime();
704  };
705 
706  /* SPKM Helpers */
707  const CKeyingMaterial& GetEncryptionKey() const;
708  bool HasEncryptionKeys() const;
709 
713 
714  bool HasSaplingSPKM() const;
715 
716  /*
717  * Main wallet lock.
718  * This lock protects all the fields added by CWallet.
719  */
721 
723 
725 
726  std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
727 
728  typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
730  unsigned int nMasterKeyMaxID;
731 
732  // Stake split threshold
734  // minimum value allowed for nStakeSplitThreshold (customizable with -minstakesplit flag)
736  // Staker status (last hashed block and time)
738 
739  // User-defined fee PIV/kb
742 
743  //Auto Combine Inputs
747 
751  WalletDatabase* GetDBHandlePtr() const { return database.get(); }
752  WalletDatabase& GetDBHandle() const { return *database; }
753 
756  const std::string& GetName() const { return m_name; }
757 
759  fs::path GetPathToDBFile() { return database->GetPathToFile(); }
760 
762  CWallet(std::string name, std::unique_ptr<WalletDatabase> dbw_in);
763  ~CWallet();
764  void SetNull();
765 
766  std::map<uint256, CWalletTx> mapWallet;
767 
768  typedef std::multimap<int64_t, CWalletTx*> TxItems;
770 
771  int64_t nOrderPosNext;
772 
773  std::set<COutPoint> setLockedCoins;
774  std::set<SaplingOutPoint> setLockedNotes;
775 
776  int64_t nTimeFirstKey;
777 
778  // Public SyncMetadata interface used for the sapling spent nullifier map.
780 
781  const CWalletTx* GetWalletTx(const uint256& hash) const;
782 
783  std::vector<CWalletTx> getWalletTxs();
784  std::string GetUniqueWalletBackupName() const;
785 
787  bool CanSupportFeature(enum WalletFeature wf);
788 
790  public:
792  AvailableCoinsFilter(bool _fIncludeDelegated,
793  bool _fIncludeColdStaking,
794  bool _fOnlySafe,
795  bool _fOnlySpendable,
796  std::set<CTxDestination>* _onlyFilteredDest,
797  int _minDepth,
798  bool _fIncludeLocked = false,
799  CAmount _nMaxOutValue = 0) :
800  fIncludeDelegated(_fIncludeDelegated),
801  fIncludeColdStaking(_fIncludeColdStaking),
802  fOnlySafe(_fOnlySafe),
803  fOnlySpendable(_fOnlySpendable),
804  onlyFilteredDest(_onlyFilteredDest),
805  minDepth(_minDepth),
806  fIncludeLocked(_fIncludeLocked),
807  nMaxOutValue(_nMaxOutValue) {}
808 
809  bool fIncludeDelegated{true};
810  bool fIncludeColdStaking{false};
811  bool fOnlySafe{true};
812  bool fOnlySpendable{false};
813  std::set<CTxDestination>* onlyFilteredDest{nullptr};
814  int minDepth{0};
815  bool fIncludeLocked{false};
816  // Select outputs with value <= nMaxOutValue
817  CAmount nMaxOutValue{0}; // 0 means not active
818  CAmount nMinOutValue{0}; // 0 means not active
819  CAmount nMinimumSumAmount{0}; // 0 means not active
820  unsigned int nMaximumCount{0}; // 0 means not active
821  };
822 
826  bool AvailableCoins(std::vector<COutput>* pCoins, // --> populates when != nullptr
827  const CCoinControl* coinControl = nullptr,
828  AvailableCoinsFilter coinsFilter = AvailableCoinsFilter()
829  ) const;
831  bool SelectCoinsToSpend(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*, unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl = nullptr) const;
832 
837  bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, uint64_t nMaxAncestors, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*, unsigned int> >& setCoinsRet, CAmount& nValueRet) const;
839  bool StakeableCoins(std::vector<CStakeableOutput>* pCoins = nullptr);
841  void GetAvailableP2CSCoins(std::vector<COutput>& vCoins) const;
842 
843  std::map<CTxDestination, std::vector<COutput> > AvailableCoinsByAddress(bool fConfirmed, CAmount maxCoinValue, bool fIncludeColdStaking);
844 
850  std::map<std::pair<CTxDestination, Optional<CTxDestination>>, std::vector<COutput>> ListCoins() const;
854  std::map<libzcash::SaplingPaymentAddress, std::vector<SaplingNoteEntry>> ListNotes() const;
855 
857  bool GetMasternodeVinAndKeys(CPubKey& pubKeyRet,
858  CKey& keyRet,
859  const COutPoint& collateralOut,
860  bool fValidateCollateral,
861  std::string& strError);
862 
863  bool IsSaplingSpent(const SaplingOutPoint& op) const;
864  bool IsSpent(const COutPoint& outpoint) const;
865  bool IsSpent(const uint256& hash, unsigned int n) const;
866 
867  bool IsLockedCoin(const uint256& hash, unsigned int n) const;
868  bool IsLockedNote(const SaplingOutPoint& op) const;
869 
870  void LockCoin(const COutPoint& output);
871  void LockNote(const SaplingOutPoint& op);
872 
873  void UnlockCoin(const COutPoint& output);
874  void UnlockNote(const SaplingOutPoint& op);
875 
876  void UnlockAllCoins();
877  void UnlockAllNotes();
878 
879  std::set<COutPoint> ListLockedCoins();
880  std::set<SaplingOutPoint> ListLockedNotes();
881 
882  /*
883  * Rescan abort properties
884  */
885  void AbortRescan() { fAbortRescan = true; }
886  bool IsAbortingRescan() { return fAbortRescan; }
887  bool IsScanning() { return fScanningWallet; }
888 
889  /*
890  * Stake Split threshold
891  */
892  bool SetStakeSplitThreshold(const CAmount sst);
894 
895  /*
896  * Requires cs_wallet lock.
897  * Lock for spending the coin c, if it's owned by the wallet, it's unspent, and:
898  * -- If ptx is not null, c is one of the outputs of *ptx
899  * -- If ptx is null, c is the output of a transaction in mapWallet
900  */
901  void LockOutpointIfMine(const CTransactionRef& ptx, const COutPoint& c);
902  /*
903  * Same functionality as above but locking the cs_wallet mutex internally.
904  * future: add capability to lock the mutex from outside of this class without exposing it.
905  */
906  void LockOutpointIfMineWithMutex(const CTransactionRef& ptx, const COutPoint& c);
907 
908  /*
909  * Requires cs_wallet lock.
910  * Called from AddToWalletIfInvolvingMe. If ptx is a ProRegTx, and the
911  * collateral (either referenced or created) is owned by this wallet,
912  * lock the corresponding coin, to prevent accidental spending.
913  */
914  void LockIfMyCollateral(const CTransactionRef& ptx);
915 
916  // keystore implementation
917  CallResult<CTxDestination> getNewAddress(const std::string& addressLabel, const std::string purpose,
919  CallResult<CTxDestination> getNewAddress(const std::string& label);
920  CallResult<CTxDestination> getNewStakingAddress(const std::string& label);
921  int64_t GetKeyCreationTime(const CWDestination& dest);
922  int64_t GetKeyCreationTime(CPubKey pubkey);
923  int64_t GetKeyCreationTime(const CTxDestination& address);
924  int64_t GetKeyCreationTime(const libzcash::SaplingPaymentAddress& address);
925 
927 
928  // Search for notes and addresses from this wallet in the tx, and add the addresses --> IVK mapping to the keystore if missing.
930  // Decrypt sapling output notes with the inputs ovk and updates saplingNoteDataMap
931  void AddExternalNotesDataToTx(CWalletTx& wtx) const;
932 
935 
937  void IncrementNoteWitnesses(const CBlockIndex* pindex,
938  const CBlock* pblock,
939  SaplingMerkleTree& saplingTree);
940 
942  void DecrementNoteWitnesses(const CBlockIndex* pindex);
943 
945  void ClearNoteWitnessCache();
946 
947 
952  const libzcash::SaplingPaymentAddress &addr);
955  const std::vector<unsigned char> &vchCryptedSecret);
958 
959 
971  const std::vector<unsigned char> &vchCryptedSecret);
972 
974 
976  bool AddKeyPubKey(const CKey& key, const CPubKey& pubkey) override;
978  bool LoadKey(const CKey& key, const CPubKey& pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); }
980  bool LoadKeyMetadata(const CPubKey& pubkey, const CKeyMetadata& metadata);
981 
982  bool LoadMinVersion(int nVersion);
983  void UpdateTimeFirstKey(int64_t nCreateTime);
984 
986  bool AddCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret) override;
988  bool LoadCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret);
989  bool AddCScript(const CScript& redeemScript) override;
990  bool LoadCScript(const CScript& redeemScript);
991 
993  bool AddDestData(const CTxDestination& dest, const std::string& key, const std::string& value);
995  bool EraseDestData(const CTxDestination& dest, const std::string& key);
997  bool LoadDestData(const CTxDestination& dest, const std::string& key, const std::string& value);
999  std::vector<std::string> GetDestValues(const std::string& prefix) const;
1000 
1002  bool AddWatchOnly(const CScript& dest) override;
1003  bool RemoveWatchOnly(const CScript& dest) override;
1005  bool LoadWatchOnly(const CScript& dest);
1006 
1009  int64_t nRelockTime;
1010  bool Lock();
1011  bool Unlock(const SecureString& strWalletPassphrase, bool anonimizeOnly = false);
1012  bool Unlock(const CKeyingMaterial& vMasterKeyIn);
1013 
1014  bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
1015  bool EncryptWallet(const SecureString& strWalletPassphrase);
1016 
1017  std::vector<CKeyID> GetAffectedKeys(const CScript& spk);
1018  void GetKeyBirthTimes(std::map<CKeyID, int64_t>& mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1019 
1024  int64_t IncOrderPosNext(WalletBatch* batch = nullptr);
1025 
1026  void MarkDirty();
1027  bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose = true);
1028  bool LoadToWallet(CWalletTx& wtxIn);
1029  void TransactionAddedToMempool(const CTransactionRef& tx) override;
1030  void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex) override;
1031  void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const uint256& blockHash, int nBlockHeight, int64_t blockTime) override;
1032  bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const CWalletTx::Confirmation& confirm, bool fUpdate);
1033  void EraseFromWallet(const uint256& hash);
1034 
1038  bool Upgrade(std::string& error, const int prevVersion);
1039  bool ActivateSaplingWallet(bool memOnly = false);
1040 
1041  int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver, bool update);
1042  CBlockIndex* ScanForWalletTransactions(CBlockIndex* pindexStart, CBlockIndex* pindexStop, const WalletRescanReserver& reserver, bool fUpdate = false, bool fromStartup = false);
1043  void TransactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) override;
1044  void ReacceptWalletTransactions(bool fFirstLoad = false);
1045  void ResendWalletTransactions(CConnman* connman) override;
1046  void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override;
1047 
1048  struct Balance {
1055  };
1056  Balance GetBalance(int min_depth = 0) const;
1057 
1058  CAmount loopTxsBalance(const std::function<void(const uint256&, const CWalletTx&, CAmount&)>&method) const;
1059  CAmount GetAvailableBalance(bool fIncludeDelegated = true, bool fIncludeShielded = true) const;
1060  CAmount GetAvailableBalance(isminefilter& filter, bool useCache = false, int minDepth = 1) const;
1061  CAmount GetColdStakingBalance() const; // delegated coins for which we have the staking key
1063  CAmount GetStakingBalance(const bool fIncludeColdStaking = true) const;
1064  CAmount GetDelegatedBalance() const; // delegated coins for which we have the spending key
1066  CAmount GetLockedCoins() const;
1067  CAmount GetLockedShieldCoins() const;
1069  CAmount GetImmatureBalance() const;
1070  CAmount GetWatchOnlyBalance() const;
1073  CAmount GetLegacyBalance(const isminefilter& filter, int minDepth) const;
1074  bool FundTransaction(CMutableTransaction& tx, CAmount &nFeeRet, bool overrideEstimatedFeeRate, const CFeeRate& specificFeeRate, int& nChangePosInOut, std::string& strFailReason, bool includeWatching, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, const CTxDestination& destChange = CNoDestination());
1080  bool CreateTransaction(const std::vector<CRecipient>& vecSend,
1081  CTransactionRef& txRet,
1082  CReserveKey& reservekey,
1083  CAmount& nFeeRet,
1084  int& nChangePosInOut,
1085  std::string& strFailReason,
1086  const CCoinControl* coinControl = nullptr,
1087  bool sign = true,
1088  CAmount nFeePay = 0,
1089  bool fIncludeDelegated = false,
1090  bool* fStakeDelegationVoided = nullptr,
1091  int nExtraSize = 0,
1092  int nMinDepth = 0);
1093 
1094  bool CreateTransaction(CScript scriptPubKey, const CAmount& nValue, CTransactionRef& tx, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl = nullptr, CAmount nFeePay = 0, bool fIncludeDelegated = false, bool* fStakeDelegationVoided = nullptr, int nExtraSize = 0, int nMinDepth = 0);
1095 
1096  // enumeration for CommitResult (return status of CommitTransaction)
1098  {
1100  Abandoned, // Failed to accept to memory pool. Successfully removed from the wallet.
1101  NotAccepted, // Failed to accept to memory pool. Unable to abandon.
1102  };
1104  {
1109  // converts CommitResult in human-readable format
1110  std::string ToString() const;
1111  };
1113  CWallet::CommitResult CommitTransaction(CTransactionRef tx, CReserveKey* reservekey, CConnman* connman, mapValue_t* extraValues=nullptr);
1114 
1115  bool CreateCoinstakeOuts(const CPivStake& stakeInput, std::vector<CTxOut>& vout, CAmount nTotal) const;
1116  bool CreateCoinStake(const CBlockIndex* pindexPrev,
1117  unsigned int nBits,
1118  CMutableTransaction& txNew,
1119  int64_t& nTxNewTime,
1120  std::vector<CStakeableOutput>* availableCoins,
1121  bool stopOnNewBlock = true) const;
1122  bool SignCoinStake(CMutableTransaction& txNew) const;
1123  void AutoCombineDust(CConnman* connman);
1124 
1125  // Shielded balances
1126  CAmount GetAvailableShieldedBalance(bool fUseCache = true) const;
1128 
1130 
1131  size_t KeypoolCountExternalKeys();
1132  bool TopUpKeyPool(unsigned int kpSize = 0);
1133  void KeepKey(int64_t nIndex);
1134  void ReturnKey(int64_t nIndex, const bool internal = false, const bool staking = false);
1135  bool GetKeyFromPool(CPubKey& key, const uint8_t& type = HDChain::ChangeType::EXTERNAL);
1136  int64_t GetOldestKeyPoolTime();
1137 
1138  std::set<std::set<CTxDestination> > GetAddressGroupings();
1139  std::map<CTxDestination, CAmount> GetAddressBalances();
1140 
1141  std::set<CTxDestination> GetLabelAddresses(const std::string& label) const;
1142 
1143  bool CreateBudgetFeeTX(CTransactionRef& tx, const uint256& hash, CReserveKey& keyChange, CAmount fee);
1144 
1145  bool IsUsed(const CTxDestination address) const;
1146  bool IsUsed(const libzcash::SaplingPaymentAddress address) const;
1147 
1148  isminetype IsMine(const CTxIn& txin) const;
1149  CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
1150  isminetype IsMine(const CTxOut& txout) const;
1151  CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
1152  bool IsChange(const CTxOut& txout) const;
1153  bool IsChange(const CTxDestination& address) const;
1154  CAmount GetChange(const CTxOut& txout) const;
1155  bool IsMine(const CTransactionRef& tx) const;
1157  bool IsFromMe(const CTransactionRef& tx) const;
1158  CAmount GetDebit(const CTransactionRef& tx, const isminefilter& filter) const;
1159  CAmount GetCredit(const CWalletTx& tx, const isminefilter& filter) const;
1160  CAmount GetChange(const CTransactionRef& tx) const;
1161 
1162  void SetBestChain(const CBlockLocator& loc) override;
1163  void SetBestChainInternal(WalletBatch& batch, const CBlockLocator& loc); // only public for testing purposes, must never be called directly in any other situation
1164  // Force balance recomputation if any transaction got conflicted
1165  void MarkAffectedTransactionsDirty(const CTransaction& tx); // only public for testing purposes, must never be called directly in any other situation
1166 
1167  DBErrors LoadWallet(bool& fFirstRunRet);
1168  DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);
1169 
1170  static std::string ParseIntoAddress(const CWDestination& dest, const std::string& purpose);
1171 
1172  bool SetAddressBook(const CWDestination& address, const std::string& strName, const std::string& purpose);
1174  bool HasAddressBook(const CWDestination& address) const;
1175  bool HasDelegator(const CTxOut& out) const;
1176  int GetAddressBookSize() const { return mapAddressBook.size(); };
1177 
1179  std::string GetPurposeForAddressBookEntry(const CWDestination& address) const;
1180  std::string GetNameForAddressBookEntry(const CWDestination& address) const;
1182 
1183  void LoadAddressBookName(const CWDestination& dest, const std::string& strName);
1184  void LoadAddressBookPurpose(const CWDestination& dest, const std::string& strPurpose);
1185 
1186  unsigned int GetKeyPoolSize();
1187  unsigned int GetStakingKeyPoolSize();
1188 
1190  bool SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr, bool fExplicit = false);
1191 
1193  bool SetMaxVersion(int nVersion);
1194 
1196  int GetVersion();
1197 
1199  std::set<uint256> GetConflicts(const uint256& txid) const;
1200 
1202  void Flush(bool shutdown=false);
1203 
1204  /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
1205  bool AbandonTransaction(const uint256& hashTx);
1206 
1207  /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
1208  static CWallet* CreateWalletFromFile(const std::string& name, const fs::path& path);
1209 
1215 
1219  bool BackupWallet(const std::string& strDest);
1220 
1228 
1233  boost::signals2::signal<void(CWallet* wallet, const CWDestination& address, const std::string& label, bool isMine, const std::string& purpose, ChangeType status)> NotifyAddressBookChanged;
1234 
1239  boost::signals2::signal<void(CWallet* wallet, const uint256& hashTx, ChangeType status)> NotifyTransactionChanged;
1240 
1242  boost::signals2::signal<void(const std::string& title, int nProgress)> ShowProgress;
1243 
1245  boost::signals2::signal<void(bool fHaveWatchOnly)> NotifyWatchonlyChanged;
1246 
1248  boost::signals2::signal<void (const bool fSuccess, const std::string& filename)> NotifyWalletBacked;
1249 
1251  boost::signals2::signal<void (const CAmount stakeSplitThreshold)> NotifySSTChanged;
1252 };
1253 
1256 {
1257 protected:
1259  int64_t nIndex;
1260  bool internal{false};
1262 
1263 public:
1264  explicit CReserveKey(CWallet* pwalletIn)
1265  {
1266  nIndex = -1;
1267  pwallet = pwalletIn;
1268  }
1269 
1270  CReserveKey() = default;
1271  CReserveKey(const CReserveKey&) = delete;
1272  CReserveKey& operator=(const CReserveKey&) = delete;
1273 
1275  {
1276  ReturnKey();
1277  }
1278 
1279  void ReturnKey();
1280  bool GetReservedKey(CPubKey& pubkey, bool internal = false);
1281  void KeepKey();
1282 };
1283 
1284 class COutput
1285 {
1286 public:
1287  const CWalletTx* tx;
1288  int i;
1289  int nDepth;
1290 
1293 
1296 
1302  bool fSafe;
1303 
1304  COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn) :
1305  tx(txIn), i(iIn), nDepth(nDepthIn), fSpendable(fSpendableIn), fSolvable(fSolvableIn), fSafe(fSafeIn)
1306  {}
1307 
1308  CAmount Value() const { return tx->tx->vout[i].nValue; }
1309  std::string ToString() const;
1310 };
1311 
1313 {
1314 public:
1315  const CBlockIndex* pindex{nullptr};
1316 
1317  CStakeableOutput(const CWalletTx* txIn, int iIn, int nDepthIn,
1318  const CBlockIndex*& pindex);
1319 
1320 };
1321 
1324 {
1325 private:
1328 public:
1330 
1331  bool reserve()
1332  {
1333  assert(!m_could_reserve);
1334  std::lock_guard<std::mutex> lock(m_wallet->mutexScanning);
1335  if (m_wallet->fScanningWallet) {
1336  return false;
1337  }
1338  m_wallet->fScanningWallet = true;
1339  m_could_reserve = true;
1340  return true;
1341  }
1342 
1343  bool isReserved() const
1344  {
1346  }
1347 
1349  {
1350  std::lock_guard<std::mutex> lock(m_wallet->mutexScanning);
1351  if (m_could_reserve) {
1352  m_wallet->fScanningWallet = false;
1353  }
1354  }
1355 };
1356 
1357 #endif // PIVX_WALLET_WALLET_H
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
false
Definition: bls_dkg.cpp:151
Address book data.
Definition: addressbook.h:31
An instance of this class represents one database.
Definition: db.h:105
AddressBook::CAddressBookData GetValue()
Definition: wallet.h:245
std::map< CWDestination, AddressBook::CAddressBookData >::iterator it
Definition: wallet.h:265
std::map< CWDestination, AddressBook::CAddressBookData > & map
Definition: wallet.h:264
std::map< CWDestination, AddressBook::CAddressBookData >::iterator itEnd
Definition: wallet.h:266
CAddressBookIterator(std::map< CWDestination, AddressBook::CAddressBookData > &_map)
Definition: wallet.h:241
const libzcash::SaplingPaymentAddress * GetShieldedDestKey()
Definition: wallet.cpp:4964
const CWDestination * GetDestKey()
Definition: wallet.cpp:4969
const CTxDestination * GetCTxDestKey()
Definition: wallet.cpp:4959
void SetFilter(CTxDestination &filter)
Definition: wallet.h:255
Definition: block.h:80
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
Coin Control Features.
Definition: coincontrol.h:34
Definition: net.h:145
Keystore which keeps the private keys encrypted.
Definition: crypter.h:127
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
Definition: crypter.cpp:156
Fee rate in PIV per kilobyte: CAmount / kB.
Definition: feerate.h:20
An encapsulated private key.
Definition: key.h:30
A key pool entry.
Definition: wallet.h:125
void Unserialize(Stream &s)
Definition: wallet.h:154
uint8_t type
Whether this keypool entry is in the internal, external or staking keypool.
Definition: wallet.h:132
bool IsExternal() const
Definition: wallet.h:140
CPubKey vchPubKey
The public key.
Definition: wallet.h:130
bool IsStaking() const
Definition: wallet.h:141
int64_t nTime
The time at which the key was generated. Set in AddKeypoolPubKeyWithDB.
Definition: wallet.h:128
CKeyPool()
Definition: wallet.cpp:4462
bool m_pre_split
Whether this key was generated for a keypool before the wallet was upgraded to HD-split.
Definition: wallet.h:134
bool IsInternal() const
Definition: wallet.h:139
void Serialize(Stream &s) const
Definition: wallet.h:144
Legacy class used for deserializing vtxPrev for backwards compatibility.
Definition: wallet.h:304
void Unserialize(Stream &s)
Definition: wallet.h:309
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:72
int nDepth
Definition: wallet.h:1289
bool fSafe
Whether this output is considered safe to spend.
Definition: wallet.h:1302
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn)
Definition: wallet.h:1304
bool fSolvable
Whether we know how to spend this output, ignoring the lack of keys.
Definition: wallet.h:1295
CAmount Value() const
Definition: wallet.h:1308
bool fSpendable
Whether we have the private keys to spend this output.
Definition: wallet.h:1292
const CWalletTx * tx
Definition: wallet.h:1287
int i
Definition: wallet.h:1288
An encapsulated public key.
Definition: pubkey.h:44
bool fSubtractFeeFromAmount
Definition: wallet.h:219
virtual bool isTransparent() const
Definition: wallet.h:222
virtual std::string getMemo() const
Definition: wallet.h:225
CAmount nAmount
Definition: wallet.h:218
virtual Optional< libzcash::SaplingPaymentAddress > getSapPaymentAddr() const
Definition: wallet.h:224
CRecipientBase(const CAmount &_nAmount, bool _fSubtractFeeFromAmount)
Definition: wallet.h:220
virtual Optional< CScript > getScript() const
Definition: wallet.h:223
CScript scriptPubKey
Definition: wallet.h:231
Optional< CScript > getScript() const override
Definition: wallet.h:235
bool isTransparent() const override
Definition: wallet.h:234
CRecipient(const CScript &_scriptPubKey, const CAmount &_nAmount, bool _fSubtractFeeFromAmount)
Definition: wallet.h:232
A key allocated from the key pool.
Definition: wallet.h:1256
int64_t nIndex
Definition: wallet.h:1259
CPubKey vchPubKey
Definition: wallet.h:1261
CReserveKey & operator=(const CReserveKey &)=delete
~CReserveKey()
Definition: wallet.h:1274
CReserveKey()=default
CWallet * pwallet
Definition: wallet.h:1258
CReserveKey(CWallet *pwalletIn)
Definition: wallet.h:1264
CReserveKey(const CReserveKey &)=delete
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:381
const CBlockIndex * pindex
Definition: wallet.h:1315
CStakeableOutput(const CWalletTx *txIn, int iIn, int nDepthIn, const CBlockIndex *&pindex)
Definition: wallet.cpp:4974
Record info about last stake attempt:
Definition: wallet.h:185
void SetLastTime(const uint64_t lastTime)
Definition: wallet.h:204
int nCoins
Definition: wallet.h:190
int64_t GetLastTime() const
Definition: wallet.h:199
void SetNull()
Definition: wallet.h:205
void SetLastTries(const int tries)
Definition: wallet.h:202
const CBlockIndex * GetLastTip() const
Definition: wallet.h:194
uint256 GetLastHash() const
Definition: wallet.h:195
int nTries
Definition: wallet.h:189
void SetLastCoins(const int coins)
Definition: wallet.h:201
int GetLastHeight() const
Definition: wallet.h:196
void SetLastTip(const CBlockIndex *lastTip)
Definition: wallet.h:203
const CBlockIndex * tipBlock
Definition: wallet.h:187
int64_t nTime
Definition: wallet.h:188
bool IsActive() const
Definition: wallet.h:213
int GetLastTries() const
Definition: wallet.h:198
int GetLastCoins() const
Definition: wallet.h:197
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:244
An input of a transaction.
Definition: transaction.h:94
An output of a transaction.
Definition: transaction.h:137
Implement this to subscribe to events generated in validation.
Capture information about block/transaction validation.
Definition: validation.h:24
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:577
WalletBatch * encrypted_batch
Definition: wallet.h:724
std::map< CWDestination, AddressBook::CAddressBookData > mapAddressBook
Destination --> label/purpose mapping.
Definition: wallet.h:675
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:766
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:4092
int nWalletMaxVersion
the maximum wallet format version: memory-only variable that specifies to what version this wallet ma...
Definition: wallet.h:597
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:728
uint256 m_last_block_processed GUARDED_BY(cs_wallet)
The following is used to keep track of how far behind the wallet is from the chain sync,...
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: wallet.cpp:4026
TxSpendMap< COutPoint > TxSpends
Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated tran...
Definition: wallet.h:638
static CWallet * CreateWalletFromFile(const std::string &name, const fs::path &path)
Definition: wallet.cpp:4251
void IncrementNoteWitnesses(const CBlockIndex *pindex, const CBlock *pblock, SaplingMerkleTree &saplingTree)
pindex is the new tip being connected.
Definition: wallet.cpp:4720
bool LoadCryptedSaplingZKey(const libzcash::SaplingExtendedFullViewingKey &extfvk, const std::vector< unsigned char > &vchCryptedSecret)
Adds an encrypted spending key to the store, without saving it to disk (used by LoadWallet)
Definition: wallet.cpp:4741
MasterKeyMap mapMasterKeys
Definition: wallet.h:729
boost::signals2::signal< void(const CAmount stakeSplitThreshold)> NotifySSTChanged
notify stake-split threshold changed
Definition: wallet.h:1251
std::string m_name
Wallet filename from wallet=<path> command line or config option.
Definition: wallet.h:604
TxItems wtxOrdered
Definition: wallet.h:769
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:756
fs::path GetPathToDBFile()
Get the path to the wallet's db file.
Definition: wallet.h:759
void DecrementNoteWitnesses(const CBlockIndex *pindex)
pindex is the old tip being disconnected.
Definition: wallet.cpp:4724
bool LoadSaplingZKeyMetadata(const libzcash::SaplingIncomingViewingKey &ivk, const CKeyMetadata &meta)
Load spending key metadata (used by LoadWallet)
Definition: wallet.cpp:4740
CStakerStatus * pStakerStatus
Definition: wallet.h:737
void LockOutpointIfMine(const CTransactionRef &ptx, const COutPoint &c)
Definition: wallet.cpp:4221
int64_t m_last_block_processed_time GUARDED_BY(cs_wallet)=0
RecursiveMutex cs_wallet
Definition: wallet.h:720
bool fDecryptionThoroughlyChecked
keeps track of whether Unlock has run a thorough check before
Definition: wallet.h:587
void AutoCombineDust(CConnman *connman)
Definition: wallet.cpp:4112
bool fCombineDust
Definition: wallet.h:744
std::unique_ptr< ScriptPubKeyMan > m_spk_man
Key manager //.
Definition: wallet.h:590
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet)
Definition: wallet.cpp:4701
CAddressBookIterator NewAddressBookIterator()
Definition: wallet.h:1178
bool AddSaplingZKey(const libzcash::SaplingExtendedSpendingKey &key)
Adds Sapling spending key to the store, and saves it to disk.
Definition: wallet.cpp:4728
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:978
CWallet(std::string name, std::unique_ptr< WalletDatabase > dbw_in)
Construct wallet with specified name and database implementation.
Definition: wallet.cpp:4535
boost::signals2::signal< void(const bool fSuccess, const std::string &filename)> NotifyWalletBacked
notify wallet file backed up
Definition: wallet.h:1248
int64_t nRelockTime
Lock Wallet Holds a timestamp at which point the wallet is scheduled (externally) to be relocked.
Definition: wallet.h:1009
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:1239
void LockOutpointIfMineWithMutex(const CTransactionRef &ptx, const COutPoint &c)
Definition: wallet.cpp:4216
std::unique_ptr< SaplingScriptPubKeyMan > m_sspk_man
Definition: wallet.h:591
bool IsAbortingRescan()
Definition: wallet.h:886
CAmount nStakeSplitThreshold
Definition: wallet.h:733
std::atomic< bool > fAbortRescan
Definition: wallet.h:580
bool IsScanning()
Definition: wallet.h:887
std::mutex mutexScanning
Definition: wallet.h:582
std::set< COutPoint > setLockedCoins
Definition: wallet.h:773
static CAmount minStakeSplitThreshold
minimum accpeted value for stake split threshold
Definition: wallet.h:735
void SetLastBlockProcessed(const CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Set last block processed height, currently only use in unit test.
Definition: wallet.h:698
void postInitProcess(CScheduler &scheduler)
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
Definition: wallet.cpp:4446
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
Definition: wallet.h:689
bool BackupWallet(const std::string &strDest)
Creates a wallet backup in strDest path.
Definition: wallet.cpp:4457
int64_t nTimeFirstKey
Definition: wallet.h:776
bool CanSupportFeature(enum WalletFeature wf)
check whether we are allowed to upgrade (or already support) to the named feature
Definition: wallet.cpp:4584
bool LoadMinVersion(int nVersion)
Definition: wallet.cpp:4590
CAmount nAutoCombineThreshold
Definition: wallet.h:745
TxSpends mapTxSpends
Definition: wallet.h:639
bool LoadSaplingZKey(const libzcash::SaplingExtendedSpendingKey &key)
Adds spending key to the store, without saving it to disk (used by LoadWallet)
Definition: wallet.cpp:4739
void LockIfMyCollateral(const CTransactionRef &ptx)
Definition: wallet.cpp:4241
int64_t nLastResend
Definition: wallet.h:630
int64_t nNextResend
Definition: wallet.h:629
std::vector< std::string > GetDestValues(const std::string &prefix) const
Get all destination values matching a prefix.
Definition: wallet.cpp:4098
bool fUseCustomFee
Definition: wallet.h:740
bool HaveSpendingKeyForPaymentAddress(const libzcash::SaplingPaymentAddress &zaddr) const
Returns true if the wallet contains the spending key.
Definition: wallet.cpp:4738
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
Definition: wallet.cpp:4085
unsigned int GetKeyPoolSize()
Definition: wallet.cpp:4691
std::set< SaplingOutPoint > setLockedNotes
Definition: wallet.h:774
CAmount GetCredit(const CTxOut &txout, const isminefilter &filter) const
Definition: wallet.cpp:4603
std::unique_ptr< WalletDatabase > database
Internal database handle.
Definition: wallet.h:607
WalletDatabase * GetDBHandlePtr() const
Get database handle used by this wallet.
Definition: wallet.h:751
int m_last_block_processed_height GUARDED_BY(cs_wallet)
static CFeeRate minTxFee
Fees smaller than this (in upiv) are considered zero fee (for transaction creation) We are ~100 times...
Definition: wallet.h:1129
std::multimap< int64_t, CWalletTx * > TxItems
Definition: wallet.h:768
void SetNull()
Definition: wallet.cpp:4546
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:1245
std::atomic< int64_t > nTimeBestReceived
Definition: wallet.h:631
bool fWalletUnlockStaking
Definition: wallet.h:722
CAmount nCustomFee
Definition: wallet.h:741
bool IsFromMe(const CTransactionRef &tx) const
should probably be renamed to IsRelevantToMe
Definition: wallet.cpp:4625
CAmount GetChange(const CTxOut &txout) const
Definition: wallet.cpp:4610
~CWallet()
Definition: wallet.cpp:4540
SaplingScriptPubKeyMan * GetSaplingScriptPubKeyMan() const
Definition: wallet.h:712
CommitStatus
Definition: wallet.h:1098
@ Abandoned
Definition: wallet.h:1100
@ OK
Definition: wallet.h:1099
@ NotAccepted
Definition: wallet.h:1101
std::string GetUniqueWalletBackupName() const
Definition: wallet.cpp:4529
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:4076
std::map< CKeyID, CKeyMetadata > mapKeyMetadata
Definition: wallet.h:726
int nWalletVersion
the current wallet version: clients below this version are not able to load the wallet
Definition: wallet.h:594
unsigned int GetStakingKeyPoolSize()
Definition: wallet.cpp:4696
libzcash::SaplingPaymentAddress GenerateNewSaplingZKey(std::string label="")
Generates new Sapling key.
Definition: wallet.cpp:4710
static const CAmount DEFAULT_STAKE_SPLIT_THRESHOLD
Definition: wallet.h:679
bool LoadSaplingPaymentAddress(const libzcash::SaplingPaymentAddress &addr, const libzcash::SaplingIncomingViewingKey &ivk)
Adds a Sapling payment address -> incoming viewing key map entry, without saving it to disk (used by ...
Definition: wallet.cpp:4744
CAmount GetStakeSplitThreshold() const
Definition: wallet.h:893
void ClearNoteWitnessCache()
clear note witness cache
Definition: wallet.cpp:4726
bool AddSaplingIncomingViewingKeyW(const libzcash::SaplingIncomingViewingKey &ivk, const libzcash::SaplingPaymentAddress &addr)
Definition: wallet.cpp:4730
std::atomic< bool > fScanningWallet
Definition: wallet.h:581
int frequency
Definition: wallet.h:746
int GetAddressBookSize() const
Definition: wallet.h:1176
void AbortRescan()
Definition: wallet.h:885
unsigned int nMasterKeyMaxID
Definition: wallet.h:730
boost::signals2::signal< void(CWallet *wallet, const CWDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
Definition: wallet.h:1233
int64_t nOrderPosNext
Definition: wallet.h:771
WalletDatabase & GetDBHandle() const
Definition: wallet.h:752
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:1242
bool AddCryptedSaplingSpendingKeyW(const libzcash::SaplingExtendedFullViewingKey &extfvk, const std::vector< unsigned char > &vchCryptedSecret)
Definition: wallet.cpp:4734
static std::atomic< bool > fFlushScheduled
Definition: wallet.h:579
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:325
void SetComment(const std::string &comment)
Store a comment.
Definition: wallet.h:481
@ CONFIRMED
Definition: wallet.h:376
@ ABANDONED
Definition: wallet.h:378
@ CONFLICTED
Definition: wallet.h:377
@ UNCONFIRMED
Definition: wallet.h:375
char fFromMe
Definition: wallet.h:345
bool isAbandoned() const
Definition: wallet.h:546
mapValue_t mapValue
Definition: wallet.h:335
CTransactionRef tx
Definition: wallet.h:364
const CWallet * pwallet
Definition: wallet.h:327
Optional< std::pair< libzcash::SaplingNotePlaintext, libzcash::SaplingPaymentAddress > > RecoverSaplingNote(const SaplingOutPoint &op, const std::set< uint256 > &ovks) const
Definition: wallet.cpp:4894
int GetDepthInMainChain() const NO_THREAD_SAFETY_ANALYSIS
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
Definition: wallet.cpp:4477
bool isUnconfirmed() const
Definition: wallet.h:556
void setConflicted()
Definition: wallet.h:555
int GetDepthAndMempool(bool &fConflicted) const
Definition: wallet.cpp:4817
bool AcceptToMemoryPool(CValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Pass this transaction to the mempool.
Definition: wallet.cpp:4501
unsigned int nTimeSmart
time received by this node
Definition: wallet.h:344
bool HasP2CSInputs() const
checks whether a tx has P2CS inputs or not
Definition: wallet.cpp:4925
bool IsFromMe(const isminefilter &filter) const
Definition: wallet.cpp:4949
CAmount nShieldedChangeCached
Definition: wallet.h:359
void SetTx(CTransactionRef arg)
Definition: wallet.h:460
void Serialize(Stream &s) const
Definition: wallet.h:397
bool IsCoinStake() const
Definition: wallet.h:563
CAmount GetShieldedChange() const
Definition: wallet.cpp:4939
int GetBlocksToMaturity() const
Definition: wallet.cpp:4486
bool IsEquivalentTo(const CWalletTx &tx) const
Definition: wallet.cpp:4824
void Unserialize(Stream &s)
Definition: wallet.h:420
CAmount GetChange() const
Definition: wallet.cpp:4930
bool IsTrusted() const
Definition: wallet.cpp:4777
bool isConflicted() const
Definition: wallet.h:554
std::string GetComment() const
Definition: wallet.h:482
Confirmation m_confirm
Definition: wallet.h:394
AmountType
position in ordered transaction list
Definition: wallet.h:349
@ CREDIT
Definition: wallet.h:349
@ AVAILABLE_CREDIT
Definition: wallet.h:349
@ DEBIT
Definition: wallet.h:349
@ IMMATURE_CREDIT
Definition: wallet.h:349
@ AMOUNTTYPE_ENUM_ELEMENTS
Definition: wallet.h:349
void SetSaplingNoteData(mapSaplingNoteData_t &noteData)
Definition: wallet.cpp:4852
static const uint256 ABANDON_HASH
Constant used in hashBlock to indicate tx has been abandoned, only used at serialization/deserializat...
Definition: wallet.h:332
bool fStakeDelegationVoided
Definition: wallet.h:354
void setConfirmed()
Definition: wallet.h:559
Optional< std::pair< libzcash::SaplingNotePlaintext, libzcash::SaplingPaymentAddress > > DecryptSaplingNote(const SaplingOutPoint &op) const
Definition: wallet.cpp:4866
bool fShieldedChangeCached
Definition: wallet.h:358
std::vector< std::pair< std::string, std::string > > vOrderForm
Definition: wallet.h:337
mapSaplingNoteData_t mapSaplingNoteData
Definition: wallet.h:336
void setAbandoned()
Definition: wallet.h:547
bool IsInMainChainImmature() const
Definition: wallet.cpp:4493
CAmount GetShieldedAvailableCredit(bool fUseCache=true) const
Definition: wallet.cpp:4954
void setUnconfirmed()
Definition: wallet.h:557
void BindWallet(CWallet *pwalletIn)
Definition: wallet.cpp:4846
const uint256 & GetHash() const
Definition: wallet.h:561
bool fChangeCached
Definition: wallet.h:355
bool fInMempool
Definition: wallet.h:356
unsigned int fTimeReceivedIsTxTime
Definition: wallet.h:338
bool isConfirmed() const
Definition: wallet.h:558
CachableAmount m_amounts[AMOUNTTYPE_ENUM_ELEMENTS]
Definition: wallet.h:352
void MarkDirty()
make sure balances are recalculated
Definition: wallet.cpp:4833
void Init(const CWallet *pwalletIn)
Definition: wallet.cpp:4757
CWalletTx(const CWallet *pwalletIn, CTransactionRef arg)
Definition: wallet.cpp:4751
bool IsCoinBase() const
Definition: wallet.h:562
CAmount nChangeCached
Definition: wallet.h:357
unsigned int nTimeReceived
Definition: wallet.h:339
int64_t nOrderPos
Definition: wallet.h:346
An outpoint - a combination of a transaction hash and an index n into its sapling output description ...
Definition: transaction.h:82
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:93
Access to the wallet database.
Definition: walletdb.h:112
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1324
bool isReserved() const
Definition: wallet.h:1343
WalletRescanReserver(CWalletRef w)
Definition: wallet.h:1329
CWalletRef m_wallet
Definition: wallet.h:1326
bool IsNull() const
Definition: uint256.h:36
Sapling functions.
Definition: address.h:30
256-bit opaque blob.
Definition: uint256.h:138
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
Definition: crypter.h:63
boost::variant< CTxDestination, libzcash::SaplingPaymentAddress > CWDestination
void UnlockCoin(const COutPoint &output)
Definition: wallet.cpp:3960
CAmount GetImmatureDelegatedBalance() const
Definition: wallet.cpp:2280
void GetAvailableP2CSCoins(std::vector< COutput > &vCoins) const
Available coins (P2CS)
Definition: wallet.cpp:2362
CAmount GetImmatureWatchOnlyBalance() const
Definition: wallet.cpp:2303
bool SelectCoinsToSpend(const std::vector< COutput > &vAvailableCoins, const CAmount &nTargetValue, std::set< std::pair< const CWalletTx *, unsigned int > > &setCoinsRet, CAmount &nValueRet, const CCoinControl *coinControl=nullptr) const
Available coins (spending)
Definition: wallet.cpp:2845
CAmount loopTxsBalance(const std::function< void(const uint256 &, const CWalletTx &, CAmount &)> &method) const
Definition: wallet.cpp:2150
int64_t GetOldestKeyPoolTime()
Definition: wallet.cpp:3757
CAmount GetUnconfirmedShieldedBalance() const
Definition: wallet.cpp:2357
static std::string ParseIntoAddress(const CWDestination &dest, const std::string &purpose)
Definition: wallet.cpp:3630
bool DelAddressBook(const CWDestination &address, const CChainParams::Base58Type addrType=CChainParams::PUBKEY_ADDRESS)
Definition: wallet.cpp:3659
CAmount GetDelegatedBalance() const
Definition: wallet.cpp:2210
void UnlockAllNotes()
Definition: wallet.cpp:3978
CAmount GetLegacyBalance(const isminefilter &filter, int minDepth) const
Definition: wallet.cpp:2316
std::map< std::pair< CTxDestination, Optional< CTxDestination > >, std::vector< COutput > > ListCoins() const
Return list of available coins and locked coins grouped by non-change output address.
Definition: wallet.cpp:2909
std::string GetPurposeForAddressBookEntry(const CWDestination &address) const
Definition: wallet.cpp:3679
void LockNote(const SaplingOutPoint &op)
Definition: wallet.cpp:3954
void KeepKey()
Definition: wallet.cpp:3932
CWallet::CommitResult CommitTransaction(CTransactionRef tx, CReserveKey &opReservekey, CConnman *connman)
Definition: wallet.cpp:3510
bool GetKeyFromPool(CPubKey &key, const uint8_t &type=HDChain::ChangeType::EXTERNAL)
Definition: wallet.cpp:3752
void LoadAddressBookPurpose(const CWDestination &dest, const std::string &strPurpose)
Definition: wallet.cpp:3705
size_t KeypoolCountExternalKeys()
Definition: wallet.cpp:3729
CAmount GetImmatureColdStakingBalance() const
Definition: wallet.cpp:2273
CAmount GetColdStakingBalance() const
Definition: wallet.cpp:2188
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CTransactionRef &txRet, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, const CCoinControl *coinControl=nullptr, bool sign=true, CAmount nFeePay=0, bool fIncludeDelegated=false, bool *fStakeDelegationVoided=nullptr, int nExtraSize=0, int nMinDepth=0)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Definition: wallet.cpp:3040
DBErrors LoadWallet(bool &fFirstRunRet)
Definition: wallet.cpp:3584
Balance GetBalance(int min_depth=0) const
Definition: wallet.cpp:2121
std::set< std::set< CTxDestination > > GetAddressGroupings()
Definition: wallet.cpp:3804
int GetLastBlockHeightLockWallet() const
Get last block processed height locking the wallet.
Definition: wallet.cpp:3320
bool SelectCoinsMinConf(const CAmount &nTargetValue, int nConfMine, int nConfTheirs, uint64_t nMaxAncestors, std::vector< COutput > vCoins, std::set< std::pair< const CWalletTx *, unsigned int > > &setCoinsRet, CAmount &nValueRet) const
Select coins until nTargetValue is reached.
Definition: wallet.cpp:2754
CAmount GetLockedShieldCoins() const
Definition: wallet.cpp:2236
bool GetMasternodeVinAndKeys(CPubKey &pubKeyRet, CKey &keyRet, const COutPoint &collateralOut, bool fValidateCollateral, std::string &strError)
Get 10000 PIV output and keys which can be used for the Masternode.
Definition: wallet.cpp:2437
CAmount GetImmatureBalance() const
Definition: wallet.cpp:2266
bool IsLockedNote(const SaplingOutPoint &op) const
Definition: wallet.cpp:3992
CAmount GetLockedCoins() const
Definition: wallet.cpp:2218
std::set< SaplingOutPoint > ListLockedNotes()
Definition: wallet.cpp:4004
DBErrors ZapWalletTx(std::vector< CWalletTx > &vWtx)
Definition: wallet.cpp:3611
CAmount GetStakingBalance(const bool fIncludeColdStaking=true) const
Definition: wallet.cpp:2196
bool FundTransaction(CMutableTransaction &tx, CAmount &nFeeRet, bool overrideEstimatedFeeRate, const CFeeRate &specificFeeRate, int &nChangePosInOut, std::string &strFailReason, bool includeWatching, bool lockUnspents, const std::set< int > &setSubtractFeeFromOutputs, const CTxDestination &destChange=CNoDestination())
Definition: wallet.cpp:2965
void LoadAddressBookName(const CWDestination &dest, const std::string &strName)
Definition: wallet.cpp:3700
bool AvailableCoins(std::vector< COutput > *pCoins, const CCoinControl *coinControl=nullptr, AvailableCoinsFilter coinsFilter=AvailableCoinsFilter()) const
populate vCoins with vector of available COutputs.
Definition: wallet.cpp:2555
bool SetStakeSplitThreshold(const CAmount sst)
Definition: wallet.cpp:4010
bool CreateCoinStake(const CBlockIndex *pindexPrev, unsigned int nBits, CMutableTransaction &txNew, int64_t &nTxNewTime, std::vector< CStakeableOutput > *availableCoins, bool stopOnNewBlock=true) const
Definition: wallet.cpp:3367
CAmount GetWatchOnlyBalance() const
Definition: wallet.cpp:2287
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:3734
bool CreateBudgetFeeTX(CTransactionRef &tx, const uint256 &hash, CReserveKey &keyChange, CAmount fee)
Definition: wallet.cpp:2944
std::vector< COutput > GetOutputsFromCoinControl(const CCoinControl *coinControl)
Return the selected known outputs.
Definition: wallet.cpp:3023
std::string GetNameForAddressBookEntry(const CWDestination &address) const
Definition: wallet.cpp:3686
CAmount GetUnconfirmedWatchOnlyBalance() const
Definition: wallet.cpp:2295
void UnlockAllCoins()
Definition: wallet.cpp:3972
bool HasDelegator(const CTxOut &out) const
Definition: wallet.cpp:3715
std::map< libzcash::SaplingPaymentAddress, std::vector< SaplingNoteEntry > > ListNotes() const
Return list of available shield notes and locked shield notes grouped by sapling address.
Definition: wallet.cpp:2939
bool HasAddressBook(const CWDestination &address) const
Definition: wallet.cpp:3710
CAmount GetAvailableBalance(bool fIncludeDelegated=true, bool fIncludeShielded=true) const
Definition: wallet.cpp:2162
OutputAvailabilityResult CheckOutputAvailability(const CTxOut &output, const unsigned int outIndex, const uint256 &wtxid, const CCoinControl *coinControl, const bool fCoinsSelected, const bool fIncludeColdStaking, const bool fIncludeDelegated, const bool fIncludeLocked) const
Definition: wallet.cpp:2511
std::set< COutPoint > ListLockedCoins()
Definition: wallet.cpp:3998
bool SetAddressBook(const CWDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:3642
bool IsLockedCoin(const uint256 &hash, unsigned int n) const
Definition: wallet.cpp:3984
bool GetReservedKey(CPubKey &pubkey, bool internal=false)
Definition: wallet.cpp:3901
CAmount GetUnconfirmedBalance(isminetype filter=ISMINE_SPENDABLE_ALL) const
Definition: wallet.cpp:2258
std::string ToString() const
Definition: wallet.cpp:3489
CAmount GetAvailableShieldedBalance(bool fUseCache=true) const
Definition: wallet.cpp:2351
void LockCoin(const COutPoint &output)
Definition: wallet.cpp:3948
std::map< CTxDestination, CAmount > GetAddressBalances()
Definition: wallet.cpp:3762
bool StakeableCoins(std::vector< CStakeableOutput > *pCoins=nullptr)
Available coins (staking)
Definition: wallet.cpp:2709
void KeepKey(int64_t nIndex)
Definition: wallet.cpp:3739
void ReturnKey(int64_t nIndex, const bool internal=false, const bool staking=false)
Definition: wallet.cpp:3744
Optional< AddressBook::CAddressBookData > GetAddressBookEntry(const CWDestination &address) const
Definition: wallet.cpp:3693
std::set< CTxDestination > GetLabelAddresses(const std::string &label) const
Definition: wallet.cpp:3887
void ReturnKey()
Definition: wallet.cpp:3940
bool CreateCoinstakeOuts(const CPivStake &stakeInput, std::vector< CTxOut > &vout, CAmount nTotal) const
Definition: wallet.cpp:3325
bool SignCoinStake(CMutableTransaction &txNew) const
Definition: wallet.cpp:3475
std::map< CTxDestination, std::vector< COutput > > AvailableCoinsByAddress(bool fConfirmed, CAmount maxCoinValue, bool fIncludeColdStaking)
Definition: wallet.cpp:2637
void UnlockNote(const SaplingOutPoint &op)
Definition: wallet.cpp:3966
CAmount GetImmatureCredit(bool fUseCache=true, const isminefilter &filter=ISMINE_SPENDABLE_ALL) const
Definition: wallet.cpp:1638
std::vector< CWalletTx > getWalletTxs()
Definition: wallet.cpp:175
CAmount GetImmatureWatchOnlyCredit(const bool fUseCache=true) const
Definition: wallet.cpp:1740
bool IsSaplingSpent(const SaplingOutPoint &op) const
Definition: wallet.cpp:711
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:306
bool Lock()
Definition: wallet.cpp:397
CallResult< CTxDestination > getNewAddress(const std::string &addressLabel, const std::string purpose, const CChainParams::Base58Type addrType=CChainParams::PUBKEY_ADDRESS)
Definition: wallet.cpp:196
void SyncTransaction(const CTransactionRef &tx, const CWalletTx::Confirmation &confirm)
Definition: wallet.cpp:1260
std::vector< CKeyID > GetAffectedKeys(const CScript &spk)
Definition: wallet.cpp:118
bool AddCScript(const CScript &redeemScript) override
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
Definition: wallet.cpp:327
void Flush(bool shutdown=false)
Flush wallet (bitdb flush)
Definition: wallet.cpp:2063
CAmount GetAvailableWatchOnlyCredit(const bool fUseCache=true) const
Definition: wallet.cpp:1749
bool SetMaxVersion(int nVersion)
change which version we're allowed to upgrade to (note that this does not immediately imply upgrading...
Definition: wallet.cpp:606
bool IsAmountCached(AmountType type, const isminefilter &filter) const
Definition: wallet.cpp:1574
bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
Definition: wallet.cpp:296
ScriptPubKeyMan * GetScriptPubKeyMan() const
Get spkm.
Definition: wallet.cpp:701
void MarkDirty()
Definition: wallet.cpp:892
bool AddWatchOnly(const CScript &dest) override
Adds a watch-only address to the store, and saves it to disk.
Definition: wallet.cpp:349
bool RemoveWatchOnly(const CScript &dest) override
Definition: wallet.cpp:358
bool Upgrade(std::string &error, const int prevVersion)
Upgrade wallet to HD and Sapling if needed.
Definition: wallet.cpp:1824
const CKeyingMaterial & GetEncryptionKey() const
Definition: wallet.cpp:691
CAmount GetColdStakingCredit(bool fUseCache=true) const
Definition: wallet.cpp:1694
void EraseFromWallet(const uint256 &hash)
Definition: wallet.cpp:1437
std::set< uint256 > GetConflicts(const uint256 &txid) const
Get wallet transactions that conflict with given transaction (spend same outputs)
Definition: wallet.cpp:618
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:457
CBlockIndex * ScanForWalletTransactions(CBlockIndex *pindexStart, CBlockIndex *pindexStop, const WalletRescanReserver &reserver, bool fUpdate=false, bool fromStartup=false)
Scan the block chain (starting in pindexStart) for transactions from or to us.
Definition: wallet.cpp:1896
isminetype IsMine(const CTxIn &txin) const
Definition: wallet.cpp:1448
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:580
bool LoadToWallet(CWalletTx &wtxIn)
Definition: wallet.cpp:983
void RelayWalletTransaction(CConnman *connman)
Definition: wallet.cpp:2036
CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const
Definition: wallet.cpp:1500
bool Unlock(const SecureString &strWalletPassphrase, bool anonimizeOnly=false)
Definition: wallet.cpp:376
bool AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose=true)
Definition: wallet.cpp:901
void AddToSpends(const COutPoint &outpoint, const uint256 &wtxid)
Definition: wallet.cpp:745
CAmount GetCachableAmount(AmountType type, const isminefilter &filter, bool recalculate=false) const
Definition: wallet.cpp:1565
bool IsKeyUsed(const CPubKey &vchPubKey) const
Definition: wallet.cpp:878
void UpdateTimeSmart()
Update smart timestamp for a transaction being added to the wallet.
Definition: wallet.cpp:1554
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
Definition: wallet.cpp:1580
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:1383
void SetBestChain(const CBlockLocator &loc) override
Notifies listeners of the new active block chain on-disk.
Definition: wallet.cpp:511
void UpdateTimeFirstKey(int64_t nCreateTime)
Update wallet first key creation time.
Definition: wallet.cpp:315
CallResult< CTxDestination > getNewStakingAddress(const std::string &label)
Definition: wallet.cpp:191
CAmount GetLockedCredit() const
Definition: wallet.cpp:1705
int64_t IncOrderPosNext(WalletBatch *batch=nullptr)
Increment the next transaction order id.
Definition: wallet.cpp:866
bool AbandonTransaction(const uint256 &hashTx)
Definition: wallet.cpp:1144
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:279
void ReacceptWalletTransactions(bool fFirstLoad=false)
Definition: wallet.cpp:2000
bool FindNotesDataAndAddMissingIVKToKeystore(const CTransaction &tx, Optional< mapSaplingNoteData_t > &saplingNoteData)
Definition: wallet.cpp:1026
bool IsHDEnabled() const
Whether the wallet is hd or not //.
Definition: wallet.cpp:156
void ResendWalletTransactions(CConnman *connman) override
Tells listeners to broadcast their data.
Definition: wallet.cpp:2068
void GetAmounts(std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, const isminefilter &filter) const
Definition: wallet.cpp:1754
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
Notifies listeners when the block chain tip advances.
Definition: wallet.cpp:2108
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:773
int64_t GetTxTime() const
Definition: wallet.cpp:1541
bool HasSaplingSPKM() const
Definition: wallet.cpp:706
bool IsChange(const CTxOut &txout) const
Definition: wallet.cpp:1515
int64_t GetKeyCreationTime(const CWDestination &dest)
Definition: wallet.cpp:221
bool ActivateSaplingWallet(bool memOnly=false)
Definition: wallet.cpp:142
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, const CWalletTx::Confirmation &confirm, bool fUpdate)
Add a transaction to the wallet, or update it.
Definition: wallet.cpp:1077
const CWalletTx * GetWalletTx(const uint256 &hash) const
Definition: wallet.cpp:166
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Adds a key to the store, and saves it to disk.
Definition: wallet.cpp:252
CAmount GetCredit(const isminefilter &filter, bool recalculate=false) const
Definition: wallet.cpp:1616
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
Definition: wallet.cpp:1859
CAmount GetColdStakingDebit(bool fUseCache=true) const
Definition: wallet.cpp:1606
void SyncMetaData(std::pair< typename TxSpendMap< T >::iterator, typename TxSpendMap< T >::iterator > range)
Definition: wallet.cpp:652
void SyncMetaDataN(std::pair< TxSpendMap< uint256 >::iterator, TxSpendMap< uint256 >::iterator > range)
Definition: wallet.cpp:646
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
Definition: wallet.cpp:371
void SetBestChainInternal(WalletBatch &batch, const CBlockLocator &loc)
Definition: wallet.cpp:517
std::string ToString() const
Definition: wallet.cpp:72
bool LoadCScript(const CScript &redeemScript)
Definition: wallet.cpp:334
bool SetupSPKM(bool newKeypool=true, bool memOnly=false)
Generates hd wallet //.
Definition: wallet.cpp:133
CAmount GetStakeDelegationDebit(bool fUseCache=true) const
Definition: wallet.cpp:1611
std::set< uint256 > GetConflicts() const
Definition: wallet.cpp:2052
bool IsUsed(const CTxDestination address) const
Definition: wallet.cpp:1462
void TransactionAddedToMempool(const CTransactionRef &tx) override
Notifies listeners of a transaction having been added to mempool.
Definition: wallet.cpp:1269
bool InMempool() const
Definition: wallet.cpp:2031
CAmount GetAvailableCredit(bool fUseCache=true, const isminefilter &filter=ISMINE_SPENDABLE) const
Definition: wallet.cpp:1647
bool HasEncryptionKeys() const
Definition: wallet.cpp:696
void BlockConnected(const std::shared_ptr< const CBlock > &pblock, const CBlockIndex *pindex) override
Notifies listeners of a block being connected.
Definition: wallet.cpp:1319
void MarkAffectedTransactionsDirty(const CTransaction &tx)
Definition: wallet.cpp:1408
void ChainTipAdded(const CBlockIndex *pindex, const CBlock *pblock, SaplingMerkleTree saplingTree)
Definition: wallet.cpp:503
CAmount GetStakeDelegationCredit(bool fUseCache=true) const
Definition: wallet.cpp:1699
void AddExternalNotesDataToTx(CWalletTx &wtx) const
Definition: wallet.cpp:1040
void MarkConflicted(const uint256 &hashBlock, int conflicting_height, const uint256 &hashTx)
Definition: wallet.cpp:1203
void TransactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason) override
Notifies listeners of a transaction leaving mempool.
Definition: wallet.cpp:1281
bool IsSaplingUpgradeEnabled() const
Whether the wallet supports Sapling or not //.
Definition: wallet.cpp:161
bool IsSpent(const COutPoint &outpoint) const
Outpoint is spent if any non-conflicted transaction spends it:
Definition: wallet.cpp:720
void BlockDisconnected(const std::shared_ptr< const CBlock > &pblock, const uint256 &blockHash, int nBlockHeight, int64_t blockTime) override
Notifies listeners of a block being disconnected.
Definition: wallet.cpp:1360
ChangeType
General change type (added, updated, removed).
Definition: guiinterface.h:24
isminetype
IsMine() return codes.
Definition: ismine.h:19
@ ISMINE_SPENDABLE_ALL
Definition: ismine.h:33
@ ISMINE_SPENDABLE
Definition: ismine.h:22
uint8_t isminefilter
used for bitflags of isminetype
Definition: ismine.h:39
@ LOCK
Definition: lockunlock.h:16
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:80
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
const char * prefix
Definition: rest.cpp:564
const char * name
Definition: rest.cpp:37
std::map< SaplingOutPoint, SaplingNoteData > mapSaplingNoteData_t
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:61
@ SER_GETHASH
Definition: serialize.h:176
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:72
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:154
A mutable version of CTransaction.
Definition: transaction.h:409
Definition: wallet.h:292
CAmount amount
Definition: wallet.h:294
int vout
Definition: wallet.h:295
CTxDestination destination
Definition: wallet.h:293
AvailableCoinsFilter(bool _fIncludeDelegated, bool _fIncludeColdStaking, bool _fOnlySafe, bool _fOnlySpendable, std::set< CTxDestination > *_onlyFilteredDest, int _minDepth, bool _fIncludeLocked=false, CAmount _nMaxOutValue=0)
Definition: wallet.h:792
std::set< CTxDestination > * onlyFilteredDest
Definition: wallet.h:813
unsigned int nMaximumCount
Definition: wallet.h:820
CAmount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
Definition: wallet.h:1049
CAmount m_mine_trusted_shield
Trusted shield, at depth=GetBalance.min_depth or more.
Definition: wallet.h:1052
CAmount m_mine_untrusted_pending
Untrusted, but in mempool (pending)
Definition: wallet.h:1050
CAmount m_mine_immature
Immature coinbases/coinstakes in the main chain.
Definition: wallet.h:1051
CAmount m_mine_untrusted_shielded_balance
Untrusted shield, but in mempool (pending)
Definition: wallet.h:1053
CAmount m_mine_cs_delegated_trusted
Trusted, at depth=GetBalance.min_depth or more. Part of m_mine_trusted as well.
Definition: wallet.h:1054
CWallet::CommitStatus status
Definition: wallet.h:1106
CValidationState state
Definition: wallet.h:1107
Confirmation(Status s=UNCONFIRMED, int b=0, const uint256 &h=UINT256_ZERO, int i=0)
Definition: wallet.h:391
Cacheable amount subdivided into watchonly and spendable parts.
Definition: ismine.h:49
Sapling note, its location in a transaction, and number of confirmations.
#define AssertLockHeld(cs)
Definition: sync.h:75
bool error(const char *fmt, const Args &... args)
Definition: system.h:77
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:50
#define NO_THREAD_SAFETY_ANALYSIS
Definition: threadsafety.h:52
#define strprintf
Definition: tinyformat.h:1056
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:456
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
Definition: txmempool.h:295
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:175
int64_t atoi64(const char *psz)
std::string i64tostr(int64_t n)
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
Definition: utiltime.cpp:27
std::vector< CWalletRef > vpwallets
Definition: wallet.cpp:33
std::map< SaplingOutPoint, SaplingNoteData > mapSaplingNoteData_t
Definition: wallet.h:271
WalletFeature
(client) version numbers for particular wallet features
Definition: wallet.h:104
@ FEATURE_SAPLING
Definition: wallet.h:118
@ FEATURE_WALLETCRYPT
Definition: wallet.h:107
@ FEATURE_PRE_SPLIT_KEYPOOL
Definition: wallet.h:116
@ FEATURE_BASE
Definition: wallet.h:105
@ FEATURE_PRE_PIVX
Definition: wallet.h:110
@ FEATURE_LATEST
Definition: wallet.h:120
@ FEATURE_COMPRPUBKEY
Definition: wallet.h:108
bool bSpendZeroConfChange
Definition: wallet.cpp:42
CAmount maxTxFee
Definition: wallet.cpp:38
bool fPayAtLeastCustomFee
Definition: wallet.cpp:41
std::multimap< T, uint256 > TxSpendMap
Definition: wallet.h:270
unsigned int nTxConfirmTarget
Definition: wallet.cpp:39
std::map< std::string, std::string > mapValue_t
Definition: wallet.h:273
CWallet * CWalletRef
Definition: wallet.h:46
bool bdisableSystemnotifications
Definition: wallet.cpp:40
CFeeRate payTxFee
Settings.
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:50
CScheduler scheduler