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 unsigned int nStakeMaxAge;
22 extern bool fWalletUnlockMintOnly;
23 extern bool fConfChange;
24 class CAccountingEntry;
30 /** (client) version numbers for particular wallet features */
33 FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output)
35 FEATURE_WALLETCRYPT = 40000, // wallet encryption
36 FEATURE_COMPRPUBKEY = 60000, // compressed public keys
37 FEATURE_LATEST = 60000
40 /** A key pool entry */
52 CKeyPool(const CPubKey& vchPubKeyIn)
55 vchPubKey = vchPubKeyIn;
60 if (!(nType & SER_GETHASH))
67 /** A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,
68 * and provides the ability to create new transactions.
70 class CWallet : public CCryptoKeyStore
73 bool SelectCoinsSimple(int64 nTargetValue, int64 nMinValue, int64 nMaxValue, unsigned int nSpendTime, int nMinConf, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet) const;
74 bool SelectCoins(int64 nTargetValue, unsigned int nSpendTime, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl *coinControl=NULL) const;
76 CWalletDB *pwalletdbEncryption;
78 // the current wallet version: clients below this version are not able to load the wallet
81 // the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded
82 int nWalletMaxVersion;
84 // selected coins metadata
85 std::map<std::pair<uint256, unsigned int>, std::pair<std::pair<CTxIndex, std::pair<const CWalletTx*,unsigned int> >, std::pair<CBlock, uint64> > > mapMeta;
88 mutable CCriticalSection cs_wallet;
91 std::string strWalletFile;
93 std::set<int64> setKeyPool;
94 std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
97 typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
98 MasterKeyMap mapMasterKeys;
99 unsigned int nMasterKeyMaxID;
103 nWalletVersion = FEATURE_BASE;
104 nWalletMaxVersion = FEATURE_BASE;
107 pwalletdbEncryption = NULL;
110 CWallet(std::string strWalletFileIn)
112 nWalletVersion = FEATURE_BASE;
113 nWalletMaxVersion = FEATURE_BASE;
114 strWalletFile = strWalletFileIn;
117 pwalletdbEncryption = NULL;
121 std::map<uint256, CWalletTx> mapWallet;
122 std::vector<uint256> vMintingWalletUpdated;
124 std::map<uint256, int> mapRequestCount;
126 std::map<CTxDestination, std::string> mapAddressBook;
128 CPubKey vchDefaultKey;
131 // check whether we are allowed to upgrade (or already support) to the named feature
132 bool CanSupportFeature(enum WalletFeature wf) { return nWalletMaxVersion >= wf; }
134 void AvailableCoinsMinConf(std::vector<COutput>& vCoins, int nConf, int64 nMinValue, int64 nMaxValue) const;
135 void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL) const;
136 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;
137 // keystore implementation
138 // Generate a new key
139 CPubKey GenerateNewKey();
140 // Adds a key to the store, and saves it to disk.
141 bool AddKey(const CKey& key);
142 // Adds a key to the store, without saving it to disk (used by LoadWallet)
143 bool LoadKey(const CKey& key) { return CCryptoKeyStore::AddKey(key); }
144 // Load metadata (used by LoadWallet)
145 bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata);
147 bool LoadMinVersion(int nVersion) { nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
149 // Adds an encrypted key to the store, and saves it to disk.
150 bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
151 // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
152 bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) { SetMinVersion(FEATURE_WALLETCRYPT); return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); }
153 bool AddCScript(const CScript& redeemScript);
154 bool LoadCScript(const CScript& redeemScript) { return CCryptoKeyStore::AddCScript(redeemScript); }
156 // Adds a watch-only address to the store, and saves it to disk.
157 bool AddWatchOnly(const CScript &dest);
158 // Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
159 bool LoadWatchOnly(const CScript &dest);
161 bool Unlock(const SecureString& strWalletPassphrase);
162 bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
163 bool EncryptWallet(const SecureString& strWalletPassphrase);
165 void GetKeyBirthTimes(std::map<CKeyID, int64> &mapKeyBirth) const;
168 /** Increment the next transaction order id
169 @return next transaction order id
171 int64 IncOrderPosNext(CWalletDB *pwalletdb = NULL);
173 typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
174 typedef std::multimap<int64, TxPair > TxItems;
176 /** Get the wallet's activity log
177 @return multimap of ordered transactions and accounting entries
178 @warning Returned pointers are *only* valid within the scope of passed acentries
180 TxItems OrderedTxItems(std::list<CAccountingEntry>& acentries, std::string strAccount = "");
183 bool AddToWallet(const CWalletTx& wtxIn);
184 bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false, bool fFindBlock = false);
185 bool EraseFromWallet(uint256 hash);
187 void WalletUpdateSpent(const CTransaction& prevout, bool fBlock = false);
188 int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
189 int ScanForWalletTransaction(const uint256& hashTx);
190 void ReacceptWalletTransactions();
191 void ResendWalletTransactions();
192 int64 GetBalance() const;
193 int64 GetWatchOnlyBalance() const;
194 int64 GetUnconfirmedBalance() const;
195 int64 GetUnconfirmedWatchOnlyBalance() const;
196 int64 GetImmatureBalance() const;
197 int64 GetImmatureWatchOnlyBalance() const;
198 int64 GetStake() const;
199 int64 GetNewMint() const;
200 int64 GetWatchOnlyStake() const;
201 int64 GetWatchOnlyNewMint() const;
202 bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL);
203 bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL);
204 bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
206 bool GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight);
207 void GetStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight);
208 bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew, CKey& key);
209 bool MergeCoins(const int64& nAmount, const int64& nMinValue, const int64& nMaxValue, std::list<uint256>& listMerged);
211 std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
212 std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
215 bool TopUpKeyPool(unsigned int nSize = 0);
216 int64 AddReserveKey(const CKeyPool& keypool);
217 void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
218 void KeepKey(int64 nIndex);
219 void ReturnKey(int64 nIndex);
220 bool GetKeyFromPool(CPubKey &key, bool fAllowReuse=true);
221 int64 GetOldestKeyPoolTime();
222 void GetAllReserveKeys(std::set<CKeyID>& setAddress) const;
224 std::set< std::set<CTxDestination> > GetAddressGroupings();
225 std::map<CTxDestination, int64> GetAddressBalances();
227 isminetype IsMine(const CTxIn& txin) const;
228 int64 GetDebit(const CTxIn& txin, const isminefilter& filter) const;
229 isminetype IsMine(const CTxOut& txout) const
231 return ::IsMine(*this, txout.scriptPubKey);
233 int64 GetCredit(const CTxOut& txout, const isminefilter& filter) const
235 if (!MoneyRange(txout.nValue))
236 throw std::runtime_error("CWallet::GetCredit() : value out of range");
237 return (IsMine(txout) & filter ? txout.nValue : 0);
239 bool IsChange(const CTxOut& txout) const;
240 int64 GetChange(const CTxOut& txout) const
242 if (!MoneyRange(txout.nValue))
243 throw std::runtime_error("CWallet::GetChange() : value out of range");
244 return (IsChange(txout) ? txout.nValue : 0);
246 bool IsMine(const CTransaction& tx) const
248 BOOST_FOREACH(const CTxOut& txout, tx.vout)
249 if (IsMine(txout) && txout.nValue >= nMinimumInputValue)
253 bool IsFromMe(const CTransaction& tx) const
255 return (GetDebit(tx, MINE_ALL) > 0);
257 int64 GetDebit(const CTransaction& tx, const isminefilter& filter) const
260 BOOST_FOREACH(const CTxIn& txin, tx.vin)
262 nDebit += GetDebit(txin, filter);
263 if (!MoneyRange(nDebit))
264 throw std::runtime_error("CWallet::GetDebit() : value out of range");
268 int64 GetCredit(const CTransaction& tx, const isminefilter& filter) const
271 BOOST_FOREACH(const CTxOut& txout, tx.vout)
273 nCredit += GetCredit(txout, filter);
274 if (!MoneyRange(nCredit))
275 throw std::runtime_error("CWallet::GetCredit() : value out of range");
279 int64 GetChange(const CTransaction& tx) const
282 BOOST_FOREACH(const CTxOut& txout, tx.vout)
284 nChange += GetChange(txout);
285 if (!MoneyRange(nChange))
286 throw std::runtime_error("CWallet::GetChange() : value out of range");
290 void SetBestChain(const CBlockLocator& loc);
292 DBErrors LoadWallet(bool& fFirstRunRet);
294 bool SetAddressBookName(const CTxDestination& address, const std::string& strName);
296 bool DelAddressBookName(const CTxDestination& address);
298 void UpdatedTransaction(const uint256 &hashTx);
300 void PrintWallet(const CBlock& block);
302 void Inventory(const uint256 &hash)
306 std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
307 if (mi != mapRequestCount.end())
312 unsigned int GetKeyPoolSize()
314 return setKeyPool.size();
317 bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx);
319 bool SetDefaultKey(const CPubKey &vchPubKey);
321 // signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower
322 bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = NULL, bool fExplicit = false);
324 // change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format)
325 bool SetMaxVersion(int nVersion);
327 // get the current wallet format (the oldest client version guaranteed to understand this wallet)
328 int GetVersion() { return nWalletVersion; }
330 void FixSpentCoins(int& nMismatchSpent, int64& nBalanceInQuestion, bool fCheckOnly = false);
331 void DisableTransaction(const CTransaction &tx);
333 /** Address book entry changed.
334 * @note called with lock cs_wallet held.
336 boost::signals2::signal<void (CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, ChangeType status)> NotifyAddressBookChanged;
338 /** Wallet transaction added, removed or updated.
339 * @note called with lock cs_wallet held.
341 boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged;
344 /** A key allocated from the key pool. */
352 CReserveKey(CWallet* pwalletIn)
365 CPubKey GetReservedKey();
370 typedef std::map<std::string, std::string> mapValue_t;
373 static void ReadOrderPos(int64& nOrderPos, mapValue_t& mapValue)
375 if (!mapValue.count("n"))
377 nOrderPos = -1; // TODO: calculate elsewhere
380 nOrderPos = atoi64(mapValue["n"].c_str());
384 static void WriteOrderPos(const int64& nOrderPos, mapValue_t& mapValue)
388 mapValue["n"] = i64tostr(nOrderPos);
392 /** A transaction with a bunch of additional info that only the owner cares about.
393 * It includes any unrecorded transactions needed to link it back to the block chain.
395 class CWalletTx : public CMerkleTx
398 const CWallet* pwallet;
401 std::vector<CMerkleTx> vtxPrev;
403 std::vector<std::pair<std::string, std::string> > vOrderForm;
404 unsigned int fTimeReceivedIsTxTime;
405 unsigned int nTimeReceived; // time received by this node
406 unsigned int nTimeSmart;
408 std::string strFromAccount;
409 std::vector<char> vfSpent; // which outputs are already spent
410 int64 nOrderPos; // position in ordered transaction list
413 mutable bool fDebitCached;
414 mutable bool fWatchDebitCached;
415 mutable bool fCreditCached;
416 mutable bool fWatchCreditCached;
417 mutable bool fAvailableCreditCached;
418 mutable bool fImmatureCreditCached;
419 mutable bool fImmatureWatchCreditCached;
420 mutable bool fAvailableWatchCreditCached;
421 mutable bool fChangeCached;
422 mutable int64 nDebitCached;
423 mutable int64 nWatchDebitCached;
424 mutable int64 nCreditCached;
425 mutable int64 nWatchCreditCached;
426 mutable int64 nAvailableCreditCached;
427 mutable int64 nImmatureCreditCached;
428 mutable int64 nImmatureWatchCreditCached;
429 mutable int64 nAvailableWatchCreditCached;
430 mutable int64 nChangeCached;
437 CWalletTx(const CWallet* pwalletIn)
442 CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn) : CMerkleTx(txIn)
447 CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn) : CMerkleTx(txIn)
452 void Init(const CWallet* pwalletIn)
458 fTimeReceivedIsTxTime = false;
462 strFromAccount.clear();
464 fDebitCached = false;
465 fWatchDebitCached = false;
466 fCreditCached = false;
467 fWatchCreditCached = false;
468 fAvailableCreditCached = false;
469 fAvailableWatchCreditCached = false;
470 fImmatureCreditCached = false;
471 fImmatureWatchCreditCached = false;
472 fChangeCached = false;
474 nWatchDebitCached = 0;
476 nWatchCreditCached = 0;
477 nAvailableCreditCached = 0;
478 nAvailableWatchCreditCached = 0;
479 nImmatureCreditCached = 0;
480 nImmatureWatchCreditCached = 0;
487 CWalletTx* pthis = const_cast<CWalletTx*>(this);
494 pthis->mapValue["fromaccount"] = pthis->strFromAccount;
497 BOOST_FOREACH(char f, vfSpent)
499 str += (f ? '1' : '0');
503 pthis->mapValue["spent"] = str;
505 WriteOrderPos(pthis->nOrderPos, pthis->mapValue);
508 pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart);
511 nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action);
514 READWRITE(vOrderForm);
515 READWRITE(fTimeReceivedIsTxTime);
516 READWRITE(nTimeReceived);
522 pthis->strFromAccount = pthis->mapValue["fromaccount"];
524 if (mapValue.count("spent"))
525 BOOST_FOREACH(char c, pthis->mapValue["spent"])
526 pthis->vfSpent.push_back(c != '0');
528 pthis->vfSpent.assign(vout.size(), fSpent);
530 ReadOrderPos(pthis->nOrderPos, pthis->mapValue);
532 pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0;
535 pthis->mapValue.erase("fromaccount");
536 pthis->mapValue.erase("version");
537 pthis->mapValue.erase("spent");
538 pthis->mapValue.erase("n");
539 pthis->mapValue.erase("timesmart");
542 // marks certain txout's as spent
543 // returns true if any update took place
544 bool UpdateSpent(const std::vector<char>& vfNewSpent)
546 bool fReturn = false;
547 for (unsigned int i = 0; i < vfNewSpent.size(); i++)
549 if (i == vfSpent.size())
552 if (vfNewSpent[i] && !vfSpent[i])
556 fAvailableCreditCached = fAvailableWatchCreditCached = false;
562 // make sure balances are recalculated
565 fCreditCached = false;
566 fAvailableCreditCached = fAvailableWatchCreditCached = false;
567 fDebitCached = fWatchDebitCached = false;
568 fChangeCached = false;
571 void BindWallet(CWallet *pwalletIn)
577 void MarkSpent(unsigned int nOut)
579 if (nOut >= vout.size())
580 throw std::runtime_error("CWalletTx::MarkSpent() : nOut out of range");
581 vfSpent.resize(vout.size());
584 vfSpent[nOut] = true;
585 fAvailableCreditCached = fAvailableWatchCreditCached = false;
589 void MarkUnspent(unsigned int nOut)
591 if (nOut >= vout.size())
592 throw std::runtime_error("CWalletTx::MarkUnspent() : nOut out of range");
593 vfSpent.resize(vout.size());
596 vfSpent[nOut] = false;
597 fAvailableCreditCached = fAvailableWatchCreditCached = false;
601 bool IsSpent(unsigned int nOut) const
603 if (nOut >= vout.size())
604 throw std::runtime_error("CWalletTx::IsSpent() : nOut out of range");
605 if (nOut >= vfSpent.size())
607 return (!!vfSpent[nOut]);
610 int64 GetDebit(const isminefilter& filter) const
616 if (filter & MINE_SPENDABLE)
619 nDebit += nDebitCached;
622 nDebitCached = pwallet->GetDebit(*this, MINE_SPENDABLE);
624 nDebit += nDebitCached;
627 if (filter & MINE_WATCH_ONLY)
629 if (fWatchDebitCached)
630 nDebit += nWatchDebitCached;
633 nWatchDebitCached = pwallet->GetDebit(*this, MINE_WATCH_ONLY);
634 fWatchDebitCached = true;
635 nDebit += nWatchDebitCached;
642 int64 GetCredit(bool fUseCache=true) const
644 // Must wait until coinbase is safely deep enough in the chain before valuing it
645 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
648 // GetBalance can assume transactions in mapWallet won't change
651 return nCreditCached;
654 nCreditCached = pwallet->GetCredit(*this, MINE_ALL);
655 fCreditCached = true;
657 return nCreditCached;
660 int64 GetImmatureCredit(bool fUseCache=true) const
662 if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
664 if (fUseCache && fImmatureCreditCached)
665 return nImmatureCreditCached;
666 nImmatureCreditCached = pwallet->GetCredit(*this, MINE_SPENDABLE);
667 fImmatureCreditCached = true;
668 return nImmatureCreditCached;
674 int64 GetImmatureWatchOnlyCredit(bool fUseCache=true) const
676 if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
678 if (fUseCache && fImmatureWatchCreditCached)
679 return nImmatureWatchCreditCached;
680 nImmatureWatchCreditCached = pwallet->GetCredit(*this, MINE_WATCH_ONLY);
681 fImmatureWatchCreditCached = true;
682 return nImmatureWatchCreditCached;
689 int64 GetAvailableCredit(bool fUseCache=true) const
691 // Must wait until coinbase is safely deep enough in the chain before valuing it
692 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
696 if (fAvailableCreditCached)
697 return nAvailableCreditCached;
701 for (unsigned int i = 0; i < vout.size(); i++)
705 const CTxOut &txout = vout[i];
706 nCredit += pwallet->GetCredit(txout, MINE_SPENDABLE);
707 if (!MoneyRange(nCredit))
708 throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
712 nAvailableCreditCached = nCredit;
713 fAvailableCreditCached = true;
718 int64 GetAvailableWatchCredit(bool fUseCache=true) const
720 // Must wait until coinbase is safely deep enough in the chain before valuing it
721 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
725 if (fAvailableWatchCreditCached)
726 return nAvailableWatchCreditCached;
730 for (unsigned int i = 0; i < vout.size(); i++)
734 const CTxOut &txout = vout[i];
735 nCredit += pwallet->GetCredit(txout, MINE_WATCH_ONLY);
736 if (!MoneyRange(nCredit))
737 throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
741 nAvailableWatchCreditCached = nCredit;
742 fAvailableWatchCreditCached = true;
747 int64 GetChange() const
750 return nChangeCached;
751 nChangeCached = pwallet->GetChange(*this);
752 fChangeCached = true;
753 return nChangeCached;
756 void GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, std::list<std::pair<CTxDestination, int64> >& listReceived,
757 std::list<std::pair<CTxDestination, int64> >& listSent, int64& nFee, std::string& strSentAccount, const isminefilter& filter) const;
759 void GetAccountAmounts(const std::string& strAccount, int64& nGenerated, int64& nReceived,
760 int64& nSent, int64& nFee, const isminefilter& filter) const;
762 bool IsFromMe(const isminefilter& filter) const
764 return (GetDebit(filter) > 0);
767 bool IsTrusted() const
769 // Quick answer in most cases
772 if (GetDepthInMainChain() >= 1)
774 if (fConfChange || !IsFromMe(MINE_ALL)) // using wtx's cached debit
777 // If no confirmations but it's from us, we can still
778 // consider it confirmed if all dependencies are confirmed
779 std::map<uint256, const CMerkleTx*> mapPrev;
780 std::vector<const CMerkleTx*> vWorkQueue;
781 vWorkQueue.reserve(vtxPrev.size()+1);
782 vWorkQueue.push_back(this);
783 for (unsigned int i = 0; i < vWorkQueue.size(); i++)
785 const CMerkleTx* ptx = vWorkQueue[i];
789 if (ptx->GetDepthInMainChain() >= 1)
791 if (!pwallet->IsFromMe(*ptx))
796 BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
797 mapPrev[tx.GetHash()] = &tx;
800 BOOST_FOREACH(const CTxIn& txin, ptx->vin)
802 if (!mapPrev.count(txin.prevout.hash))
804 vWorkQueue.push_back(mapPrev[txin.prevout.hash]);
813 int64 GetTxTime() const;
814 int GetRequestCount() const;
816 void AddSupportingTransactions(CTxDB& txdb);
818 bool AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs=true);
819 bool AcceptWalletTransaction();
821 void RelayWalletTransaction(CTxDB& txdb);
822 void RelayWalletTransaction();
836 COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn)
838 tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn;
841 std::string ToString() const
843 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());
848 printf("%s\n", ToString().c_str());
855 /** Private key that includes an expiration date in case it never gets used. */
862 std::string strComment;
863 //// todo: add something to note what created it (user, getnewaddress, change)
864 //// maybe should have a map<string, string> property map
866 CWalletKey(int64 nExpires=0)
868 nTimeCreated = (nExpires ? GetTime() : 0);
869 nTimeExpires = nExpires;
874 if (!(nType & SER_GETHASH))
876 READWRITE(vchPrivKey);
877 READWRITE(nTimeCreated);
878 READWRITE(nTimeExpires);
879 READWRITE(strComment);
888 /** Account information.
889 * Stored in wallet with key "acc"+string account name.
903 vchPubKey = CPubKey();
908 if (!(nType & SER_GETHASH))
910 READWRITE(vchPubKey);
916 /** Internal transfers.
917 * Database key is acentry<account><counter>.
919 class CAccountingEntry
922 std::string strAccount;
925 std::string strOtherAccount;
926 std::string strComment;
928 int64 nOrderPos; // position in ordered transaction list
941 strOtherAccount.clear();
948 CAccountingEntry& me = *const_cast<CAccountingEntry*>(this);
949 if (!(nType & SER_GETHASH))
951 // Note: strAccount is serialized as part of the key, not here.
952 READWRITE(nCreditDebit);
954 READWRITE(strOtherAccount);
958 WriteOrderPos(nOrderPos, me.mapValue);
960 if (!(mapValue.empty() && _ssExtra.empty()))
962 CDataStream ss(nType, nVersion);
963 ss.insert(ss.begin(), '\0');
965 ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
966 me.strComment.append(ss.str());
970 READWRITE(strComment);
972 size_t nSepPos = strComment.find("\0", 0, 1);
976 if (std::string::npos != nSepPos)
978 CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion);
980 me._ssExtra = std::vector<char>(ss.begin(), ss.end());
982 ReadOrderPos(me.nOrderPos, me.mapValue);
984 if (std::string::npos != nSepPos)
985 me.strComment.erase(nSepPos);
987 me.mapValue.erase("n");
991 std::vector<char> _ssExtra;
994 bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);