1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_WALLET_H
6 #define BITCOIN_WALLET_H
17 #include "ui_interface.h"
21 extern bool fWalletUnlockMintOnly;
22 extern bool fConfChange;
23 class CAccountingEntry;
29 /** (client) version numbers for particular wallet features */
32 FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output)
34 FEATURE_WALLETCRYPT = 40000, // wallet encryption
35 FEATURE_COMPRPUBKEY = 60000, // compressed public keys
36 FEATURE_LATEST = 60000
39 /** A key pool entry */
51 CKeyPool(const CPubKey& vchPubKeyIn)
54 vchPubKey = vchPubKeyIn;
59 if (!(nType & SER_GETHASH))
66 /** A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,
67 * and provides the ability to create new transactions.
69 class CWallet : public CCryptoKeyStore
72 bool SelectCoinsSimple(int64 nTargetValue, unsigned int nSpendTime, int nMinConf, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const;
73 bool SelectCoins(int64 nTargetValue, unsigned int nSpendTime, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl *coinControl=NULL) const;
75 CWalletDB *pwalletdbEncryption;
77 // the current wallet version: clients below this version are not able to load the wallet
80 // the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded
81 int nWalletMaxVersion;
84 mutable CCriticalSection cs_wallet;
87 std::string strWalletFile;
89 std::set<int64> setKeyPool;
90 std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
93 typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
94 MasterKeyMap mapMasterKeys;
95 unsigned int nMasterKeyMaxID;
99 nWalletVersion = FEATURE_BASE;
100 nWalletMaxVersion = FEATURE_BASE;
103 pwalletdbEncryption = NULL;
106 CWallet(std::string strWalletFileIn)
108 nWalletVersion = FEATURE_BASE;
109 nWalletMaxVersion = FEATURE_BASE;
110 strWalletFile = strWalletFileIn;
113 pwalletdbEncryption = NULL;
117 std::map<uint256, CWalletTx> mapWallet;
119 std::map<uint256, int> mapRequestCount;
121 std::map<CTxDestination, std::string> mapAddressBook;
123 CPubKey vchDefaultKey;
126 // check whether we are allowed to upgrade (or already support) to the named feature
127 bool CanSupportFeature(enum WalletFeature wf) { return nWalletMaxVersion >= wf; }
129 void AvailableCoinsMinConf(std::vector<COutput>& vCoins, int nConf) const;
130 void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL) const;
131 bool SelectCoinsMinConf(int64 nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const;
132 // keystore implementation
133 // Generate a new key
134 CPubKey GenerateNewKey();
135 // Adds a key to the store, and saves it to disk.
136 bool AddKey(const CKey& key);
137 // Adds a key to the store, without saving it to disk (used by LoadWallet)
138 bool LoadKey(const CKey& key) { return CCryptoKeyStore::AddKey(key); }
139 // Load metadata (used by LoadWallet)
140 bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata);
142 bool LoadMinVersion(int nVersion) { nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
144 // Adds an encrypted key to the store, and saves it to disk.
145 bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
146 // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
147 bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) { SetMinVersion(FEATURE_WALLETCRYPT); return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); }
148 bool AddCScript(const CScript& redeemScript);
149 bool LoadCScript(const CScript& redeemScript) { return CCryptoKeyStore::AddCScript(redeemScript); }
151 // Adds a watch-only address to the store, and saves it to disk.
152 bool AddWatchOnly(const CScript &dest);
153 // Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
154 bool LoadWatchOnly(const CScript &dest);
156 bool Unlock(const SecureString& strWalletPassphrase);
157 bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
158 bool EncryptWallet(const SecureString& strWalletPassphrase);
160 void GetKeyBirthTimes(std::map<CKeyID, int64> &mapKeyBirth) const;
163 /** Increment the next transaction order id
164 @return next transaction order id
166 int64 IncOrderPosNext(CWalletDB *pwalletdb = NULL);
168 typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
169 typedef std::multimap<int64, TxPair > TxItems;
171 /** Get the wallet's activity log
172 @return multimap of ordered transactions and accounting entries
173 @warning Returned pointers are *only* valid within the scope of passed acentries
175 TxItems OrderedTxItems(std::list<CAccountingEntry>& acentries, std::string strAccount = "");
178 bool AddToWallet(const CWalletTx& wtxIn);
179 bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false, bool fFindBlock = false);
180 bool EraseFromWallet(uint256 hash);
181 void WalletUpdateSpent(const CTransaction& prevout, bool fBlock = false);
182 int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
183 int ScanForWalletTransaction(const uint256& hashTx);
184 void ReacceptWalletTransactions();
185 void ResendWalletTransactions();
186 int64 GetBalance() const;
187 int64 GetBalanceWatchOnly() const;
188 int64 GetUnconfirmedBalance() const;
189 int64 GetImmatureBalance() const;
190 int64 GetStake() const;
191 int64 GetNewMint() const;
192 bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL);
193 bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL);
194 bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
196 bool GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight);
197 void GetStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight);
198 bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew, CKey& key);
200 std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
201 std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
204 bool TopUpKeyPool(unsigned int nSize = 0);
205 int64 AddReserveKey(const CKeyPool& keypool);
206 void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
207 void KeepKey(int64 nIndex);
208 void ReturnKey(int64 nIndex);
209 bool GetKeyFromPool(CPubKey &key, bool fAllowReuse=true);
210 int64 GetOldestKeyPoolTime();
211 void GetAllReserveKeys(std::set<CKeyID>& setAddress) const;
213 std::set< std::set<CTxDestination> > GetAddressGroupings();
214 std::map<CTxDestination, int64> GetAddressBalances();
216 isminetype IsMine(const CTxIn& txin) const;
217 int64 GetDebit(const CTxIn& txin) const;
218 isminetype IsMine(const CTxOut& txout) const
220 return ::IsMine(*this, txout.scriptPubKey);
222 int64 GetCredit(const CTxOut& txout) const
224 if (!MoneyRange(txout.nValue))
225 throw std::runtime_error("CWallet::GetCredit() : value out of range");
226 isminetype ismine = IsMine(txout);
227 return (ismine != MINE_NO ? txout.nValue : 0);
229 int64 GetCreditWatchOnly(const CTxOut& txout) const
231 if (!MoneyRange(txout.nValue))
232 throw std::runtime_error("CWallet::GetCreditWatchOnly() : value out of range");
233 isminetype ismine = IsMine(txout);
234 if (ismine != MINE_WATCH_ONLY)
236 return (ismine != MINE_NO ? txout.nValue : 0);
238 bool IsChange(const CTxOut& txout) const;
239 int64 GetChange(const CTxOut& txout) const
241 if (!MoneyRange(txout.nValue))
242 throw std::runtime_error("CWallet::GetChange() : value out of range");
243 return (IsChange(txout) ? txout.nValue : 0);
245 bool IsMine(const CTransaction& tx) const
247 BOOST_FOREACH(const CTxOut& txout, tx.vout)
248 if (IsMine(txout) && txout.nValue >= nMinimumInputValue)
252 bool IsFromMe(const CTransaction& tx) const
254 return (GetDebit(tx) > 0);
256 int64 GetDebit(const CTransaction& tx) const
259 BOOST_FOREACH(const CTxIn& txin, tx.vin)
261 nDebit += GetDebit(txin);
262 if (!MoneyRange(nDebit))
263 throw std::runtime_error("CWallet::GetDebit() : value out of range");
267 int64 GetCredit(const CTransaction& tx) const
270 BOOST_FOREACH(const CTxOut& txout, tx.vout)
272 nCredit += GetCredit(txout);
273 if (!MoneyRange(nCredit))
274 throw std::runtime_error("CWallet::GetCredit() : value out of range");
278 int64 GetCreditWatchOnly(const CTransaction& tx) const
281 BOOST_FOREACH(const CTxOut& txout, tx.vout)
283 nCredit += GetCreditWatchOnly(txout);
284 if (!MoneyRange(nCredit))
285 throw std::runtime_error("CWallet::GetCredit() : value out of range");
289 int64 GetChange(const CTransaction& tx) const
292 BOOST_FOREACH(const CTxOut& txout, tx.vout)
294 nChange += GetChange(txout);
295 if (!MoneyRange(nChange))
296 throw std::runtime_error("CWallet::GetChange() : value out of range");
300 void SetBestChain(const CBlockLocator& loc);
302 DBErrors LoadWallet(bool& fFirstRunRet);
304 bool SetAddressBookName(const CTxDestination& address, const std::string& strName);
306 bool DelAddressBookName(const CTxDestination& address);
308 void UpdatedTransaction(const uint256 &hashTx);
310 void PrintWallet(const CBlock& block);
312 void Inventory(const uint256 &hash)
316 std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
317 if (mi != mapRequestCount.end())
322 unsigned int GetKeyPoolSize()
324 return setKeyPool.size();
327 bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx);
329 bool SetDefaultKey(const CPubKey &vchPubKey);
331 // signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower
332 bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = NULL, bool fExplicit = false);
334 // change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format)
335 bool SetMaxVersion(int nVersion);
337 // get the current wallet format (the oldest client version guaranteed to understand this wallet)
338 int GetVersion() { return nWalletVersion; }
340 void FixSpentCoins(int& nMismatchSpent, int64& nBalanceInQuestion, bool fCheckOnly = false);
341 void DisableTransaction(const CTransaction &tx);
343 /** Address book entry changed.
344 * @note called with lock cs_wallet held.
346 boost::signals2::signal<void (CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, ChangeType status)> NotifyAddressBookChanged;
348 /** Wallet transaction added, removed or updated.
349 * @note called with lock cs_wallet held.
351 boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged;
354 /** A key allocated from the key pool. */
362 CReserveKey(CWallet* pwalletIn)
375 CPubKey GetReservedKey();
380 typedef std::map<std::string, std::string> mapValue_t;
383 static void ReadOrderPos(int64& nOrderPos, mapValue_t& mapValue)
385 if (!mapValue.count("n"))
387 nOrderPos = -1; // TODO: calculate elsewhere
390 nOrderPos = atoi64(mapValue["n"].c_str());
394 static void WriteOrderPos(const int64& nOrderPos, mapValue_t& mapValue)
398 mapValue["n"] = i64tostr(nOrderPos);
402 /** A transaction with a bunch of additional info that only the owner cares about.
403 * It includes any unrecorded transactions needed to link it back to the block chain.
405 class CWalletTx : public CMerkleTx
408 const CWallet* pwallet;
411 std::vector<CMerkleTx> vtxPrev;
413 std::vector<std::pair<std::string, std::string> > vOrderForm;
414 unsigned int fTimeReceivedIsTxTime;
415 unsigned int nTimeReceived; // time received by this node
416 unsigned int nTimeSmart;
418 std::string strFromAccount;
419 std::vector<char> vfSpent; // which outputs are already spent
420 int64 nOrderPos; // position in ordered transaction list
423 mutable bool fDebitCached;
424 mutable bool fCreditCached;
425 mutable bool fWatchOnlyCreditCached;
426 mutable bool fAvailableCreditCached;
427 mutable bool fAvailableWatchOnlyCreditCached;
428 mutable bool fChangeCached;
429 mutable int64 nDebitCached;
430 mutable int64 nCreditCached;
431 mutable int64 nWatchOnlyCreditCached;
432 mutable int64 nAvailableCreditCached;
433 mutable int64 nAvailableWatchOnlyCreditCached;
434 mutable int64 nChangeCached;
441 CWalletTx(const CWallet* pwalletIn)
446 CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn) : CMerkleTx(txIn)
451 CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn) : CMerkleTx(txIn)
456 void Init(const CWallet* pwalletIn)
462 fTimeReceivedIsTxTime = false;
466 strFromAccount.clear();
468 fDebitCached = false;
469 fCreditCached = false;
470 fWatchOnlyCreditCached = false;
471 fAvailableCreditCached = false;
472 fAvailableWatchOnlyCreditCached = false;
473 fChangeCached = false;
476 nWatchOnlyCreditCached = 0;
477 nAvailableCreditCached = 0;
478 nAvailableWatchOnlyCreditCached = 0;
485 CWalletTx* pthis = const_cast<CWalletTx*>(this);
492 pthis->mapValue["fromaccount"] = pthis->strFromAccount;
495 BOOST_FOREACH(char f, vfSpent)
497 str += (f ? '1' : '0');
501 pthis->mapValue["spent"] = str;
503 WriteOrderPos(pthis->nOrderPos, pthis->mapValue);
506 pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart);
509 nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action);
512 READWRITE(vOrderForm);
513 READWRITE(fTimeReceivedIsTxTime);
514 READWRITE(nTimeReceived);
520 pthis->strFromAccount = pthis->mapValue["fromaccount"];
522 if (mapValue.count("spent"))
523 BOOST_FOREACH(char c, pthis->mapValue["spent"])
524 pthis->vfSpent.push_back(c != '0');
526 pthis->vfSpent.assign(vout.size(), fSpent);
528 ReadOrderPos(pthis->nOrderPos, pthis->mapValue);
530 pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0;
533 pthis->mapValue.erase("fromaccount");
534 pthis->mapValue.erase("version");
535 pthis->mapValue.erase("spent");
536 pthis->mapValue.erase("n");
537 pthis->mapValue.erase("timesmart");
540 // marks certain txout's as spent
541 // returns true if any update took place
542 bool UpdateSpent(const std::vector<char>& vfNewSpent)
544 bool fReturn = false;
545 for (unsigned int i = 0; i < vfNewSpent.size(); i++)
547 if (i == vfSpent.size())
550 if (vfNewSpent[i] && !vfSpent[i])
554 fAvailableCreditCached = fAvailableWatchOnlyCreditCached = false;
560 // make sure balances are recalculated
563 fCreditCached = false;
564 fAvailableCreditCached = fAvailableWatchOnlyCreditCached = false;
565 fDebitCached = false;
566 fChangeCached = false;
569 void BindWallet(CWallet *pwalletIn)
575 void MarkSpent(unsigned int nOut)
577 if (nOut >= vout.size())
578 throw std::runtime_error("CWalletTx::MarkSpent() : nOut out of range");
579 vfSpent.resize(vout.size());
582 vfSpent[nOut] = true;
583 fAvailableCreditCached = fAvailableWatchOnlyCreditCached = false;
587 void MarkUnspent(unsigned int nOut)
589 if (nOut >= vout.size())
590 throw std::runtime_error("CWalletTx::MarkUnspent() : nOut out of range");
591 vfSpent.resize(vout.size());
594 vfSpent[nOut] = false;
595 fAvailableCreditCached = fAvailableWatchOnlyCreditCached = false;
599 bool IsSpent(unsigned int nOut) const
601 if (nOut >= vout.size())
602 throw std::runtime_error("CWalletTx::IsSpent() : nOut out of range");
603 if (nOut >= vfSpent.size())
605 return (!!vfSpent[nOut]);
608 int64 GetDebit() const
614 nDebitCached = pwallet->GetDebit(*this);
619 int64 GetCredit(bool fUseCache=true) const
621 // Must wait until coinbase is safely deep enough in the chain before valuing it
622 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
625 // GetBalance can assume transactions in mapWallet won't change
628 return nCreditCached;
631 nCreditCached = pwallet->GetCredit(*this);
632 fCreditCached = true;
634 return nCreditCached;
637 int64 GetAvailableCredit(bool fUseCache=true) const
639 // Must wait until coinbase is safely deep enough in the chain before valuing it
640 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
644 if (fAvailableCreditCached)
645 return nAvailableCreditCached;
649 for (unsigned int i = 0; i < vout.size(); i++)
653 const CTxOut &txout = vout[i];
654 nCredit += pwallet->GetCredit(txout);
655 if (!MoneyRange(nCredit))
656 throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
660 nAvailableCreditCached = nCredit;
661 fAvailableCreditCached = true;
666 int64 GetCreditWatchOnly(bool fUseCache=true) const
668 // Must wait until coinbase is safely deep enough in the chain before valuing it
669 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
672 // GetBalance can assume transactions in mapWallet won't change
674 if (fWatchOnlyCreditCached)
675 return nWatchOnlyCreditCached;
678 nWatchOnlyCreditCached = pwallet->GetCreditWatchOnly(*this);
679 fWatchOnlyCreditCached = true;
681 return nWatchOnlyCreditCached;
684 int64 GetAvailableCreditWatchOnly(bool fUseCache=true) const
686 // Must wait until coinbase is safely deep enough in the chain before valuing it
687 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
691 if (fAvailableWatchOnlyCreditCached)
692 return nAvailableWatchOnlyCreditCached;
696 for (unsigned int i = 0; i < vout.size(); i++)
700 const CTxOut &txout = vout[i];
701 nCredit += pwallet->GetCreditWatchOnly(txout);
702 if (!MoneyRange(nCredit))
703 throw std::runtime_error("CWalletTx::GetAvailableCreditWatchOnly() : value out of range");
707 nAvailableWatchOnlyCreditCached = nCredit;
708 fAvailableWatchOnlyCreditCached = true;
714 int64 GetChange() const
717 return nChangeCached;
718 nChangeCached = pwallet->GetChange(*this);
719 fChangeCached = true;
720 return nChangeCached;
723 void GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, std::list<std::pair<CTxDestination, int64> >& listReceived,
724 std::list<std::pair<CTxDestination, int64> >& listSent, int64& nFee, std::string& strSentAccount) const;
726 void GetAccountAmounts(const std::string& strAccount, int64& nGenerated, int64& nReceived,
727 int64& nSent, int64& nFee) const;
729 bool IsFromMe() const
731 return (GetDebit() > 0);
734 bool IsTrusted() const
736 // Quick answer in most cases
739 if (GetDepthInMainChain() >= 1)
741 if (fConfChange || !IsFromMe()) // using wtx's cached debit
744 // If no confirmations but it's from us, we can still
745 // consider it confirmed if all dependencies are confirmed
746 std::map<uint256, const CMerkleTx*> mapPrev;
747 std::vector<const CMerkleTx*> vWorkQueue;
748 vWorkQueue.reserve(vtxPrev.size()+1);
749 vWorkQueue.push_back(this);
750 for (unsigned int i = 0; i < vWorkQueue.size(); i++)
752 const CMerkleTx* ptx = vWorkQueue[i];
756 if (ptx->GetDepthInMainChain() >= 1)
758 if (!pwallet->IsFromMe(*ptx))
763 BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
764 mapPrev[tx.GetHash()] = &tx;
767 BOOST_FOREACH(const CTxIn& txin, ptx->vin)
769 if (!mapPrev.count(txin.prevout.hash))
771 vWorkQueue.push_back(mapPrev[txin.prevout.hash]);
780 int64 GetTxTime() const;
781 int GetRequestCount() const;
783 void AddSupportingTransactions(CTxDB& txdb);
785 bool AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs=true);
786 bool AcceptWalletTransaction();
788 void RelayWalletTransaction(CTxDB& txdb);
789 void RelayWalletTransaction();
803 COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn)
805 tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn;
808 std::string ToString() const
810 return strprintf("COutput(%s, %d, %d, %d) [%s]", tx->GetHash().ToString().substr(0,10).c_str(), i, fSpendable, nDepth, FormatMoney(tx->vout[i].nValue).c_str());
815 printf("%s\n", ToString().c_str());
822 /** Private key that includes an expiration date in case it never gets used. */
829 std::string strComment;
830 //// todo: add something to note what created it (user, getnewaddress, change)
831 //// maybe should have a map<string, string> property map
833 CWalletKey(int64 nExpires=0)
835 nTimeCreated = (nExpires ? GetTime() : 0);
836 nTimeExpires = nExpires;
841 if (!(nType & SER_GETHASH))
843 READWRITE(vchPrivKey);
844 READWRITE(nTimeCreated);
845 READWRITE(nTimeExpires);
846 READWRITE(strComment);
855 /** Account information.
856 * Stored in wallet with key "acc"+string account name.
870 vchPubKey = CPubKey();
875 if (!(nType & SER_GETHASH))
877 READWRITE(vchPubKey);
883 /** Internal transfers.
884 * Database key is acentry<account><counter>.
886 class CAccountingEntry
889 std::string strAccount;
892 std::string strOtherAccount;
893 std::string strComment;
895 int64 nOrderPos; // position in ordered transaction list
908 strOtherAccount.clear();
915 CAccountingEntry& me = *const_cast<CAccountingEntry*>(this);
916 if (!(nType & SER_GETHASH))
918 // Note: strAccount is serialized as part of the key, not here.
919 READWRITE(nCreditDebit);
921 READWRITE(strOtherAccount);
925 WriteOrderPos(nOrderPos, me.mapValue);
927 if (!(mapValue.empty() && _ssExtra.empty()))
929 CDataStream ss(nType, nVersion);
930 ss.insert(ss.begin(), '\0');
932 ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
933 me.strComment.append(ss.str());
937 READWRITE(strComment);
939 size_t nSepPos = strComment.find("\0", 0, 1);
943 if (std::string::npos != nSepPos)
945 CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion);
947 me._ssExtra = std::vector<char>(ss.begin(), ss.end());
949 ReadOrderPos(me.nOrderPos, me.mapValue);
951 if (std::string::npos != nSepPos)
952 me.strComment.erase(nSepPos);
954 me.mapValue.erase("n");
958 std::vector<char> _ssExtra;
961 bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);