1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
10 void ThreadFlushWalletDB(void* parg);
13 unsigned int nWalletDBUpdated;
14 uint64 nAccountingEntryNumber = 0;
22 static CCriticalSection cs_db;
23 static bool fDbEnvInit = false;
25 static map<string, int> mapFileUseCount;
26 static map<string, Db*> mapDb;
46 CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL)
52 fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
53 bool fCreate = strchr(pszMode, 'c');
54 unsigned int nFlags = DB_THREAD;
64 string strDataDir = GetDataDir();
65 string strLogDir = strDataDir + "/database";
66 filesystem::create_directory(strLogDir.c_str());
67 string strErrorFile = strDataDir + "/db.log";
68 printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str());
70 dbenv.set_lg_dir(strLogDir.c_str());
71 dbenv.set_lg_max(10000000);
72 dbenv.set_lk_max_locks(10000);
73 dbenv.set_lk_max_objects(10000);
74 dbenv.set_errfile(fopen(strErrorFile.c_str(), "a")); /// debug
75 dbenv.set_flags(DB_AUTO_COMMIT, 1);
76 ret = dbenv.open(strDataDir.c_str(),
86 throw runtime_error(strprintf("CDB() : error %d opening database environment", ret));
91 ++mapFileUseCount[strFile];
95 pdb = new Db(&dbenv, 0);
97 ret = pdb->open(NULL, // Txn pointer
99 "main", // Logical db name
100 DB_BTREE, // Database type
108 CRITICAL_BLOCK(cs_db)
109 --mapFileUseCount[strFile];
111 throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret));
114 if (fCreate && !Exists(string("version")))
116 bool fTmp = fReadOnly;
118 WriteVersion(VERSION);
122 mapDb[strFile] = pdb;
132 vTxn.front()->abort();
136 // Flush database activity from memory pool to disk log
137 unsigned int nMinutes = 0;
140 if (strFile == "addr.dat")
142 if (strFile == "blkindex.dat" && IsInitialBlockDownload() && nBestHeight % 500 != 0)
144 dbenv.txn_checkpoint(0, nMinutes, 0);
146 CRITICAL_BLOCK(cs_db)
147 --mapFileUseCount[strFile];
150 void CloseDb(const string& strFile)
152 CRITICAL_BLOCK(cs_db)
154 if (mapDb[strFile] != NULL)
156 // Close the database handle
157 Db* pdb = mapDb[strFile];
160 mapDb[strFile] = NULL;
165 void DBFlush(bool fShutdown)
167 // Flush log data to the actual data file
168 // on all files that are not in use
169 printf("DBFlush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started");
172 CRITICAL_BLOCK(cs_db)
174 map<string, int>::iterator mi = mapFileUseCount.begin();
175 while (mi != mapFileUseCount.end())
177 string strFile = (*mi).first;
178 int nRefCount = (*mi).second;
179 printf("%s refcount=%d\n", strFile.c_str(), nRefCount);
182 // Move log data to the dat file
184 dbenv.txn_checkpoint(0, 0, 0);
185 printf("%s flush\n", strFile.c_str());
186 dbenv.lsn_reset(strFile.c_str(), 0);
187 mapFileUseCount.erase(mi++);
195 if (mapFileUseCount.empty())
196 dbenv.log_archive(&listp, DB_ARCH_REMOVE);
212 bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex)
216 return Read(make_pair(string("tx"), hash), txindex);
219 bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex)
222 return Write(make_pair(string("tx"), hash), txindex);
225 bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight)
230 uint256 hash = tx.GetHash();
231 CTxIndex txindex(pos, tx.vout.size());
232 return Write(make_pair(string("tx"), hash), txindex);
235 bool CTxDB::EraseTxIndex(const CTransaction& tx)
238 uint256 hash = tx.GetHash();
240 return Erase(make_pair(string("tx"), hash));
243 bool CTxDB::ContainsTx(uint256 hash)
246 return Exists(make_pair(string("tx"), hash));
249 bool CTxDB::ReadOwnerTxes(uint160 hash160, int nMinHeight, vector<CTransaction>& vtx)
255 Dbc* pcursor = GetCursor();
259 unsigned int fFlags = DB_SET_RANGE;
264 if (fFlags == DB_SET_RANGE)
265 ssKey << string("owner") << hash160 << CDiskTxPos(0, 0, 0);
267 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
269 if (ret == DB_NOTFOUND)
281 ssKey >> strType >> hashItem >> pos;
283 ssValue >> nItemHeight;
286 if (strType != "owner" || hashItem != hash160)
288 if (nItemHeight >= nMinHeight)
290 vtx.resize(vtx.size()+1);
291 if (!vtx.back().ReadFromDisk(pos))
303 bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex)
307 if (!ReadTxIndex(hash, txindex))
309 return (tx.ReadFromDisk(txindex.pos));
312 bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx)
315 return ReadDiskTx(hash, tx, txindex);
318 bool CTxDB::ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex)
320 return ReadDiskTx(outpoint.hash, tx, txindex);
323 bool CTxDB::ReadDiskTx(COutPoint outpoint, CTransaction& tx)
326 return ReadDiskTx(outpoint.hash, tx, txindex);
329 bool CTxDB::WriteBlockIndex(const CDiskBlockIndex& blockindex)
331 return Write(make_pair(string("blockindex"), blockindex.GetBlockHash()), blockindex);
334 bool CTxDB::EraseBlockIndex(uint256 hash)
336 return Erase(make_pair(string("blockindex"), hash));
339 bool CTxDB::ReadHashBestChain(uint256& hashBestChain)
341 return Read(string("hashBestChain"), hashBestChain);
344 bool CTxDB::WriteHashBestChain(uint256 hashBestChain)
346 return Write(string("hashBestChain"), hashBestChain);
349 bool CTxDB::ReadBestInvalidWork(CBigNum& bnBestInvalidWork)
351 return Read(string("bnBestInvalidWork"), bnBestInvalidWork);
354 bool CTxDB::WriteBestInvalidWork(CBigNum bnBestInvalidWork)
356 return Write(string("bnBestInvalidWork"), bnBestInvalidWork);
359 CBlockIndex* InsertBlockIndex(uint256 hash)
365 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
366 if (mi != mapBlockIndex.end())
370 CBlockIndex* pindexNew = new CBlockIndex();
372 throw runtime_error("LoadBlockIndex() : new CBlockIndex failed");
373 mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
374 pindexNew->phashBlock = &((*mi).first);
379 bool CTxDB::LoadBlockIndex()
381 // Get database cursor
382 Dbc* pcursor = GetCursor();
386 // Load mapBlockIndex
387 unsigned int fFlags = DB_SET_RANGE;
392 if (fFlags == DB_SET_RANGE)
393 ssKey << make_pair(string("blockindex"), uint256(0));
395 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
397 if (ret == DB_NOTFOUND)
405 if (strType == "blockindex")
407 CDiskBlockIndex diskindex;
408 ssValue >> diskindex;
410 // Construct block index object
411 CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
412 pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
413 pindexNew->pnext = InsertBlockIndex(diskindex.hashNext);
414 pindexNew->nFile = diskindex.nFile;
415 pindexNew->nBlockPos = diskindex.nBlockPos;
416 pindexNew->nHeight = diskindex.nHeight;
417 pindexNew->nVersion = diskindex.nVersion;
418 pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
419 pindexNew->nTime = diskindex.nTime;
420 pindexNew->nBits = diskindex.nBits;
421 pindexNew->nNonce = diskindex.nNonce;
423 // Watch for genesis block
424 if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == hashGenesisBlock)
425 pindexGenesisBlock = pindexNew;
427 if (!pindexNew->CheckIndex())
428 return error("LoadBlockIndex() : CheckIndex failed at %d", pindexNew->nHeight);
437 // Calculate bnChainWork
438 vector<pair<int, CBlockIndex*> > vSortedByHeight;
439 vSortedByHeight.reserve(mapBlockIndex.size());
440 BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
442 CBlockIndex* pindex = item.second;
443 vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
445 sort(vSortedByHeight.begin(), vSortedByHeight.end());
446 BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
448 CBlockIndex* pindex = item.second;
449 pindex->bnChainWork = (pindex->pprev ? pindex->pprev->bnChainWork : 0) + pindex->GetBlockWork();
452 // Load hashBestChain pointer to end of best chain
453 if (!ReadHashBestChain(hashBestChain))
455 if (pindexGenesisBlock == NULL)
457 return error("CTxDB::LoadBlockIndex() : hashBestChain not loaded");
459 if (!mapBlockIndex.count(hashBestChain))
460 return error("CTxDB::LoadBlockIndex() : hashBestChain not found in the block index");
461 pindexBest = mapBlockIndex[hashBestChain];
462 nBestHeight = pindexBest->nHeight;
463 bnBestChainWork = pindexBest->bnChainWork;
464 printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight);
466 // Load bnBestInvalidWork, OK if it doesn't exist
467 ReadBestInvalidWork(bnBestInvalidWork);
469 // Verify blocks in the best chain
470 CBlockIndex* pindexFork = NULL;
471 for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
473 if (pindex->nHeight < nBestHeight-2500 && !mapArgs.count("-checkblocks"))
476 if (!block.ReadFromDisk(pindex))
477 return error("LoadBlockIndex() : block.ReadFromDisk failed");
478 if (!block.CheckBlock())
480 printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
481 pindexFork = pindex->pprev;
486 // Reorg back to the fork
487 printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight);
489 if (!block.ReadFromDisk(pindexFork))
490 return error("LoadBlockIndex() : block.ReadFromDisk failed");
492 block.SetBestChain(txdb, pindexFork);
506 bool CAddrDB::WriteAddress(const CAddress& addr)
508 return Write(make_pair(string("addr"), addr.GetKey()), addr);
511 bool CAddrDB::EraseAddress(const CAddress& addr)
513 return Erase(make_pair(string("addr"), addr.GetKey()));
516 bool CAddrDB::LoadAddresses()
518 CRITICAL_BLOCK(cs_mapAddresses)
520 // Load user provided addresses
521 CAutoFile filein = fopen((GetDataDir() + "/addr.txt").c_str(), "rt");
527 while (fgets(psz, sizeof(psz), filein))
529 CAddress addr(psz, NODE_NETWORK);
530 addr.nTime = 0; // so it won't relay unless successfully connected
539 Dbc* pcursor = GetCursor();
548 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
549 if (ret == DB_NOTFOUND)
557 if (strType == "addr")
561 mapAddresses.insert(make_pair(addr.GetKey(), addr));
566 printf("Loaded %d addresses\n", mapAddresses.size());
574 return CAddrDB("cr+").LoadAddresses();
584 static set<int64> setKeyPool;
585 static CCriticalSection cs_setKeyPool;
587 bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account)
590 return Read(make_pair(string("acc"), strAccount), account);
593 bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
595 return Write(make_pair(string("acc"), strAccount), account);
598 bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
600 return Write(make_tuple(string("acentry"), acentry.strAccount, ++nAccountingEntryNumber), acentry);
603 int64 CWalletDB::GetAccountCreditDebit(const string& strAccount)
605 list<CAccountingEntry> entries;
606 ListAccountCreditDebit(strAccount, entries);
608 int64 nCreditDebit = 0;
609 BOOST_FOREACH (const CAccountingEntry& entry, entries)
610 nCreditDebit += entry.nCreditDebit;
615 void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
617 int64 nCreditDebit = 0;
619 bool fAllAccounts = (strAccount == "*");
621 Dbc* pcursor = GetCursor();
623 throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");
624 unsigned int fFlags = DB_SET_RANGE;
629 if (fFlags == DB_SET_RANGE)
630 ssKey << make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64(0));
632 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
634 if (ret == DB_NOTFOUND)
639 throw runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB");
645 if (strType != "acentry")
647 CAccountingEntry acentry;
648 ssKey >> acentry.strAccount;
649 if (!fAllAccounts && acentry.strAccount != strAccount)
653 entries.push_back(acentry);
660 bool CWalletDB::LoadWallet()
662 vchDefaultKey.clear();
663 int nFileVersion = 0;
664 vector<uint256> vWalletUpgrade;
668 // Tray icon sometimes disappears on 9.10 karmic koala 64-bit, leaving no way to access the program
669 fMinimizeToTray = false;
670 fMinimizeOnClose = false;
673 //// todo: shouldn't we catch exceptions and try to recover and continue?
674 CRITICAL_BLOCK(cs_mapWallet)
675 CRITICAL_BLOCK(cs_mapKeys)
678 Dbc* pcursor = GetCursor();
687 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
688 if (ret == DB_NOTFOUND)
694 // Taking advantage of the fact that pair serialization
695 // is just the two items serialized one after the other
698 if (strType == "name")
702 ssValue >> mapAddressBook[strAddress];
704 else if (strType == "tx")
708 CWalletTx& wtx = mapWallet[hash];
711 if (wtx.GetHash() != hash)
712 printf("Error in wallet.dat, hash mismatch\n");
714 // Undo serialize changes in 31600
715 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
717 if (!ssValue.empty())
721 ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
722 printf("LoadWallet() upgrading tx ver=%d %d '%s' %s\n", wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount.c_str(), hash.ToString().c_str());
723 wtx.fTimeReceivedIsTxTime = fTmp;
727 printf("LoadWallet() repairing tx ver=%d %s\n", wtx.fTimeReceivedIsTxTime, hash.ToString().c_str());
728 wtx.fTimeReceivedIsTxTime = 0;
730 vWalletUpgrade.push_back(hash);
734 //printf("LoadWallet %s\n", wtx.GetHash().ToString().c_str());
735 //printf(" %12I64d %s %s %s\n",
736 // wtx.vout[0].nValue,
737 // DateTimeStrFormat("%x %H:%M:%S", wtx.GetBlockTime()).c_str(),
738 // wtx.hashBlock.ToString().substr(0,20).c_str(),
739 // wtx.mapValue["message"].c_str());
741 else if (strType == "acentry")
747 if (nNumber > nAccountingEntryNumber)
748 nAccountingEntryNumber = nNumber;
750 else if (strType == "key" || strType == "wkey")
752 vector<unsigned char> vchPubKey;
755 if (strType == "key")
756 ssValue >> wkey.vchPrivKey;
760 mapKeys[vchPubKey] = wkey.vchPrivKey;
761 mapPubKeys[Hash160(vchPubKey)] = vchPubKey;
763 else if (strType == "defaultkey")
765 ssValue >> vchDefaultKey;
767 else if (strType == "pool")
771 setKeyPool.insert(nIndex);
773 else if (strType == "version")
775 ssValue >> nFileVersion;
776 if (nFileVersion == 10300)
779 else if (strType == "setting")
786 if (strKey == "fGenerateBitcoins") ssValue >> fGenerateBitcoins;
788 if (strKey == "nTransactionFee") ssValue >> nTransactionFee;
789 if (strKey == "addrIncoming") ssValue >> addrIncoming;
790 if (strKey == "fLimitProcessors") ssValue >> fLimitProcessors;
791 if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors;
792 if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray;
793 if (strKey == "fMinimizeOnClose") ssValue >> fMinimizeOnClose;
794 if (strKey == "fUseProxy") ssValue >> fUseProxy;
795 if (strKey == "addrProxy") ssValue >> addrProxy;
796 if (fHaveUPnP && strKey == "fUseUPnP") ssValue >> fUseUPnP;
802 BOOST_FOREACH(uint256 hash, vWalletUpgrade)
803 WriteTx(hash, mapWallet[hash]);
805 printf("nFileVersion = %d\n", nFileVersion);
806 printf("fGenerateBitcoins = %d\n", fGenerateBitcoins);
807 printf("nTransactionFee = %"PRI64d"\n", nTransactionFee);
808 printf("addrIncoming = %s\n", addrIncoming.ToString().c_str());
809 printf("fMinimizeToTray = %d\n", fMinimizeToTray);
810 printf("fMinimizeOnClose = %d\n", fMinimizeOnClose);
811 printf("fUseProxy = %d\n", fUseProxy);
812 printf("addrProxy = %s\n", addrProxy.ToString().c_str());
814 printf("fUseUPnP = %d\n", fUseUPnP);
818 if (nFileVersion < VERSION)
820 // Get rid of old debug.log file in current directory
821 if (nFileVersion <= 105 && !pszSetDataDir[0])
824 WriteVersion(VERSION);
831 bool LoadWallet(bool& fFirstRunRet)
833 fFirstRunRet = false;
834 if (!CWalletDB("cr+").LoadWallet())
836 fFirstRunRet = vchDefaultKey.empty();
838 if (mapKeys.count(vchDefaultKey))
841 keyUser.SetPubKey(vchDefaultKey);
842 keyUser.SetPrivKey(mapKeys[vchDefaultKey]);
846 // Create new keyUser and set as default key
847 RandAddSeedPerfmon();
850 vchDefaultKey = GetKeyFromKeyPool();
851 walletdb.WriteDefaultKey(vchDefaultKey);
852 walletdb.WriteName(PubKeyToAddress(vchDefaultKey), "");
855 CreateThread(ThreadFlushWalletDB, NULL);
859 void ThreadFlushWalletDB(void* parg)
861 static bool fOneThread;
865 if (mapArgs.count("-noflushwallet"))
868 unsigned int nLastSeen = nWalletDBUpdated;
869 unsigned int nLastFlushed = nWalletDBUpdated;
870 int64 nLastWalletUpdate = GetTime();
875 if (nLastSeen != nWalletDBUpdated)
877 nLastSeen = nWalletDBUpdated;
878 nLastWalletUpdate = GetTime();
881 if (nLastFlushed != nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2)
883 TRY_CRITICAL_BLOCK(cs_db)
885 // Don't do this if any databases are in use
887 map<string, int>::iterator mi = mapFileUseCount.begin();
888 while (mi != mapFileUseCount.end())
890 nRefCount += (*mi).second;
894 if (nRefCount == 0 && !fShutdown)
896 string strFile = "wallet.dat";
897 map<string, int>::iterator mi = mapFileUseCount.find(strFile);
898 if (mi != mapFileUseCount.end())
900 printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
901 printf("Flushing wallet.dat\n");
902 nLastFlushed = nWalletDBUpdated;
903 int64 nStart = GetTimeMillis();
905 // Flush wallet.dat so it's self contained
907 dbenv.txn_checkpoint(0, 0, 0);
908 dbenv.lsn_reset(strFile.c_str(), 0);
910 mapFileUseCount.erase(mi++);
911 printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart);
919 void BackupWallet(const string& strDest)
923 CRITICAL_BLOCK(cs_db)
925 const string strFile = "wallet.dat";
926 if (!mapFileUseCount.count(strFile) || mapFileUseCount[strFile] == 0)
928 // Flush log data to the dat file
930 dbenv.txn_checkpoint(0, 0, 0);
931 dbenv.lsn_reset(strFile.c_str(), 0);
932 mapFileUseCount.erase(strFile);
935 filesystem::path pathSrc(GetDataDir() + "/" + strFile);
936 filesystem::path pathDest(strDest);
937 if (filesystem::is_directory(pathDest))
938 pathDest = pathDest / strFile;
939 #if BOOST_VERSION >= 104000
940 filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists);
942 filesystem::copy_file(pathSrc, pathDest);
944 printf("copied wallet.dat to %s\n", pathDest.string().c_str());
954 void CWalletDB::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool)
957 keypool.vchPubKey.clear();
958 CRITICAL_BLOCK(cs_main)
959 CRITICAL_BLOCK(cs_mapWallet)
960 CRITICAL_BLOCK(cs_setKeyPool)
963 int64 nTargetSize = max(GetArg("-keypool", 100), (int64)0);
964 while (setKeyPool.size() < nTargetSize+1)
967 if (!setKeyPool.empty())
968 nEnd = *(--setKeyPool.end()) + 1;
969 if (!Write(make_pair(string("pool"), nEnd), CKeyPool(GenerateNewKey())))
970 throw runtime_error("ReserveKeyFromKeyPool() : writing generated key failed");
971 setKeyPool.insert(nEnd);
972 printf("keypool added key %"PRI64d", size=%d\n", nEnd, setKeyPool.size());
975 // Get the oldest key
976 assert(!setKeyPool.empty());
977 nIndex = *(setKeyPool.begin());
978 setKeyPool.erase(setKeyPool.begin());
979 if (!Read(make_pair(string("pool"), nIndex), keypool))
980 throw runtime_error("ReserveKeyFromKeyPool() : read failed");
981 if (!mapKeys.count(keypool.vchPubKey))
982 throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool");
983 assert(!keypool.vchPubKey.empty());
984 printf("keypool reserve %"PRI64d"\n", nIndex);
988 void CWalletDB::KeepKey(int64 nIndex)
990 // Remove from key pool
991 CRITICAL_BLOCK(cs_main)
992 CRITICAL_BLOCK(cs_mapWallet)
994 Erase(make_pair(string("pool"), nIndex));
996 printf("keypool keep %"PRI64d"\n", nIndex);
999 void CWalletDB::ReturnKey(int64 nIndex)
1001 // Return to key pool
1002 CRITICAL_BLOCK(cs_setKeyPool)
1003 setKeyPool.insert(nIndex);
1004 printf("keypool return %"PRI64d"\n", nIndex);
1007 vector<unsigned char> GetKeyFromKeyPool()
1012 walletdb.ReserveKeyFromKeyPool(nIndex, keypool);
1013 walletdb.KeepKey(nIndex);
1014 return keypool.vchPubKey;
1017 int64 GetOldestKeyPoolTime()
1022 walletdb.ReserveKeyFromKeyPool(nIndex, keypool);
1023 walletdb.ReturnKey(nIndex);
1024 return keypool.nTime;