Dash Core  0.12.2.1
P2P Digital Currency
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-2017 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 "streams.h"
13 #include "tinyformat.h"
14 #include "ui_interface.h"
15 #include "util.h"
16 #include "utilstrencodings.h"
17 #include "validationinterface.h"
18 #include "wallet/crypter.h"
19 #include "wallet/wallet_ismine.h"
20 #include "wallet/walletdb.h"
21 
22 #include <algorithm>
23 #include <map>
24 #include <set>
25 #include <stdexcept>
26 #include <stdint.h>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 #include <boost/shared_ptr.hpp>
32 
36 extern CFeeRate payTxFee;
37 extern CAmount maxTxFee;
38 extern unsigned int nTxConfirmTarget;
39 extern bool bSpendZeroConfChange;
40 extern bool fSendFreeTransactions;
41 
42 extern bool fLargeWorkForkFound;
43 extern bool fLargeWorkInvalidChainFound;
44 
45 static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
49 static const CAmount nHighTransactionFeeWarning = 0.01 * COIN;
51 static const CAmount DEFAULT_LEGACY_FALLBACK_FEE = 20000;
54 
59 static const CAmount DEFAULT_LEGACY_TRANSACTION_MINFEE = 10000; // was 1000
62 static const CAmount DEFAULT_TRANSACTION_MAXFEE = 0.2 * COIN; // "smallest denom" + X * "denom tails"
64 static const CAmount MIN_CHANGE = CENT;
66 static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
68 static const bool DEFAULT_SEND_FREE_TRANSACTIONS = false;
70 static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 2;
74 static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000;
75 static const bool DEFAULT_WALLETBROADCAST = true;
76 
78 static const bool DEFAULT_USE_HD_WALLET = false;
79 
80 class CBlockIndex;
81 class CCoinControl;
82 class COutput;
83 class CReserveKey;
84 class CScript;
85 class CTxMemPool;
86 class CWalletTx;
87 
90 {
91  FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output)
92 
93  FEATURE_WALLETCRYPT = 40000, // wallet encryption
94  FEATURE_COMPRPUBKEY = 60000, // compressed public keys
95  FEATURE_HD = 120200, // Hierarchical key derivation after BIP32 (HD Wallet), BIP44 (multi-coin), BIP39 (mnemonic)
96  // which uses on-the-fly private key derivation
97 
99 };
100 
102 {
107  ONLY_1000 = 5, // find masternode outputs including locked ones (use with caution)
109 };
110 
112 {
115  std::vector<CTxIn> vecTxIn;
117  {
118  nAmount = 0;
119  }
120 };
121 
123 class CKeyPool
124 {
125 public:
126  int64_t nTime;
128  bool fInternal; // for change outputs
129 
130  CKeyPool();
131  CKeyPool(const CPubKey& vchPubKeyIn, bool fInternalIn);
132 
134 
135  template <typename Stream, typename Operation>
136  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
137  if (!(nType & SER_GETHASH))
138  READWRITE(nVersion);
139  READWRITE(nTime);
141  if (ser_action.ForRead()) {
142  try {
144  }
145  catch (std::ios_base::failure&) {
146  /* flag as external address if we can't read the internal boolean
147  (this will be the case for any wallet before the HD chain split version) */
148  fInternal = false;
149  }
150  }
151  else {
153  }
154  }
155 };
156 
159 {
160 public:
161  std::string name;
162  std::string purpose;
163 
165  {
166  purpose = "unknown";
167  }
168 
169  typedef std::map<std::string, std::string> StringMap;
171 };
172 
174 {
178 };
179 
180 typedef std::map<std::string, std::string> mapValue_t;
181 
182 
183 static void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
184 {
185  if (!mapValue.count("n"))
186  {
187  nOrderPos = -1; // TODO: calculate elsewhere
188  return;
189  }
190  nOrderPos = atoi64(mapValue["n"].c_str());
191 }
192 
193 
194 static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
195 {
196  if (nOrderPos == -1)
197  return;
198  mapValue["n"] = i64tostr(nOrderPos);
199 }
200 
202 {
205  int vout;
206 };
207 
209 class CMerkleTx : public CTransaction
210 {
211 private:
213  static const uint256 ABANDON_HASH;
214 
215 public:
217 
218  /* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest
219  * block in the chain we know this or any in-wallet dependency conflicts
220  * with. Older clients interpret nIndex == -1 as unconfirmed for backward
221  * compatibility.
222  */
223  int nIndex;
224 
226  {
227  Init();
228  }
229 
230  CMerkleTx(const CTransaction& txIn) : CTransaction(txIn)
231  {
232  Init();
233  }
234 
235  void Init()
236  {
237  hashBlock = uint256();
238  nIndex = -1;
239  }
240 
242 
243  template <typename Stream, typename Operation>
244  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
245  std::vector<uint256> vMerkleBranch; // For compatibility with older versions.
246  READWRITE(*(CTransaction*)this);
247  nVersion = this->nVersion;
248  READWRITE(hashBlock);
249  READWRITE(vMerkleBranch);
250  READWRITE(nIndex);
251  }
252 
253  int SetMerkleBranch(const CBlock& block);
254 
261  int GetDepthInMainChain(const CBlockIndex* &pindexRet, bool enableIX = true) const;
262  int GetDepthInMainChain(bool enableIX = true) const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet, enableIX); }
263  bool IsInMainChain() const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet) > 0; }
264  int GetBlocksToMaturity() const;
265  bool AcceptToMemoryPool(bool fLimitFree=true, bool fRejectAbsurdFee=true);
266  bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
267  bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
269 };
270 
275 class CWalletTx : public CMerkleTx
276 {
277 private:
278  const CWallet* pwallet;
279 
280 public:
282  std::vector<std::pair<std::string, std::string> > vOrderForm;
283  unsigned int fTimeReceivedIsTxTime;
284  unsigned int nTimeReceived;
285  unsigned int nTimeSmart;
286  char fFromMe;
287  std::string strFromAccount;
288  int64_t nOrderPos;
289 
290  // memory only
291  mutable bool fDebitCached;
292  mutable bool fCreditCached;
293  mutable bool fImmatureCreditCached;
298  mutable bool fWatchDebitCached;
299  mutable bool fWatchCreditCached;
302  mutable bool fChangeCached;
315 
317  {
318  Init(NULL);
319  }
320 
321  CWalletTx(const CWallet* pwalletIn)
322  {
323  Init(pwalletIn);
324  }
325 
326  CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn) : CMerkleTx(txIn)
327  {
328  Init(pwalletIn);
329  }
330 
331  CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn) : CMerkleTx(txIn)
332  {
333  Init(pwalletIn);
334  }
335 
336  void Init(const CWallet* pwalletIn)
337  {
338  pwallet = pwalletIn;
339  mapValue.clear();
340  vOrderForm.clear();
341  fTimeReceivedIsTxTime = false;
342  nTimeReceived = 0;
343  nTimeSmart = 0;
344  fFromMe = false;
345  strFromAccount.clear();
346  fDebitCached = false;
347  fCreditCached = false;
348  fImmatureCreditCached = false;
349  fAvailableCreditCached = false;
350  fAnonymizedCreditCached = false;
351  fDenomUnconfCreditCached = false;
352  fDenomConfCreditCached = false;
353  fWatchDebitCached = false;
354  fWatchCreditCached = false;
357  fChangeCached = false;
358  nDebitCached = 0;
359  nCreditCached = 0;
365  nWatchDebitCached = 0;
366  nWatchCreditCached = 0;
369  nChangeCached = 0;
370  nOrderPos = -1;
371  }
372 
374 
375  template <typename Stream, typename Operation>
376  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
377  if (ser_action.ForRead())
378  Init(NULL);
379  char fSpent = false;
380 
381  if (!ser_action.ForRead())
382  {
383  mapValue["fromaccount"] = strFromAccount;
384 
386 
387  if (nTimeSmart)
388  mapValue["timesmart"] = strprintf("%u", nTimeSmart);
389  }
390 
391  READWRITE(*(CMerkleTx*)this);
392  std::vector<CMerkleTx> vUnused;
393  READWRITE(vUnused);
399  READWRITE(fSpent);
400 
401  if (ser_action.ForRead())
402  {
403  strFromAccount = mapValue["fromaccount"];
404 
406 
407  nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
408  }
409 
410  mapValue.erase("fromaccount");
411  mapValue.erase("version");
412  mapValue.erase("spent");
413  mapValue.erase("n");
414  mapValue.erase("timesmart");
415  }
416 
418  void MarkDirty()
419  {
420  fCreditCached = false;
421  fAvailableCreditCached = false;
422  fImmatureCreditCached = false;
423  fAnonymizedCreditCached = false;
424  fDenomUnconfCreditCached = false;
425  fDenomConfCreditCached = false;
426  fWatchDebitCached = false;
427  fWatchCreditCached = false;
430  fDebitCached = false;
431  fChangeCached = false;
432  }
433 
434  void BindWallet(CWallet *pwalletIn)
435  {
436  pwallet = pwalletIn;
437  MarkDirty();
438  }
439 
441  CAmount GetDebit(const isminefilter& filter) const;
442  CAmount GetCredit(const isminefilter& filter) const;
443  CAmount GetImmatureCredit(bool fUseCache=true) const;
444  CAmount GetAvailableCredit(bool fUseCache=true) const;
445  CAmount GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const;
446  CAmount GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const;
447  CAmount GetChange() const;
448 
449  CAmount GetAnonymizedCredit(bool fUseCache=true) const;
450  CAmount GetDenominatedCredit(bool unconfirmed, bool fUseCache=true) const;
451 
452  void GetAmounts(std::list<COutputEntry>& listReceived,
453  std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
454 
455  void GetAccountAmounts(const std::string& strAccount, CAmount& nReceived,
456  CAmount& nSent, CAmount& nFee, const isminefilter& filter) const;
457 
458  bool IsFromMe(const isminefilter& filter) const
459  {
460  return (GetDebit(filter) > 0);
461  }
462 
463  // True if only scriptSigs are different
464  bool IsEquivalentTo(const CWalletTx& tx) const;
465 
466  bool InMempool() const;
467  bool IsTrusted() const;
468 
469  bool WriteToDisk(CWalletDB *pwalletdb);
470 
471  int64_t GetTxTime() const;
472  int GetRequestCount() const;
473 
474  bool RelayWalletTransaction(CConnman* connman, std::string strCommand="tx");
475 
476  std::set<uint256> GetConflicts() const;
477 };
478 
479 
480 
481 
482 class COutput
483 {
484 public:
485  const CWalletTx *tx;
486  int i;
487  int nDepth;
489  bool fSolvable;
490 
491  COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn)
492  {
493  tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; fSolvable = fSolvableIn;
494  }
495 
496  //Used with Darksend. Will return largest nondenom, then denominations, then very small inputs
497  int Priority() const;
498 
499  std::string ToString() const;
500 };
501 
502 
503 
504 
507 {
508 public:
510  int64_t nTimeCreated;
511  int64_t nTimeExpires;
512  std::string strComment;
515 
516  CWalletKey(int64_t nExpires=0);
517 
519 
520  template <typename Stream, typename Operation>
521  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
522  if (!(nType & SER_GETHASH))
523  READWRITE(nVersion);
528  }
529 };
530 
536 {
537 public:
538  std::string strAccount;
540  int64_t nTime;
541  std::string strOtherAccount;
542  std::string strComment;
544  int64_t nOrderPos;
545  uint64_t nEntryNo;
546 
548  {
549  SetNull();
550  }
551 
552  void SetNull()
553  {
554  nCreditDebit = 0;
555  nTime = 0;
556  strAccount.clear();
557  strOtherAccount.clear();
558  strComment.clear();
559  nOrderPos = -1;
560  nEntryNo = 0;
561  }
562 
564 
565  template <typename Stream, typename Operation>
566  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
567  if (!(nType & SER_GETHASH))
568  READWRITE(nVersion);
571  READWRITE(nTime);
573 
574  if (!ser_action.ForRead())
575  {
577 
578  if (!(mapValue.empty() && _ssExtra.empty()))
579  {
580  CDataStream ss(nType, nVersion);
581  ss.insert(ss.begin(), '\0');
582  ss << mapValue;
583  ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
584  strComment.append(ss.str());
585  }
586  }
587 
589 
590  size_t nSepPos = strComment.find("\0", 0, 1);
591  if (ser_action.ForRead())
592  {
593  mapValue.clear();
594  if (std::string::npos != nSepPos)
595  {
596  CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion);
597  ss >> mapValue;
598  _ssExtra = std::vector<char>(ss.begin(), ss.end());
599  }
601  }
602  if (std::string::npos != nSepPos)
603  strComment.erase(nSepPos);
604 
605  mapValue.erase("n");
606  }
607 
608 private:
609  std::vector<char> _ssExtra;
610 };
611 
612 
618 {
619 private:
625  bool SelectCoins(const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = NULL, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend = true) const;
626 
628 
631 
634 
635  int64_t nNextResend;
636  int64_t nLastResend;
638 
640  mutable std::vector<CompactTallyItem> vecAnonymizableTallyCached;
642  mutable std::vector<CompactTallyItem> vecAnonymizableTallyCachedNonDenom;
643 
649  typedef std::multimap<COutPoint, uint256> TxSpends;
651  void AddToSpends(const COutPoint& outpoint, const uint256& wtxid);
652  void AddToSpends(const uint256& wtxid);
653 
654  std::set<COutPoint> setWalletUTXO;
655 
656  /* Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
657  void MarkConflicted(const uint256& hashBlock, const uint256& hashTx);
658 
659  void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
660 
661  /* HD derive new child key (on internal or external chain) */
662  void DeriveNewChildKey(const CKeyMetadata& metadata, CKey& secretRet, uint32_t nAccountIndex, bool fInternal /*= false*/);
663 
664 public:
665  /*
666  * Main wallet lock.
667  * This lock protects all the fields added by CWallet
668  * except for:
669  * fFileBacked (immutable after instantiation)
670  * strWalletFile (immutable after instantiation)
671  */
673 
675  const std::string strWalletFile;
676 
677  void LoadKeyPool(int nIndex, const CKeyPool &keypool)
678  {
679  if (keypool.fInternal) {
680  setInternalKeyPool.insert(nIndex);
681  } else {
682  setExternalKeyPool.insert(nIndex);
683  }
684 
685  // If no metadata exists yet, create a default with the pool key's
686  // creation time. Note that this may be overwritten by actually
687  // stored metadata for that key later, which is fine.
688  CKeyID keyid = keypool.vchPubKey.GetID();
689  if (mapKeyMetadata.count(keyid) == 0)
690  mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
691  }
692 
693  std::set<int64_t> setInternalKeyPool;
694  std::set<int64_t> setExternalKeyPool;
695  std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
696 
697  typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
699  unsigned int nMasterKeyMaxID;
700 
702  {
703  SetNull();
704  }
705 
706  CWallet(const std::string& strWalletFileIn)
707  : strWalletFile(strWalletFileIn)
708  {
709  SetNull();
710 
711  fFileBacked = true;
712  }
713 
715  {
716  delete pwalletdbEncryption;
717  pwalletdbEncryption = NULL;
718  }
719 
720  void SetNull()
721  {
724  fFileBacked = false;
725  nMasterKeyMaxID = 0;
726  pwalletdbEncryption = NULL;
727  nOrderPosNext = 0;
728  nNextResend = 0;
729  nLastResend = 0;
730  nTimeFirstKey = 0;
731  fBroadcastTransactions = false;
732  fAnonymizableTallyCached = false;
736  }
737 
738  std::map<uint256, CWalletTx> mapWallet;
739  std::list<CAccountingEntry> laccentries;
740 
741  typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
742  typedef std::multimap<int64_t, TxPair > TxItems;
744 
745  int64_t nOrderPosNext;
746  std::map<uint256, int> mapRequestCount;
747 
748  std::map<CTxDestination, CAddressBookData> mapAddressBook;
749 
751 
752  std::set<COutPoint> setLockedCoins;
753 
754  int64_t nTimeFirstKey;
756 
757  std::map<CKeyID, CHDPubKey> mapHdPubKeys; //<! memory map of HD extended pubkeys
758 
759  const CWalletTx* GetWalletTx(const uint256& hash) const;
760 
763 
767  void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend = false) const;
768 
775  bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, bool fUseInstantSend = false) const;
776 
777  bool SelectCoinsByDenominations(int nDenom, CAmount nValueMin, CAmount nValueMax, std::vector<CTxIn>& vecTxInRet, std::vector<COutput>& vCoinsRet, CAmount& nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax);
778  bool GetCollateralTxIn(CTxIn& txinRet, CAmount& nValueRet) const;
779  bool SelectCoinsDark(CAmount nValueMin, CAmount nValueMax, std::vector<CTxIn>& vecTxInRet, CAmount& nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax) const;
780  bool SelectCoinsGrouppedByAddresses(std::vector<CompactTallyItem>& vecTallyRet, bool fSkipDenominated = true, bool fAnonymizable = true, bool fSkipUnconfirmed = true) const;
781 
783  bool GetMasternodeOutpointAndKeys(COutPoint& outpointRet, CPubKey& pubKeyRet, CKey& keyRet, std::string strTxHash = "", std::string strOutputIndex = "");
785  bool GetOutpointAndKeysFromOutput(const COutput& out, COutPoint& outpointRet, CPubKey& pubKeyRet, CKey& keyRet);
786 
787  bool HasCollateralInputs(bool fOnlyConfirmed = true) const;
788  bool IsCollateralAmount(CAmount nInputAmount) const;
789  int CountInputsWithAmount(CAmount nInputAmount);
790 
791  // get the PrivateSend chain depth for a given input
792  int GetRealOutpointPrivateSendRounds(const COutPoint& outpoint, int nRounds) const;
793  // respect current settings
794  int GetOutpointPrivateSendRounds(const COutPoint& outpoint) const;
795 
796  bool IsDenominated(const COutPoint& outpoint) const;
797  bool IsDenominatedAmount(CAmount nInputAmount) const;
798 
799  bool IsSpent(const uint256& hash, unsigned int n) const;
800 
801  bool IsLockedCoin(uint256 hash, unsigned int n) const;
802  void LockCoin(COutPoint& output);
803  void UnlockCoin(COutPoint& output);
804  void UnlockAllCoins();
805  void ListLockedCoins(std::vector<COutPoint>& vOutpts);
806 
811  CPubKey GenerateNewKey(uint32_t nAccountIndex, bool fInternal /*= false*/);
813  bool HaveKey(const CKeyID &address) const;
815  bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
817  bool GetKey(const CKeyID &address, CKey& keyOut) const;
819  bool AddHDPubKey(const CExtPubKey &extPubKey, bool fInternal);
821  bool LoadHDPubKey(const CHDPubKey &hdPubKey);
823  bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey);
825  bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); }
827  bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata);
828 
829  bool LoadMinVersion(int nVersion) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
830 
832  bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
834  bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
835  bool AddCScript(const CScript& redeemScript);
836  bool LoadCScript(const CScript& redeemScript);
837 
839  bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
841  bool EraseDestData(const CTxDestination &dest, const std::string &key);
843  bool LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
845  bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const;
846 
848  bool AddWatchOnly(const CScript &dest);
849  bool RemoveWatchOnly(const CScript &dest);
851  bool LoadWatchOnly(const CScript &dest);
852 
853  bool Unlock(const SecureString& strWalletPassphrase, bool fForMixingOnly = false);
854  bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
855  bool EncryptWallet(const SecureString& strWalletPassphrase);
856 
857  void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const;
858 
863  int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL);
864 
865  void MarkDirty();
866  bool AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb);
867  void SyncTransaction(const CTransaction& tx, const CBlock* pblock);
868  bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate);
869  int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
871  void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman);
872  std::vector<uint256> ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman);
873  CAmount GetBalance() const;
875  CAmount GetImmatureBalance() const;
879 
880  CAmount GetAnonymizableBalance(bool fSkipDenominated = false, bool fSkipUnconfirmed = true) const;
882  float GetAverageAnonymizedRounds() const;
884  CAmount GetNeedsToBeAnonymizedBalance(CAmount nMinBalance = 0) const;
885  CAmount GetDenominatedBalance(bool unconfirmed=false) const;
886 
887  bool GetBudgetSystemCollateralTX(CTransaction& tx, uint256 hash, CAmount amount, bool fUseInstantSend);
888  bool GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount amount, bool fUseInstantSend);
889 
894  bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosRet, std::string& strFailReason, bool includeWatching);
895 
900  bool CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosRet,
901  std::string& strFailReason, const CCoinControl *coinControl = NULL, bool sign = true, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=false);
902  bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, std::string strCommand="tx");
903 
904  bool CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason);
905  bool ConvertList(std::vector<CTxIn> vecTxIn, std::vector<CAmount>& vecAmounts);
906 
907  bool AddAccountingEntry(const CAccountingEntry&, CWalletDB & pwalletdb);
908 
915  static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
920  static CAmount GetRequiredFee(unsigned int nTxBytes);
921 
922  bool NewKeyPool();
923  size_t KeypoolCountExternalKeys();
924  size_t KeypoolCountInternalKeys();
925  bool TopUpKeyPool(unsigned int kpSize = 0);
926  void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fInternal);
927  void KeepKey(int64_t nIndex);
928  void ReturnKey(int64_t nIndex, bool fInternal);
929  bool GetKeyFromPool(CPubKey &key, bool fInternal /*= false*/);
930  int64_t GetOldestKeyPoolTime();
931  void GetAllReserveKeys(std::set<CKeyID>& setAddress) const;
932 
933  std::set< std::set<CTxDestination> > GetAddressGroupings();
934  std::map<CTxDestination, CAmount> GetAddressBalances();
935 
936  std::set<CTxDestination> GetAccountAddresses(const std::string& strAccount) const;
937 
938  isminetype IsMine(const CTxIn& txin) const;
939  CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
940  isminetype IsMine(const CTxOut& txout) const;
941  CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
942  bool IsChange(const CTxOut& txout) const;
943  CAmount GetChange(const CTxOut& txout) const;
944  bool IsMine(const CTransaction& tx) const;
946  bool IsFromMe(const CTransaction& tx) const;
947  CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
948  CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
949  CAmount GetChange(const CTransaction& tx) const;
950  void SetBestChain(const CBlockLocator& loc);
951 
952  DBErrors LoadWallet(bool& fFirstRunRet);
953  DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);
954 
955  bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose);
956 
957  bool DelAddressBook(const CTxDestination& address);
958 
959  bool UpdatedTransaction(const uint256 &hashTx);
960 
961  void Inventory(const uint256 &hash)
962  {
963  {
964  LOCK(cs_wallet);
965  std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
966  if (mi != mapRequestCount.end())
967  (*mi).second++;
968  }
969  }
970 
971  void GetScriptForMining(boost::shared_ptr<CReserveScript> &script);
972  void ResetRequestCount(const uint256 &hash)
973  {
974  LOCK(cs_wallet);
975  mapRequestCount[hash] = 0;
976  };
977 
978  unsigned int GetKeyPoolSize()
979  {
980  AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool
981  return setInternalKeyPool.size() + setExternalKeyPool.size();
982  }
983 
984  bool SetDefaultKey(const CPubKey &vchPubKey);
985 
987  bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = NULL, bool fExplicit = false);
988 
990  bool SetMaxVersion(int nVersion);
991 
994 
996  std::set<uint256> GetConflicts(const uint256& txid) const;
997 
999  void Flush(bool shutdown=false);
1000 
1002  static bool Verify(const std::string& walletFile, std::string& warningString, std::string& errorString);
1003 
1008  boost::signals2::signal<void (CWallet *wallet, const CTxDestination
1009  &address, const std::string &label, bool isMine,
1010  const std::string &purpose,
1012 
1017  boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx,
1019 
1021  boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
1022 
1024  boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
1025 
1029  void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
1030 
1031  /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
1032  bool AbandonTransaction(const uint256& hashTx);
1033 
1038  /* Returns true if HD is enabled */
1039  bool IsHDEnabled();
1040  /* Generates a new HD chain */
1041  void GenerateNewHDChain();
1042  /* Set the HD chain model (chain child index counters) */
1043  bool SetHDChain(const CHDChain& chain, bool memonly);
1044  bool SetCryptedHDChain(const CHDChain& chain, bool memonly);
1045  bool GetDecryptedHDChain(CHDChain& hdChainRet);
1046 };
1047 
1050 {
1051 protected:
1053  int64_t nIndex;
1056 public:
1057  CReserveKey(CWallet* pwalletIn)
1058  {
1059  nIndex = -1;
1060  pwallet = pwalletIn;
1061  fInternal = false;
1062  }
1063 
1065  {
1066  ReturnKey();
1067  }
1068 
1069  void ReturnKey();
1070  bool GetReservedKey(CPubKey &pubkey, bool fInternalIn /*= false*/);
1071  void KeepKey();
1072  void KeepScript() { KeepKey(); }
1073 };
1074 
1075 
1081 {
1082 public:
1084 
1086  {
1087  SetNull();
1088  }
1089 
1090  void SetNull()
1091  {
1092  vchPubKey = CPubKey();
1093  }
1094 
1096 
1097  template <typename Stream, typename Operation>
1098  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
1099  if (!(nType & SER_GETHASH))
1100  READWRITE(nVersion);
1102  }
1103 };
1104 
1105 #endif // BITCOIN_WALLET_WALLET_H
CAmount nImmatureCreditCached
Definition: wallet.h:305
CWallet()
Definition: wallet.h:701
CAmount GetCredit(const isminefilter &filter) const
Definition: wallet.cpp:1824
int64_t nLastResend
Definition: wallet.h:636
int CountInputsWithAmount(CAmount nInputAmount)
Definition: wallet.cpp:3044
void KeepKey(int64_t nIndex)
Definition: wallet.cpp:3877
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Definition: wallet.h:1024
CMerkleTx(const CTransaction &txIn)
Definition: wallet.h:230
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:66
bool isAbandoned() const
Definition: wallet.h:267
int64_t nTimeExpires
Definition: wallet.h:511
unsigned int GetKeyPoolSize()
Definition: wallet.h:978
void SetNull()
Definition: wallet.h:720
const CWalletTx * tx
Definition: wallet.h:485
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
Definition: standard.h:69
void ReturnKey(int64_t nIndex, bool fInternal)
Definition: wallet.cpp:3889
CAmount GetAnonymizedBalance() const
Definition: wallet.cpp:2177
static const unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
Definition: wallet.h:70
CAmount nAmount
Definition: wallet.h:176
bool IsFromMe(const CTransaction &tx) const
Definition: wallet.cpp:1499
int64_t nTime
Definition: wallet.h:126
void SetBestChain(const CBlockLocator &loc)
Definition: wallet.cpp:521
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: wallet.h:521
std::set< CTxDestination > GetAccountAddresses(const std::string &strAccount) const
Definition: wallet.cpp:4087
int64_t nOrderPosNext
Definition: wallet.h:745
bool AddAccountingEntry(const CAccountingEntry &, CWalletDB &pwalletdb)
Definition: wallet.cpp:3579
std::string strOtherAccount
Definition: wallet.h:541
~CReserveKey()
Definition: wallet.h:1064
CAmount nWatchDebitCached
Definition: wallet.h:310
bool fSpendable
Definition: wallet.h:488
void SetBroadcastTransactions(bool broadcast)
Definition: wallet.h:1029
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:3683
#define READWRITE(obj)
Definition: serialize.h:175
char fFromMe
Definition: wallet.h:286
std::set< uint256 > GetConflicts(const uint256 &txid) const
Get wallet transactions that conflict with given transaction (spend same outputs) ...
Definition: wallet.cpp:566
CAmount nAvailableCreditCached
Definition: wallet.h:306
std::vector< CTxIn > vecTxIn
Definition: wallet.h:115
bool fSubtractFeeFromAmount
Definition: wallet.h:177
CAccount()
Definition: wallet.h:1085
bool fFileBacked
Definition: wallet.h:674
CWallet * pwallet
Definition: wallet.h:1052
CWalletKey(int64_t nExpires=0)
Definition: wallet.cpp:4380
TxItems wtxOrdered
Definition: wallet.h:743
bool fDenomConfCreditCached
Definition: wallet.h:297
bool SelectCoinsDark(CAmount nValueMin, CAmount nValueMax, std::vector< CTxIn > &vecTxInRet, CAmount &nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax) const
Definition: wallet.cpp:2930
bool GetCollateralTxIn(CTxIn &txinRet, CAmount &nValueRet) const
Definition: wallet.cpp:2967
bool SelectCoinsMinConf(const CAmount &nTargetValue, int nConfMine, int nConfTheirs, std::vector< COutput > vCoins, std::set< std::pair< const CWalletTx *, unsigned int > > &setCoinsRet, CAmount &nValueRet, bool fUseInstantSend=false) const
Definition: wallet.cpp:2498
void ReserveKeyFromKeyPool(int64_t &nIndex, CKeyPool &keypool, bool fInternal)
Definition: wallet.cpp:3841
static const CAmount nHighTransactionFeeWarning
-paytxfee will warn if called with a higher fee than this amount (in satoshis) per KB ...
Definition: wallet.h:49
bool IsHDEnabled()
Definition: wallet.cpp:1485
void GenerateNewHDChain()
Definition: wallet.cpp:1392
#define strprintf
Definition: tinyformat.h:1011
mapValue_t mapValue
Definition: wallet.h:543
CPubKey vchPubKey
Definition: wallet.h:127
bool IsFromMe(const isminefilter &filter) const
Definition: wallet.h:458
int nIndex
Definition: wallet.h:223
CAmount GetImmatureCredit(bool fUseCache=true) const
Definition: wallet.cpp:1857
CCriticalSection cs_wallet
Definition: wallet.h:672
bool CanSupportFeature(enum WalletFeature wf)
check whether we are allowed to upgrade (or already support) to the named feature ...
Definition: wallet.h:762
CAmount nCreditCached
Definition: wallet.h:304
WalletFeature
Definition: wallet.h:89
static const CAmount COIN
Definition: amount.h:16
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:4325
CAmount nAmount
Definition: wallet.h:114
bool LoadMinVersion(int nVersion)
Definition: wallet.h:829
bool fInternal
Definition: wallet.h:128
bool AddToWallet(const CWalletTx &wtxIn, bool fFromLoadWallet, CWalletDB *pwalletdb)
Definition: wallet.cpp:880
CAmount GetUnconfirmedBalance() const
Definition: wallet.cpp:2286
int64_t IncOrderPosNext(CWalletDB *pwalletdb=NULL)
Definition: wallet.cpp:856
bool GetOutpointAndKeysFromOutput(const COutput &out, COutPoint &outpointRet, CPubKey &pubKeyRet, CKey &keyRet)
Extract txin information and keys from output.
Definition: wallet.cpp:3015
std::multimap< int64_t, TxPair > TxItems
Definition: wallet.h:742
bool AbandonTransaction(const uint256 &hashTx)
Definition: wallet.cpp:1066
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:75
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
Add a key to the store.
Definition: crypter.cpp:302
std::map< std::string, std::string > StringMap
Definition: wallet.h:169
bool SelectCoinsByDenominations(int nDenom, CAmount nValueMin, CAmount nValueMax, std::vector< CTxIn > &vecTxInRet, std::vector< COutput > &vCoinsRet, CAmount &nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax)
Definition: wallet.cpp:2762
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:344
bool IsSpent(const uint256 &hash, unsigned int n) const
Definition: wallet.cpp:682
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:61
CAmount GetImmatureWatchOnlyCredit(const bool &fUseCache=true) const
Definition: wallet.cpp:1901
bool fCreditCached
Definition: wallet.h:292
int64_t nIndex
Definition: wallet.h:1053
bool fDebitCached
position in ordered transaction list
Definition: wallet.h:291
bool Unlock(const SecureString &strWalletPassphrase, bool fForMixingOnly=false)
Definition: wallet.cpp:404
Definition: pubkey.h:27
mapValue_t mapValue
Definition: wallet.h:281
bool fAnonymizedCreditCached
Definition: wallet.h:295
ADD_SERIALIZE_METHODS
Definition: wallet.h:133
CAmount GetImmatureWatchOnlyBalance() const
Definition: wallet.cpp:2346
std::string ToString() const
Definition: wallet.cpp:79
static const uint256 ABANDON_HASH
Definition: wallet.h:213
Definition: net.h:108
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:697
void UnlockAllCoins()
Definition: wallet.cpp:4215
CAmount nChangeCached
Definition: wallet.h:314
bool GetDecryptedHDChain(CHDChain &hdChainRet)
Definition: wallet.cpp:1464
int GetRealOutpointPrivateSendRounds(const COutPoint &outpoint, int nRounds) const
Definition: wallet.cpp:1242
const_iterator end() const
Definition: streams.h:120
bool HasCollateralInputs(bool fOnlyConfirmed=true) const
Definition: wallet.cpp:3072
CAmount GetAvailableCredit(bool fUseCache=true) const
Definition: wallet.cpp:1871
bool AcceptToMemoryPool(bool fLimitFree=true, bool fRejectAbsurdFee=true)
Definition: wallet.cpp:4457
bool GetBroadcastTransactions() const
Definition: wallet.h:1027
const CWalletTx * GetWalletTx(const uint256 &hash) const
Definition: wallet.cpp:94
static void ReadOrderPos(int64_t &nOrderPos, mapValue_t &mapValue)
Definition: wallet.h:183
bool IsLockedCoin(uint256 hash, unsigned int n) const
Definition: wallet.cpp:4221
std::set< uint256 > GetConflicts() const
Definition: wallet.cpp:1781
CFeeRate payTxFee
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn)
Definition: wallet.h:491
int GetDepthInMainChain(bool enableIX=true) const
Definition: wallet.h:262
void Flush(bool shutdown=false)
Flush wallet (bitdb flush)
Definition: wallet.cpp:589
StringMap destdata
Definition: wallet.h:170
CWalletDB * pwalletdbEncryption
Definition: wallet.h:627
CAmount GetChange(const CTxOut &txout) const
Definition: wallet.cpp:1385
std::string name
Definition: wallet.h:161
std::pair< CWalletTx *, CAccountingEntry * > TxPair
Definition: wallet.h:741
CMerkleTx()
Definition: wallet.h:225
ADD_SERIALIZE_METHODS
Definition: wallet.h:241
bool fSendFreeTransactions
Definition: wallet.cpp:49
unsigned int nMasterKeyMaxID
Definition: wallet.h:699
bool AddToWalletIfInvolvingMe(const CTransaction &tx, const CBlock *pblock, bool fUpdate)
Definition: wallet.cpp:1028
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: wallet.h:566
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, CConnman *connman, std::string strCommand="tx")
Definition: wallet.cpp:3527
CAmount GetNeedsToBeAnonymizedBalance(CAmount nMinBalance=0) const
Definition: wallet.cpp:2244
DBErrors
Definition: walletdb.h:34
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:3779
TxSpends mapTxSpends
Definition: wallet.h:650
CAmount GetAnonymizableBalance(bool fSkipDenominated=false, bool fSkipUnconfirmed=true) const
Definition: wallet.cpp:2155
static const unsigned int DEFAULT_KEYPOOL_SIZE
Definition: wallet.h:45
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
GetPubKey implementation that also checks the mapHdPubKeys.
Definition: wallet.cpp:202
static const CAmount DEFAULT_DIP0001_FALLBACK_FEE
Definition: wallet.h:52
CAmount nAnonymizedCreditCached
Definition: wallet.h:307
int SetMerkleBranch(const CBlock &block)
Definition: wallet.cpp:4386
bool IsNull() const
Definition: uint256.h:33
bool LoadCScript(const CScript &redeemScript)
Definition: wallet.cpp:358
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:738
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:3703
std::set< COutPoint > setWalletUTXO
Definition: wallet.h:654
const std::string strWalletFile
Definition: wallet.h:675
int nWalletMaxVersion
the maximum wallet format version: memory-only variable that specifies to what version this wallet ma...
Definition: wallet.h:633
int nWalletVersion
the current wallet version: clients below this version are not able to load the wallet ...
Definition: wallet.h:630
unsigned int nTimeReceived
Definition: wallet.h:284
CAmount GetChange() const
Definition: wallet.cpp:2023
void DeriveNewChildKey(const CKeyMetadata &metadata, CKey &secretRet, uint32_t nAccountIndex, bool fInternal)
Definition: wallet.cpp:140
bool fBroadcastTransactions
Definition: wallet.h:637
bool IsInMainChain() const
Definition: wallet.h:263
bool fAnonymizableTallyCached
Definition: wallet.h:639
std::string strComment
Definition: wallet.h:542
unsigned int nTxConfirmTarget
Definition: wallet.cpp:47
CAmount GetWatchOnlyBalance() const
Definition: wallet.cpp:2315
AvailableCoinsType
Definition: wallet.h:101
CAmount GetDenominatedCredit(bool unconfirmed, bool fUseCache=true) const
Definition: wallet.cpp:1978
bool AddCScript(const CScript &redeemScript)
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
Definition: wallet.cpp:349
bool GetKey(const CKeyID &address, CKey &keyOut) const
GetKey implementation that can derive a HD private key on the fly.
Definition: wallet.cpp:216
bool fAvailableWatchCreditCached
Definition: wallet.h:301
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Definition: wallet.h:1018
bool SelectCoins(const CAmount &nTargetValue, std::set< std::pair< const CWalletTx *, unsigned int > > &setCoinsRet, CAmount &nValueRet, const CCoinControl *coinControl=NULL, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=true) const
Definition: wallet.cpp:2623
static const CAmount MIN_CHANGE
minimum change amount
Definition: wallet.h:64
bool UpdatedTransaction(const uint256 &hashTx)
Definition: wallet.cpp:4168
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet) ...
Definition: wallet.h:993
int64_t CAmount
Definition: amount.h:14
bool SetMinVersion(enum WalletFeature, CWalletDB *pwalletdbIn=NULL, bool fExplicit=false)
signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVe...
Definition: wallet.cpp:527
CWalletTx()
Definition: wallet.h:316
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
Definition: key.h:32
bool IsChange(const CTxOut &txout) const
Definition: wallet.cpp:1363
CPubKey GenerateNewKey(uint32_t nAccountIndex, bool fInternal)
Definition: wallet.cpp:103
int vout
Definition: wallet.h:205
#define AssertLockHeld(cs)
Definition: sync.h:96
static const CAmount DEFAULT_DIP0001_TRANSACTION_MINFEE
Definition: wallet.h:60
static CFeeRate minTxFee
Definition: wallet.h:909
DBErrors ZapWalletTx(std::vector< CWalletTx > &vWtx)
Definition: wallet.cpp:3657
CAmount GetBalance() const
Definition: wallet.cpp:2139
CAmount nCreditDebit
Definition: wallet.h:539
int nDepth
Definition: wallet.h:487
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Definition: wallet.h:1011
size_t KeypoolCountInternalKeys()
Definition: wallet.cpp:3773
bool GetKeyFromPool(CPubKey &key, bool fInternal)
Definition: wallet.cpp:3903
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosRet, std::string &strFailReason, const CCoinControl *coinControl=NULL, bool sign=true, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=false)
Definition: wallet.cpp:3173
CAmount nDenomConfCreditCached
Definition: wallet.h:309
bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata)
Load metadata (used by LoadWallet)
Definition: wallet.cpp:334
int64_t GetOldestKeyPoolTime()
Definition: wallet.cpp:3933
CAmount nAvailableWatchCreditCached
Definition: wallet.h:313
uint64_t nEntryNo
position in ordered transaction list
Definition: wallet.h:545
CPubKey vchPubKey
Definition: wallet.h:1083
const int32_t nVersion
Definition: transaction.h:232
std::list< CAccountingEntry > laccentries
Definition: wallet.h:739
bool fDenomUnconfCreditCached
Definition: wallet.h:296
bool hashUnset() const
Definition: wallet.h:266
CAmount nDenomUnconfCreditCached
Definition: wallet.h:308
ChangeType
Definition: ui_interface.h:21
bool AddWatchOnly(const CScript &dest)
Adds a watch-only address to the store, and saves it to disk.
Definition: wallet.cpp:374
std::map< CKeyID, CKeyMetadata > mapKeyMetadata
Definition: wallet.h:695
bool SetHDChain(const CHDChain &chain, bool memonly)
Definition: wallet.cpp:1429
void UnlockCoin(COutPoint &output)
Definition: wallet.cpp:4204
bool RemoveWatchOnly(const CScript &dest)
Definition: wallet.cpp:385
CWalletTx(const CWallet *pwalletIn, const CTransaction &txIn)
Definition: wallet.h:331
CAmount GetUnconfirmedWatchOnlyBalance() const
Definition: wallet.cpp:2331
const_iterator begin() const
Definition: streams.h:118
#define LOCK(cs)
Definition: sync.h:168
~CWallet()
Definition: wallet.h:714
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE
Largest (in bytes) free transaction we&#39;re willing to create.
Definition: wallet.h:74
int64_t GetTxTime() const
Definition: wallet.cpp:1540
std::string purpose
Definition: wallet.h:162
CAmount GetCredit(const CTxOut &txout, const isminefilter &filter) const
Definition: wallet.cpp:1356
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:554
std::vector< char > _ssExtra
Definition: wallet.h:609
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Definition: wallet.h:1021
bool HaveKey(const CKeyID &address) const
HaveKey implementation that also checks the mapHdPubKeys.
Definition: wallet.cpp:244
float GetAverageAnonymizedRounds() const
Definition: wallet.cpp:2202
static CFeeRate fallbackFee
Definition: wallet.h:910
bool fLargeWorkInvalidChainFound
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: wallet.h:1098
unsigned int nTimeSmart
time received by this node
Definition: wallet.h:285
ADD_SERIALIZE_METHODS
Definition: wallet.h:373
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:4351
CPubKey vchDefaultKey
Definition: wallet.h:750
bool fAnonymizableTallyCachedNonDenom
Definition: wallet.h:641
std::vector< uint256 > ResendWalletTransactionsBefore(int64_t nTime, CConnman *connman)
Definition: wallet.cpp:2081
bool ConvertList(std::vector< CTxIn > vecTxIn, std::vector< CAmount > &vecAmounts)
Definition: wallet.cpp:3158
static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool &pool)
Definition: wallet.cpp:3596
static const CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:62
void GetAllReserveKeys(std::set< CKeyID > &setAddress) const
Definition: wallet.cpp:4151
bool bSpendZeroConfChange
Definition: wallet.cpp:48
void setAbandoned()
Definition: wallet.h:268
CAmount maxTxFee
Definition: wallet.cpp:46
static const bool DEFAULT_USE_HD_WALLET
if set, all keys will be derived by using BIP39/BIP44
Definition: wallet.h:78
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
Definition: wallet.cpp:1793
bool NewKeyPool()
Definition: wallet.cpp:3743
std::vector< std::pair< std::string, std::string > > vOrderForm
Definition: wallet.h:282
static const CAmount CENT
Definition: amount.h:17
static const CAmount DEFAULT_LEGACY_TRANSACTION_MINFEE
-mintxfee default
Definition: wallet.h:59
static const bool DEFAULT_SEND_FREE_TRANSACTIONS
Default for -sendfreetransactions.
Definition: wallet.h:68
bool SetCryptedHDChain(const CHDChain &chain, bool memonly)
Definition: wallet.cpp:1442
bool fImmatureWatchCreditCached
Definition: wallet.h:300
static const CAmount DEFAULT_LEGACY_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:51
std::string strComment
Definition: wallet.h:512
void GetAmounts(std::list< COutputEntry > &listReceived, std::list< COutputEntry > &listSent, CAmount &nFee, std::string &strSentAccount, const isminefilter &filter) const
Definition: wallet.cpp:1585
std::map< CKeyID, CHDPubKey > mapHdPubKeys
Definition: wallet.h:757
CWalletTx(const CWallet *pwalletIn, const CMerkleTx &txIn)
Definition: wallet.h:326
void KeepKey()
Definition: wallet.cpp:4120
uint8_t isminefilter
Definition: wallet_ismine.h:29
CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const
Definition: wallet.cpp:1225
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:4345
bool IsEquivalentTo(const CWalletTx &tx) const
Definition: wallet.cpp:2072
ADD_SERIALIZE_METHODS
Definition: wallet.h:1095
Definition: wallet.py:1
bool IsDenominatedAmount(CAmount nInputAmount) const
Definition: wallet.cpp:1343
void AddToSpends(const COutPoint &outpoint, const uint256 &wtxid)
Definition: wallet.cpp:701
void MarkDirty()
Definition: wallet.cpp:868
void MarkConflicted(const uint256 &hashBlock, const uint256 &hashTx)
Definition: wallet.cpp:1127
DBErrors LoadWallet(bool &fFirstRunRet)
Definition: wallet.cpp:3616
bool CreateCollateralTransaction(CMutableTransaction &txCollateral, std::string &strReason)
Definition: wallet.cpp:3088
void SetNull()
Definition: wallet.h:1090
CPubKey vchPubKey
Definition: wallet.h:1054
void SetNull()
Definition: wallet.h:552
int64_t nOrderPos
Definition: wallet.h:288
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
Definition: wallet.cpp:4336
bool SelectCoinsGrouppedByAddresses(std::vector< CompactTallyItem > &vecTallyRet, bool fSkipDenominated=true, bool fAnonymizable=true, bool fSkipUnconfirmed=true) const
Definition: wallet.cpp:2831
static const CAmount nHighTransactionMaxFeeWarning
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
Definition: wallet.h:72
std::string strFromAccount
Definition: wallet.h:287
size_t KeypoolCountExternalKeys()
Definition: wallet.cpp:3767
static void WriteOrderPos(const int64_t &nOrderPos, mapValue_t &mapValue)
Definition: wallet.h:194
bool AddHDPubKey(const CExtPubKey &extPubKey, bool fInternal)
Adds a HDPubKey into the wallet(database)
Definition: wallet.cpp:260
void ReturnKey()
Definition: wallet.cpp:4129
void Init(const CWallet *pwalletIn)
Definition: wallet.h:336
std::set< COutPoint > setLockedCoins
Definition: wallet.h:752
int64_t nNextResend
Definition: wallet.h:635
bool GetReservedKey(CPubKey &pubkey, bool fInternalIn)
Definition: wallet.cpp:4101
CAmount nImmatureWatchCreditCached
Definition: wallet.h:312
int ScanForWalletTransactions(CBlockIndex *pindexStart, bool fUpdate=false)
Definition: wallet.cpp:1687
static vector< COutput > vCoins
bool IsCollateralAmount(CAmount nInputAmount) const
Definition: wallet.cpp:3080
void Init()
Definition: wallet.h:235
int GetOutpointPrivateSendRounds(const COutPoint &outpoint) const
Definition: wallet.cpp:1321
bool fWatchCreditCached
Definition: wallet.h:299
bool GetBudgetSystemCollateralTX(CTransaction &tx, uint256 hash, CAmount amount, bool fUseInstantSend)
Definition: wallet.cpp:3123
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:723
isminetype IsMine(const CTxIn &txin) const
Definition: wallet.cpp:1210
void ResetRequestCount(const uint256 &hash)
Definition: wallet.h:972
void MarkDirty()
make sure balances are recalculated
Definition: wallet.h:418
void GetScriptForMining(boost::shared_ptr< CReserveScript > &script)
Definition: wallet.cpp:4182
static bool Verify(const std::string &walletFile, std::string &warningString, std::string &errorString)
Verify the wallet database and perform salvage if required.
Definition: wallet.cpp:594
void ResendWalletTransactions(int64_t nBestBlockTime, CConnman *connman)
Definition: wallet.cpp:2105
CAmount nDebitCached
Definition: wallet.h:303
CAmount GetDenominatedBalance(bool unconfirmed=false) const
Definition: wallet.cpp:2268
CTxDestination txdest
Definition: wallet.h:113
const CWallet * pwallet
Definition: wallet.h:278
void GetAccountAmounts(const std::string &strAccount, CAmount &nReceived, CAmount &nSent, CAmount &nFee, const isminefilter &filter) const
Definition: wallet.cpp:1641
bool IsTrusted() const
Definition: wallet.cpp:2041
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: wallet.h:244
MasterKeyMap mapMasterKeys
Definition: wallet.h:698
bool fLargeWorkForkFound
void ReacceptWalletTransactions()
Definition: wallet.cpp:1728
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:825
bool fChangeCached
Definition: wallet.h:302
std::vector< CompactTallyItem > vecAnonymizableTallyCached
Definition: wallet.h:640
int i
Definition: wallet.h:486
#define LIMITED_STRING(obj, n)
Definition: serialize.h:389
iterator insert(iterator it, const char &x=char())
Definition: streams.h:129
std::map< uint256, int > mapRequestCount
Definition: wallet.h:746
std::map< CTxDestination, CAmount > GetAddressBalances()
Definition: wallet.cpp:3954
int64_t atoi64(const char *psz)
unsigned int fTimeReceivedIsTxTime
Definition: wallet.h:283
std::string i64tostr(int64_t n)
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: wallet.h:136
std::vector< CompactTallyItem > vecAnonymizableTallyCachedNonDenom
Definition: wallet.h:642
bool fWatchDebitCached
Definition: wallet.h:298
CScript scriptPubKey
Definition: wallet.h:175
bool FundTransaction(CMutableTransaction &tx, CAmount &nFeeRet, int &nChangePosRet, std::string &strFailReason, bool includeWatching)
Definition: wallet.cpp:2727
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:748
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:447
bool IsDenominated(const COutPoint &outpoint) const
Definition: wallet.cpp:1328
bool fAvailableCreditCached
Definition: wallet.h:294
bool GetMasternodeOutpointAndKeys(COutPoint &outpointRet, CPubKey &pubKeyRet, CKey &keyRet, std::string strTxHash="", std::string strOutputIndex="")
Get 1000DASH output and keys which can be used for the Masternode.
Definition: wallet.cpp:2987
Definition: pubkey.h:37
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: wallet.h:376
CTxDestination destination
Definition: wallet.h:203
static CAmount GetRequiredFee(unsigned int nTxBytes)
Definition: wallet.cpp:3591
std::string str() const
Definition: streams.h:109
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet) ...
Definition: wallet.cpp:399
bool WriteToDisk(CWalletDB *pwalletdb)
Definition: wallet.cpp:1677
static const CAmount DEFAULT_TRANSACTION_FEE
-paytxfee default
Definition: wallet.h:47
int Priority() const
Definition: wallet.cpp:84
CAmount amount
Definition: wallet.h:204
CKeyPool()
Definition: wallet.cpp:4367
bool LoadHDPubKey(const CHDPubKey &hdPubKey)
loads a HDPubKey into the wallets memory
Definition: wallet.cpp:252
bool fImmatureCreditCached
Definition: wallet.h:293
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
Adds an encrypted key to the store, and saves it to disk.
Definition: wallet.cpp:313
std::set< int64_t > setExternalKeyPool
Definition: wallet.h:694
std::string strAccount
Definition: wallet.h:538
isminetype
Definition: wallet_ismine.h:17
void LockCoin(COutPoint &output)
Definition: wallet.cpp:4193
CPrivKey vchPrivKey
Definition: wallet.h:509
void BindWallet(CWallet *pwalletIn)
Definition: wallet.h:434
ADD_SERIALIZE_METHODS
Definition: wallet.h:518
int64_t nTimeFirstKey
Definition: wallet.h:754
int64_t nTime
Definition: wallet.h:540
void KeepScript()
Definition: wallet.h:1072
Definition: block.h:73
void ListLockedCoins(std::vector< COutPoint > &vOutpts)
Definition: wallet.cpp:4229
int64_t nOrderPos
Definition: wallet.h:544
CReserveKey(CWallet *pwalletIn)
Definition: wallet.h:1057
void Inventory(const uint256 &hash)
Definition: wallet.h:961
std::multimap< COutPoint, uint256 > TxSpends
Definition: wallet.h:649
int64_t nTimeCreated
Definition: wallet.h:510
Definition: key.h:35
CAmount GetImmatureBalance() const
Definition: wallet.cpp:2301
CAmount nWatchCreditCached
Definition: wallet.h:311
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >)
Definition: wallet.cpp:641
int GetBlocksToMaturity() const
Definition: wallet.cpp:4449
int GetDepthInMainChain(const CBlockIndex *&pindexRet, bool enableIX=true) const
Definition: wallet.cpp:4416
CWallet(const std::string &strWalletFileIn)
Definition: wallet.h:706
std::set< int64_t > setInternalKeyPool
Definition: wallet.h:693
int64_t nKeysLeftSinceAutoBackup
Definition: wallet.h:755
CWalletTx(const CWallet *pwalletIn)
Definition: wallet.h:321
void LoadKeyPool(int nIndex, const CKeyPool &keypool)
Definition: wallet.h:677
uint256 hashBlock
Definition: wallet.h:216
bool RelayWalletTransaction(CConnman *connman, std::string strCommand="tx")
Definition: wallet.cpp:1760
CAmount GetAnonymizedCredit(bool fUseCache=true) const
Definition: wallet.cpp:1944
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const
Definition: wallet.cpp:4273
bool SetDefaultKey(const CPubKey &vchPubKey)
Definition: wallet.cpp:3728
bool InMempool() const
Definition: wallet.cpp:2032
CAmount GetNormalizedAnonymizedBalance() const
Definition: wallet.cpp:2224
bool fSolvable
Definition: wallet.h:489
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
Adds a key to the store, and saves it to disk.
Definition: wallet.cpp:288
CAmount GetAvailableWatchOnlyCredit(const bool &fUseCache=true) const
Definition: wallet.cpp:1915
std::set< std::set< CTxDestination > > GetAddressGroupings()
Definition: wallet.cpp:3994
std::map< std::string, std::string > mapValue_t
Definition: wallet.h:180
int GetRequestCount() const
Definition: wallet.cpp:1546
void SyncTransaction(const CTransaction &tx, const CBlock *pblock)
Definition: wallet.cpp:1189
bool fInternal
Definition: wallet.h:1055
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, bool fIncludeZeroValue=false, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=false) const
Definition: wallet.cpp:2360