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;
87 // stake mining statistics
89 uint64 nCoinDaysTried;
92 mutable CCriticalSection cs_wallet;
95 std::string strWalletFile;
97 std::set<int64> setKeyPool;
98 std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
101 typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
102 MasterKeyMap mapMasterKeys;
103 unsigned int nMasterKeyMaxID;
107 nWalletVersion = FEATURE_BASE;
108 nWalletMaxVersion = FEATURE_BASE;
111 pwalletdbEncryption = NULL;
116 CWallet(std::string strWalletFileIn)
118 nWalletVersion = FEATURE_BASE;
119 nWalletMaxVersion = FEATURE_BASE;
120 strWalletFile = strWalletFileIn;
123 pwalletdbEncryption = NULL;
129 std::map<uint256, CWalletTx> mapWallet;
130 std::vector<uint256> vMintingWalletUpdated;
132 std::map<uint256, int> mapRequestCount;
134 std::map<CTxDestination, std::string> mapAddressBook;
136 CPubKey vchDefaultKey;
139 // check whether we are allowed to upgrade (or already support) to the named feature
140 bool CanSupportFeature(enum WalletFeature wf) { return nWalletMaxVersion >= wf; }
142 void AvailableCoinsMinConf(std::vector<COutput>& vCoins, int nConf, int64 nMinValue, int64 nMaxValue) const;
143 void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL) const;
144 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;
145 // keystore implementation
146 // Generate a new key
147 CPubKey GenerateNewKey();
148 // Adds a key to the store, and saves it to disk.
149 bool AddKey(const CKey& key);
150 // Adds a key to the store, without saving it to disk (used by LoadWallet)
151 bool LoadKey(const CKey& key) { return CCryptoKeyStore::AddKey(key); }
152 // Load metadata (used by LoadWallet)
153 bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata);
155 bool LoadMinVersion(int nVersion) { nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
157 // Adds an encrypted key to the store, and saves it to disk.
158 bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
159 // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
160 bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) { SetMinVersion(FEATURE_WALLETCRYPT); return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); }
161 bool AddCScript(const CScript& redeemScript);
162 bool LoadCScript(const CScript& redeemScript) { return CCryptoKeyStore::AddCScript(redeemScript); }
164 // Adds a watch-only address to the store, and saves it to disk.
165 bool AddWatchOnly(const CScript &dest);
166 // Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
167 bool LoadWatchOnly(const CScript &dest);
169 bool Unlock(const SecureString& strWalletPassphrase);
170 bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
171 bool EncryptWallet(const SecureString& strWalletPassphrase);
173 void GetKeyBirthTimes(std::map<CKeyID, int64> &mapKeyBirth) const;
176 /** Increment the next transaction order id
177 @return next transaction order id
179 int64 IncOrderPosNext(CWalletDB *pwalletdb = NULL);
181 typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
182 typedef std::multimap<int64, TxPair > TxItems;
184 /** Get the wallet's activity log
185 @return multimap of ordered transactions and accounting entries
186 @warning Returned pointers are *only* valid within the scope of passed acentries
188 TxItems OrderedTxItems(std::list<CAccountingEntry>& acentries, std::string strAccount = "");
191 bool AddToWallet(const CWalletTx& wtxIn);
192 bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false, bool fFindBlock = false);
193 bool EraseFromWallet(uint256 hash);
195 void WalletUpdateSpent(const CTransaction& prevout, bool fBlock = false);
196 int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
197 int ScanForWalletTransaction(const uint256& hashTx);
198 void ReacceptWalletTransactions();
199 void ResendWalletTransactions();
200 int64 GetBalance() const;
201 int64 GetWatchOnlyBalance() const;
202 int64 GetUnconfirmedBalance() const;
203 int64 GetUnconfirmedWatchOnlyBalance() const;
204 int64 GetImmatureBalance() const;
205 int64 GetImmatureWatchOnlyBalance() const;
206 int64 GetStake() const;
207 int64 GetNewMint() const;
208 int64 GetWatchOnlyStake() const;
209 int64 GetWatchOnlyNewMint() const;
210 bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL);
211 bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL);
212 bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
214 void GetStakeStats(float &nKernelsRate, float &nCoinDaysRate);
215 void GetStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight);
216 bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew, CKey& key);
217 bool MergeCoins(const int64& nAmount, const int64& nMinValue, const int64& nMaxValue, std::list<uint256>& listMerged);
219 std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
220 std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
223 bool TopUpKeyPool(unsigned int nSize = 0);
224 int64 AddReserveKey(const CKeyPool& keypool);
225 void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
226 void KeepKey(int64 nIndex);
227 void ReturnKey(int64 nIndex);
228 bool GetKeyFromPool(CPubKey &key, bool fAllowReuse=true);
229 int64 GetOldestKeyPoolTime();
230 void GetAllReserveKeys(std::set<CKeyID>& setAddress) const;
232 std::set< std::set<CTxDestination> > GetAddressGroupings();
233 std::map<CTxDestination, int64> GetAddressBalances();
235 isminetype IsMine(const CTxIn& txin) const;
236 int64 GetDebit(const CTxIn& txin, const isminefilter& filter) const;
237 isminetype IsMine(const CTxOut& txout) const
239 return ::IsMine(*this, txout.scriptPubKey);
241 int64 GetCredit(const CTxOut& txout, const isminefilter& filter) const
243 if (!MoneyRange(txout.nValue))
244 throw std::runtime_error("CWallet::GetCredit() : value out of range");
245 return (IsMine(txout) & filter ? txout.nValue : 0);
247 bool IsChange(const CTxOut& txout) const;
248 int64 GetChange(const CTxOut& txout) const
250 if (!MoneyRange(txout.nValue))
251 throw std::runtime_error("CWallet::GetChange() : value out of range");
252 return (IsChange(txout) ? txout.nValue : 0);
254 bool IsMine(const CTransaction& tx) const
256 BOOST_FOREACH(const CTxOut& txout, tx.vout)
257 if (IsMine(txout) && txout.nValue >= nMinimumInputValue)
261 bool IsFromMe(const CTransaction& tx) const
263 return (GetDebit(tx, MINE_ALL) > 0);
265 int64 GetDebit(const CTransaction& tx, const isminefilter& filter) const
268 BOOST_FOREACH(const CTxIn& txin, tx.vin)
270 nDebit += GetDebit(txin, filter);
271 if (!MoneyRange(nDebit))
272 throw std::runtime_error("CWallet::GetDebit() : value out of range");
276 int64 GetCredit(const CTransaction& tx, const isminefilter& filter) const
279 BOOST_FOREACH(const CTxOut& txout, tx.vout)
281 nCredit += GetCredit(txout, filter);
282 if (!MoneyRange(nCredit))
283 throw std::runtime_error("CWallet::GetCredit() : value out of range");
287 int64 GetChange(const CTransaction& tx) const
290 BOOST_FOREACH(const CTxOut& txout, tx.vout)
292 nChange += GetChange(txout);
293 if (!MoneyRange(nChange))
294 throw std::runtime_error("CWallet::GetChange() : value out of range");
298 void SetBestChain(const CBlockLocator& loc);
300 DBErrors LoadWallet(bool& fFirstRunRet);
302 bool SetAddressBookName(const CTxDestination& address, const std::string& strName);
304 bool DelAddressBookName(const CTxDestination& address);
306 void UpdatedTransaction(const uint256 &hashTx);
308 void PrintWallet(const CBlock& block);
310 void Inventory(const uint256 &hash)
314 std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
315 if (mi != mapRequestCount.end())
320 unsigned int GetKeyPoolSize()
322 return setKeyPool.size();
325 bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx);
327 bool SetDefaultKey(const CPubKey &vchPubKey);
329 // signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower
330 bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = NULL, bool fExplicit = false);
332 // change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format)
333 bool SetMaxVersion(int nVersion);
335 // get the current wallet format (the oldest client version guaranteed to understand this wallet)
336 int GetVersion() { return nWalletVersion; }
338 void FixSpentCoins(int& nMismatchSpent, int64& nBalanceInQuestion, bool fCheckOnly = false);
339 void DisableTransaction(const CTransaction &tx);
341 /** Address book entry changed.
342 * @note called with lock cs_wallet held.
344 boost::signals2::signal<void (CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, ChangeType status)> NotifyAddressBookChanged;
346 /** Wallet transaction added, removed or updated.
347 * @note called with lock cs_wallet held.
349 boost::signals2::signal<void (CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged;
352 /** A key allocated from the key pool. */
360 CReserveKey(CWallet* pwalletIn)
373 CPubKey GetReservedKey();
378 typedef std::map<std::string, std::string> mapValue_t;
381 static void ReadOrderPos(int64& nOrderPos, mapValue_t& mapValue)
383 if (!mapValue.count("n"))
385 nOrderPos = -1; // TODO: calculate elsewhere
388 nOrderPos = atoi64(mapValue["n"].c_str());
392 static void WriteOrderPos(const int64& nOrderPos, mapValue_t& mapValue)
396 mapValue["n"] = i64tostr(nOrderPos);
400 /** A transaction with a bunch of additional info that only the owner cares about.
401 * It includes any unrecorded transactions needed to link it back to the block chain.
403 class CWalletTx : public CMerkleTx
406 const CWallet* pwallet;
409 std::vector<CMerkleTx> vtxPrev;
411 std::vector<std::pair<std::string, std::string> > vOrderForm;
412 unsigned int fTimeReceivedIsTxTime;
413 unsigned int nTimeReceived; // time received by this node
414 unsigned int nTimeSmart;
416 std::string strFromAccount;
417 std::vector<char> vfSpent; // which outputs are already spent
418 int64 nOrderPos; // position in ordered transaction list
421 mutable bool fDebitCached;
422 mutable bool fWatchDebitCached;
423 mutable bool fCreditCached;
424 mutable bool fWatchCreditCached;
425 mutable bool fAvailableCreditCached;
426 mutable bool fImmatureCreditCached;
427 mutable bool fImmatureWatchCreditCached;
428 mutable bool fAvailableWatchCreditCached;
429 mutable bool fChangeCached;
430 mutable int64 nDebitCached;
431 mutable int64 nWatchDebitCached;
432 mutable int64 nCreditCached;
433 mutable int64 nWatchCreditCached;
434 mutable int64 nAvailableCreditCached;
435 mutable int64 nImmatureCreditCached;
436 mutable int64 nImmatureWatchCreditCached;
437 mutable int64 nAvailableWatchCreditCached;
438 mutable int64 nChangeCached;
445 CWalletTx(const CWallet* pwalletIn)
450 CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn) : CMerkleTx(txIn)
455 CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn) : CMerkleTx(txIn)
460 void Init(const CWallet* pwalletIn)
466 fTimeReceivedIsTxTime = false;
470 strFromAccount.clear();
472 fDebitCached = false;
473 fWatchDebitCached = false;
474 fCreditCached = false;
475 fWatchCreditCached = false;
476 fAvailableCreditCached = false;
477 fAvailableWatchCreditCached = false;
478 fImmatureCreditCached = false;
479 fImmatureWatchCreditCached = false;
480 fChangeCached = false;
482 nWatchDebitCached = 0;
484 nWatchCreditCached = 0;
485 nAvailableCreditCached = 0;
486 nAvailableWatchCreditCached = 0;
487 nImmatureCreditCached = 0;
488 nImmatureWatchCreditCached = 0;
495 CWalletTx* pthis = const_cast<CWalletTx*>(this);
502 pthis->mapValue["fromaccount"] = pthis->strFromAccount;
505 BOOST_FOREACH(char f, vfSpent)
507 str += (f ? '1' : '0');
511 pthis->mapValue["spent"] = str;
513 WriteOrderPos(pthis->nOrderPos, pthis->mapValue);
516 pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart);
519 nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action);
522 READWRITE(vOrderForm);
523 READWRITE(fTimeReceivedIsTxTime);
524 READWRITE(nTimeReceived);
530 pthis->strFromAccount = pthis->mapValue["fromaccount"];
532 if (mapValue.count("spent"))
533 BOOST_FOREACH(char c, pthis->mapValue["spent"])
534 pthis->vfSpent.push_back(c != '0');
536 pthis->vfSpent.assign(vout.size(), fSpent);
538 ReadOrderPos(pthis->nOrderPos, pthis->mapValue);
540 pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0;
543 pthis->mapValue.erase("fromaccount");
544 pthis->mapValue.erase("version");
545 pthis->mapValue.erase("spent");
546 pthis->mapValue.erase("n");
547 pthis->mapValue.erase("timesmart");
550 // marks certain txout's as spent
551 // returns true if any update took place
552 bool UpdateSpent(const std::vector<char>& vfNewSpent)
554 bool fReturn = false;
555 for (unsigned int i = 0; i < vfNewSpent.size(); i++)
557 if (i == vfSpent.size())
560 if (vfNewSpent[i] && !vfSpent[i])
564 fAvailableCreditCached = fAvailableWatchCreditCached = false;
570 // make sure balances are recalculated
573 fCreditCached = false;
574 fAvailableCreditCached = fAvailableWatchCreditCached = false;
575 fDebitCached = fWatchDebitCached = false;
576 fChangeCached = false;
579 void BindWallet(CWallet *pwalletIn)
585 void MarkSpent(unsigned int nOut)
587 if (nOut >= vout.size())
588 throw std::runtime_error("CWalletTx::MarkSpent() : nOut out of range");
589 vfSpent.resize(vout.size());
592 vfSpent[nOut] = true;
593 fAvailableCreditCached = fAvailableWatchCreditCached = false;
597 void MarkUnspent(unsigned int nOut)
599 if (nOut >= vout.size())
600 throw std::runtime_error("CWalletTx::MarkUnspent() : nOut out of range");
601 vfSpent.resize(vout.size());
604 vfSpent[nOut] = false;
605 fAvailableCreditCached = fAvailableWatchCreditCached = false;
609 bool IsSpent(unsigned int nOut) const
611 if (nOut >= vout.size())
612 throw std::runtime_error("CWalletTx::IsSpent() : nOut out of range");
613 if (nOut >= vfSpent.size())
615 return (!!vfSpent[nOut]);
618 int64 GetDebit(const isminefilter& filter) const
624 if (filter & MINE_SPENDABLE)
627 nDebit += nDebitCached;
630 nDebitCached = pwallet->GetDebit(*this, MINE_SPENDABLE);
632 nDebit += nDebitCached;
635 if (filter & MINE_WATCH_ONLY)
637 if (fWatchDebitCached)
638 nDebit += nWatchDebitCached;
641 nWatchDebitCached = pwallet->GetDebit(*this, MINE_WATCH_ONLY);
642 fWatchDebitCached = true;
643 nDebit += nWatchDebitCached;
650 int64 GetCredit(bool fUseCache=true) const
652 // Must wait until coinbase is safely deep enough in the chain before valuing it
653 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
656 // GetBalance can assume transactions in mapWallet won't change
659 return nCreditCached;
662 nCreditCached = pwallet->GetCredit(*this, MINE_ALL);
663 fCreditCached = true;
665 return nCreditCached;
668 int64 GetImmatureCredit(bool fUseCache=true) const
670 if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
672 if (fUseCache && fImmatureCreditCached)
673 return nImmatureCreditCached;
674 nImmatureCreditCached = pwallet->GetCredit(*this, MINE_SPENDABLE);
675 fImmatureCreditCached = true;
676 return nImmatureCreditCached;
682 int64 GetImmatureWatchOnlyCredit(bool fUseCache=true) const
684 if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
686 if (fUseCache && fImmatureWatchCreditCached)
687 return nImmatureWatchCreditCached;
688 nImmatureWatchCreditCached = pwallet->GetCredit(*this, MINE_WATCH_ONLY);
689 fImmatureWatchCreditCached = true;
690 return nImmatureWatchCreditCached;
697 int64 GetAvailableCredit(bool fUseCache=true) const
699 // Must wait until coinbase is safely deep enough in the chain before valuing it
700 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
704 if (fAvailableCreditCached)
705 return nAvailableCreditCached;
709 for (unsigned int i = 0; i < vout.size(); i++)
713 const CTxOut &txout = vout[i];
714 nCredit += pwallet->GetCredit(txout, MINE_SPENDABLE);
715 if (!MoneyRange(nCredit))
716 throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
720 nAvailableCreditCached = nCredit;
721 fAvailableCreditCached = true;
726 int64 GetAvailableWatchCredit(bool fUseCache=true) const
728 // Must wait until coinbase is safely deep enough in the chain before valuing it
729 if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0)
733 if (fAvailableWatchCreditCached)
734 return nAvailableWatchCreditCached;
738 for (unsigned int i = 0; i < vout.size(); i++)
742 const CTxOut &txout = vout[i];
743 nCredit += pwallet->GetCredit(txout, MINE_WATCH_ONLY);
744 if (!MoneyRange(nCredit))
745 throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
749 nAvailableWatchCreditCached = nCredit;
750 fAvailableWatchCreditCached = true;
755 int64 GetChange() const
758 return nChangeCached;
759 nChangeCached = pwallet->GetChange(*this);
760 fChangeCached = true;
761 return nChangeCached;
764 void GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, std::list<std::pair<CTxDestination, int64> >& listReceived,
765 std::list<std::pair<CTxDestination, int64> >& listSent, int64& nFee, std::string& strSentAccount, const isminefilter& filter) const;
767 void GetAccountAmounts(const std::string& strAccount, int64& nGenerated, int64& nReceived,
768 int64& nSent, int64& nFee, const isminefilter& filter) const;
770 bool IsFromMe(const isminefilter& filter) const
772 return (GetDebit(filter) > 0);
775 bool IsTrusted() const
777 // Quick answer in most cases
780 if (GetDepthInMainChain() >= 1)
782 if (fConfChange || !IsFromMe(MINE_ALL)) // using wtx's cached debit
785 // If no confirmations but it's from us, we can still
786 // consider it confirmed if all dependencies are confirmed
787 std::map<uint256, const CMerkleTx*> mapPrev;
788 std::vector<const CMerkleTx*> vWorkQueue;
789 vWorkQueue.reserve(vtxPrev.size()+1);
790 vWorkQueue.push_back(this);
791 for (unsigned int i = 0; i < vWorkQueue.size(); i++)
793 const CMerkleTx* ptx = vWorkQueue[i];
797 if (ptx->GetDepthInMainChain() >= 1)
799 if (!pwallet->IsFromMe(*ptx))
804 BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
805 mapPrev[tx.GetHash()] = &tx;
808 BOOST_FOREACH(const CTxIn& txin, ptx->vin)
810 if (!mapPrev.count(txin.prevout.hash))
812 vWorkQueue.push_back(mapPrev[txin.prevout.hash]);
821 int64 GetTxTime() const;
822 int GetRequestCount() const;
824 void AddSupportingTransactions(CTxDB& txdb);
826 bool AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs=true);
827 bool AcceptWalletTransaction();
829 void RelayWalletTransaction(CTxDB& txdb);
830 void RelayWalletTransaction();
844 COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn)
846 tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn;
849 std::string ToString() const
851 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());
856 printf("%s\n", ToString().c_str());
863 /** Private key that includes an expiration date in case it never gets used. */
870 std::string strComment;
871 //// todo: add something to note what created it (user, getnewaddress, change)
872 //// maybe should have a map<string, string> property map
874 CWalletKey(int64 nExpires=0)
876 nTimeCreated = (nExpires ? GetTime() : 0);
877 nTimeExpires = nExpires;
882 if (!(nType & SER_GETHASH))
884 READWRITE(vchPrivKey);
885 READWRITE(nTimeCreated);
886 READWRITE(nTimeExpires);
887 READWRITE(strComment);
896 /** Account information.
897 * Stored in wallet with key "acc"+string account name.
911 vchPubKey = CPubKey();
916 if (!(nType & SER_GETHASH))
918 READWRITE(vchPubKey);
924 /** Internal transfers.
925 * Database key is acentry<account><counter>.
927 class CAccountingEntry
930 std::string strAccount;
933 std::string strOtherAccount;
934 std::string strComment;
936 int64 nOrderPos; // position in ordered transaction list
949 strOtherAccount.clear();
956 CAccountingEntry& me = *const_cast<CAccountingEntry*>(this);
957 if (!(nType & SER_GETHASH))
959 // Note: strAccount is serialized as part of the key, not here.
960 READWRITE(nCreditDebit);
962 READWRITE(strOtherAccount);
966 WriteOrderPos(nOrderPos, me.mapValue);
968 if (!(mapValue.empty() && _ssExtra.empty()))
970 CDataStream ss(nType, nVersion);
971 ss.insert(ss.begin(), '\0');
973 ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
974 me.strComment.append(ss.str());
978 READWRITE(strComment);
980 size_t nSepPos = strComment.find("\0", 0, 1);
984 if (std::string::npos != nSepPos)
986 CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion);
988 me._ssExtra = std::vector<char>(ss.begin(), ss.end());
990 ReadOrderPos(me.nOrderPos, me.mapValue);
992 if (std::string::npos != nSepPos)
993 me.strComment.erase(nSepPos);
995 me.mapValue.erase("n");
999 std::vector<char> _ssExtra;
1002 bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);