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 GetWatchOnlyBalance() const;
188 int64 GetUnconfirmedBalance() const;
189 int64 GetUnconfirmedWatchOnlyBalance() const;
190 int64 GetImmatureBalance() const;
191 int64 GetImmatureWatchOnlyBalance() const;
192 int64 GetStake() const;
193 int64 GetNewMint() const;
194 int64 GetWatchOnlyStake() const;
195 int64 GetWatchOnlyNewMint() const;
196 bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL);
197 bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL);
198 bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
200 bool GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight);
201 void GetStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight);
202 bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew, CKey& key);
204 std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
205 std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
208 bool TopUpKeyPool(unsigned int nSize = 0);
209 int64 AddReserveKey(const CKeyPool& keypool);
210 void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
211 void KeepKey(int64 nIndex);
212 void ReturnKey(int64 nIndex);
213 bool GetKeyFromPool(CPubKey &key, bool fAllowReuse=true);
214 int64 GetOldestKeyPoolTime();
215 void GetAllReserveKeys(std::set<CKeyID>& setAddress) const;
217 std::set< std::set<CTxDestination> > GetAddressGroupings();
218 std::map<CTxDestination, int64> GetAddressBalances();
220 isminetype IsMine(const CTxIn& txin) const;
221 int64 GetDebit(const CTxIn& txin, const isminefilter& filter) const;
222 isminetype IsMine(const CTxOut& txout) const
224 return ::IsMine(*this, txout.scriptPubKey);
226 int64 GetCredit(const CTxOut& txout, const isminefilter& filter) const
228 if (!MoneyRange(txout.nValue))
229 throw std::runtime_error("CWallet::GetCredit() : value out of range");
230 return (IsMine(txout) & filter ? txout.nValue : 0);
232 bool IsChange(const CTxOut& txout) const;
233 int64 GetChange(const CTxOut& txout) const
235 if (!MoneyRange(txout.nValue))
236 throw std::runtime_error("CWallet::GetChange() : value out of range");
237 return (IsChange(txout) ? txout.nValue : 0);
239 bool IsMine(const CTransaction& tx) const
241 BOOST_FOREACH(const CTxOut& txout, tx.vout)
242 if (IsMine(txout) && txout.nValue >= nMinimumInputValue)
246 bool IsFromMe(const CTransaction& tx) const
248 return (GetDebit(tx, MINE_ALL) > 0);
250 int64 GetDebit(const CTransaction& tx, const isminefilter& filter) const
253 BOOST_FOREACH(const CTxIn& txin, tx.vin)
255 nDebit += GetDebit(txin, filter);
256 if (!MoneyRange(nDebit))
257 throw std::runtime_error("CWallet::GetDebit() : value out of range");
261 int64 GetCredit(const CTransaction& tx, const isminefilter& filter) const
264 BOOST_FOREACH(const CTxOut& txout, tx.vout)
266 nCredit += GetCredit(txout, filter);
267 if (!MoneyRange(nCredit))
268 throw std::runtime_error("CWallet::GetCredit() : value out of range");
272 int64 GetChange(const CTransaction& tx) const
275 BOOST_FOREACH(const CTxOut& txout, tx.vout)
277 nChange += GetChange(txout);
278 if (!MoneyRange(nChange))
279 throw std::runtime_error("CWallet::GetChange() : value out of range");
283 void SetBestChain(const CBlockLocator& loc);
285 DBErrors LoadWallet(bool& fFirstRunRet);
287 bool SetAddressBookName(const CTxDestination& address, const std::string& strName);
289 bool DelAddressBookName(const CTxDestination& address);
291 void UpdatedTransaction(const uint256 &hashTx);
293 void PrintWallet(const CBlock& block);
295 void Inventory(const uint256 &hash)
299 std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
300 if (mi != mapRequestCount.end())
305 unsigned int GetKeyPoolSize()
307 return setKeyPool.size();
310 bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx);
312 bool SetDefaultKey(const CPubKey &vchPubKey);
314 // signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower
315 bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = NULL, bool fExplicit = false);
317 // change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format)
318 bool SetMaxVersion(int nVersion);
320 // get the current wallet format (the oldest client version guaranteed to understand this wallet)
321 int GetVersion() { return nWalletVersion; }
323 void FixSpentCoins(int& nMismatchSpent, int64& nBalanceInQuestion, bool fCheckOnly = false);
324 void DisableTransaction(const CTransaction &tx);
326 /** Address book entry changed.
327 * @note called with lock cs_wallet held.
329 boost::signals2::signal<void (CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, ChangeType status)> NotifyAddressBookChanged;
331 /** Wallet transaction added, removed or updated.
332 * @note called with lock cs_wallet held.
334 boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged;
337 /** A key allocated from the key pool. */
345 CReserveKey(CWallet* pwalletIn)
358 CPubKey GetReservedKey();
363 typedef std::map<std::string, std::string> mapValue_t;
366 static void ReadOrderPos(int64& nOrderPos, mapValue_t& mapValue)
368 if (!mapValue.count("n"))
370 nOrderPos = -1; // TODO: calculate elsewhere
373 nOrderPos = atoi64(mapValue["n"].c_str());
377 static void WriteOrderPos(const int64& nOrderPos, mapValue_t& mapValue)
381 mapValue["n"] = i64tostr(nOrderPos);
385 /** A transaction with a bunch of additional info that only the owner cares about.
386 * It includes any unrecorded transactions needed to link it back to the block chain.
388 class CWalletTx : public CMerkleTx
391 const CWallet* pwallet;
394 std::vector<CMerkleTx> vtxPrev;
396 std::vector<std::pair<std::string, std::string> > vOrderForm;
397 unsigned int fTimeReceivedIsTxTime;
398 unsigned int nTimeReceived; // time received by this node
399 unsigned int nTimeSmart;
401 std::string strFromAccount;
402 std::vector<char> vfSpent; // which outputs are already spent
403 int64 nOrderPos; // position in ordered transaction list
406 mutable bool fDebitCached;
407 mutable bool fWatchDebitCached;
408 mutable bool fCreditCached;
409 mutable bool fWatchCreditCached;
410 mutable bool fAvailableCreditCached;
411 mutable bool fImmatureCreditCached;
412 mutable bool fImmatureWatchCreditCached;
413 mutable bool fAvailableWatchCreditCached;
414 mutable bool fChangeCached;
415 mutable int64 nDebitCached;
416 mutable int64 nWatchDebitCached;
417 mutable int64 nCreditCached;
418 mutable int64 nWatchCreditCached;
419 mutable int64 nAvailableCreditCached;
420 mutable int64 nImmatureCreditCached;
421 mutable int64 nImmatureWatchCreditCached;
422 mutable int64 nAvailableWatchCreditCached;
423 mutable int64 nChangeCached;
430 CWalletTx(const CWallet* pwalletIn)
435 CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn) : CMerkleTx(txIn)
440 CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn) : CMerkleTx(txIn)
445 void Init(const CWallet* pwalletIn)
451 fTimeReceivedIsTxTime = false;
455 strFromAccount.clear();
457 fDebitCached = false;
458 fWatchDebitCached = false;
459 fCreditCached = false;
460 fWatchCreditCached = false;
461 fAvailableCreditCached = false;
462 fAvailableWatchCreditCached = false;
463 fChangeCached = false;
465 nWatchDebitCached = 0;
467 nWatchCreditCached = 0;
468 nAvailableCreditCached = 0;
469 nAvailableWatchCreditCached = 0;
476 CWalletTx* pthis = const_cast<CWalletTx*>(this);
483 pthis->mapValue["fromaccount"] = pthis->strFromAccount;
486 BOOST_FOREACH(char f, vfSpent)
488 str += (f ? '1' : '0');
492 pthis->mapValue["spent"] = str;
494 WriteOrderPos(pthis->nOrderPos, pthis->mapValue);
497 pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart);
500 nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action);
503 READWRITE(vOrderForm);
504 READWRITE(fTimeReceivedIsTxTime);
505 READWRITE(nTimeReceived);
511 pthis->strFromAccount = pthis->mapValue["fromaccount"];
513 if (mapValue.count("spent"))
514 BOOST_FOREACH(char c, pthis->mapValue["spent"])
515 pthis->vfSpent.push_back(c != '0');
517 pthis->vfSpent.assign(vout.size(), fSpent);
519 ReadOrderPos(pthis->nOrderPos, pthis->mapValue);
521 pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0;
524 pthis->mapValue.erase("fromaccount");
525 pthis->mapValue.erase("version");
526 pthis->mapValue.erase("spent");
527 pthis->mapValue.erase("n");
528 pthis->mapValue.erase("timesmart");
531 // marks certain txout's as spent
532 // returns true if any update took place
533 bool UpdateSpent(const std::vector<char>& vfNewSpent)
535 bool fReturn = false;
536 for (unsigned int i = 0; i < vfNewSpent.size(); i++)
538 if (i == vfSpent.size())
541 if (vfNewSpent[i] && !vfSpent[i])
545 fAvailableCreditCached = fAvailableWatchCreditCached = false;
551 // make sure balances are recalculated
554 fCreditCached = false;
555 fAvailableCreditCached = fAvailableWatchCreditCached = false;
556 fDebitCached = fWatchDebitCached = false;
557 fChangeCached = false;
560 void BindWallet(CWallet *pwalletIn)
566 void MarkSpent(unsigned int nOut)
568 if (nOut >= vout.size())
569 throw std::runtime_error("CWalletTx::MarkSpent() : nOut out of range");
570 vfSpent.resize(vout.size());
573 vfSpent[nOut] = true;
574 fAvailableCreditCached = fAvailableWatchCreditCached = false;
578 void MarkUnspent(unsigned int nOut)
580 if (nOut >= vout.size())
581 throw std::runtime_error("CWalletTx::MarkUnspent() : nOut out of range");
582 vfSpent.resize(vout.size());
585 vfSpent[nOut] = false;
586 fAvailableCreditCached = fAvailableWatchCreditCached = false;
590 bool IsSpent(unsigned int nOut) const
592 if (nOut >= vout.size())
593 throw std::runtime_error("CWalletTx::IsSpent() : nOut out of range");
594 if (nOut >= vfSpent.size())
596 return (!!vfSpent[nOut]);
599 int64 GetDebit(const isminefilter& filter) const
605 if (filter & MINE_SPENDABLE)
608 nDebit += nDebitCached;
611 nDebitCached = pwallet->GetDebit(*this, MINE_SPENDABLE);
613 nDebit += nDebitCached;
616 if (filter & MINE_WATCH_ONLY)
618 if (fWatchDebitCached)
619 nDebit += nWatchDebitCached;
622 nWatchDebitCached = pwallet->GetDebit(*this, MINE_WATCH_ONLY);
623 fWatchDebitCached = true;
624 nDebit += nWatchDebitCached;
631 int64 GetCredit(bool fUseCache=true) const
633 // Must wait until coinbase is safely deep enough in the chain before valuing it
634 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
637 // GetBalance can assume transactions in mapWallet won't change
640 return nCreditCached;
643 nCreditCached = pwallet->GetCredit(*this, MINE_ALL);
644 fCreditCached = true;
646 return nCreditCached;
649 int64 GetImmatureCredit(bool fUseCache=true) const
651 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0 && IsInMainChain())
653 if (fUseCache && fImmatureCreditCached)
654 return nImmatureCreditCached;
655 nImmatureCreditCached = pwallet->GetCredit(*this, MINE_SPENDABLE);
656 fImmatureCreditCached = true;
657 return nImmatureCreditCached;
663 int64 GetImmatureWatchOnlyCredit(bool fUseCache=true) const
665 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0 && IsInMainChain())
667 if (fUseCache && fImmatureWatchCreditCached)
668 return nImmatureWatchCreditCached;
669 nImmatureWatchCreditCached = pwallet->GetCredit(*this, MINE_WATCH_ONLY);
670 fImmatureWatchCreditCached = true;
671 return nImmatureWatchCreditCached;
678 int64 GetAvailableCredit(bool fUseCache=true) const
680 // Must wait until coinbase is safely deep enough in the chain before valuing it
681 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
685 if (fAvailableCreditCached)
686 return nAvailableCreditCached;
690 for (unsigned int i = 0; i < vout.size(); i++)
694 const CTxOut &txout = vout[i];
695 nCredit += pwallet->GetCredit(txout, MINE_SPENDABLE);
696 if (!MoneyRange(nCredit))
697 throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
701 nAvailableCreditCached = nCredit;
702 fAvailableCreditCached = true;
707 int64 GetAvailableWatchCredit(bool fUseCache=true) const
709 // Must wait until coinbase is safely deep enough in the chain before valuing it
710 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
714 if (fAvailableWatchCreditCached)
715 return nAvailableWatchCreditCached;
719 for (unsigned int i = 0; i < vout.size(); i++)
723 const CTxOut &txout = vout[i];
724 nCredit += pwallet->GetCredit(txout, MINE_WATCH_ONLY);
725 if (!MoneyRange(nCredit))
726 throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
730 nAvailableWatchCreditCached = nCredit;
731 fAvailableWatchCreditCached = true;
736 int64 GetChange() const
739 return nChangeCached;
740 nChangeCached = pwallet->GetChange(*this);
741 fChangeCached = true;
742 return nChangeCached;
745 void GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, std::list<std::pair<CTxDestination, int64> >& listReceived,
746 std::list<std::pair<CTxDestination, int64> >& listSent, int64& nFee, std::string& strSentAccount, const isminefilter& filter) const;
748 void GetAccountAmounts(const std::string& strAccount, int64& nGenerated, int64& nReceived,
749 int64& nSent, int64& nFee, const isminefilter& filter) const;
751 bool IsFromMe(const isminefilter& filter) const
753 return (GetDebit(filter) > 0);
756 bool IsTrusted() const
758 // Quick answer in most cases
761 if (GetDepthInMainChain() >= 1)
763 if (fConfChange || !IsFromMe(MINE_ALL)) // using wtx's cached debit
766 // If no confirmations but it's from us, we can still
767 // consider it confirmed if all dependencies are confirmed
768 std::map<uint256, const CMerkleTx*> mapPrev;
769 std::vector<const CMerkleTx*> vWorkQueue;
770 vWorkQueue.reserve(vtxPrev.size()+1);
771 vWorkQueue.push_back(this);
772 for (unsigned int i = 0; i < vWorkQueue.size(); i++)
774 const CMerkleTx* ptx = vWorkQueue[i];
778 if (ptx->GetDepthInMainChain() >= 1)
780 if (!pwallet->IsFromMe(*ptx))
785 BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
786 mapPrev[tx.GetHash()] = &tx;
789 BOOST_FOREACH(const CTxIn& txin, ptx->vin)
791 if (!mapPrev.count(txin.prevout.hash))
793 vWorkQueue.push_back(mapPrev[txin.prevout.hash]);
802 int64 GetTxTime() const;
803 int GetRequestCount() const;
805 void AddSupportingTransactions(CTxDB& txdb);
807 bool AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs=true);
808 bool AcceptWalletTransaction();
810 void RelayWalletTransaction(CTxDB& txdb);
811 void RelayWalletTransaction();
825 COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn)
827 tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn;
830 std::string ToString() const
832 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());
837 printf("%s\n", ToString().c_str());
844 /** Private key that includes an expiration date in case it never gets used. */
851 std::string strComment;
852 //// todo: add something to note what created it (user, getnewaddress, change)
853 //// maybe should have a map<string, string> property map
855 CWalletKey(int64 nExpires=0)
857 nTimeCreated = (nExpires ? GetTime() : 0);
858 nTimeExpires = nExpires;
863 if (!(nType & SER_GETHASH))
865 READWRITE(vchPrivKey);
866 READWRITE(nTimeCreated);
867 READWRITE(nTimeExpires);
868 READWRITE(strComment);
877 /** Account information.
878 * Stored in wallet with key "acc"+string account name.
892 vchPubKey = CPubKey();
897 if (!(nType & SER_GETHASH))
899 READWRITE(vchPubKey);
905 /** Internal transfers.
906 * Database key is acentry<account><counter>.
908 class CAccountingEntry
911 std::string strAccount;
914 std::string strOtherAccount;
915 std::string strComment;
917 int64 nOrderPos; // position in ordered transaction list
930 strOtherAccount.clear();
937 CAccountingEntry& me = *const_cast<CAccountingEntry*>(this);
938 if (!(nType & SER_GETHASH))
940 // Note: strAccount is serialized as part of the key, not here.
941 READWRITE(nCreditDebit);
943 READWRITE(strOtherAccount);
947 WriteOrderPos(nOrderPos, me.mapValue);
949 if (!(mapValue.empty() && _ssExtra.empty()))
951 CDataStream ss(nType, nVersion);
952 ss.insert(ss.begin(), '\0');
954 ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
955 me.strComment.append(ss.str());
959 READWRITE(strComment);
961 size_t nSepPos = strComment.find("\0", 0, 1);
965 if (std::string::npos != nSepPos)
967 CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion);
969 me._ssExtra = std::vector<char>(ss.begin(), ss.end());
971 ReadOrderPos(me.nOrderPos, me.mapValue);
973 if (std::string::npos != nSepPos)
974 me.strComment.erase(nSepPos);
976 me.mapValue.erase("n");
980 std::vector<char> _ssExtra;
983 bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);