Raven Core  3.0.0
P2P Digital Currency
wallet.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Raven 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 RAVEN_WALLET_WALLET_H
8 #define RAVEN_WALLET_WALLET_H
9 
10 #include "amount.h"
11 #include "policy/feerate.h"
12 #include "streams.h"
13 #include "tinyformat.h"
14 #include "ui_interface.h"
15 #include "utilstrencodings.h"
16 #include "validationinterface.h"
17 #include "script/ismine.h"
18 #include "script/sign.h"
19 #include "wallet/crypter.h"
20 #include "wallet/walletdb.h"
21 #include "wallet/rpcwallet.h"
22 #include "assets/assettypes.h"
23 
24 #include <algorithm>
25 #include <atomic>
26 #include <map>
27 #include <set>
28 #include <stdexcept>
29 #include <stdint.h>
30 #include <string>
31 #include <utility>
32 #include <vector>
33 
34 
36 extern std::vector<CWalletRef> vpwallets;
37 
41 extern CFeeRate payTxFee;
42 extern unsigned int nTxConfirmTarget;
43 extern bool bSpendZeroConfChange;
44 extern bool fWalletRbf;
45 
46 static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
48 static const CAmount DEFAULT_TRANSACTION_FEE = 0;
50 static const CAmount DEFAULT_FALLBACK_FEE = 1025000;
52 static const CAmount DEFAULT_DISCARD_FEE = 25000;
54 static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000000;
56 static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
58 static const CAmount MIN_CHANGE = CENT;
60 static const CAmount MIN_FINAL_CHANGE = MIN_CHANGE/2;
62 static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
64 static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false;
66 static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
68 static const bool DEFAULT_WALLET_RBF = false;
69 static const bool DEFAULT_WALLETBROADCAST = true;
70 static const bool DEFAULT_DISABLE_WALLET = false;
71 
72 extern const char * DEFAULT_WALLET_DAT;
73 
74 static const int64_t TIMESTAMP_MIN = 0;
75 
76 class CBlockIndex;
77 class CCoinControl;
78 class COutput;
79 class CReserveKey;
80 class CScript;
81 class CScheduler;
82 class CTxMemPool;
84 class CWalletTx;
85 struct FeeCalculation;
86 enum class FeeEstimateMode;
87 
90 {
91  FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output)
92 
93  FEATURE_WALLETCRYPT = 10000, // wallet encryption
94  FEATURE_COMPRPUBKEY = 10000, // compressed public keys
95 
96  FEATURE_HD = 10000, // Hierarchical key derivation after BIP32 (HD Wallet)
97 
98  FEATURE_HD_SPLIT = 10000, // Wallet with HD chain split (change outputs will use m/0'/1'/k)
99 
100  FEATURE_NO_DEFAULT_KEY = 10000, // Wallet without a default key written
101 
102  FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version
103 };
104 
105 
107 class CKeyPool
108 {
109 public:
110  int64_t nTime;
112  bool fInternal; // for change outputs
113 
114  CKeyPool();
115  CKeyPool(const CPubKey& vchPubKeyIn, bool internalIn);
116 
118 
119  template <typename Stream, typename Operation>
120  inline void SerializationOp(Stream& s, Operation ser_action) {
121  int nVersion = s.GetVersion();
122  if (!(s.GetType() & SER_GETHASH))
123  READWRITE(nVersion);
124  READWRITE(nTime);
125  READWRITE(vchPubKey);
126  if (ser_action.ForRead()) {
127  try {
128  READWRITE(fInternal);
129  }
130  catch (std::ios_base::failure&) {
131  /* flag as external address if we can't read the internal boolean
132  (this will be the case for any wallet before the HD chain split version) */
133  fInternal = false;
134  }
135  }
136  else {
137  READWRITE(fInternal);
138  }
139  }
140 };
141 
144 {
145 public:
146  std::string name;
147  std::string purpose;
148 
149  CAddressBookData() : purpose("unknown") {}
150 
151  typedef std::map<std::string, std::string> StringMap;
152  StringMap destdata;
153 };
154 
156 {
160 };
161 
162 typedef std::map<std::string, std::string> mapValue_t;
163 
164 
165 static inline void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
166 {
167  if (!mapValue.count("n"))
168  {
169  nOrderPos = -1; // TODO: calculate elsewhere
170  return;
171  }
172  nOrderPos = atoi64(mapValue["n"].c_str());
173 }
174 
175 
176 static inline void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
177 {
178  if (nOrderPos == -1)
179  return;
180  mapValue["n"] = i64tostr(nOrderPos);
181 }
182 
184 {
187  int vout;
188 };
189 
192 {
194  std::string assetName;
197  std::string message;
198  int64_t expireTime;
199  int vout;
200 };
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  bool IsInMainChain() const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet) > 0; }
270  int GetBlocksToMaturity() const;
272  bool AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state);
273  bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
274  bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
275  void setAbandoned() { hashBlock = ABANDON_HASH; }
276 
277  const uint256& GetHash() const { return tx->GetHash(); }
278  bool IsCoinBase() const { return tx->IsCoinBase(); }
279 };
280 
285 class CWalletTx : public CMerkleTx
286 {
287 private:
288  const CWallet* pwallet;
289 
290 public:
317  std::vector<std::pair<std::string, std::string> > vOrderForm;
318  unsigned int fTimeReceivedIsTxTime;
319  unsigned int nTimeReceived;
320 
329  unsigned int nTimeSmart;
335  char fFromMe;
336  std::string strFromAccount;
337  int64_t nOrderPos;
338 
339  // memory only
340  mutable bool fDebitCached;
341  mutable bool fCreditCached;
342  mutable bool fImmatureCreditCached;
344  mutable bool fWatchDebitCached;
345  mutable bool fWatchCreditCached;
348  mutable bool fChangeCached;
358 
360  {
361  Init(nullptr);
362  }
363 
364  CWalletTx(const CWallet* pwalletIn, CTransactionRef arg) : CMerkleTx(std::move(arg))
365  {
366  Init(pwalletIn);
367  }
368 
369  void Init(const CWallet* pwalletIn)
370  {
371  pwallet = pwalletIn;
372  mapValue.clear();
373  vOrderForm.clear();
374  fTimeReceivedIsTxTime = false;
375  nTimeReceived = 0;
376  nTimeSmart = 0;
377  fFromMe = false;
378  strFromAccount.clear();
379  fDebitCached = false;
380  fCreditCached = false;
381  fImmatureCreditCached = false;
382  fAvailableCreditCached = false;
383  fWatchDebitCached = false;
384  fWatchCreditCached = false;
385  fImmatureWatchCreditCached = false;
386  fAvailableWatchCreditCached = false;
387  fChangeCached = false;
388  nDebitCached = 0;
389  nCreditCached = 0;
390  nImmatureCreditCached = 0;
391  nAvailableCreditCached = 0;
392  nWatchDebitCached = 0;
393  nWatchCreditCached = 0;
394  nAvailableWatchCreditCached = 0;
395  nImmatureWatchCreditCached = 0;
396  nChangeCached = 0;
397  nOrderPos = -1;
398  }
399 
401 
402  template <typename Stream, typename Operation>
403  inline void SerializationOp(Stream& s, Operation ser_action) {
404  if (ser_action.ForRead())
405  Init(nullptr);
406  char fSpent = false;
407 
408  if (!ser_action.ForRead())
409  {
410  mapValue["fromaccount"] = strFromAccount;
411 
412  WriteOrderPos(nOrderPos, mapValue);
413 
414  if (nTimeSmart)
415  mapValue["timesmart"] = strprintf("%u", nTimeSmart);
416  }
417 
418  READWRITE(*(CMerkleTx*)this);
419  std::vector<CMerkleTx> vUnused;
420  READWRITE(vUnused);
421  READWRITE(mapValue);
422  READWRITE(vOrderForm);
423  READWRITE(fTimeReceivedIsTxTime);
424  READWRITE(nTimeReceived);
425  READWRITE(fFromMe);
426  READWRITE(fSpent);
427 
428  if (ser_action.ForRead())
429  {
430  strFromAccount = mapValue["fromaccount"];
431 
432  ReadOrderPos(nOrderPos, mapValue);
433 
434  nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
435  }
436 
437  mapValue.erase("fromaccount");
438  mapValue.erase("spent");
439  mapValue.erase("n");
440  mapValue.erase("timesmart");
441  }
442 
444  void MarkDirty()
445  {
446  fCreditCached = false;
447  fAvailableCreditCached = false;
448  fImmatureCreditCached = false;
449  fWatchDebitCached = false;
450  fWatchCreditCached = false;
451  fAvailableWatchCreditCached = false;
452  fImmatureWatchCreditCached = false;
453  fDebitCached = false;
454  fChangeCached = false;
455  }
456 
457  void BindWallet(CWallet *pwalletIn)
458  {
459  pwallet = pwalletIn;
460  MarkDirty();
461  }
462 
464  CAmount GetDebit(const isminefilter& filter) const;
465  CAmount GetCredit(const isminefilter& filter) const;
466  CAmount GetImmatureCredit(bool fUseCache=true) const;
467  CAmount GetAvailableCredit(bool fUseCache=true) const;
468  CAmount GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const;
469  CAmount GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const;
470  CAmount GetChange() const;
471 
472  void GetAmounts(std::list<COutputEntry>& listReceived,
473  std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
474 
475  void GetAmounts(std::list<COutputEntry>& listReceived,
476  std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter, std::list<CAssetOutputEntry>& assetsReceived, std::list<CAssetOutputEntry>& assetsSent) const;
477 
478  bool IsFromMe(const isminefilter& filter) const
479  {
480  return (GetDebit(filter) > 0);
481  }
482 
483  // True if only scriptSigs are different
484  bool IsEquivalentTo(const CWalletTx& tx) const;
485 
486  bool InMempool() const;
487  bool IsTrusted() const;
488 
489  int64_t GetTxTime() const;
490  int GetRequestCount() const;
491 
492  // RelayWalletTransaction may only be called if fBroadcastTransactions!
493  bool RelayWalletTransaction(CConnman* connman);
494 
495  std::set<uint256> GetConflicts() const;
496 };
497 
498 
499 class CInputCoin {
500 public:
501  CInputCoin(const CWalletTx* walletTx, unsigned int i)
502  {
503  if (!walletTx)
504  throw std::invalid_argument("walletTx should not be null");
505  if (i >= walletTx->tx->vout.size())
506  throw std::out_of_range("The output index is out of range");
507 
508  outpoint = COutPoint(walletTx->GetHash(), i);
509  txout = walletTx->tx->vout[i];
510  }
511 
514 
515  bool operator<(const CInputCoin& rhs) const {
516  return outpoint < rhs.outpoint;
517  }
518 
519  bool operator!=(const CInputCoin& rhs) const {
520  return outpoint != rhs.outpoint;
521  }
522 
523  bool operator==(const CInputCoin& rhs) const {
524  return outpoint == rhs.outpoint;
525  }
526 };
527 
528 class COutput
529 {
530 public:
531  const CWalletTx *tx;
532  int i;
533  int nDepth;
534 
537 
539  bool fSolvable;
540 
546  bool fSafe;
547 
548  COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn)
549  {
550  tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; fSolvable = fSolvableIn; fSafe = fSafeIn;
551  }
552 
553  std::string ToString() const;
554 };
555 
556 
557 
558 
561 {
562 public:
564  int64_t nTimeCreated;
565  int64_t nTimeExpires;
566  std::string strComment;
569 
570  explicit CWalletKey(int64_t nExpires=0);
571 
573 
574  template <typename Stream, typename Operation>
575  inline void SerializationOp(Stream& s, Operation ser_action) {
576  int nVersion = s.GetVersion();
577  if (!(s.GetType() & SER_GETHASH))
578  READWRITE(nVersion);
579  READWRITE(vchPrivKey);
580  READWRITE(nTimeCreated);
581  READWRITE(nTimeExpires);
582  READWRITE(LIMITED_STRING(strComment, 65536));
583  }
584 };
585 
591 {
592 public:
593  std::string strAccount;
595  int64_t nTime;
596  std::string strOtherAccount;
597  std::string strComment;
599  int64_t nOrderPos;
600  uint64_t nEntryNo;
601 
603  {
604  SetNull();
605  }
606 
607  void SetNull()
608  {
609  nCreditDebit = 0;
610  nTime = 0;
611  strAccount.clear();
612  strOtherAccount.clear();
613  strComment.clear();
614  nOrderPos = -1;
615  nEntryNo = 0;
616  }
617 
619 
620  template <typename Stream, typename Operation>
621  inline void SerializationOp(Stream& s, Operation ser_action) {
622  int nVersion = s.GetVersion();
623  if (!(s.GetType() & SER_GETHASH))
624  READWRITE(nVersion);
626  READWRITE(nCreditDebit);
627  READWRITE(nTime);
628  READWRITE(LIMITED_STRING(strOtherAccount, 65536));
629 
630  if (!ser_action.ForRead())
631  {
632  WriteOrderPos(nOrderPos, mapValue);
633 
634  if (!(mapValue.empty() && _ssExtra.empty()))
635  {
636  CDataStream ss(s.GetType(), s.GetVersion());
637  ss.insert(ss.begin(), '\0');
638  ss << mapValue;
639  ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
640  strComment.append(ss.str());
641  }
642  }
643 
644  READWRITE(LIMITED_STRING(strComment, 65536));
645 
646  size_t nSepPos = strComment.find("\0", 0, 1);
647  if (ser_action.ForRead())
648  {
649  mapValue.clear();
650  if (std::string::npos != nSepPos)
651  {
652  CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
653  ss >> mapValue;
654  _ssExtra = std::vector<char>(ss.begin(), ss.end());
655  }
656  ReadOrderPos(nOrderPos, mapValue);
657  }
658  if (std::string::npos != nSepPos)
659  strComment.erase(nSepPos);
660 
661  mapValue.erase("n");
662  }
663 
664 private:
665  std::vector<char> _ssExtra;
666 };
667 
668 
673 class CWallet final : public CCryptoKeyStore, public CValidationInterface
674 {
675 private:
676  static std::atomic<bool> fFlushScheduled;
677  std::atomic<bool> fAbortRescan;
678  std::atomic<bool> fScanningWallet;
679 
685  bool SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = nullptr) const;
686 
687  bool SelectAssets(const std::map<std::string, std::vector<COutput> >& mapAvailableAssets, const std::map<std::string, CAmount>& mapAssetTargetValue, std::set<CInputCoin>& setCoinsRet, std::map<std::string, CAmount>& nValueRet) const;
688 
690 
693 
696 
697  int64_t nNextResend;
698  int64_t nLastResend;
700 
706  typedef std::multimap<COutPoint, uint256> TxSpends;
707  TxSpends mapTxSpends;
708  void AddToSpends(const COutPoint& outpoint, const uint256& wtxid);
709  void AddToSpends(const uint256& wtxid);
710 
711  /* Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
712  void MarkConflicted(const uint256& hashBlock, const uint256& hashTx);
713 
714  void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
715 
716  /* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected.
717  * Should be called with pindexBlock and posInBlock if this is for a transaction that is included in a block. */
718  void SyncTransaction(const CTransactionRef& tx, const CBlockIndex *pindex = nullptr, int posInBlock = 0);
719 
720  /* the HD chain data model (external chain counters) */
722 
723  /* HD derive new child key (on internal or external chain) */
724  void DeriveNewChildKey(CWalletDB &walletdb, CKeyMetadata& metadata, CKey& secret, bool internal = false);
725 
726  std::set<int64_t> setInternalKeyPool;
727  std::set<int64_t> setExternalKeyPool;
729  std::map<CKeyID, int64_t> m_pool_key_to_index;
730 
731  int64_t nTimeFirstKey;
732 
742  bool AddWatchOnly(const CScript& dest) override;
743 
744  std::unique_ptr<CWalletDBWrapper> dbw;
745 
746 public:
747  /*
748  * Main wallet lock.
749  * This lock protects all the fields added by CWallet.
750  */
752 
757  {
758  return *dbw;
759  }
760 
763  std::string GetName() const
764  {
765  if (dbw) {
766  return dbw->GetName();
767  } else {
768  return "dummy";
769  }
770  }
771 
772  void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool);
773 
774  // Map from Key ID (for regular keys) or Script ID (for watch-only keys) to
775  // key metadata.
776  std::map<CTxDestination, CKeyMetadata> mapKeyMetadata;
777 
778  typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
779  MasterKeyMap mapMasterKeys;
780  unsigned int nMasterKeyMaxID;
781 
782  // Create wallet with dummy database handle
783  CWallet(): dbw(new CWalletDBWrapper())
784  {
785  SetNull();
786  }
787 
788  // Create wallet with passed-in database handle
789  explicit CWallet(std::unique_ptr<CWalletDBWrapper> dbw_in) : dbw(std::move(dbw_in))
790  {
791  SetNull();
792  }
793 
795  {
796  delete pwalletdbEncryption;
797  pwalletdbEncryption = nullptr;
798  }
799 
800  void SetNull()
801  {
802  nWalletVersion = FEATURE_BASE;
803  nWalletMaxVersion = FEATURE_BASE;
804  nMasterKeyMaxID = 0;
805  pwalletdbEncryption = nullptr;
806  nOrderPosNext = 0;
807  nAccountingEntryNumber = 0;
808  nNextResend = 0;
809  nLastResend = 0;
810  m_max_keypool_index = 0;
811  nTimeFirstKey = 0;
812  fBroadcastTransactions = false;
813  nRelockTime = 0;
814  fAbortRescan = false;
815  fScanningWallet = false;
816  }
817 
818  std::map<uint256, CWalletTx> mapWallet;
819  std::list<CAccountingEntry> laccentries;
820 
821  typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
822  typedef std::multimap<int64_t, TxPair > TxItems;
823  TxItems wtxOrdered;
824 
825  int64_t nOrderPosNext;
827  std::map<uint256, int> mapRequestCount;
828 
829  std::map<CTxDestination, CAddressBookData> mapAddressBook;
830 
831  std::set<COutPoint> setLockedCoins;
832 
833  const CWalletTx* GetWalletTx(const uint256& hash) const;
834 
836  bool CanSupportFeature(enum WalletFeature wf) const { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
837 
841  void AvailableCoinsAll(std::vector<COutput>& vCoins, std::map<std::string, std::vector<COutput> >& mapAssetCoins,
842  bool fGetRVN = true, bool fOnlyAssets = false,
843  bool fOnlySafe = true, const CCoinControl *coinControl = nullptr,
844  const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY,
845  const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t& nMaximumCount = 0,
846  const int& nMinDepth = 0, const int& nMaxDepth = 9999999) const;
847 
851  void AvailableAssets(std::map<std::string, std::vector<COutput> > &mapAssetCoins, bool fOnlySafe = true,
852  const CCoinControl *coinControl = nullptr, const CAmount &nMinimumAmount = 1,
853  const CAmount &nMaximumAmount = MAX_MONEY, const CAmount &nMinimumSumAmount = MAX_MONEY,
854  const uint64_t &nMaximumCount = 0, const int &nMinDepth = 0, const int &nMaxDepth = 9999999) const;
855 
859  void AvailableCoinsWithAssets(std::vector<COutput> &vCoins, std::map<std::string, std::vector<COutput> > &mapAssetCoins,
860  bool fOnlySafe = true, const CCoinControl *coinControl = nullptr, const CAmount &nMinimumAmount = 1,
861  const CAmount &nMaximumAmount = MAX_MONEY, const CAmount &nMinimumSumAmount = MAX_MONEY,
862  const uint64_t &nMaximumCount = 0, const int &nMinDepth = 0, const int &nMaxDepth = 9999999) const;
866  void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr,
867  const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY,
868  const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t& nMaximumCount = 0,
869  const int& nMinDepth = 0, const int& nMaxDepth = 9999999) const;
870 
874  std::map<CTxDestination, std::vector<COutput>> ListCoins() const;
875 
879  std::map<CTxDestination, std::vector<COutput>> ListAssets() const;
880 
881 
885  const CTxOut& FindNonChangeParentOutput(const CTransaction& tx, int output) const;
886 
893  bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, uint64_t nMaxAncestors, std::vector<COutput> vCoins, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet) const;
894  bool SelectAssetsMinConf(const CAmount& nTargetValue, const int nConfMine, const int nConfTheirs, const uint64_t nMaxAncestors, const std::string& strAssetName, std::vector<COutput> vCoins, std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet) const;
895 
896  bool IsSpent(const uint256& hash, unsigned int n) const;
897 
898  bool IsLockedCoin(uint256 hash, unsigned int n) const;
899  void LockCoin(const COutPoint& output);
900  void UnlockCoin(const COutPoint& output);
901  void UnlockAllCoins();
902  void ListLockedCoins(std::vector<COutPoint>& vOutpts) const;
903 
904  /*
905  * Rescan abort properties
906  */
907  void AbortRescan() { fAbortRescan = true; }
908  bool IsAbortingRescan() { return fAbortRescan; }
909  bool IsScanning() { return fScanningWallet; }
910 
915  CPubKey GenerateNewKey(CWalletDB& walletdb, bool internal = false);
917  bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override;
918  bool AddKeyPubKeyWithDB(CWalletDB &walletdb,const CKey& key, const CPubKey &pubkey);
920  bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); }
922  bool LoadKeyMetadata(const CTxDestination& pubKey, const CKeyMetadata &metadata);
923 
924  bool LoadMinVersion(int nVersion) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
925  void UpdateTimeFirstKey(int64_t nCreateTime);
926 
928  bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) override;
930  bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
931  bool AddCScript(const CScript& redeemScript) override;
932  bool LoadCScript(const CScript& redeemScript);
933 
935  bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
937  bool EraseDestData(const CTxDestination &dest, const std::string &key);
939  bool LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
941  bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const;
943  std::vector<std::string> GetDestValues(const std::string& prefix) const;
944 
946  bool AddWatchOnly(const CScript& dest, int64_t nCreateTime);
947  bool RemoveWatchOnly(const CScript &dest) override;
949  bool LoadWatchOnly(const CScript &dest);
950 
952  int64_t nRelockTime;
953 
954  bool Unlock(const SecureString& strWalletPassphrase);
955  bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
956  bool EncryptWallet(const SecureString& strWalletPassphrase);
957 
958  void GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) const;
959  unsigned int ComputeTimeSmart(const CWalletTx& wtx) const;
960 
965  int64_t IncOrderPosNext(CWalletDB *pwalletdb = nullptr);
966  DBErrors ReorderTransactions();
967  bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "");
968  bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false);
969 
970  void MarkDirty();
971  bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
972  bool LoadToWallet(const CWalletTx& wtxIn);
973  void TransactionAddedToMempool(const CTransactionRef& tx) override;
974  void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) override;
975  void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) override;
976  bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate);
977  int64_t RescanFromTime(int64_t startTime, bool update);
978  CBlockIndex* ScanForWalletTransactions(CBlockIndex* pindexStart, CBlockIndex* pindexStop, bool fUpdate = false);
979  void ReacceptWalletTransactions();
980  void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) override;
981  // ResendWalletTransactionsBefore may only be called if fBroadcastTransactions!
982  std::vector<uint256> ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman);
983  CAmount GetBalance() const;
984  CAmount GetUnconfirmedBalance() const;
985  CAmount GetImmatureBalance() const;
986  CAmount GetWatchOnlyBalance() const;
987  CAmount GetUnconfirmedWatchOnlyBalance() const;
988  CAmount GetImmatureWatchOnlyBalance() const;
989  CAmount GetLegacyBalance(const isminefilter& filter, int minDepth, const std::string* account) const;
990  CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const;
991 
996  bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, std::string& strFailReason, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl);
997  bool SignTransaction(CMutableTransaction& tx);
998 
1000  bool CreateTransactionWithAssets(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
1001  std::string& strFailReason, const CCoinControl& coin_control, const std::vector<CNewAsset> assets, const CTxDestination destination, const AssetType& assetType, bool sign = true);
1002 
1003  bool CreateTransactionWithTransferAsset(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
1004  std::string& strFailReason, const CCoinControl& coin_control, bool sign = true);
1005 
1006  bool CreateTransactionWithReissueAsset(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
1007  std::string& strFailReason, const CCoinControl& coin_control, const CReissueAsset& reissueAsset, const CTxDestination destination, bool sign = true);
1008 
1009  bool CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
1010  std::string& strFailReason, const CCoinControl& coin_control, bool sign = true);
1011 
1017  bool CreateTransactionAll(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
1018  std::string& strFailReason, const CCoinControl& coin_control, bool fNewAsset, const CNewAsset& asset, const CTxDestination dest, bool fTransferAsset, bool fReissueAsset, const CReissueAsset& reissueAsset, const AssetType& assetType, bool sign = true);
1019 
1020  bool CreateTransactionAll(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet,
1021  int& nChangePosInOut, std::string& strFailReason, const CCoinControl& coin_control, bool fNewAsset, const std::vector<CNewAsset> assets, const CTxDestination destination, bool fTransferAsset, bool fReissueAsset, const CReissueAsset& reissueAsset, const AssetType& assetType, bool sign);
1022 
1023  bool CreateNewChangeAddress(CReserveKey& reservekey, CKeyID& keyID, std::string& strFailReason);
1024 
1027  bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state);
1028 
1029  void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
1030  bool AddAccountingEntry(const CAccountingEntry&);
1031  bool AddAccountingEntry(const CAccountingEntry&, CWalletDB *pwalletdb);
1032  template <typename ContainerType>
1033  bool DummySignTx(CMutableTransaction &txNew, const ContainerType &coins) const;
1034 
1038 
1039  bool NewKeyPool();
1040  size_t KeypoolCountExternalKeys();
1041  bool TopUpKeyPool(unsigned int kpSize = 0);
1042  void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fRequestedInternal);
1043  void KeepKey(int64_t nIndex);
1044  void ReturnKey(int64_t nIndex, bool fInternal, const CPubKey& pubkey);
1045  bool GetKeyFromPool(CPubKey &key, bool internal = false);
1046  int64_t GetOldestKeyPoolTime();
1050  void MarkReserveKeysAsUsed(int64_t keypool_id);
1051  const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
1052 
1053  std::set< std::set<CTxDestination> > GetAddressGroupings();
1054  std::map<CTxDestination, CAmount> GetAddressBalances();
1055 
1056  std::set<CTxDestination> GetAccountAddresses(const std::string& strAccount) const;
1057 
1058  isminetype IsMine(const CTxIn& txin) const;
1063  CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
1064  CAmount GetDebit(const CTxIn& txin, const isminefilter& filter, CAssetOutputEntry& assetData) const;
1065  isminetype IsMine(const CTxOut& txout) const;
1066  CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
1067  bool IsChange(const CTxOut& txout) const;
1068  CAmount GetChange(const CTxOut& txout) const;
1069  bool IsMine(const CTransaction& tx) const;
1071  bool IsFromMe(const CTransaction& tx) const;
1072  CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
1074  bool IsAllFromMe(const CTransaction& tx, const isminefilter& filter) const;
1075  CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
1076  CAmount GetChange(const CTransaction& tx) const;
1077  void SetBestChain(const CBlockLocator& loc) override;
1078 
1079  DBErrors LoadWallet(bool& fFirstRunRet);
1080  DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);
1081  DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut);
1082 
1083  bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose);
1084 
1085  bool DelAddressBook(const CTxDestination& address);
1086 
1087  const std::string& GetAccountName(const CScript& scriptPubKey) const;
1088 
1089  void Inventory(const uint256 &hash) override
1090  {
1091  {
1092  LOCK(cs_wallet);
1093  std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
1094  if (mi != mapRequestCount.end())
1095  (*mi).second++;
1096  }
1097  }
1098 
1099  void GetScriptForMining(std::shared_ptr<CReserveScript> &script); // override;
1100 
1101  unsigned int GetKeyPoolSize()
1102  {
1103  AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool
1104  return setInternalKeyPool.size() + setExternalKeyPool.size();
1105  }
1106 
1108  bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = nullptr, bool fExplicit = false);
1109 
1111  bool SetMaxVersion(int nVersion);
1112 
1114  int GetVersion() { LOCK(cs_wallet); return nWalletVersion; }
1115 
1117  std::set<uint256> GetConflicts(const uint256& txid) const;
1118 
1120  bool HasWalletSpend(const uint256& txid) const;
1121 
1123  void Flush(bool shutdown=false);
1124 
1129  boost::signals2::signal<void (CWallet *wallet, const CTxDestination
1130  &address, const std::string &label, bool isMine,
1131  const std::string &purpose,
1133 
1138  boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx,
1140 
1142  boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
1143 
1145  boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
1146 
1148  bool GetBroadcastTransactions() const { return fBroadcastTransactions; }
1150  void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
1151 
1153  bool TransactionCanBeAbandoned(const uint256& hashTx) const;
1154 
1155  /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
1156  bool AbandonTransaction(const uint256& hashTx);
1157 
1159  bool MarkReplaced(const uint256& originalHash, const uint256& newHash);
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 
1168  void postInitProcess(CScheduler& scheduler);
1169 
1170  bool BackupWallet(const std::string& strDest);
1171 
1172  /* Set the HD chain model (chain child index counters) */
1173  bool SetHDChain(const CHDChain& chain, bool memonly);
1174  const CHDChain& GetHDChain() const { return hdChain; }
1175 
1176  /* Returns true if HD is enabled */
1177  bool IsHDEnabled() const;
1178 
1179  /* Generates a new HD seed (will not be activated) */
1180  CPubKey GenerateNewSeed();
1181 
1182  /* Derives a new HD seed (will not be activated) */
1183  CPubKey DeriveNewSeed(const CKey& key);
1184 
1185  /* Set the current HD seed (will reset the chain child index counters)
1186  Sets the seed's version based on the current wallet version (so the
1187  caller must ensure the current wallet version is correct before calling
1188  this function). */
1189  bool SetHDSeed(const CPubKey& key);
1190 };
1191 
1193 class CReserveKey final : public CReserveScript
1194 {
1195 protected:
1197  int64_t nIndex;
1200 public:
1201  explicit CReserveKey(CWallet* pwalletIn)
1202  {
1203  nIndex = -1;
1204  pwallet = pwalletIn;
1205  fInternal = false;
1206  }
1207 
1208  CReserveKey() = default;
1209  CReserveKey(const CReserveKey&) = delete;
1210  CReserveKey& operator=(const CReserveKey&) = delete;
1211 
1213  {
1214  ReturnKey();
1215  }
1216 
1217  void ReturnKey();
1218  bool GetReservedKey(CPubKey &pubkey, bool internal = false);
1219  void KeepKey();
1220  void KeepScript() override { KeepKey(); }
1221 };
1222 
1223 
1229 {
1230 public:
1232 
1234  {
1235  SetNull();
1236  }
1237 
1238  void SetNull()
1239  {
1240  vchPubKey = CPubKey();
1241  }
1242 
1244 
1245  template <typename Stream, typename Operation>
1246  inline void SerializationOp(Stream& s, Operation ser_action) {
1247  int nVersion = s.GetVersion();
1248  if (!(s.GetType() & SER_GETHASH))
1249  READWRITE(nVersion);
1250  READWRITE(vchPubKey);
1251  }
1252 };
1253 
1254 // Helper for producing a bunch of max-sized low-S signatures (eg 72 bytes)
1255 // ContainerType is meant to hold pair<CWalletTx *, int>, and be iterable
1256 // so that each entry corresponds to each vIn, in order.
1257 // Returns true if all inputs could be signed normally, false if any were padded out for sizing purposes.
1258 template <typename ContainerType>
1259 bool CWallet::DummySignTx(CMutableTransaction &txNew, const ContainerType &coins) const
1260 {
1261  bool allSigned = true;
1262 
1263  // pad past max expected sig length (256)
1264  const std::string zeros = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
1265  const unsigned char* cstrZeros = (unsigned char*)zeros.c_str();
1266 
1267  // Fill in dummy signatures for fee calculation.
1268  int nIn = 0;
1269  for (const auto& coin : coins)
1270  {
1271  const CScript& scriptPubKey = coin.txout.scriptPubKey;
1272  SignatureData sigdata;
1273 
1274  if (!ProduceSignature(DummySignatureCreator(this), scriptPubKey, sigdata))
1275  {
1276  // just add dummy 256 bytes as sigdata if this fails (can't necessarily sign for all inputs)
1277  CScript dummyScript = CScript(cstrZeros, cstrZeros + 256);
1278  SignatureData dummyData = SignatureData(dummyScript);
1279  UpdateTransaction(txNew, nIn, dummyData);
1280  allSigned = false;
1281  } else {
1282  UpdateTransaction(txNew, nIn, sigdata);
1283  }
1284 
1285  nIn++;
1286  }
1287  return allSigned;
1288 }
1289 
1290 #endif // RAVEN_WALLET_WALLET_H
int64_t nTimeCreated
Definition: wallet.h:564
bool fChangeCached
Definition: wallet.h:348
const CWallet * pwallet
Definition: wallet.h:288
std::atomic< bool > fScanningWallet
Definition: wallet.h:678
void UpdateTransaction(CMutableTransaction &tx, unsigned int nIn, const SignatureData &data)
Definition: sign.cpp:236
CWallet * pwallet
Definition: wallet.h:1196
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
bool CanSupportFeature(enum WalletFeature wf) const
check whether we are allowed to upgrade (or already support) to the named feature ...
Definition: wallet.h:836
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:621
int64_t nNextResend
Definition: wallet.h:697
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:403
Account information.
Definition: wallet.h:1228
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:575
int i
Definition: wallet.h:532
int64_t nOrderPos
position in ordered transaction list
Definition: wallet.h:599
CAmount nImmatureWatchCreditCached
Definition: wallet.h:355
bool DummySignTx(CMutableTransaction &txNew, const ContainerType &coins) const
Definition: wallet.h:1259
void BindWallet(CWallet *pwalletIn)
Definition: wallet.h:457
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:89
bool fSolvable
Whether we know how to spend this output, ignoring the lack of keys.
Definition: wallet.h:539
CPrivKey vchPrivKey
Definition: wallet.h:563
int64_t nIndex
Definition: wallet.h:1197
const char * DEFAULT_WALLET_DAT
Definition: wallet.cpp:51
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:132
#define READWRITE(obj)
Definition: serialize.h:163
CAmount nCreditCached
Definition: wallet.h:350
uint64_t nAccountingEntryNumber
Definition: wallet.h:826
const std::map< CKeyID, int64_t > & GetAllReserveKeys() const
Definition: wallet.h:1051
char fFromMe
From me flag is set to 1 for transactions that were created by the wallet on this raven node...
Definition: wallet.h:335
CAmount nChangeCached
Definition: wallet.h:357
COutPoint outpoint
Definition: wallet.h:512
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:829
CCriticalSection cs_wallet
Definition: wallet.h:751
#define strprintf
Definition: tinyformat.h:1054
std::unique_ptr< CWalletDBWrapper > dbw
Definition: wallet.h:744
const uint256 & GetHash() const
Definition: wallet.h:277
bool IsFromMe(const isminefilter &filter) const
Definition: wallet.h:478
std::vector< char > _ssExtra
Definition: wallet.h:665
int nIndex
Definition: wallet.h:219
bool fImmatureCreditCached
Definition: wallet.h:342
std::string strFromAccount
Definition: wallet.h:336
WalletFeature
(client) version numbers for particular wallet features
Definition: wallet.h:89
FeeEstimateMode
Definition: fees.h:98
TxItems wtxOrdered
Definition: wallet.h:823
const char * prefix
Definition: rest.cpp:568
bool fInternal
Definition: wallet.h:1199
txnouttype type
Definition: wallet.h:193
CWalletDB * pwalletdbEncryption
Definition: wallet.h:689
uint256 hashBlock
Definition: wallet.h:212
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:706
int64_t expireTime
Definition: wallet.h:198
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:57
int64_t nOrderPos
position in ordered transaction list
Definition: wallet.h:337
CWallet * CWalletRef
Definition: wallet.h:35
std::set< int64_t > setInternalKeyPool
Definition: wallet.h:726
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey, SigVersion sigversion)
Definition: ismine.cpp:32
CMerkleTx(CTransactionRef arg)
Definition: wallet.h:227
uint8_t isminefilter
used for bitflags of isminetype
Definition: ismine.h:30
int64_t nTimeFirstKey
Definition: wallet.h:731
mapValue_t mapValue
Definition: wallet.h:598
std::map< CKeyID, int64_t > m_pool_key_to_index
Definition: wallet.h:729
void SetNull()
Definition: wallet.h:1238
CPubKey vchPubKey
Definition: wallet.h:1198
void MarkDirty()
make sure balances are recalculated
Definition: wallet.h:444
bool fSubtractFeeFromAmount
Definition: wallet.h:159
unsigned int GetKeyPoolSize()
Definition: wallet.h:1101
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:778
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
CFeeRate payTxFee
Settings.
std::string strComment
Definition: wallet.h:566
std::string name
Definition: wallet.h:146
std::map< CTxDestination, CKeyMetadata > mapKeyMetadata
Definition: wallet.h:776
~CReserveKey()
Definition: wallet.h:1212
std::atomic< bool > fAbortRescan
Definition: wallet.h:677
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:50
CAmount nWatchDebitCached
Definition: wallet.h:353
Keystore which keeps the private keys encrypted.
Definition: crypter.h:116
int64_t m_max_keypool_index
Definition: wallet.h:728
bool fSpendable
Whether we have the private keys to spend this output.
Definition: wallet.h:536
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:436
int64_t nTimeExpires
Definition: wallet.h:565
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:179
bool fAvailableCreditCached
Definition: wallet.h:343
bool IsNull() const
Definition: uint256.h:33
std::string purpose
Definition: wallet.h:147
void Init()
Definition: wallet.h:237
CHDChain hdChain
Definition: wallet.h:721
Coin Control Features.
Definition: coincontrol.h:17
CAccount()
Definition: wallet.h:1233
unsigned int nTxConfirmTarget
Definition: wallet.cpp:47
RVN START.
Definition: wallet.h:191
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: wallet.h:316
bool fDebitCached
Definition: wallet.h:340
std::list< CAccountingEntry > laccentries
Definition: wallet.h:819
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
std::multimap< int64_t, TxPair > TxItems
Definition: wallet.h:822
bool fAvailableWatchCreditCached
Definition: wallet.h:347
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:33
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:1139
#define AssertLockHeld(cs)
Definition: sync.h:86
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:1150
std::string strComment
Definition: wallet.h:597
ADD_SERIALIZE_METHODS
Definition: wallet.h:400
An instance of this class represents one database.
Definition: db.h:94
int64_t nTime
Definition: wallet.h:110
CScript scriptPubKey
Definition: wallet.h:157
unsigned int nMasterKeyMaxID
Definition: wallet.h:780
static CFeeRate m_discard_rate
Definition: wallet.h:1037
ADD_SERIALIZE_METHODS
Definition: wallet.h:1243
int GetDepthInMainChain() const
Definition: wallet.h:268
bool fWalletRbf
Definition: wallet.cpp:49
int nDepth
Definition: wallet.h:533
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced, bool bypass_limits, const CAmount nAbsurdFee)
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions repla...
uint64_t nEntryNo
Definition: wallet.h:600
std::string GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:763
ChangeType
General change type (added, updated, removed).
Definition: ui_interface.h:20
CTransactionRef tx
Definition: wallet.h:211
isminetype
IsMine() return codes.
Definition: ismine.h:18
An input of a transaction.
Definition: transaction.h:67
CInputCoin(const CWalletTx *walletTx, unsigned int i)
Definition: wallet.h:501
#define LOCK(cs)
Definition: sync.h:176
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:139
int GetVersion()
get the current wallet format (the oldest client version guaranteed to understand this wallet) ...
Definition: wallet.h:1114
CKeyPool()
Definition: wallet.cpp:4736
std::string assetName
Definition: wallet.h:194
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:251
An encapsulated public key.
Definition: pubkey.h:40
bool fSafe
Whether this output is considered safe to spend.
Definition: wallet.h:546
std::set< COutPoint > setLockedCoins
Definition: wallet.h:831
TxSpends mapTxSpends
Definition: wallet.h:707
CAmount amount
Definition: wallet.h:186
void KeepScript() override
Definition: wallet.h:1220
bool IsCoinBase() const
Definition: wallet.h:278
std::map< std::string, std::string > StringMap
Definition: wallet.h:151
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:920
bool bSpendZeroConfChange
Definition: wallet.cpp:48
Definition: net.h:120
An output of a transaction.
Definition: transaction.h:137
ADD_SERIALIZE_METHODS
Definition: wallet.h:248
void SetNull()
Definition: wallet.h:800
std::map< uint256, int > mapRequestCount
Definition: wallet.h:827
std::set< int64_t > setExternalKeyPool
Definition: wallet.h:727
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
bool fWatchCreditCached
Definition: wallet.h:345
ADD_SERIALIZE_METHODS
Definition: wallet.h:117
void Inventory(const uint256 &hash) override
Notifies listeners about an inventory item being seen on the network.
Definition: wallet.h:1089
unsigned int fTimeReceivedIsTxTime
Definition: wallet.h:318
bool LoadMinVersion(int nVersion)
Definition: wallet.h:924
Access to the wallet database.
Definition: walletdb.h:142
CWalletDBWrapper & GetDBHandle()
Get database handle used by this wallet.
Definition: wallet.h:756
bool fCreditCached
Definition: wallet.h:341
int nWalletMaxVersion
the maximum wallet format version: memory-only variable that specifies to what version this wallet ma...
Definition: wallet.h:695
CAmount nAmount
Definition: wallet.h:158
std::vector< CWalletRef > vpwallets
Definition: wallet.cpp:44
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:285
bool operator<(const CInputCoin &rhs) const
Definition: wallet.h:515
AssetType
Definition: assettypes.h:21
bool IsInMainChain() const
Definition: wallet.h:269
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:1148
bool operator!=(const CInputCoin &rhs) const
Definition: wallet.h:519
bool fBroadcastTransactions
Definition: wallet.h:699
CPubKey vchPubKey
Definition: wallet.h:1231
txnouttype
Definition: standard.h:57
RVN END.
Definition: validation.h:30
256-bit opaque blob.
Definition: uint256.h:123
void Init(const CWallet *pwalletIn)
Definition: wallet.h:369
CPubKey vchPubKey
Definition: wallet.h:111
CAmount nWatchCreditCached
Definition: wallet.h:354
CWalletTx(const CWallet *pwalletIn, CTransactionRef arg)
Definition: wallet.h:364
static std::atomic< bool > fFlushScheduled
Definition: wallet.h:676
void setAbandoned()
Definition: wallet.h:275
int vout
Definition: wallet.h:199
CAmount nAvailableCreditCached
Definition: wallet.h:352
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:416
CWallet()
Definition: wallet.h:783
iterator insert(iterator it, const char &x=char())
Definition: streams.h:245
std::string message
Definition: wallet.h:197
ADD_SERIALIZE_METHODS
Definition: wallet.h:618
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:1132
static CFeeRate fallbackFee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:1036
MasterKeyMap mapMasterKeys
Definition: wallet.h:779
int vout
Definition: wallet.h:187
A key allocated from the key pool.
Definition: wallet.h:1193
CWalletTx()
Definition: wallet.h:359
Address book data.
Definition: wallet.h:143
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:172
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:396
StringMap destdata
Definition: wallet.h:152
int64_t nOrderPosNext
Definition: wallet.h:825
CTxDestination destination
Definition: wallet.h:185
unsigned int nTimeSmart
Stable timestamp that never changes, and reflects the order a transaction was added to the wallet...
Definition: wallet.h:329
void SetNull()
Definition: wallet.h:607
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:1246
ADD_SERIALIZE_METHODS
Definition: wallet.h:572
Private key that includes an expiration date in case it never gets used.
Definition: wallet.h:560
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:30
Internal transfers.
Definition: wallet.h:590
const CWalletTx * tx
Definition: wallet.h:531
#define LIMITED_STRING(obj, n)
Definition: serialize.h:369
static CFeeRate minTxFee
Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) Override with ...
Definition: wallet.h:1035
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:692
bool IsScanning()
Definition: wallet.h:909
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:673
Fee rate in satoshis 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:548
CAccountingEntry()
Definition: wallet.h:602
CReserveKey(CWallet *pwalletIn)
Definition: wallet.h:1201
void AbortRescan()
Definition: wallet.h:907
CWallet(std::unique_ptr< CWalletDBWrapper > dbw_in)
Definition: wallet.h:789
Definition: wallet.h:183
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:818
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:1142
void SerializationOp(Stream &s, Operation ser_action)
Definition: wallet.h:120
A mutable version of CTransaction.
Definition: transaction.h:389
CAmount nAvailableWatchCreditCached
Definition: wallet.h:356
bool IsAbortingRescan()
Definition: wallet.h:908
int64_t nLastResend
Definition: wallet.h:698
CMerkleTx()
Definition: wallet.h:221
unsigned int nTimeReceived
time received by this node
Definition: wallet.h:319
bool fWatchDebitCached
Definition: wallet.h:344
An encapsulated private key.
Definition: key.h:36
CAmount nAmount
Definition: wallet.h:196
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:270
bool hashUnset() const
Definition: wallet.h:273
bool fImmatureWatchCreditCached
Definition: wallet.h:346
const CHDChain & GetHDChain() const
Definition: wallet.h:1174
CTxDestination destination
Definition: wallet.h:195
std::pair< CWalletTx *, CAccountingEntry * > TxPair
Definition: wallet.h:821
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:1145
std::string strOtherAccount
Definition: wallet.h:596
bool fInternal
Definition: wallet.h:112
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:952
CAmount nCreditDebit
Definition: wallet.h:594
int64_t nTime
Definition: wallet.h:595
CTxOut txout
Definition: wallet.h:513
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
Definition: sync.h:92
CAmount nImmatureCreditCached
Definition: wallet.h:351
RVN END.
Definition: wallet.h:204
std::map< std::string, std::string > mapValue_t
Definition: wallet.h:162
A signature creator that just produces 72-byte empty signatures.
Definition: sign.h:56
~CWallet()
Definition: wallet.h:794
A key pool entry.
Definition: wallet.h:107
bool operator==(const CInputCoin &rhs) const
Definition: wallet.h:523
std::vector< std::pair< std::string, std::string > > vOrderForm
Definition: wallet.h:317
bool isAbandoned() const
Definition: wallet.h:274
CAmount nDebitCached
Definition: wallet.h:349
std::string strAccount
Definition: wallet.h:593