Fabcoin Core  0.16.2
P2P Digital Currency
wallet.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef FABCOIN_WALLET_WALLET_H
7 #define FABCOIN_WALLET_WALLET_H
8 
9 #include <amount.h>
10 #include <policy/feerate.h>
11 #include <streams.h>
12 #include <tinyformat.h>
13 #include <ui_interface.h>
14 #include <utilstrencodings.h>
15 #include <validationinterface.h>
16 #include <script/ismine.h>
17 #include <script/sign.h>
18 #include <wallet/crypter.h>
19 #include <wallet/walletdb.h>
20 #include <wallet/rpcwallet.h>
21 #include <consensus/params.h>
22 
23 #include <algorithm>
24 #include <atomic>
25 #include <map>
26 #include <set>
27 #include <stdexcept>
28 #include <stdint.h>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
34 extern std::vector<CWalletRef> vpwallets;
35 
40 extern CFeeRate payTxFee;
41 extern unsigned int nTxConfirmTarget;
42 extern bool bSpendZeroConfChange;
43 extern bool bZeroBalanceAddressToken;
44 extern bool fWalletRbf;
45 extern bool fWalletUnlockStakingOnly;
46 extern bool fNotUseChangeAddress;
47 extern bool fCheckForUpdates;
48 extern bool fBatchProcessingMode;
49 
50 static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
52 static const CAmount DEFAULT_TRANSACTION_FEE = 0;
54 static const CAmount DEFAULT_FALLBACK_FEE = 20000;
56 static const CAmount DEFAULT_DISCARD_FEE = 10000;
58 //static const CAmount DEFAULT_TRANSACTION_MINFEE = 400000;
59 static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
61 static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
63 static const CAmount MIN_CHANGE = CENT;
65 static const CAmount MIN_FINAL_CHANGE = MIN_CHANGE/2;
67 static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
69 static const bool DEFAULT_ZERO_BALANCE_ADDRESS_TOKEN = true;
71 static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false;
73 static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
75 static const bool DEFAULT_WALLET_RBF = false;
76 static const bool DEFAULT_WALLETBROADCAST = true;
77 static const bool DEFAULT_DISABLE_WALLET = false;
79 static const bool DEFAULT_USE_HD_WALLET = true;
80 
81 extern const char * DEFAULT_WALLET_DAT;
82 
83 static const int64_t TIMESTAMP_MIN = 0;
84 
85 static const bool DEFAULT_NOT_USE_CHANGE_ADDRESS = false;
86 
87 static const bool DEFAULT_CHECK_FOR_UPDATES = true;
88 
89 class CBlockIndex;
90 class CCoinControl;
91 class COutput;
92 class CReserveKey;
93 class CScript;
94 class CScheduler;
95 class CTxMemPool;
97 class CWalletTx;
98 class CTokenTx;
99 class CContractBookData;
100 struct FeeCalculation;
101 enum class FeeEstimateMode;
102 
105 {
106  FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output)
107 
108  FEATURE_WALLETCRYPT = 40000, // wallet encryption
109  FEATURE_COMPRPUBKEY = 60000, // compressed public keys
110 
111  FEATURE_HD = 130000, // Hierarchical key derivation after BIP32 (HD Wallet)
112 
113  FEATURE_HD_SPLIT = 139900, // Wallet with HD chain split (change outputs will use m/0'/1'/k)
114 
115  FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version
116 };
117 
118 
120 class CKeyPool
121 {
122 public:
123  int64_t nTime;
125  bool fInternal; // for change outputs
126 
127  CKeyPool();
128  CKeyPool(const CPubKey& vchPubKeyIn, bool internalIn);
129 
131 
132  template <typename Stream, typename Operation>
133  inline void SerializationOp(Stream& s, Operation ser_action) {
134  int nVersion = s.GetVersion();
135  if (!(s.GetType() & SER_GETHASH))
136  READWRITE(nVersion);
137  READWRITE(nTime);
138  READWRITE(vchPubKey);
139  if (ser_action.ForRead()) {
140  try {
141  READWRITE(fInternal);
142  }
143  catch (std::ios_base::failure&) {
144  /* flag as external address if we can't read the internal boolean
145  (this will be the case for any wallet before the HD chain split version) */
146  fInternal = false;
147  }
148  }
149  else {
150  READWRITE(fInternal);
151  }
152  }
153 };
154 
157 {
158 public:
159  std::string name;
160  std::string purpose;
161 
162  CAddressBookData() : purpose("unknown") {}
163 
164  typedef std::map<std::string, std::string> StringMap;
165  StringMap destdata;
166 };
167 
169 {
173 };
174 
175 typedef std::map<std::string, std::string> mapValue_t;
176 
177 
178 static inline void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
179 {
180  if (!mapValue.count("n"))
181  {
182  nOrderPos = -1; // TODO: calculate elsewhere
183  return;
184  }
185  nOrderPos = atoi64(mapValue["n"].c_str());
186 }
187 
188 
189 static inline void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
190 {
191  if (nOrderPos == -1)
192  return;
193  mapValue["n"] = i64tostr(nOrderPos);
194 }
195 
197 {
200  int vout;
201 };
202 
205 {
206 private:
208  static const uint256 ABANDON_HASH;
209 
210 public:
213 
214  /* An nIndex == -1 means that hashBlock (in nonzero) refers to the earliest
215  * block in the chain we know this or any in-wallet dependency conflicts
216  * with. Older clients interpret nIndex == -1 as unconfirmed for backward
217  * compatibility.
218  */
219  int nIndex;
220 
222  {
223  SetTx(MakeTransactionRef());
224  Init();
225  }
226 
228  {
229  SetTx(std::move(arg));
230  Init();
231  }
232 
235  operator const CTransaction&() const { return *tx; }
236 
237  void Init()
238  {
239  hashBlock = uint256();
240  nIndex = -1;
241  }
242 
244  {
245  tx = std::move(arg);
246  }
247 
249 
250  template <typename Stream, typename Operation>
251  inline void SerializationOp(Stream& s, Operation ser_action) {
252  std::vector<uint256> vMerkleBranch; // For compatibility with older versions.
253  READWRITE(tx);
254  READWRITE(hashBlock);
255  READWRITE(vMerkleBranch);
256  READWRITE(nIndex);
257  }
258 
259  void SetMerkleBranch(const CBlockIndex* pIndex, int posInBlock);
260 
267  int GetDepthInMainChain(const CBlockIndex* &pindexRet) const;
268  int GetDepthInMainChain() const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); }
269  int GetHeight() const;
270  bool IsInMainChain() const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet) > 0; }
271  int GetBlocksToMaturity() const;
273  bool AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state);
274  bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
275  bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
276  void setAbandoned() { hashBlock = ABANDON_HASH; }
277 
278  const uint256& GetHash() const { return tx->GetHash(); }
279  bool IsCoinBase() const { return tx->IsCoinBase(); }
280  bool IsCoinStake() const { return false; }
281 };
282 
287 class CWalletTx : public CMerkleTx
288 {
289 private:
290  const CWallet* pwallet;
291 
292 public:
319  std::vector<std::pair<std::string, std::string> > vOrderForm;
320  unsigned int fTimeReceivedIsTxTime;
321  unsigned int nTimeReceived;
322 
331  unsigned int nTimeSmart;
337  char fFromMe;
338  std::string strFromAccount;
339  int64_t nOrderPos;
340 
341  // memory only
342  mutable bool fDebitCached;
343  mutable bool fCreditCached;
344  mutable bool fImmatureCreditCached;
346  mutable bool fWatchDebitCached;
347  mutable bool fWatchCreditCached;
350  mutable bool fChangeCached;
360 
362  {
363  Init(nullptr);
364  }
365 
366  CWalletTx(const CWallet* pwalletIn, CTransactionRef arg) : CMerkleTx(std::move(arg))
367  {
368  Init(pwalletIn);
369  }
370 
371  void Init(const CWallet* pwalletIn)
372  {
373  pwallet = pwalletIn;
374  mapValue.clear();
375  vOrderForm.clear();
376  fTimeReceivedIsTxTime = false;
377  nTimeReceived = 0;
378  nTimeSmart = 0;
379  fFromMe = false;
380  strFromAccount.clear();
381  fDebitCached = false;
382  fCreditCached = false;
383  fImmatureCreditCached = false;
384  fAvailableCreditCached = false;
385  fWatchDebitCached = false;
386  fWatchCreditCached = false;
387  fImmatureWatchCreditCached = false;
388  fAvailableWatchCreditCached = false;
389  fChangeCached = false;
390  nDebitCached = 0;
391  nCreditCached = 0;
392  nImmatureCreditCached = 0;
393  nAvailableCreditCached = 0;
394  nWatchDebitCached = 0;
395  nWatchCreditCached = 0;
396  nAvailableWatchCreditCached = 0;
397  nImmatureWatchCreditCached = 0;
398  nChangeCached = 0;
399  nOrderPos = -1;
400  }
401 
403 
404  template <typename Stream, typename Operation>
405  inline void SerializationOp(Stream& s, Operation ser_action) {
406  if (ser_action.ForRead())
407  Init(nullptr);
408  char fSpent = false;
409 
410  if (!ser_action.ForRead())
411  {
412  mapValue["fromaccount"] = strFromAccount;
413 
414  WriteOrderPos(nOrderPos, mapValue);
415 
416  if (nTimeSmart)
417  mapValue["timesmart"] = strprintf("%u", nTimeSmart);
418  }
419 
420  READWRITE(*(CMerkleTx*)this);
421  std::vector<CMerkleTx> vUnused;
422  READWRITE(vUnused);
423  READWRITE(mapValue);
424  READWRITE(vOrderForm);
425  READWRITE(fTimeReceivedIsTxTime);
426  READWRITE(nTimeReceived);
427  READWRITE(fFromMe);
428  READWRITE(fSpent);
429 
430  if (ser_action.ForRead())
431  {
432  strFromAccount = mapValue["fromaccount"];
433 
434  ReadOrderPos(nOrderPos, mapValue);
435 
436  nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
437  }
438 
439  mapValue.erase("fromaccount");
440  mapValue.erase("spent");
441  mapValue.erase("n");
442  mapValue.erase("timesmart");
443  }
444 
446  void MarkDirty()
447  {
448  fCreditCached = false;
449  fAvailableCreditCached = false;
450  fImmatureCreditCached = false;
451  fWatchDebitCached = false;
452  fWatchCreditCached = false;
453  fAvailableWatchCreditCached = false;
454  fImmatureWatchCreditCached = false;
455  fDebitCached = false;
456  fChangeCached = false;
457  }
458 
459  void BindWallet(CWallet *pwalletIn)
460  {
461  pwallet = pwalletIn;
462  MarkDirty();
463  }
464 
466  CAmount GetDebit(const isminefilter& filter) const;
467  CAmount GetCredit(const isminefilter& filter) const;
468  CAmount GetImmatureCredit(bool fUseCache=true) const;
469  CAmount GetAvailableCredit(bool fUseCache=true) const;
470  CAmount GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const;
471  CAmount GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const;
472  CAmount GetChange() const;
473 
474  void GetAmounts(std::list<COutputEntry>& listReceived,
475  std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
476 
477  bool IsFromMe(const isminefilter& filter) const
478  {
479  return (GetDebit(filter) > 0);
480  }
481 
482  // True if only scriptSigs are different
483  bool IsEquivalentTo(const CWalletTx& tx) const;
484 
485  bool InMempool() const;
486  bool IsTrusted() const;
487 
488  int64_t GetTxTime() const;
489  int GetRequestCount() const;
490 
491  // RelayWalletTransaction may only be called if fBroadcastTransactions!
492  bool RelayWalletTransaction(CConnman* connman);
493 
494  std::set<uint256> GetConflicts() const;
495 };
496 
497 
498 class CInputCoin {
499 public:
500  CInputCoin(const CWalletTx* walletTx, unsigned int i)
501  {
502  if (!walletTx)
503  throw std::invalid_argument("walletTx should not be null");
504  if (i >= walletTx->tx->vout.size())
505  throw std::out_of_range("The output index is out of range");
506 
507  outpoint = COutPoint(walletTx->GetHash(), i);
508  txout = walletTx->tx->vout[i];
509  }
510 
513 
514  bool operator<(const CInputCoin& rhs) const {
515  return outpoint < rhs.outpoint;
516  }
517 
518  bool operator!=(const CInputCoin& rhs) const {
519  return outpoint != rhs.outpoint;
520  }
521 
522  bool operator==(const CInputCoin& rhs) const {
523  return outpoint == rhs.outpoint;
524  }
525 };
526 
527 class COutput
528 {
529 public:
530  const CWalletTx *tx;
531  int i;
532  int nDepth;
533 
536 
538  bool fSolvable;
539 
545  bool fSafe;
546 
547  COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn)
548  {
549  tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; fSolvable = fSolvableIn; fSafe = fSafeIn;
550  }
551 
552  std::string ToString() const;
553 };
554 
555 
556 
557 
560 {
561 public:
563  int64_t nTimeCreated;
564  int64_t nTimeExpires;
565  std::string strComment;
568 
569  CWalletKey(int64_t nExpires=0);
570 
572 
573  template <typename Stream, typename Operation>
574  inline void SerializationOp(Stream& s, Operation ser_action) {
575  int nVersion = s.GetVersion();
576  if (!(s.GetType() & SER_GETHASH))
577  READWRITE(nVersion);
578  READWRITE(vchPrivKey);
579  READWRITE(nTimeCreated);
580  READWRITE(nTimeExpires);
581  READWRITE(LIMITED_STRING(strComment, 65536));
582  }
583 };
584 
590 {
591 public:
592  std::string strAccount;
594  int64_t nTime;
595  std::string strOtherAccount;
596  std::string strComment;
598  int64_t nOrderPos;
599  uint64_t nEntryNo;
600 
602  {
603  SetNull();
604  }
605 
606  void SetNull()
607  {
608  nCreditDebit = 0;
609  nTime = 0;
610  strAccount.clear();
611  strOtherAccount.clear();
612  strComment.clear();
613  nOrderPos = -1;
614  nEntryNo = 0;
615  }
616 
618 
619  template <typename Stream, typename Operation>
620  inline void SerializationOp(Stream& s, Operation ser_action) {
621  int nVersion = s.GetVersion();
622  if (!(s.GetType() & SER_GETHASH))
623  READWRITE(nVersion);
625  READWRITE(nCreditDebit);
626  READWRITE(nTime);
627  READWRITE(LIMITED_STRING(strOtherAccount, 65536));
628 
629  if (!ser_action.ForRead())
630  {
631  WriteOrderPos(nOrderPos, mapValue);
632 
633  if (!(mapValue.empty() && _ssExtra.empty()))
634  {
635  CDataStream ss(s.GetType(), s.GetVersion());
636  ss.insert(ss.begin(), '\0');
637  ss << mapValue;
638  ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
639  strComment.append(ss.str());
640  }
641  }
642 
643  READWRITE(LIMITED_STRING(strComment, 65536));
644 
645  size_t nSepPos = strComment.find("\0", 0, 1);
646  if (ser_action.ForRead())
647  {
648  mapValue.clear();
649  if (std::string::npos != nSepPos)
650  {
651  CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
652  ss >> mapValue;
653  _ssExtra = std::vector<char>(ss.begin(), ss.end());
654  }
655  ReadOrderPos(nOrderPos, mapValue);
656  }
657  if (std::string::npos != nSepPos)
658  strComment.erase(nSepPos);
659 
660  mapValue.erase("n");
661  }
662 
663 private:
664  std::vector<char> _ssExtra;
665 };
666 
667 
673 {
674 private:
675  static std::atomic<bool> fFlushScheduled;
676  std::atomic<bool> fAbortRescan;
677  std::atomic<bool> fScanningWallet;
678 
684  bool SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = nullptr) const;
685 
687 
690 
693 
694  int64_t nNextResend;
695  int64_t nLastResend;
697 
703  typedef std::multimap<COutPoint, uint256> TxSpends;
704  TxSpends mapTxSpends;
705  void AddToSpends(const COutPoint& outpoint, const uint256& wtxid);
706  void AddToSpends(const uint256& wtxid);
707 
708  /* Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
709  void MarkConflicted(const uint256& hashBlock, const uint256& hashTx);
710 
711  void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
712 
713  /* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected.
714  * Should be called with pindexBlock and posInBlock if this is for a transaction that is included in a block. */
715  void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindex = nullptr, int posInBlock = 0);
716 
717  /* the HD chain data model (external chain counters) */
719 
720  /* HD derive new child key (on internal or external chain) */
721  void DeriveNewChildKey(CWalletDB &walletdb, CKeyMetadata& metadata, CKey& secret, bool internal = false);
722 
723  std::set<int64_t> setInternalKeyPool;
724  std::set<int64_t> setExternalKeyPool;
726  std::map<CKeyID, int64_t> m_pool_key_to_index;
727 
728  int64_t nTimeFirstKey;
729 
739  bool AddWatchOnly(const CScript& dest) override;
740 
741  std::unique_ptr<CWalletDBWrapper> dbw;
742 
743 public:
744  /*
745  * Main wallet lock.
746  * This lock protects all the fields added by CWallet.
747  */
749 
754  {
755  return *dbw;
756  }
757 
760  std::string GetName() const
761  {
762  if (dbw) {
763  return dbw->GetName();
764  } else {
765  return "dummy";
766  }
767  }
768 
769  void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool);
770 
771  // Map from Key ID (for regular keys) or Script ID (for watch-only keys) to
772  // key metadata.
773  std::map<CTxDestination, CKeyMetadata> mapKeyMetadata;
774 
775  typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
776  MasterKeyMap mapMasterKeys;
777  unsigned int nMasterKeyMaxID;
778 
779  // Create wallet with dummy database handle
780  CWallet(): dbw(new CWalletDBWrapper())
781  {
782  SetNull();
783  }
784 
785  // Create wallet with passed-in database handle
786  CWallet(std::unique_ptr<CWalletDBWrapper> dbw_in) : dbw(std::move(dbw_in))
787  {
788  SetNull();
789  }
790 
792  {
793  delete pwalletdbEncryption;
794  pwalletdbEncryption = nullptr;
795  }
796 
797  void SetNull()
798  {
799  nWalletVersion = FEATURE_BASE;
800  nWalletMaxVersion = FEATURE_BASE;
801  nMasterKeyMaxID = 0;
802  pwalletdbEncryption = nullptr;
803  nOrderPosNext = 0;
804  nAccountingEntryNumber = 0;
805  nNextResend = 0;
806  nLastResend = 0;
807  m_max_keypool_index = 0;
808  nTimeFirstKey = 0;
809  fBroadcastTransactions = false;
810  nRelockTime = 0;
811  fAbortRescan = false;
812  fScanningWallet = false;
813  }
814 
815  std::map<uint256, CWalletTx> mapWallet;
816  std::list<CAccountingEntry> laccentries;
817 
818  typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
819  typedef std::multimap<int64_t, TxPair > TxItems;
820  TxItems wtxOrdered;
821 
822  int64_t nOrderPosNext;
824  std::map<uint256, int> mapRequestCount;
825 
826  std::map<CTxDestination, CAddressBookData> mapAddressBook;
827 
828  std::map<std::string, CContractBookData> mapContractBook;
829 
831 
832  std::set<COutPoint> setLockedCoins;
833 
834  std::map<uint256, CTokenInfo> mapToken;
835 
836  std::map<uint256, CTokenTx> mapTokenTx;
837 
838  const CWalletTx* GetWalletTx(const uint256& hash) const;
839 
841  bool CanSupportFeature(enum WalletFeature wf) const { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
842 
846  void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t& nMaximumCount = 0, const int& nMinDepth = 0, const int& nMaxDepth = 9999999) const;
847 
851  std::map<CTxDestination, std::vector<COutput>> ListCoins() const;
852 
856  const CTxOut& FindNonChangeParentOutput(const CTransaction& tx, int output) const;
857 
864  bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, uint64_t nMaxAncestors, std::vector<COutput> vCoins, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet) const;
865 
866  bool IsSpent(const uint256& hash, unsigned int n) const;
867 
868  bool IsLockedCoin(uint256 hash, unsigned int n) const;
869  void LockCoin(const COutPoint& output);
870  void UnlockCoin(const COutPoint& output);
871  void UnlockAllCoins();
872  void ListLockedCoins(std::vector<COutPoint>& vOutpts) const;
873 
874  /*
875  * Rescan abort properties
876  */
877  void AbortRescan() { fAbortRescan = true; }
878  bool IsAbortingRescan() { return fAbortRescan; }
879  bool IsScanning() { return fScanningWallet; }
880 
885  CPubKey GenerateNewKey(CWalletDB& walletdb, bool internal = false);
887  bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override;
888  bool AddKeyPubKeyWithDB(CWalletDB &walletdb,const CKey& key, const CPubKey &pubkey);
890  bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); }
892  bool LoadKeyMetadata(const CTxDestination& pubKey, const CKeyMetadata &metadata);
893 
894  bool LoadMinVersion(int nVersion) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
895  void UpdateTimeFirstKey(int64_t nCreateTime);
896 
898  bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) override;
900  bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
901  bool AddCScript(const CScript& redeemScript) override;
902  bool LoadCScript(const CScript& redeemScript);
903 
905  bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
907  bool EraseDestData(const CTxDestination &dest, const std::string &key);
909  bool LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
911  bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const;
913  std::vector<std::string> GetDestValues(const std::string& prefix) const;
914 
916  bool AddWatchOnly(const CScript& dest, int64_t nCreateTime);
917  bool RemoveWatchOnly(const CScript &dest) override;
919  bool LoadWatchOnly(const CScript &dest);
920 
922  int64_t nRelockTime;
923 
924  bool Unlock(const SecureString& strWalletPassphrase);
925  bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
926  bool EncryptWallet(const SecureString& strWalletPassphrase);
927 
928  void GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) const;
929  unsigned int ComputeTimeSmart(const CWalletTx& wtx) const;
930 
931  bool LoadToken(const CTokenInfo &token);
932 
933  bool LoadTokenTx(const CTokenTx &tokenTx);
934 
936  bool LoadContractData(const std::string &address, const std::string &key, const std::string &value);
937 
942  int64_t IncOrderPosNext(CWalletDB *pwalletdb = nullptr);
943  DBErrors ReorderTransactions();
944  bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "");
945  bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false);
946 
947  void MarkDirty();
948  bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
949  bool LoadToWallet(const CWalletTx& wtxIn);
950  void TransactionAddedToMempool(const CTransactionRef& tx) override;
951  void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) override;
952  void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) override;
953  bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate);
954  int64_t RescanFromTime(int64_t startTime, bool update);
955  CBlockIndex* ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
956  void ReacceptWalletTransactions();
957  void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) override;
958  // ResendWalletTransactionsBefore may only be called if fBroadcastTransactions!
959  std::vector<uint256> ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman);
960  CAmount GetBalance() const;
961  CAmount GetUnconfirmedBalance() const;
962  CAmount GetImmatureBalance() const;
963  CAmount GetWatchOnlyBalance() const;
964  CAmount GetUnconfirmedWatchOnlyBalance() const;
965  CAmount GetImmatureWatchOnlyBalance() const;
966  CAmount GetLegacyBalance(const isminefilter& filter, int minDepth, const std::string* account) const;
967  CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const;
968 
973  bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl);
974  bool SignTransaction(CMutableTransaction& tx);
975 
981  bool CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
982  std::string& strFailReason, const CCoinControl& coin_control, bool sign = true, CAmount nGasFee=0, bool hasSender=false);
983  bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state);
984 
985  void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
986  bool AddAccountingEntry(const CAccountingEntry&);
987  bool AddAccountingEntry(const CAccountingEntry&, CWalletDB *pwalletdb);
988  template <typename ContainerType>
989  bool DummySignTx(CMutableTransaction &txNew, const ContainerType &coins) const;
990 
998  static CAmount GetMinimumFee(unsigned int nTxBytes, const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation *feeCalc);
1003  static CAmount GetRequiredFee(unsigned int nTxBytes);
1004 
1005  bool NewKeyPool();
1006  size_t KeypoolCountExternalKeys();
1007  bool TopUpKeyPool(unsigned int kpSize = 0);
1008  void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fRequestedInternal);
1009  void KeepKey(int64_t nIndex);
1010  void ReturnKey(int64_t nIndex, bool fInternal, const CPubKey& pubkey);
1011  bool GetKeyFromPool(CPubKey &key, bool internal = false);
1012  int64_t GetOldestKeyPoolTime();
1016  void MarkReserveKeysAsUsed(int64_t keypool_id);
1017  const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
1018 
1019  std::set< std::set<CTxDestination> > GetAddressGroupings();
1020  std::map<CTxDestination, CAmount> GetAddressBalances();
1021 
1022  std::set<CTxDestination> GetAccountAddresses(const std::string& strAccount) const;
1023 
1024  isminetype IsMine(const CTxIn& txin) const;
1029  CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
1030  isminetype IsMine(const CTxOut& txout) const;
1031  CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
1032  bool IsChange(const CTxOut& txout) const;
1033  CAmount GetChange(const CTxOut& txout) const;
1034  bool IsMine(const CTransaction& tx) const;
1036  bool IsFromMe(const CTransaction& tx) const;
1037  CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
1039  bool IsAllFromMe(const CTransaction& tx, const isminefilter& filter) const;
1040  CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
1041  CAmount GetChange(const CTransaction& tx) const;
1042  void SetBestChain(const CBlockLocator& loc) override;
1043 
1044  DBErrors LoadWallet(bool& fFirstRunRet);
1045  DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);
1046  DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut);
1047 
1048  bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose);
1049 
1050  bool DelAddressBook(const CTxDestination& address);
1051 
1052  const std::string& GetAccountName(const CScript& scriptPubKey) const;
1053 
1054  bool SetContractBook(const std::string& strAddress, const std::string& strName, const std::string& strAbi);
1055 
1056  bool DelContractBook(const std::string& strAddress);
1057 
1058  void Inventory(const uint256 &hash) override
1059  {
1060  {
1061  LOCK(cs_wallet);
1062  std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
1063  if (mi != mapRequestCount.end())
1064  (*mi).second++;
1065  }
1066  }
1067 
1068  void GetScriptForMining(std::shared_ptr<CReserveScript> &script);
1069  void ResetRequestCount(const uint256 &hash)
1070  {
1071  LOCK(cs_wallet);
1072  mapRequestCount[hash] = 0;
1073  };
1074 
1075  unsigned int GetKeyPoolSize()
1076  {
1077  AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool
1078  return setInternalKeyPool.size() + setExternalKeyPool.size();
1079  }
1080 
1081  bool SetDefaultKey(const CPubKey &vchPubKey);
1082 
1084  bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = nullptr, bool fExplicit = false);
1085 
1087  bool SetMaxVersion(int nVersion);
1088 
1090  int GetVersion() { LOCK(cs_wallet); return nWalletVersion; }
1091 
1093  std::set<uint256> GetConflicts(const uint256& txid) const;
1094 
1096  bool HasWalletSpend(const uint256& txid) const;
1097 
1099  void Flush(bool shutdown=false);
1100 
1102  // This function will perform salvage on the wallet if requested, as long as only one wallet is
1103  // being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
1104  static bool Verify();
1105 
1110  boost::signals2::signal<void (CWallet *wallet, const CTxDestination
1111  &address, const std::string &label, bool isMine,
1112  const std::string &purpose,
1114 
1119  boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx,
1121 
1126  boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx,
1128 
1130  boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
1131 
1133  boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
1134 
1136  boost::signals2::signal<void (CWallet *wallet, const uint256 &hashToken,
1138 
1140  boost::signals2::signal<void (CWallet *wallet, const std::string &address,
1141  const std::string &label, const std::string &abi,
1143 
1145  bool GetBroadcastTransactions() const { return fBroadcastTransactions; }
1147  void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
1148 
1150  bool TransactionCanBeAbandoned(const uint256& hashTx) const;
1151 
1152  /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
1153  bool AbandonTransaction(const uint256& hashTx);
1154 
1156  bool MarkReplaced(const uint256& originalHash, const uint256& newHash);
1157 
1158  /* Returns the wallets help message */
1159  static std::string GetWalletHelpString(bool showDebug);
1160 
1161  /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
1162  static CWallet* CreateWalletFromFile(const std::string walletFile);
1163  static bool InitLoadWallet();
1164 
1169  void postInitProcess(CScheduler& scheduler);
1170 
1171  /* Wallets parameter interaction */
1172  static bool ParameterInteraction();
1173 
1174  bool BackupWallet(const std::string& strDest);
1175 
1176  /* Set the HD chain model (chain child index counters) */
1177  bool SetHDChain(const CHDChain& chain, bool memonly);
1178  const CHDChain& GetHDChain() const { return hdChain; }
1179 
1180  /* Returns true if HD is enabled */
1181  bool IsHDEnabled() const;
1182 
1183  /* Generates a new HD master key (will not be activated) */
1184  CPubKey GenerateNewHDMasterKey();
1185 
1186  /* Set the current HD master key (will reset the chain child index counters)
1187  Sets the master key's version based on the current wallet version (so the
1188  caller must ensure the current wallet version is correct before calling
1189  this function). */
1190  bool SetHDMasterKey(const CPubKey& key);
1191 
1192  /* Add token entry into the wallet */
1193  bool AddTokenEntry(const CTokenInfo& token, bool fFlushOnClose=true);
1194 
1195  /* Add token tx entry into the wallet */
1196  bool AddTokenTxEntry(const CTokenTx& tokenTx, bool fFlushOnClose=true);
1197 
1198  /* Get details token tx entry into the wallet */
1199  bool GetTokenTxDetails(const CTokenTx &wtx, uint256& credit, uint256& debit, std::string& tokenSymbol, uint8_t& decimals) const;
1200 
1201  /* Check if token transaction is mine */
1202  bool IsTokenTxMine(const CTokenTx &wtx) const;
1203 
1204  /* Remove token entry from the wallet */
1205  bool RemoveTokenEntry(const uint256& tokenHash, bool fFlushOnClose=true);
1206 };
1207 
1210 {
1211 protected:
1213  int64_t nIndex;
1216 public:
1217  CReserveKey(CWallet* pwalletIn)
1218  {
1219  nIndex = -1;
1220  pwallet = pwalletIn;
1221  fInternal = false;
1222  }
1223 
1224  CReserveKey() = default;
1225  CReserveKey(const CReserveKey&) = delete;
1226  CReserveKey& operator=(const CReserveKey&) = delete;
1227 
1229  {
1230  ReturnKey();
1231  }
1232 
1233  void ReturnKey();
1234  bool GetReservedKey(CPubKey &pubkey, bool internal = false);
1235  void KeepKey();
1236  void KeepScript() override { KeepKey(); }
1237 };
1238 
1239 
1245 {
1246 public:
1248 
1250  {
1251  SetNull();
1252  }
1253 
1254  void SetNull()
1255  {
1256  vchPubKey = CPubKey();
1257  }
1258 
1260 
1261  template <typename Stream, typename Operation>
1262  inline void SerializationOp(Stream& s, Operation ser_action) {
1263  int nVersion = s.GetVersion();
1264  if (!(s.GetType() & SER_GETHASH))
1265  READWRITE(nVersion);
1266  READWRITE(vchPubKey);
1267  }
1268 };
1269 
1270 // Helper for producing a bunch of max-sized low-S signatures (eg 72 bytes)
1271 // ContainerType is meant to hold pair<CWalletTx *, int>, and be iterable
1272 // so that each entry corresponds to each vIn, in order.
1273 template <typename ContainerType>
1274 bool CWallet::DummySignTx(CMutableTransaction &txNew, const ContainerType &coins) const
1275 {
1276  // Fill in dummy signatures for fee calculation.
1277  int nIn = 0;
1278  for (const auto& coin : coins)
1279  {
1280  const CScript& scriptPubKey = coin.txout.scriptPubKey;
1281  SignatureData sigdata;
1282 
1283  if (!ProduceSignature(DummySignatureCreator(this), scriptPubKey, sigdata))
1284  {
1285  return false;
1286  } else {
1287  UpdateTransaction(txNew, nIn, sigdata);
1288  }
1289 
1290  nIn++;
1291  }
1292  return true;
1293 }
1294 
1296 {
1297 public:
1298  static const int CURRENT_VERSION=1;
1300  std::string strContractAddress;
1301  std::string strTokenName;
1302  std::string strTokenSymbol;
1303  uint8_t nDecimals;
1304  std::string strSenderAddress;
1305 
1306  // Wallet data for token transaction
1307  int64_t nCreateTime;
1309  int64_t blockNumber;
1310 
1312  {
1313  SetNull();
1314  }
1315 
1317 
1318  template <typename Stream, typename Operation>
1319  inline void SerializationOp(Stream& s, Operation ser_action) {
1320  if (!(s.GetType() & SER_GETHASH))
1321  {
1322  READWRITE(nVersion);
1323  READWRITE(nCreateTime);
1324  READWRITE(strTokenName);
1325  READWRITE(strTokenSymbol);
1326  READWRITE(blockHash);
1327  READWRITE(blockNumber);
1328  }
1329  READWRITE(nDecimals);
1330  READWRITE(strContractAddress);
1331  READWRITE(strSenderAddress);
1332  }
1333 
1334  void SetNull()
1335  {
1336  nVersion = CTokenInfo::CURRENT_VERSION;
1337  nCreateTime = 0;
1338  strContractAddress = "";
1339  strTokenName = "";
1340  strTokenSymbol = "";
1341  nDecimals = 0;
1342  strSenderAddress = "";
1343  blockHash.SetNull();
1344  blockNumber = -1;
1345  }
1346 
1347  uint256 GetHash() const;
1348 };
1349 
1351 {
1352 public:
1353  static const int CURRENT_VERSION=1;
1355  std::string strContractAddress;
1356  std::string strSenderAddress;
1357  std::string strReceiverAddress;
1360 
1361  // Wallet data for token transaction
1362  int64_t nCreateTime;
1364  int64_t blockNumber;
1365  std::string strLabel;
1366 
1368  {
1369  SetNull();
1370  }
1371 
1373 
1374  template <typename Stream, typename Operation>
1375  inline void SerializationOp(Stream& s, Operation ser_action) {
1376  if (!(s.GetType() & SER_GETHASH))
1377  {
1378  READWRITE(nVersion);
1379  READWRITE(nCreateTime);
1380  READWRITE(blockHash);
1381  READWRITE(blockNumber);
1382  READWRITE(LIMITED_STRING(strLabel, 65536));
1383  }
1384  READWRITE(strContractAddress);
1385  READWRITE(strSenderAddress);
1386  READWRITE(strReceiverAddress);
1387  READWRITE(nValue);
1388  READWRITE(transactionHash);
1389  }
1390 
1391  void SetNull()
1392  {
1393  nVersion = CTokenTx::CURRENT_VERSION;
1394  nCreateTime = 0;
1395  strContractAddress = "";
1396  strSenderAddress = "";
1397  strReceiverAddress = "";
1398  nValue.SetNull();
1399  transactionHash.SetNull();
1400  blockHash.SetNull();
1401  blockNumber = -1;
1402  strLabel = "";
1403  }
1404 
1405  uint256 GetHash() const;
1406 };
1407 
1410 {
1411 public:
1412  std::string name;
1413  std::string abi;
1414 
1416  {}
1417 };
1418 
1419 #endif // FABCOIN_WALLET_WALLET_H
int64_t nTimeCreated
Definition: wallet.h:563
std::string strTokenSymbol
Definition: wallet.h:1302
bool fChangeCached
Definition: wallet.h:350
const CWallet * pwallet
Definition: wallet.h:290
std::atomic< bool > fScanningWallet
Definition: wallet.h:677
void UpdateTransaction(CMutableTransaction &tx, unsigned int nIn, const SignatureData &data)
Definition: sign.cpp:198
CWallet * pwallet
Definition: wallet.h:1212
void SetTx(CTransactionRef arg)
Definition: wallet.h:243
static const uint256 ABANDON_HASH
Constant used in hashBlock to indicate tx has been abandoned.
Definition: wallet.h:208
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:620
Contract book data.
Definition: wallet.h:1409
int64_t nNextResend
Definition: wallet.h:694
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:405
Account information.
Definition: wallet.h:1244
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:574
bool fNotUseChangeAddress
Definition: wallet.cpp:48
int i
Definition: wallet.h:531
int64_t nOrderPos
position in ordered transaction list
Definition: wallet.h:598
CAmount nImmatureWatchCreditCached
Definition: wallet.h:357
std::string strReceiverAddress
Definition: wallet.h:1357
void BindWallet(CWallet *pwalletIn)
Definition: wallet.h:459
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:79
int64_t nCreateTime
Definition: wallet.h:1307
bool fSolvable
Whether we know how to spend this output, ignoring the lack of keys.
Definition: wallet.h:538
void SetNull()
Definition: uint256.h:46
CPrivKey vchPrivKey
Definition: wallet.h:562
int64_t nIndex
Definition: wallet.h:1213
std::string abi
Definition: wallet.h:1413
const char * DEFAULT_WALLET_DAT
Definition: wallet.cpp:52
Describes a place in the block chain to another node such that if the other node doesn&#39;t have the sam...
Definition: block.h:251
#define READWRITE(obj)
Definition: serialize.h:179
std::map< uint256, CTokenTx > mapTokenTx
Definition: wallet.h:836
CAmount nCreditCached
Definition: wallet.h:352
uint64_t nAccountingEntryNumber
Definition: wallet.h:823
int nVersion
Definition: wallet.h:1299
char fFromMe
From me flag is set to 1 for transactions that were created by the wallet on this fabcoin node...
Definition: wallet.h:337
ADD_SERIALIZE_METHODS
Definition: wallet.h:1372
CAmount nChangeCached
Definition: wallet.h:359
COutPoint outpoint
Definition: wallet.h:511
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:826
CCriticalSection cs_wallet
Definition: wallet.h:748
const uint256 & GetHash() const
Definition: wallet.h:278
#define strprintf
Definition: tinyformat.h:1054
std::unique_ptr< CWalletDBWrapper > dbw
Definition: wallet.h:741
std::vector< char > _ssExtra
Definition: wallet.h:664
int nIndex
Definition: wallet.h:219
std::string GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:760
bool fImmatureCreditCached
Definition: wallet.h:344
std::string strFromAccount
Definition: wallet.h:338
WalletFeature
(client) version numbers for particular wallet features
Definition: wallet.h:104
TxItems wtxOrdered
Definition: wallet.h:820
const char * prefix
Definition: rest.cpp:623
bool IsCoinStake() const
Definition: wallet.h:280
std::map< uint256, CTokenInfo > mapToken
Definition: wallet.h:834
CPubKey vchDefaultKey
Definition: wallet.h:830
bool fInternal
Definition: wallet.h:1215
bool DummySignTx(CMutableTransaction &txNew, const ContainerType &coins) const
Definition: wallet.h:1274
bool operator<(const CInputCoin &rhs) const
Definition: wallet.h:514
CWalletDB * pwalletdbEncryption
Definition: wallet.h:686
FeeEstimateMode
Definition: fees.h:96
uint256 hashBlock
Definition: wallet.h:212
bool hashUnset() const
Definition: wallet.h:274
CTokenInfo()
Definition: wallet.h:1311
std::multimap< COutPoint, uint256 > TxSpends
Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated tran...
Definition: wallet.h:703
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:1375
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:56
int64_t nOrderPos
position in ordered transaction list
Definition: wallet.h:339
CWallet * CWalletRef
Definition: wallet.h:33
std::set< int64_t > setInternalKeyPool
Definition: wallet.h:723
bool operator!=(const CInputCoin &rhs) const
Definition: wallet.h:518
std::string strSenderAddress
Definition: wallet.h:1304
bool fCheckForUpdates
Definition: wallet.cpp:49
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey, SigVersion sigversion)
Definition: ismine.cpp:29
CMerkleTx(CTransactionRef arg)
Definition: wallet.h:227
uint8_t isminefilter
used for bitflags of isminetype
Definition: ismine.h:29
int64_t nTimeFirstKey
Definition: wallet.h:728
std::hash for asio::adress
Definition: Common.h:323
mapValue_t mapValue
Definition: wallet.h:597
std::map< CKeyID, int64_t > m_pool_key_to_index
Definition: wallet.h:726
void SetNull()
Definition: wallet.h:1254
CPubKey vchPubKey
Definition: wallet.h:1214
void MarkDirty()
make sure balances are recalculated
Definition: wallet.h:446
bool fSubtractFeeFromAmount
Definition: wallet.h:172
unsigned int GetKeyPoolSize()
Definition: wallet.h:1075
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:775
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:146
CFeeRate payTxFee
Transaction fee set by the user.
std::string strComment
Definition: wallet.h:565
int nVersion
Definition: wallet.h:1354
std::string name
Definition: wallet.h:159
std::map< CTxDestination, CKeyMetadata > mapKeyMetadata
Definition: wallet.h:773
void SetNull()
Definition: wallet.h:1334
int64_t blockNumber
Definition: wallet.h:1364
~CReserveKey()
Definition: wallet.h:1228
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTokenTransactionChanged
Wallet token transaction added, removed or updated.
Definition: wallet.h:1127
std::atomic< bool > fAbortRescan
Definition: wallet.h:676
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:51
CAmount nWatchDebitCached
Definition: wallet.h:355
Keystore which keeps the private keys encrypted.
Definition: crypter.h:113
int64_t m_max_keypool_index
Definition: wallet.h:725
bool fSpendable
Whether we have the private keys to spend this output.
Definition: wallet.h:535
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:437
int64_t nTimeExpires
Definition: wallet.h:564
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:141
bool fAvailableCreditCached
Definition: wallet.h:345
std::string purpose
Definition: wallet.h:160
void Init()
Definition: wallet.h:237
CHDChain hdChain
Definition: wallet.h:718
Coin Control Features.
Definition: coincontrol.h:16
CAmount nReserveBalance
Settings.
Definition: wallet.cpp:55
CAccount()
Definition: wallet.h:1249
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:1145
unsigned int nTxConfirmTarget
Definition: wallet.cpp:44
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: wallet.h:318
void ResetRequestCount(const uint256 &hash)
Definition: wallet.h:1069
std::string strContractAddress
Definition: wallet.h:1355
int GetDepthInMainChain() const
Definition: wallet.h:268
bool fDebitCached
Definition: wallet.h:342
std::list< CAccountingEntry > laccentries
Definition: wallet.h:816
int64_t CAmount
Amount in lius (Can be negative)
Definition: amount.h:15
std::multimap< int64_t, TxPair > TxItems
Definition: wallet.h:819
bool fAvailableWatchCreditCached
Definition: wallet.h:349
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
Definition: crypter.cpp:208
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
secp256k1: const unsigned int PRIVATE_KEY_SIZE = 279; const unsigned int PUBLIC_KEY_SIZE = 65; const ...
Definition: key.h:32
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:1120
#define AssertLockHeld(cs)
Definition: sync.h:85
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:1147
std::string strComment
Definition: wallet.h:596
ADD_SERIALIZE_METHODS
Definition: wallet.h:402
static const int CURRENT_VERSION
Definition: wallet.h:1298
An instance of this class represents one database.
Definition: db.h:93
bool IsInMainChain() const
Definition: wallet.h:270
int64_t nTime
Definition: wallet.h:123
CScript scriptPubKey
Definition: wallet.h:170
unsigned int nMasterKeyMaxID
Definition: wallet.h:777
bool fBatchProcessingMode
Definition: wallet.cpp:50
static CFeeRate m_discard_rate
Definition: wallet.h:993
ADD_SERIALIZE_METHODS
Definition: wallet.h:1259
bool fWalletRbf
Definition: wallet.cpp:47
int nDepth
Definition: wallet.h:532
bool operator==(const CInputCoin &rhs) const
Definition: wallet.h:522
uint64_t nEntryNo
Definition: wallet.h:599
uint256 blockHash
Definition: wallet.h:1308
ChangeType
General change type (added, updated, removed).
Definition: ui_interface.h:19
CTransactionRef tx
Definition: wallet.h:211
std::string strContractAddress
Definition: wallet.h:1300
isminetype
IsMine() return codes.
Definition: ismine.h:17
An input of a transaction.
Definition: transaction.h:61
CInputCoin(const CWalletTx *walletTx, unsigned int i)
Definition: wallet.h:500
ADD_SERIALIZE_METHODS
Definition: wallet.h:1316
bool IsNull() const
Definition: uint256.h:38
#define LOCK(cs)
Definition: sync.h:175
We want to be able to estimate feerates that are needed on tx&#39;s to be included in a certain number of...
Definition: fees.h:162
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet) ...
Definition: wallet.h:1090
CKeyPool()
Definition: wallet.cpp:4458
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:251
An encapsulated public key.
Definition: pubkey.h:39
bool fSafe
Whether this output is considered safe to spend.
Definition: wallet.h:545
std::set< COutPoint > setLockedCoins
Definition: wallet.h:832
TxSpends mapTxSpends
Definition: wallet.h:704
CAmount amount
Definition: wallet.h:199
void KeepScript() override
Definition: wallet.h:1236
std::map< std::string, std::string > StringMap
Definition: wallet.h:164
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:890
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:1319
bool bSpendZeroConfChange
Definition: wallet.cpp:45
const CHDChain & GetHDChain() const
Definition: wallet.h:1178
Definition: net.h:120
int64_t blockNumber
Definition: wallet.h:1309
An output of a transaction.
Definition: transaction.h:131
ADD_SERIALIZE_METHODS
Definition: wallet.h:248
void SetNull()
Definition: wallet.h:797
std::map< uint256, int > mapRequestCount
Definition: wallet.h:824
std::set< int64_t > setExternalKeyPool
Definition: wallet.h:724
bool IsFromMe(const isminefilter &filter) const
Definition: wallet.h:477
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:18
bool fWatchCreditCached
Definition: wallet.h:347
ADD_SERIALIZE_METHODS
Definition: wallet.h:130
void Inventory(const uint256 &hash) override
Notifies listeners about an inventory item being seen on the network.
Definition: wallet.h:1058
unsigned int fTimeReceivedIsTxTime
Definition: wallet.h:320
bool LoadMinVersion(int nVersion)
Definition: wallet.h:894
bool bZeroBalanceAddressToken
Definition: wallet.cpp:46
Access to the wallet database.
Definition: walletdb.h:143
CWalletDBWrapper & GetDBHandle()
Get database handle used by this wallet.
Definition: wallet.h:753
bool fCreditCached
Definition: wallet.h:343
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced, bool fOverrideMempoolLimit, const CAmount nAbsurdFee, bool rawTx)
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions repla...
int nWalletMaxVersion
the maximum wallet format version: memory-only variable that specifies to what version this wallet ma...
Definition: wallet.h:692
CAmount nAmount
Definition: wallet.h:171
std::string strLabel
Definition: wallet.h:1365
std::vector< CWalletRef > vpwallets
Definition: wallet.cpp:41
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:287
const std::map< CKeyID, int64_t > & GetAllReserveKeys() const
Definition: wallet.h:1017
std::string name
Definition: wallet.h:1412
bool fBroadcastTransactions
Definition: wallet.h:696
CPubKey vchPubKey
Definition: wallet.h:1247
Signature sign(Secret const &_k, h256 const &_hash)
Returns siganture of message hash.
Definition: Common.cpp:233
Capture information about block/transaction validation.
Definition: validation.h:27
256-bit opaque blob.
Definition: uint256.h:132
void Init(const CWallet *pwalletIn)
Definition: wallet.h:371
CPubKey vchPubKey
Definition: wallet.h:124
CAmount nWatchCreditCached
Definition: wallet.h:356
CWalletTx(const CWallet *pwalletIn, CTransactionRef arg)
Definition: wallet.h:366
static std::atomic< bool > fFlushScheduled
Definition: wallet.h:675
void setAbandoned()
Definition: wallet.h:276
uint8_t nDecimals
Definition: wallet.h:1303
CAmount nAvailableCreditCached
Definition: wallet.h:354
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:465
CWallet()
Definition: wallet.h:780
iterator insert(iterator it, const char &x=char())
Definition: streams.h:244
int64_t nCreateTime
Definition: wallet.h:1362
void SetNull()
Definition: wallet.h:1391
ADD_SERIALIZE_METHODS
Definition: wallet.h:617
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
Definition: wallet.h:1113
static CFeeRate fallbackFee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:992
MasterKeyMap mapMasterKeys
Definition: wallet.h:776
int vout
Definition: wallet.h:200
A key allocated from the key pool.
Definition: wallet.h:1209
CWalletTx()
Definition: wallet.h:361
std::map< std::string, CContractBookData > mapContractBook
Definition: wallet.h:828
Address book data.
Definition: wallet.h:156
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:177
boost::signals2::signal< void(CWallet *wallet, const std::string &address, const std::string &label, const std::string &abi, ChangeType status)> NotifyContractBookChanged
Contract book entry changed.
Definition: wallet.h:1142
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:417
StringMap destdata
Definition: wallet.h:165
int64_t nOrderPosNext
Definition: wallet.h:822
CTxDestination destination
Definition: wallet.h:198
bool fWalletUnlockStakingOnly
Definition: wallet.cpp:328
unsigned int nTimeSmart
Stable timestamp that never changes, and reflects the order a transaction was added to the wallet...
Definition: wallet.h:331
void SetNull()
Definition: wallet.h:606
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:1262
ADD_SERIALIZE_METHODS
Definition: wallet.h:571
bool CanSupportFeature(enum WalletFeature wf) const
check whether we are allowed to upgrade (or already support) to the named feature ...
Definition: wallet.h:841
Private key that includes an expiration date in case it never gets used.
Definition: wallet.h:559
Internal transfers.
Definition: wallet.h:589
const CWalletTx * tx
Definition: wallet.h:530
#define LIMITED_STRING(obj, n)
Definition: serialize.h:391
static CFeeRate minTxFee
Fees smaller than this (in liu) are considered zero fee (for transaction creation) Override with -min...
Definition: wallet.h:991
int64_t atoi64(const char *psz)
int nWalletVersion
the current wallet version: clients below this version are not able to load the wallet ...
Definition: wallet.h:689
bool isAbandoned() const
Definition: wallet.h:275
bool IsScanning()
Definition: wallet.h:879
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:672
Fee rate in liu per kilobyte: CAmount / kB.
Definition: feerate.h:20
std::string i64tostr(int64_t n)
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn)
Definition: wallet.h:547
CAccountingEntry()
Definition: wallet.h:601
CReserveKey(CWallet *pwalletIn)
Definition: wallet.h:1217
void AbortRescan()
Definition: wallet.h:877
CWallet(std::unique_ptr< CWalletDBWrapper > dbw_in)
Definition: wallet.h:786
Definition: wallet.h:196
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:815
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:1130
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:133
A mutable version of CTransaction.
Definition: transaction.h:390
CAmount nAvailableWatchCreditCached
Definition: wallet.h:358
bool IsAbortingRescan()
Definition: wallet.h:878
uint256 nValue
Definition: wallet.h:1358
int64_t nLastResend
Definition: wallet.h:695
std::string strSenderAddress
Definition: wallet.h:1356
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
Definition: Common.h:326
CMerkleTx()
Definition: wallet.h:221
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
unsigned int nTimeReceived
time received by this node
Definition: wallet.h:321
bool fWatchDebitCached
Definition: wallet.h:346
An encapsulated private key.
Definition: key.h:35
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:275
bool fImmatureWatchCreditCached
Definition: wallet.h:348
static const int CURRENT_VERSION
Definition: wallet.h:1353
std::pair< CWalletTx *, CAccountingEntry * > TxPair
Definition: wallet.h:818
uint256 transactionHash
Definition: wallet.h:1359
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:1133
std::string strOtherAccount
Definition: wallet.h:595
uint256 blockHash
Definition: wallet.h:1363
CTokenTx()
Definition: wallet.h:1367
bool fInternal
Definition: wallet.h:125
int64_t nRelockTime
Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock().
Definition: wallet.h:922
CAmount nCreditDebit
Definition: wallet.h:593
int64_t nTime
Definition: wallet.h:594
CTxOut txout
Definition: wallet.h:512
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
Definition: sync.h:91
CAmount nImmatureCreditCached
Definition: wallet.h:353
A transaction with a merkle branch linking it to the block chain.
Definition: wallet.h:204
std::map< std::string, std::string > mapValue_t
Definition: wallet.h:175
A signature creator that just produces 72-byte empty signatures.
Definition: sign.h:56
~CWallet()
Definition: wallet.h:791
bool IsCoinBase() const
Definition: wallet.h:279
A key pool entry.
Definition: wallet.h:120
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashToken, ChangeType status)> NotifyTokenChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:1137
std::vector< std::pair< std::string, std::string > > vOrderForm
Definition: wallet.h:319
CAmount nDebitCached
Definition: wallet.h:351
std::string strTokenName
Definition: wallet.h:1301
std::string strAccount
Definition: wallet.h:592