aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/addrman.cpp5
-rw-r--r--src/addrman.h6
-rw-r--r--src/alert.cpp10
-rw-r--r--src/bitcoinrpc.cpp10
-rw-r--r--src/core.cpp18
-rw-r--r--src/db.cpp30
-rw-r--r--src/init.cpp72
-rw-r--r--src/leveldb.cpp8
-rw-r--r--src/leveldb.h5
-rw-r--r--src/main.cpp150
-rw-r--r--src/main.h4
-rw-r--r--src/miner.cpp24
-rw-r--r--src/net.cpp95
-rw-r--r--src/net.h15
-rw-r--r--src/netbase.cpp26
-rw-r--r--src/noui.cpp4
-rw-r--r--src/protocol.cpp4
-rw-r--r--src/qt/bitcoin.cpp8
-rw-r--r--src/rpcdump.cpp8
-rw-r--r--src/script.cpp4
-rw-r--r--src/script.h4
-rw-r--r--src/sync.cpp26
-rw-r--r--src/txdb.cpp2
-rw-r--r--src/uint256.h94
-rw-r--r--src/util.cpp36
-rw-r--r--src/util.h27
-rw-r--r--src/wallet.cpp57
-rw-r--r--src/wallet.h2
-rw-r--r--src/walletdb.cpp34
29 files changed, 389 insertions, 399 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index 780edde90f..731ff2abed 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -261,8 +261,6 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId, int nOrigin)
void CAddrMan::Good_(const CService &addr, int64 nTime)
{
-// printf("Good: addr=%s\n", addr.ToString().c_str());
-
int nId;
CAddrInfo *pinfo = Find(addr, &nId);
@@ -304,7 +302,7 @@ void CAddrMan::Good_(const CService &addr, int64 nTime)
// TODO: maybe re-add the node, but for now, just bail out
if (nUBucket == -1) return;
- printf("Moving %s to tried\n", addr.ToString().c_str());
+ LogPrint("addrman", "Moving %s to tried\n", addr.ToString().c_str());
// move nId to the tried tables
MakeTried(info, nId, nUBucket);
@@ -351,7 +349,6 @@ bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePen
} else {
pinfo = Create(addr, source, &nId);
pinfo->nTime = max((int64)0, (int64)pinfo->nTime - nTimePenalty);
-// printf("Added %s [nTime=%fhr]\n", pinfo->ToString().c_str(), (GetAdjustedTime() - pinfo->nTime) / 3600.0);
nNew++;
fNew = true;
}
diff --git a/src/addrman.h b/src/addrman.h
index 7af6afd78f..081543ace4 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -403,7 +403,7 @@ public:
LOCK(cs);
int err;
if ((err=Check_()))
- printf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
+ LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
}
#endif
}
@@ -419,7 +419,7 @@ public:
Check();
}
if (fRet)
- printf("Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew);
+ LogPrint("addr", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew);
return fRet;
}
@@ -435,7 +435,7 @@ public:
Check();
}
if (nAdd)
- printf("Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew);
+ LogPrint("addr", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew);
return nAdd > 0;
}
diff --git a/src/alert.cpp b/src/alert.cpp
index e00847aadb..c9cde17955 100644
--- a/src/alert.cpp
+++ b/src/alert.cpp
@@ -76,7 +76,7 @@ std::string CUnsignedAlert::ToString() const
void CUnsignedAlert::print() const
{
- printf("%s", ToString().c_str());
+ LogPrintf("%s", ToString().c_str());
}
void CAlert::SetNull()
@@ -200,13 +200,13 @@ bool CAlert::ProcessAlert(bool fThread)
const CAlert& alert = (*mi).second;
if (Cancels(alert))
{
- printf("cancelling alert %d\n", alert.nID);
+ LogPrint("alert", "cancelling alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else if (!alert.IsInEffect())
{
- printf("expiring alert %d\n", alert.nID);
+ LogPrint("alert", "expiring alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
@@ -220,7 +220,7 @@ bool CAlert::ProcessAlert(bool fThread)
const CAlert& alert = item.second;
if (alert.Cancels(*this))
{
- printf("alert already cancelled by %d\n", alert.nID);
+ LogPrint("alert", "alert already cancelled by %d\n", alert.nID);
return false;
}
}
@@ -258,6 +258,6 @@ bool CAlert::ProcessAlert(bool fThread)
}
}
- printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
+ LogPrint("alert", "accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
return true;
}
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index d1082c7ecf..b61e0d37ab 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -796,12 +796,12 @@ void StartRPCThreads()
filesystem::path pathCertFile(GetArg("-rpcsslcertificatechainfile", "server.cert"));
if (!pathCertFile.is_complete()) pathCertFile = filesystem::path(GetDataDir()) / pathCertFile;
if (filesystem::exists(pathCertFile)) rpc_ssl_context->use_certificate_chain_file(pathCertFile.string());
- else printf("ThreadRPCServer ERROR: missing server certificate file %s\n", pathCertFile.string().c_str());
+ else LogPrintf("ThreadRPCServer ERROR: missing server certificate file %s\n", pathCertFile.string().c_str());
filesystem::path pathPKFile(GetArg("-rpcsslprivatekeyfile", "server.pem"));
if (!pathPKFile.is_complete()) pathPKFile = filesystem::path(GetDataDir()) / pathPKFile;
if (filesystem::exists(pathPKFile)) rpc_ssl_context->use_private_key_file(pathPKFile.string(), ssl::context::pem);
- else printf("ThreadRPCServer ERROR: missing server private key file %s\n", pathPKFile.string().c_str());
+ else LogPrintf("ThreadRPCServer ERROR: missing server private key file %s\n", pathPKFile.string().c_str());
string strCiphers = GetArg("-rpcsslciphers", "TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH");
SSL_CTX_set_cipher_list(rpc_ssl_context->impl(), strCiphers.c_str());
@@ -931,7 +931,7 @@ void JSONRequest::parse(const Value& valRequest)
throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string");
strMethod = valMethod.get_str();
if (strMethod != "getwork" && strMethod != "getblocktemplate")
- printf("ThreadRPCServer method=%s\n", strMethod.c_str());
+ LogPrint("rpc", "ThreadRPCServer method=%s\n", strMethod.c_str());
// Parse params
Value valParams = find_value(request, "params");
@@ -1005,7 +1005,7 @@ void ServiceConnection(AcceptedConnection *conn)
}
if (!HTTPAuthorized(mapHeaders))
{
- printf("ThreadRPCServer incorrect password attempt from %s\n", conn->peer_address_to_string().c_str());
+ LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", conn->peer_address_to_string().c_str());
/* Deter brute-forcing short passwords.
If this results in a DOS the user really
shouldn't have their RPC port exposed.*/
@@ -1319,7 +1319,7 @@ int main(int argc, char *argv[])
{
if (argc >= 2 && string(argv[1]) == "-server")
{
- printf("server ready\n");
+ LogPrintf("server ready\n");
ThreadRPCServer(NULL);
}
else
diff --git a/src/core.cpp b/src/core.cpp
index afba0959cf..99b5c6641a 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -13,7 +13,7 @@ std::string COutPoint::ToString() const
void COutPoint::print() const
{
- printf("%s\n", ToString().c_str());
+ LogPrintf("%s\n", ToString().c_str());
}
CTxIn::CTxIn(COutPoint prevoutIn, CScript scriptSigIn, unsigned int nSequenceIn)
@@ -47,7 +47,7 @@ std::string CTxIn::ToString() const
void CTxIn::print() const
{
- printf("%s\n", ToString().c_str());
+ LogPrintf("%s\n", ToString().c_str());
}
CTxOut::CTxOut(int64 nValueIn, CScript scriptPubKeyIn)
@@ -70,7 +70,7 @@ std::string CTxOut::ToString() const
void CTxOut::print() const
{
- printf("%s\n", ToString().c_str());
+ LogPrintf("%s\n", ToString().c_str());
}
uint256 CTransaction::GetHash() const
@@ -125,7 +125,7 @@ std::string CTransaction::ToString() const
void CTransaction::print() const
{
- printf("%s", ToString().c_str());
+ LogPrintf("%s", ToString().c_str());
}
// Amount compression:
@@ -282,7 +282,7 @@ uint256 CBlock::CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMer
void CBlock::print() const
{
- printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu")\n",
+ LogPrintf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu")\n",
GetHash().ToString().c_str(),
nVersion,
hashPrevBlock.ToString().c_str(),
@@ -291,11 +291,11 @@ void CBlock::print() const
vtx.size());
for (unsigned int i = 0; i < vtx.size(); i++)
{
- printf(" ");
+ LogPrintf(" ");
vtx[i].print();
}
- printf(" vMerkleTree: ");
+ LogPrintf(" vMerkleTree: ");
for (unsigned int i = 0; i < vMerkleTree.size(); i++)
- printf("%s ", vMerkleTree[i].ToString().c_str());
- printf("\n");
+ LogPrintf("%s ", vMerkleTree[i].ToString().c_str());
+ LogPrintf("\n");
}
diff --git a/src/db.cpp b/src/db.cpp
index 03f46f3c26..f722c52e93 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -38,7 +38,7 @@ void CDBEnv::EnvShutdown()
fDbEnvInit = false;
int ret = dbenv.close(0);
if (ret != 0)
- printf("EnvShutdown exception: %s (%d)\n", DbEnv::strerror(ret), ret);
+ LogPrintf("EnvShutdown exception: %s (%d)\n", DbEnv::strerror(ret), ret);
if (!fMockDb)
DbEnv(0).remove(path.string().c_str(), 0);
}
@@ -70,7 +70,7 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
filesystem::path pathLogDir = path / "database";
filesystem::create_directory(pathLogDir);
filesystem::path pathErrorFile = path / "db.log";
- printf("dbenv.open LogDir=%s ErrorFile=%s\n", pathLogDir.string().c_str(), pathErrorFile.string().c_str());
+ LogPrintf("dbenv.open LogDir=%s ErrorFile=%s\n", pathLogDir.string().c_str(), pathErrorFile.string().c_str());
unsigned int nEnvFlags = 0;
if (GetBoolArg("-privdb", true))
@@ -111,7 +111,7 @@ void CDBEnv::MakeMock()
boost::this_thread::interruption_point();
- printf("CDBEnv::MakeMock()\n");
+ LogPrint("db", "CDBEnv::MakeMock()\n");
dbenv.set_cachesize(1, 0, 1);
dbenv.set_lg_bsize(10485760*4);
@@ -168,16 +168,16 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive,
int result = db.verify(strFile.c_str(), NULL, &strDump, flags);
if (result == DB_VERIFY_BAD)
{
- printf("Error: Salvage found errors, all data may not be recoverable.\n");
+ LogPrintf("Error: Salvage found errors, all data may not be recoverable.\n");
if (!fAggressive)
{
- printf("Error: Rerun with aggressive mode to ignore errors and continue.\n");
+ LogPrintf("Error: Rerun with aggressive mode to ignore errors and continue.\n");
return false;
}
}
if (result != 0 && result != DB_VERIFY_BAD)
{
- printf("ERROR: db salvage failed: %d\n",result);
+ LogPrintf("ERROR: db salvage failed: %d\n",result);
return false;
}
@@ -348,7 +348,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
bitdb.mapFileUseCount.erase(strFile);
bool fSuccess = true;
- printf("Rewriting %s...\n", strFile.c_str());
+ LogPrintf("Rewriting %s...\n", strFile.c_str());
string strFileRes = strFile + ".rewrite";
{ // surround usage of db with extra {}
CDB db(strFile.c_str(), "r");
@@ -362,7 +362,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
0);
if (ret > 0)
{
- printf("Cannot create database file %s\n", strFileRes.c_str());
+ LogPrintf("Cannot create database file %s\n", strFileRes.c_str());
fSuccess = false;
}
@@ -418,7 +418,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
fSuccess = false;
}
if (!fSuccess)
- printf("Rewriting of %s FAILED!\n", strFileRes.c_str());
+ LogPrintf("Rewriting of %s FAILED!\n", strFileRes.c_str());
return fSuccess;
}
}
@@ -433,7 +433,7 @@ void CDBEnv::Flush(bool fShutdown)
int64 nStart = GetTimeMillis();
// Flush log data to the actual data file
// on all files that are not in use
- printf("Flush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started");
+ LogPrint("db", "Flush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started");
if (!fDbEnvInit)
return;
{
@@ -443,23 +443,23 @@ void CDBEnv::Flush(bool fShutdown)
{
string strFile = (*mi).first;
int nRefCount = (*mi).second;
- printf("%s refcount=%d\n", strFile.c_str(), nRefCount);
+ LogPrint("db", "%s refcount=%d\n", strFile.c_str(), nRefCount);
if (nRefCount == 0)
{
// Move log data to the dat file
CloseDb(strFile);
- printf("%s checkpoint\n", strFile.c_str());
+ LogPrint("db", "%s checkpoint\n", strFile.c_str());
dbenv.txn_checkpoint(0, 0, 0);
- printf("%s detach\n", strFile.c_str());
+ LogPrint("db", "%s detach\n", strFile.c_str());
if (!fMockDb)
dbenv.lsn_reset(strFile.c_str(), 0);
- printf("%s closed\n", strFile.c_str());
+ LogPrint("db", "%s closed\n", strFile.c_str());
mapFileUseCount.erase(mi++);
}
else
mi++;
}
- printf("DBFlush(%s)%s ended %15"PRI64d"ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart);
+ LogPrint("db", "DBFlush(%s)%s ended %15"PRI64d"ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart);
if (fShutdown)
{
char** listp;
diff --git a/src/init.cpp b/src/init.cpp
index 87c6e27072..fb03e7b663 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -284,13 +284,13 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
FILE *file = OpenBlockFile(pos, true);
if (!file)
break;
- printf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile);
+ LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile);
LoadExternalBlockFile(file, &pos);
nFile++;
}
pblocktree->WriteReindexing(false);
fReindex = false;
- printf("Reindexing finished\n");
+ LogPrintf("Reindexing finished\n");
// To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked):
InitBlockIndex();
}
@@ -302,7 +302,7 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
if (file) {
CImportingNow imp;
filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
- printf("Importing bootstrap.dat...\n");
+ LogPrintf("Importing bootstrap.dat...\n");
LoadExternalBlockFile(file);
RenameOver(pathBootstrap, pathBootstrapOld);
}
@@ -313,7 +313,7 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
FILE *file = fopen(path.string().c_str(), "rb");
if (file) {
CImportingNow imp;
- printf("Importing %s...\n", path.string().c_str());
+ LogPrintf("Importing %s...\n", path.string().c_str());
LoadExternalBlockFile(file);
}
}
@@ -426,7 +426,7 @@ bool AppInit2(boost::thread_group& threadGroup)
// ********************************************************* Step 3: parameter-to-internal-flags
- fDebug = GetBoolArg("-debug", false);
+ if (mapMultiArgs.count("-debug")) fDebug = true;
fBenchmark = GetBoolArg("-benchmark", false);
mempool.fChecks = GetBoolArg("-checkmempool", RegTest());
Checkpoints::fEnabled = GetBoolArg("-checkpoints", true);
@@ -522,21 +522,21 @@ bool AppInit2(boost::thread_group& threadGroup)
if (GetBoolArg("-shrinkdebugfile", !fDebug))
ShrinkDebugFile();
- printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
- printf("Bitcoin version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str());
- printf("Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION));
+ LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
+ LogPrintf("Bitcoin version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str());
+ LogPrintf("Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION));
if (!fLogTimestamps)
- printf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()).c_str());
- printf("Default data directory %s\n", GetDefaultDataDir().string().c_str());
- printf("Using data directory %s\n", strDataDir.c_str());
- printf("Using at most %i connections (%i file descriptors available)\n", nMaxConnections, nFD);
+ LogPrintf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()).c_str());
+ LogPrintf("Default data directory %s\n", GetDefaultDataDir().string().c_str());
+ LogPrintf("Using data directory %s\n", strDataDir.c_str());
+ LogPrintf("Using at most %i connections (%i file descriptors available)\n", nMaxConnections, nFD);
std::ostringstream strErrors;
if (fDaemon)
fprintf(stdout, "Bitcoin server starting\n");
if (nScriptCheckThreads) {
- printf("Using %u threads for script verification\n", nScriptCheckThreads);
+ LogPrintf("Using %u threads for script verification\n", nScriptCheckThreads);
for (int i=0; i<nScriptCheckThreads-1; i++)
threadGroup.create_thread(&ThreadScriptCheck);
}
@@ -554,7 +554,7 @@ bool AppInit2(boost::thread_group& threadGroup)
boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%"PRI64d".bak", GetTime());
try {
boost::filesystem::rename(pathDatabase, pathDatabaseBak);
- printf("Moved old %s to %s. Retrying.\n", pathDatabase.string().c_str(), pathDatabaseBak.string().c_str());
+ LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string().c_str(), pathDatabaseBak.string().c_str());
} catch(boost::filesystem::filesystem_error &error) {
// failure is ok (well, not really, but it's not worse than what we started with)
}
@@ -705,12 +705,12 @@ bool AppInit2(boost::thread_group& threadGroup)
filesystem::path dest = blocksDir / strprintf("blk%05u.dat", i-1);
try {
filesystem::create_hard_link(source, dest);
- printf("Hardlinked %s -> %s\n", source.string().c_str(), dest.string().c_str());
+ LogPrintf("Hardlinked %s -> %s\n", source.string().c_str(), dest.string().c_str());
linked = true;
} catch (filesystem::filesystem_error & e) {
// Note: hardlink creation failing is not a disaster, it just means
// blocks will get re-downloaded from peers.
- printf("Error hardlinking blk%04u.dat : %s\n", i, e.what());
+ LogPrintf("Error hardlinking blk%04u.dat : %s\n", i, e.what());
break;
}
}
@@ -783,7 +783,7 @@ bool AppInit2(boost::thread_group& threadGroup)
break;
}
} catch(std::exception &e) {
- if (fDebug) printf("%s\n", e.what());
+ if (fDebug) LogPrintf("%s\n", e.what());
strLoadError = _("Error opening block database");
break;
}
@@ -801,7 +801,7 @@ bool AppInit2(boost::thread_group& threadGroup)
fReindex = true;
fRequestShutdown = false;
} else {
- printf("Aborted block database rebuild. Exiting.\n");
+ LogPrintf("Aborted block database rebuild. Exiting.\n");
return false;
}
} else {
@@ -815,10 +815,10 @@ bool AppInit2(boost::thread_group& threadGroup)
// As the program has not fully started yet, Shutdown() is possibly overkill.
if (fRequestShutdown)
{
- printf("Shutdown requested. Exiting.\n");
+ LogPrintf("Shutdown requested. Exiting.\n");
return false;
}
- printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);
+ LogPrintf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);
if (GetBoolArg("-printblockindex", false) || GetBoolArg("-printblocktree", false))
{
@@ -840,12 +840,12 @@ bool AppInit2(boost::thread_group& threadGroup)
ReadBlockFromDisk(block, pindex);
block.BuildMerkleTree();
block.print();
- printf("\n");
+ LogPrintf("\n");
nFound++;
}
}
if (nFound == 0)
- printf("No blocks matching %s were found\n", strMatch.c_str());
+ LogPrintf("No blocks matching %s were found\n", strMatch.c_str());
return false;
}
@@ -872,7 +872,7 @@ bool AppInit2(boost::thread_group& threadGroup)
else if (nLoadWalletRet == DB_NEED_REWRITE)
{
strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n";
- printf("%s", strErrors.str().c_str());
+ LogPrintf("%s", strErrors.str().c_str());
return InitError(strErrors.str());
}
else
@@ -884,12 +884,12 @@ bool AppInit2(boost::thread_group& threadGroup)
int nMaxVersion = GetArg("-upgradewallet", 0);
if (nMaxVersion == 0) // the -upgradewallet without argument case
{
- printf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
+ LogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
nMaxVersion = CLIENT_VERSION;
pwalletMain->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
}
else
- printf("Allowing wallet upgrade up to %i\n", nMaxVersion);
+ LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
if (nMaxVersion < pwalletMain->GetVersion())
strErrors << _("Cannot downgrade wallet") << "\n";
pwalletMain->SetMaxVersion(nMaxVersion);
@@ -910,8 +910,8 @@ bool AppInit2(boost::thread_group& threadGroup)
pwalletMain->SetBestChain(CBlockLocator(pindexBest));
}
- printf("%s", strErrors.str().c_str());
- printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);
+ LogPrintf("%s", strErrors.str().c_str());
+ LogPrintf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);
RegisterWallet(pwalletMain);
@@ -930,10 +930,10 @@ bool AppInit2(boost::thread_group& threadGroup)
if (pindexBest && pindexBest != pindexRescan)
{
uiInterface.InitMessage(_("Rescanning..."));
- printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
+ LogPrintf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
nStart = GetTimeMillis();
pwalletMain->ScanForWalletTransactions(pindexRescan, true);
- printf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart);
+ LogPrintf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart);
pwalletMain->SetBestChain(CBlockLocator(pindexBest));
nWalletDBUpdated++;
}
@@ -962,10 +962,10 @@ bool AppInit2(boost::thread_group& threadGroup)
{
CAddrDB adb;
if (!adb.Read(addrman))
- printf("Invalid or missing peers.dat; recreating\n");
+ LogPrintf("Invalid or missing peers.dat; recreating\n");
}
- printf("Loaded %i addresses from peers.dat %"PRI64d"ms\n",
+ LogPrintf("Loaded %i addresses from peers.dat %"PRI64d"ms\n",
addrman.size(), GetTimeMillis() - nStart);
// ********************************************************* Step 11: start node
@@ -979,11 +979,11 @@ bool AppInit2(boost::thread_group& threadGroup)
RandAddSeedPerfmon();
//// debug print
- printf("mapBlockIndex.size() = %"PRIszu"\n", mapBlockIndex.size());
- printf("nBestHeight = %d\n", nBestHeight);
- printf("setKeyPool.size() = %"PRIszu"\n", pwalletMain->setKeyPool.size());
- printf("mapWallet.size() = %"PRIszu"\n", pwalletMain->mapWallet.size());
- printf("mapAddressBook.size() = %"PRIszu"\n", pwalletMain->mapAddressBook.size());
+ LogPrintf("mapBlockIndex.size() = %"PRIszu"\n", mapBlockIndex.size());
+ LogPrintf("nBestHeight = %d\n", nBestHeight);
+ LogPrintf("setKeyPool.size() = %"PRIszu"\n", pwalletMain->setKeyPool.size());
+ LogPrintf("mapWallet.size() = %"PRIszu"\n", pwalletMain->mapWallet.size());
+ LogPrintf("mapAddressBook.size() = %"PRIszu"\n", pwalletMain->mapAddressBook.size());
StartNode(threadGroup);
diff --git a/src/leveldb.cpp b/src/leveldb.cpp
index 5e3fa08f5e..fb202367c4 100644
--- a/src/leveldb.cpp
+++ b/src/leveldb.cpp
@@ -15,7 +15,7 @@
void HandleError(const leveldb::Status &status) throw(leveldb_error) {
if (status.ok())
return;
- printf("%s\n", status.ToString().c_str());
+ LogPrintf("%s\n", status.ToString().c_str());
if (status.IsCorruption())
throw leveldb_error("Database corrupted");
if (status.IsIOError())
@@ -48,15 +48,15 @@ CLevelDB::CLevelDB(const boost::filesystem::path &path, size_t nCacheSize, bool
options.env = penv;
} else {
if (fWipe) {
- printf("Wiping LevelDB in %s\n", path.string().c_str());
+ LogPrintf("Wiping LevelDB in %s\n", path.string().c_str());
leveldb::DestroyDB(path.string(), options);
}
boost::filesystem::create_directory(path);
- printf("Opening LevelDB in %s\n", path.string().c_str());
+ LogPrintf("Opening LevelDB in %s\n", path.string().c_str());
}
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
HandleError(status);
- printf("Opened LevelDB successfully\n");
+ LogPrintf("Opened LevelDB successfully\n");
}
CLevelDB::~CLevelDB() {
diff --git a/src/leveldb.h b/src/leveldb.h
index 79262edbb5..7daddeb493 100644
--- a/src/leveldb.h
+++ b/src/leveldb.h
@@ -5,6 +5,7 @@
#define BITCOIN_LEVELDB_H
#include "serialize.h"
+#include "util.h"
#include <leveldb/db.h>
#include <leveldb/write_batch.h>
@@ -91,7 +92,7 @@ public:
if (!status.ok()) {
if (status.IsNotFound())
return false;
- printf("LevelDB read failure: %s\n", status.ToString().c_str());
+ LogPrintf("LevelDB read failure: %s\n", status.ToString().c_str());
HandleError(status);
}
try {
@@ -120,7 +121,7 @@ public:
if (!status.ok()) {
if (status.IsNotFound())
return false;
- printf("LevelDB read failure: %s\n", status.ToString().c_str());
+ LogPrintf("LevelDB read failure: %s\n", status.ToString().c_str());
HandleError(status);
}
return true;
diff --git a/src/main.cpp b/src/main.cpp
index 4b2c32e345..61d457eafc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -415,7 +415,7 @@ bool AddOrphanTx(const CTransaction& tx)
unsigned int sz = tx.GetSerializeSize(SER_NETWORK, CTransaction::CURRENT_VERSION);
if (sz > 5000)
{
- printf("ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString().c_str());
+ LogPrint("mempool", "ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString().c_str());
return false;
}
@@ -423,7 +423,7 @@ bool AddOrphanTx(const CTransaction& tx)
BOOST_FOREACH(const CTxIn& txin, tx.vin)
mapOrphanTransactionsByPrev[txin.prevout.hash].insert(hash);
- printf("stored orphan tx %s (mapsz %"PRIszu")\n", hash.ToString().c_str(),
+ LogPrint("mempool", "stored orphan tx %s (mapsz %"PRIszu")\n", hash.ToString().c_str(),
mapOrphanTransactions.size());
return true;
}
@@ -668,7 +668,7 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock)
{
vMerkleBranch.clear();
nIndex = -1;
- printf("ERROR: SetMerkleBranch() : couldn't find tx in block\n");
+ LogPrintf("ERROR: SetMerkleBranch() : couldn't find tx in block\n");
return 0;
}
@@ -917,7 +917,7 @@ bool CTxMemPool::accept(CValidationState &state, const CTransaction &tx, bool fL
if (dFreeCount >= GetArg("-limitfreerelay", 15)*10*1000)
return error("CTxMemPool::accept() : free transaction rejected by rate limiter");
if (fDebug)
- printf("Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize);
+ LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize);
dFreeCount += nSize;
}
@@ -934,7 +934,7 @@ bool CTxMemPool::accept(CValidationState &state, const CTransaction &tx, bool fL
LOCK(cs);
if (ptxOld)
{
- printf("CTxMemPool::accept() : replacing tx %s with new version\n", ptxOld->GetHash().ToString().c_str());
+ LogPrint("mempool", "CTxMemPool::accept() : replacing tx %s with new version\n", ptxOld->GetHash().ToString().c_str());
remove(*ptxOld);
}
addUnchecked(hash, tx);
@@ -946,7 +946,7 @@ bool CTxMemPool::accept(CValidationState &state, const CTransaction &tx, bool fL
EraseFromWallets(ptxOld->GetHash());
SyncWithWallets(hash, tx, NULL, true);
- printf("CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n",
+ LogPrint("mempool", "CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n",
hash.ToString().c_str(),
mapTx.size());
return true;
@@ -1021,7 +1021,7 @@ void CTxMemPool::check(CCoinsViewCache *pcoins) const
if (!fChecks)
return;
- printf("Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size());
+ LogPrintf("Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size());
LOCK(cs);
for (std::map<uint256, CTransaction>::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
@@ -1354,7 +1354,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
// Limit adjustment step
int64 nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
- printf(" nActualTimespan = %"PRI64d" before bounds\n", nActualTimespan);
+ LogPrintf(" nActualTimespan = %"PRI64d" before bounds\n", nActualTimespan);
if (nActualTimespan < nTargetTimespan/4)
nActualTimespan = nTargetTimespan/4;
if (nActualTimespan > nTargetTimespan*4)
@@ -1370,10 +1370,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
bnNew = Params().ProofOfWorkLimit();
/// debug print
- printf("GetNextWorkRequired RETARGET\n");
- printf("nTargetTimespan = %"PRI64d" nActualTimespan = %"PRI64d"\n", nTargetTimespan, nActualTimespan);
- printf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString().c_str());
- printf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str());
+ LogPrintf("GetNextWorkRequired RETARGET\n");
+ LogPrintf("nTargetTimespan = %"PRI64d" nActualTimespan = %"PRI64d"\n", nTargetTimespan, nActualTimespan);
+ LogPrintf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString().c_str());
+ LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str());
return bnNew.GetCompact();
}
@@ -1446,14 +1446,14 @@ void CheckForkWarningConditions()
}
if (pindexBestForkTip)
{
- printf("CheckForkWarningConditions: Warning: Large valid fork found\n forking the chain at height %d (%s)\n lasting to height %d (%s).\nChain state database corruption likely.\n",
+ LogPrintf("CheckForkWarningConditions: Warning: Large valid fork found\n forking the chain at height %d (%s)\n lasting to height %d (%s).\nChain state database corruption likely.\n",
pindexBestForkBase->nHeight, pindexBestForkBase->phashBlock->ToString().c_str(),
pindexBestForkTip->nHeight, pindexBestForkTip->phashBlock->ToString().c_str());
fLargeWorkForkFound = true;
}
else
{
- printf("CheckForkWarningConditions: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n");
+ LogPrintf("CheckForkWarningConditions: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n");
fLargeWorkInvalidChainFound = true;
}
}
@@ -1504,11 +1504,11 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
pblocktree->WriteBestInvalidWork(CBigNum(nBestInvalidWork));
uiInterface.NotifyBlocksChanged();
}
- printf("InvalidChainFound: invalid block=%s height=%d log2_work=%.8g date=%s\n",
+ LogPrintf("InvalidChainFound: invalid block=%s height=%d log2_work=%.8g date=%s\n",
pindexNew->GetBlockHash().ToString().c_str(), pindexNew->nHeight,
log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S",
pindexNew->GetBlockTime()).c_str());
- printf("InvalidChainFound: current best=%s height=%d log2_work=%.8g date=%s\n",
+ LogPrintf("InvalidChainFound: current best=%s height=%d log2_work=%.8g date=%s\n",
hashBestChain.ToString().c_str(), nBestHeight, log(nBestChainWork.getdouble())/log(2.0),
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexBest->GetBlockTime()).c_str());
CheckForkWarningConditions();
@@ -1967,7 +1967,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
}
int64 nTime = GetTimeMicros() - nStart;
if (fBenchmark)
- printf("- Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin)\n", (unsigned)block.vtx.size(), 0.001 * nTime, 0.001 * nTime / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * nTime / (nInputs-1));
+ LogPrintf("- Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin)\n", (unsigned)block.vtx.size(), 0.001 * nTime, 0.001 * nTime / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * nTime / (nInputs-1));
if (GetValueOut(block.vtx[0]) > GetBlockValue(pindex->nHeight, nFees))
return state.DoS(100, error("ConnectBlock() : coinbase pays too much (actual=%"PRI64d" vs limit=%"PRI64d")", GetValueOut(block.vtx[0]), GetBlockValue(pindex->nHeight, nFees)));
@@ -1976,7 +1976,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
return state.DoS(100, false);
int64 nTime2 = GetTimeMicros() - nStart;
if (fBenchmark)
- printf("- Verify %u txins: %.2fms (%.3fms/txin)\n", nInputs - 1, 0.001 * nTime2, nInputs <= 1 ? 0 : 0.001 * nTime2 / (nInputs-1));
+ LogPrintf("- Verify %u txins: %.2fms (%.3fms/txin)\n", nInputs - 1, 0.001 * nTime2, nInputs <= 1 ? 0 : 0.001 * nTime2 / (nInputs-1));
if (fJustCheck)
return true;
@@ -2052,8 +2052,8 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
reverse(vConnect.begin(), vConnect.end());
if (vDisconnect.size() > 0) {
- printf("REORGANIZE: Disconnect %"PRIszu" blocks; %s...\n", vDisconnect.size(), pfork->GetBlockHash().ToString().c_str());
- printf("REORGANIZE: Connect %"PRIszu" blocks; ...%s\n", vConnect.size(), pindexNew->GetBlockHash().ToString().c_str());
+ LogPrintf("REORGANIZE: Disconnect %"PRIszu" blocks; %s...\n", vDisconnect.size(), pfork->GetBlockHash().ToString().c_str());
+ LogPrintf("REORGANIZE: Connect %"PRIszu" blocks; ...%s\n", vConnect.size(), pindexNew->GetBlockHash().ToString().c_str());
}
// Disconnect shorter branch
@@ -2066,7 +2066,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
if (!DisconnectBlock(block, state, pindex, view))
return error("SetBestBlock() : DisconnectBlock %s failed", pindex->GetBlockHash().ToString().c_str());
if (fBenchmark)
- printf("- Disconnect: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
+ LogPrintf("- Disconnect: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
// Queue memory transactions to resurrect.
// We only do this for blocks after the last checkpoint (reorganisation before that
@@ -2091,7 +2091,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
return error("SetBestBlock() : ConnectBlock %s failed", pindex->GetBlockHash().ToString().c_str());
}
if (fBenchmark)
- printf("- Connect: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
+ LogPrintf("- Connect: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
// Queue memory transactions to delete
BOOST_FOREACH(const CTransaction& tx, block.vtx)
@@ -2104,7 +2104,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
assert(view.Flush());
int64 nTime = GetTimeMicros() - nStart;
if (fBenchmark)
- printf("- Flush %i transactions: %.2fms (%.4fms/tx)\n", nModified, 0.001 * nTime, 0.001 * nTime / nModified);
+ LogPrintf("- Flush %i transactions: %.2fms (%.4fms/tx)\n", nModified, 0.001 * nTime, 0.001 * nTime / nModified);
// Make sure it's successfully written to disk before changing memory structure
bool fIsInitialDownload = IsInitialBlockDownload();
@@ -2161,7 +2161,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
nBestChainWork = pindexNew->nChainWork;
nTimeBestReceived = GetTime();
nTransactionsUpdated++;
- printf("SetBestChain: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f\n",
+ LogPrintf("SetBestChain: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f\n",
hashBestChain.ToString().c_str(), nBestHeight, log(nBestChainWork.getdouble())/log(2.0), (unsigned long)pindexNew->nChainTx,
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexBest->GetBlockTime()).c_str(),
Checkpoints::GuessVerificationProgress(pindexBest));
@@ -2178,7 +2178,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
pindex = pindex->pprev;
}
if (nUpgraded > 0)
- printf("SetBestChain: %d of last 100 blocks above version %d\n", nUpgraded, CBlock::CURRENT_VERSION);
+ LogPrintf("SetBestChain: %d of last 100 blocks above version %d\n", nUpgraded, CBlock::CURRENT_VERSION);
if (nUpgraded > 100/2)
// strMiscWarning is read by GetWarnings(), called by Qt and the JSON-RPC code to warn the user:
strMiscWarning = _("Warning: This version is obsolete, upgrade required!");
@@ -2264,7 +2264,7 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd
}
} else {
while (infoLastBlockFile.nSize + nAddSize >= MAX_BLOCKFILE_SIZE) {
- printf("Leaving block file %i: %s\n", nLastBlockFile, infoLastBlockFile.ToString().c_str());
+ LogPrintf("Leaving block file %i: %s\n", nLastBlockFile, infoLastBlockFile.ToString().c_str());
FlushBlockFile(true);
nLastBlockFile++;
infoLastBlockFile.SetNull();
@@ -2285,7 +2285,7 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd
if (CheckDiskSpace(nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos)) {
FILE *file = OpenBlockFile(pos);
if (file) {
- printf("Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile);
+ LogPrintf("Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile);
AllocateFileRange(file, pos.nPos, nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos);
fclose(file);
}
@@ -2331,7 +2331,7 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
if (CheckDiskSpace(nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos)) {
FILE *file = OpenUndoFile(pos);
if (file) {
- printf("Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile);
+ LogPrintf("Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile);
AllocateFileRange(file, pos.nPos, nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos);
fclose(file);
}
@@ -2549,7 +2549,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
// If we don't already have its previous block, shunt it off to holding area until we get it
if (pblock->hashPrevBlock != 0 && !mapBlockIndex.count(pblock->hashPrevBlock))
{
- printf("ProcessBlock: ORPHAN BLOCK, prev=%s\n", pblock->hashPrevBlock.ToString().c_str());
+ LogPrintf("ProcessBlock: ORPHAN BLOCK, prev=%s\n", pblock->hashPrevBlock.ToString().c_str());
// Accept orphans as long as there is a node to request its parents from
if (pfrom) {
@@ -2588,7 +2588,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
mapOrphanBlocksByPrev.erase(hashPrev);
}
- printf("ProcessBlock: ACCEPTED\n");
+ LogPrintf("ProcessBlock: ACCEPTED\n");
return true;
}
@@ -2754,7 +2754,7 @@ uint256 CPartialMerkleTree::ExtractMatches(std::vector<uint256> &vMatch) {
bool AbortNode(const std::string &strMessage) {
strMiscWarning = strMessage;
- printf("*** %s\n", strMessage.c_str());
+ LogPrintf("*** %s\n", strMessage.c_str());
uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_ERROR);
StartShutdown();
return false;
@@ -2785,12 +2785,12 @@ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
if (!file && !fReadOnly)
file = fopen(path.string().c_str(), "wb+");
if (!file) {
- printf("Unable to open file %s\n", path.string().c_str());
+ LogPrintf("Unable to open file %s\n", path.string().c_str());
return NULL;
}
if (pos.nPos) {
if (fseek(file, pos.nPos, SEEK_SET)) {
- printf("Unable to seek to position %u of %s\n", pos.nPos, path.string().c_str());
+ LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string().c_str());
fclose(file);
return NULL;
}
@@ -2853,9 +2853,9 @@ bool static LoadBlockIndexDB()
// Load block file info
pblocktree->ReadLastBlockFile(nLastBlockFile);
- printf("LoadBlockIndexDB(): last block file = %i\n", nLastBlockFile);
+ LogPrintf("LoadBlockIndexDB(): last block file = %i\n", nLastBlockFile);
if (pblocktree->ReadBlockFileInfo(nLastBlockFile, infoLastBlockFile))
- printf("LoadBlockIndexDB(): last block file info: %s\n", infoLastBlockFile.ToString().c_str());
+ LogPrintf("LoadBlockIndexDB(): last block file info: %s\n", infoLastBlockFile.ToString().c_str());
// Load nBestInvalidWork, OK if it doesn't exist
CBigNum bnBestInvalidWork;
@@ -2869,7 +2869,7 @@ bool static LoadBlockIndexDB()
// Check whether we have a transaction index
pblocktree->ReadFlag("txindex", fTxIndex);
- printf("LoadBlockIndexDB(): transaction index %s\n", fTxIndex ? "enabled" : "disabled");
+ LogPrintf("LoadBlockIndexDB(): transaction index %s\n", fTxIndex ? "enabled" : "disabled");
// Load hashBestChain pointer to end of best chain
pindexBest = pcoinsTip->GetBestBlock();
@@ -2886,7 +2886,7 @@ bool static LoadBlockIndexDB()
vBlockIndexByHeight[pindex->nHeight] = pindex;
pindex = pindex->pprev;
}
- printf("LoadBlockIndexDB(): hashBestChain=%s height=%d date=%s\n",
+ LogPrintf("LoadBlockIndexDB(): hashBestChain=%s height=%d date=%s\n",
hashBestChain.ToString().c_str(), nBestHeight,
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexBest->GetBlockTime()).c_str());
@@ -2904,7 +2904,7 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth)
if (nCheckDepth > nBestHeight)
nCheckDepth = nBestHeight;
nCheckLevel = std::max(0, std::min(4, nCheckLevel));
- printf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
+ LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
CCoinsViewCache coins(*pcoinsTip, true);
CBlockIndex* pindexState = pindexBest;
CBlockIndex* pindexFailure = NULL;
@@ -2961,7 +2961,7 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth)
}
}
- printf("No coin database inconsistencies in last %i blocks (%i transactions)\n", pindexBest->nHeight - pindexState->nHeight, nGoodTransactions);
+ LogPrintf("No coin database inconsistencies in last %i blocks (%i transactions)\n", pindexBest->nHeight - pindexState->nHeight, nGoodTransactions);
return true;
}
@@ -2995,7 +2995,7 @@ bool InitBlockIndex() {
// Use the provided setting for -txindex in the new database
fTxIndex = GetBoolArg("-txindex", false);
pblocktree->WriteFlag("txindex", fTxIndex);
- printf("Initializing databases...\n");
+ LogPrintf("Initializing databases...\n");
// Only add the genesis block if not reindexing (in which case we reuse the one already on disk)
if (!fReindex) {
@@ -3048,25 +3048,25 @@ void PrintBlockTree()
if (nCol > nPrevCol)
{
for (int i = 0; i < nCol-1; i++)
- printf("| ");
- printf("|\\\n");
+ LogPrintf("| ");
+ LogPrintf("|\\\n");
}
else if (nCol < nPrevCol)
{
for (int i = 0; i < nCol; i++)
- printf("| ");
- printf("|\n");
+ LogPrintf("| ");
+ LogPrintf("|\n");
}
nPrevCol = nCol;
// print columns
for (int i = 0; i < nCol; i++)
- printf("| ");
+ LogPrintf("| ");
// print item
CBlock block;
ReadBlockFromDisk(block, pindex);
- printf("%d (blk%05u.dat:0x%x) %s tx %"PRIszu"",
+ LogPrintf("%d (blk%05u.dat:0x%x) %s tx %"PRIszu"",
pindex->nHeight,
pindex->GetBlockPos().nFile, pindex->GetBlockPos().nPos,
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", block.GetBlockTime()).c_str(),
@@ -3151,7 +3151,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
break;
}
} catch (std::exception &e) {
- printf("%s() : Deserialize or I/O error caught during load\n", __PRETTY_FUNCTION__);
+ LogPrintf("%s() : Deserialize or I/O error caught during load\n", __PRETTY_FUNCTION__);
}
}
fclose(fileIn);
@@ -3159,7 +3159,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
AbortNode(_("Error: system error: ") + e.what());
}
if (nLoaded > 0)
- printf("Loaded %i blocks from external file in %"PRI64d"ms\n", nLoaded, GetTimeMillis() - nStart);
+ LogPrintf("Loaded %i blocks from external file in %"PRI64d"ms\n", nLoaded, GetTimeMillis() - nStart);
return nLoaded > 0;
}
@@ -3381,11 +3381,10 @@ void static ProcessGetData(CNode* pfrom)
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
RandAddSeedPerfmon();
- if (fDebug)
- printf("received: %s (%"PRIszu" bytes)\n", strCommand.c_str(), vRecv.size());
+ LogPrint("net", "received: %s (%"PRIszu" bytes)\n", strCommand.c_str(), vRecv.size());
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
{
- printf("dropmessagestest DROPPING RECV MESSAGE\n");
+ LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n");
return true;
}
@@ -3411,7 +3410,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
// Since February 20, 2012, the protocol is initiated at version 209,
// and earlier versions are no longer supported
- printf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString().c_str(), pfrom->nVersion);
+ LogPrintf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString().c_str(), pfrom->nVersion);
pfrom->fDisconnect = true;
return false;
}
@@ -3438,7 +3437,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// Disconnect if we connected to ourself
if (nNonce == nLocalHostNonce && nNonce > 1)
{
- printf("connected to self at %s, disconnecting\n", pfrom->addr.ToString().c_str());
+ LogPrintf("connected to self at %s, disconnecting\n", pfrom->addr.ToString().c_str());
pfrom->fDisconnect = true;
return true;
}
@@ -3489,7 +3488,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->fSuccessfullyConnected = true;
- printf("receive version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString().c_str(), addrFrom.ToString().c_str(), pfrom->addr.ToString().c_str());
+ LogPrintf("receive version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString().c_str(), addrFrom.ToString().c_str(), pfrom->addr.ToString().c_str());
cPeerBlockCounts.input(pfrom->nStartingHeight);
}
@@ -3602,8 +3601,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->AddInventoryKnown(inv);
bool fAlreadyHave = AlreadyHave(inv);
- if (fDebug)
- printf(" got inventory: %s %s\n", inv.ToString().c_str(), fAlreadyHave ? "have" : "new");
+ LogPrint("net", " got inventory: %s %s\n", inv.ToString().c_str(), fAlreadyHave ? "have" : "new");
if (!fAlreadyHave) {
if (!fImporting && !fReindex)
@@ -3616,7 +3614,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// this situation and push another getblocks to continue.
PushGetBlocks(pfrom, mapBlockIndex[inv.hash], uint256(0));
if (fDebug)
- printf("force request: %s\n", inv.ToString().c_str());
+ LogPrintf("force request: %s\n", inv.ToString().c_str());
}
// Track requests for our stuff
@@ -3636,10 +3634,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
if (fDebugNet || (vInv.size() != 1))
- printf("received getdata (%"PRIszu" invsz)\n", vInv.size());
+ LogPrint("net", "received getdata (%"PRIszu" invsz)\n", vInv.size());
if ((fDebugNet && vInv.size() > 0) || (vInv.size() == 1))
- printf("received getdata for: %s\n", vInv[0].ToString().c_str());
+ LogPrint("net", "received getdata for: %s\n", vInv[0].ToString().c_str());
pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end());
ProcessGetData(pfrom);
@@ -3659,12 +3657,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (pindex)
pindex = pindex->GetNextInMainChain();
int nLimit = 500;
- printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().c_str(), nLimit);
+ LogPrint("net", "getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().c_str(), nLimit);
for (; pindex; pindex = pindex->GetNextInMainChain())
{
if (pindex->GetBlockHash() == hashStop)
{
- printf(" getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
+ LogPrint("net", " getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
break;
}
pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
@@ -3672,7 +3670,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
// When this block is requested, we'll send an inv that'll make them
// getblocks the next batch of inventory.
- printf(" getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
+ LogPrint("net", " getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
pfrom->hashContinue = pindex->GetBlockHash();
break;
}
@@ -3706,7 +3704,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// we must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end
vector<CBlock> vHeaders;
int nLimit = 2000;
- printf("getheaders %d to %s\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().c_str());
+ LogPrint("net", "getheaders %d to %s\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().c_str());
for (; pindex; pindex = pindex->GetNextInMainChain())
{
vHeaders.push_back(pindex->GetBlockHeader());
@@ -3756,7 +3754,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (mempool.accept(stateDummy, orphanTx, true, &fMissingInputs2))
{
- printf(" accepted orphan tx %s\n", orphanHash.ToString().c_str());
+ LogPrint("mempool", " accepted orphan tx %s\n", orphanHash.ToString().c_str());
RelayTransaction(orphanTx, orphanHash);
mapAlreadyAskedFor.erase(CInv(MSG_TX, orphanHash));
vWorkQueue.push_back(orphanHash);
@@ -3766,7 +3764,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
// invalid or too-little-fee orphan
vEraseQueue.push_back(orphanHash);
- printf(" removed orphan tx %s\n", orphanHash.ToString().c_str());
+ LogPrint("mempool", " removed orphan tx %s\n", orphanHash.ToString().c_str());
}
mempool.check(pcoinsTip);
}
@@ -3782,7 +3780,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// DoS prevention: do not allow mapOrphanTransactions to grow unbounded
unsigned int nEvicted = LimitOrphanTxSize(MAX_ORPHAN_TRANSACTIONS);
if (nEvicted > 0)
- printf("mapOrphan overflow, removed %u tx\n", nEvicted);
+ LogPrint("mempool", "mapOrphan overflow, removed %u tx\n", nEvicted);
}
int nDoS;
if (state.IsInvalid(nDoS))
@@ -3795,7 +3793,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CBlock block;
vRecv >> block;
- printf("received block %s\n", block.GetHash().ToString().c_str());
+ LogPrint("net", "received block %s\n", block.GetHash().ToString().c_str());
// block.print();
CInv inv(MSG_BLOCK, block.GetHash());
@@ -3958,7 +3956,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
bool ProcessMessages(CNode* pfrom)
{
//if (fDebug)
- // printf("ProcessMessages(%zu messages)\n", pfrom->vRecvMsg.size());
+ // LogPrintf("ProcessMessages(%zu messages)\n", pfrom->vRecvMsg.size());
//
// Message format
@@ -3983,7 +3981,7 @@ bool ProcessMessages(CNode* pfrom)
CNetMessage& msg = *it;
//if (fDebug)
- // printf("ProcessMessages(message %u msgsz, %zu bytes, complete:%s)\n",
+ // LogPrintf("ProcessMessages(message %u msgsz, %zu bytes, complete:%s)\n",
// msg.hdr.nMessageSize, msg.vRecv.size(),
// msg.complete() ? "Y" : "N");
@@ -3996,7 +3994,7 @@ bool ProcessMessages(CNode* pfrom)
// Scan for message start
if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE) != 0) {
- printf("\n\nPROCESSMESSAGE: INVALID MESSAGESTART\n\n");
+ LogPrintf("\n\nPROCESSMESSAGE: INVALID MESSAGESTART\n\n");
fOk = false;
break;
}
@@ -4005,7 +4003,7 @@ bool ProcessMessages(CNode* pfrom)
CMessageHeader& hdr = msg.hdr;
if (!hdr.IsValid())
{
- printf("\n\nPROCESSMESSAGE: ERRORS IN HEADER %s\n\n\n", hdr.GetCommand().c_str());
+ LogPrintf("\n\nPROCESSMESSAGE: ERRORS IN HEADER %s\n\n\n", hdr.GetCommand().c_str());
continue;
}
string strCommand = hdr.GetCommand();
@@ -4020,7 +4018,7 @@ bool ProcessMessages(CNode* pfrom)
memcpy(&nChecksum, &hash, sizeof(nChecksum));
if (nChecksum != hdr.nChecksum)
{
- printf("ProcessMessages(%s, %u bytes) : CHECKSUM ERROR nChecksum=%08x hdr.nChecksum=%08x\n",
+ LogPrintf("ProcessMessages(%s, %u bytes) : CHECKSUM ERROR nChecksum=%08x hdr.nChecksum=%08x\n",
strCommand.c_str(), nMessageSize, nChecksum, hdr.nChecksum);
continue;
}
@@ -4040,12 +4038,12 @@ bool ProcessMessages(CNode* pfrom)
if (strstr(e.what(), "end of data"))
{
// Allow exceptions from under-length message on vRecv
- printf("ProcessMessages(%s, %u bytes) : Exception '%s' caught, normally caused by a message being shorter than its stated length\n", strCommand.c_str(), nMessageSize, e.what());
+ LogPrintf("ProcessMessages(%s, %u bytes) : Exception '%s' caught, normally caused by a message being shorter than its stated length\n", strCommand.c_str(), nMessageSize, e.what());
}
else if (strstr(e.what(), "size too large"))
{
// Allow exceptions from over-long size
- printf("ProcessMessages(%s, %u bytes) : Exception '%s' caught\n", strCommand.c_str(), nMessageSize, e.what());
+ LogPrintf("ProcessMessages(%s, %u bytes) : Exception '%s' caught\n", strCommand.c_str(), nMessageSize, e.what());
}
else
{
@@ -4062,7 +4060,7 @@ bool ProcessMessages(CNode* pfrom)
}
if (!fRet)
- printf("ProcessMessage(%s, %u bytes) FAILED\n", strCommand.c_str(), nMessageSize);
+ LogPrintf("ProcessMessage(%s, %u bytes) FAILED\n", strCommand.c_str(), nMessageSize);
}
// In case the connection got shut down, its receive buffer was wiped
@@ -4225,7 +4223,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
if (!AlreadyHave(inv))
{
if (fDebugNet)
- printf("sending getdata: %s\n", inv.ToString().c_str());
+ LogPrint("net", "sending getdata: %s\n", inv.ToString().c_str());
vGetData.push_back(inv);
if (vGetData.size() >= 1000)
{
diff --git a/src/main.h b/src/main.h
index 38079cb6ec..952917cebe 100644
--- a/src/main.h
+++ b/src/main.h
@@ -880,7 +880,7 @@ public:
void print() const
{
- printf("%s\n", ToString().c_str());
+ LogPrintf("%s\n", ToString().c_str());
}
};
@@ -962,7 +962,7 @@ public:
void print() const
{
- printf("%s\n", ToString().c_str());
+ LogPrintf("%s\n", ToString().c_str());
}
};
diff --git a/src/miner.cpp b/src/miner.cpp
index 3ecf1609e1..5f79fedba2 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -106,10 +106,10 @@ public:
void print() const
{
- printf("COrphan(hash=%s, dPriority=%.1f, dFeePerKb=%.1f)\n",
+ LogPrintf("COrphan(hash=%s, dPriority=%.1f, dFeePerKb=%.1f)\n",
ptx->GetHash().ToString().c_str(), dPriority, dFeePerKb);
BOOST_FOREACH(uint256 hash, setDependsOn)
- printf(" setDependsOn %s\n", hash.ToString().c_str());
+ LogPrintf(" setDependsOn %s\n", hash.ToString().c_str());
}
};
@@ -211,7 +211,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
// or other transactions in the memory pool.
if (!mempool.mapTx.count(txin.prevout.hash))
{
- printf("ERROR: mempool transaction missing input\n");
+ LogPrintf("ERROR: mempool transaction missing input\n");
if (fDebug) assert("mempool transaction missing input" == 0);
fMissingInputs = true;
if (porphan)
@@ -331,7 +331,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if (fPrintPriority)
{
- printf("priority %.1f feeperkb %.1f txid %s\n",
+ LogPrintf("priority %.1f feeperkb %.1f txid %s\n",
dPriority, dFeePerKb, tx.GetHash().ToString().c_str());
}
@@ -355,7 +355,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
nLastBlockTx = nBlockTx;
nLastBlockSize = nBlockSize;
- printf("CreateNewBlock(): total size %"PRI64u"\n", nBlockSize);
+ LogPrintf("CreateNewBlock(): total size %"PRI64u"\n", nBlockSize);
pblock->vtx[0].vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees);
pblocktemplate->vTxFees[0] = -nFees;
@@ -463,10 +463,10 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
return false;
//// debug print
- printf("BitcoinMiner:\n");
- printf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str());
+ LogPrintf("BitcoinMiner:\n");
+ LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str());
pblock->print();
- printf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str());
+ LogPrintf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str());
// Found a solution
{
@@ -494,7 +494,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
void static BitcoinMiner(CWallet *pwallet)
{
- printf("BitcoinMiner started\n");
+ LogPrintf("BitcoinMiner started\n");
SetThreadPriority(THREAD_PRIORITY_LOWEST);
RenameThread("bitcoin-miner");
@@ -522,7 +522,7 @@ void static BitcoinMiner(CWallet *pwallet)
CBlock *pblock = &pblocktemplate->block;
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
- printf("Running BitcoinMiner with %"PRIszu" transactions in block (%u bytes)\n", pblock->vtx.size(),
+ LogPrintf("Running BitcoinMiner with %"PRIszu" transactions in block (%u bytes)\n", pblock->vtx.size(),
::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION));
//
@@ -603,7 +603,7 @@ void static BitcoinMiner(CWallet *pwallet)
if (GetTime() - nLogTime > 30 * 60)
{
nLogTime = GetTime();
- printf("hashmeter %6.0f khash/s\n", dHashesPerSec/1000.0);
+ LogPrintf("hashmeter %6.0f khash/s\n", dHashesPerSec/1000.0);
}
}
}
@@ -633,7 +633,7 @@ void static BitcoinMiner(CWallet *pwallet)
} }
catch (boost::thread_interrupted)
{
- printf("BitcoinMiner terminated\n");
+ LogPrintf("BitcoinMiner terminated\n");
throw;
}
}
diff --git a/src/net.cpp b/src/net.cpp
index 02b99fd049..781dbfadca 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -173,14 +173,14 @@ bool RecvLine(SOCKET hSocket, string& strLine)
if (nBytes == 0)
{
// socket closed
- printf("socket closed\n");
+ LogPrint("net", "socket closed\n");
return false;
}
else
{
// socket error
int nErr = WSAGetLastError();
- printf("recv failed: %d\n", nErr);
+ LogPrint("net", "recv failed: %d\n", nErr);
return false;
}
}
@@ -226,7 +226,7 @@ bool AddLocal(const CService& addr, int nScore)
if (IsLimited(addr))
return false;
- printf("AddLocal(%s,%i)\n", addr.ToString().c_str(), nScore);
+ LogPrintf("AddLocal(%s,%i)\n", addr.ToString().c_str(), nScore);
{
LOCK(cs_mapLocalHost);
@@ -334,7 +334,7 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha
while (strLine.size() > 0 && isspace(strLine[strLine.size()-1]))
strLine.resize(strLine.size()-1);
CService addr(strLine,0,true);
- printf("GetMyExternalIP() received [%s] %s\n", strLine.c_str(), addr.ToString().c_str());
+ LogPrintf("GetMyExternalIP() received [%s] %s\n", strLine.c_str(), addr.ToString().c_str());
if (!addr.IsValid() || !addr.IsRoutable())
return false;
ipRet.SetIP(addr);
@@ -409,7 +409,7 @@ void ThreadGetMyExternalIP()
CNetAddr addrLocalHost;
if (GetMyExternalIP(addrLocalHost))
{
- printf("GetMyExternalIP() returned %s\n", addrLocalHost.ToStringIP().c_str());
+ LogPrintf("GetMyExternalIP() returned %s\n", addrLocalHost.ToStringIP().c_str());
AddLocal(addrLocalHost, LOCAL_HTTP);
}
}
@@ -473,7 +473,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
/// debug print
- printf("trying connection %s lastseen=%.1fhrs\n",
+ LogPrint("net", "trying connection %s lastseen=%.1fhrs\n",
pszDest ? pszDest : addrConnect.ToString().c_str(),
pszDest ? 0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0);
@@ -483,17 +483,16 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
{
addrman.Attempt(addrConnect);
- /// debug print
- printf("connected %s\n", pszDest ? pszDest : addrConnect.ToString().c_str());
+ LogPrint("net", "connected %s\n", pszDest ? pszDest : addrConnect.ToString().c_str());
// Set to non-blocking
#ifdef WIN32
u_long nOne = 1;
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR)
- printf("ConnectSocket() : ioctlsocket non-blocking setting failed, error %d\n", WSAGetLastError());
+ LogPrintf("ConnectSocket() : ioctlsocket non-blocking setting failed, error %d\n", WSAGetLastError());
#else
if (fcntl(hSocket, F_SETFL, O_NONBLOCK) == SOCKET_ERROR)
- printf("ConnectSocket() : fcntl non-blocking setting failed, error %d\n", errno);
+ LogPrintf("ConnectSocket() : fcntl non-blocking setting failed, error %d\n", errno);
#endif
// Add node
@@ -519,7 +518,7 @@ void CNode::CloseSocketDisconnect()
fDisconnect = true;
if (hSocket != INVALID_SOCKET)
{
- printf("disconnecting node %s\n", addrName.c_str());
+ LogPrint("net", "disconnecting node %s\n", addrName.c_str());
closesocket(hSocket);
hSocket = INVALID_SOCKET;
}
@@ -546,7 +545,7 @@ void CNode::PushVersion()
CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService("0.0.0.0",0)));
CAddress addrMe = GetLocalAddress(&addr);
RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));
- printf("send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString().c_str(), addrYou.ToString().c_str(), addr.ToString().c_str());
+ LogPrint("net", "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString().c_str(), addrYou.ToString().c_str(), addr.ToString().c_str());
PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe,
nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()), nBestHeight, true);
}
@@ -583,7 +582,7 @@ bool CNode::Misbehaving(int howmuch)
{
if (addr.IsLocal())
{
- printf("Warning: Local node %s misbehaving (delta: %d)!\n", addrName.c_str(), howmuch);
+ LogPrintf("Warning: Local node %s misbehaving (delta: %d)!\n", addrName.c_str(), howmuch);
return false;
}
@@ -591,7 +590,7 @@ bool CNode::Misbehaving(int howmuch)
if (nMisbehavior >= GetArg("-banscore", 100))
{
int64 banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban
- printf("Misbehaving: %s (%d -> %d) DISCONNECTING\n", addr.ToString().c_str(), nMisbehavior-howmuch, nMisbehavior);
+ LogPrintf("Misbehaving: %s (%d -> %d) DISCONNECTING\n", addr.ToString().c_str(), nMisbehavior-howmuch, nMisbehavior);
{
LOCK(cs_setBanned);
if (setBanned[addr] < banTime)
@@ -600,7 +599,7 @@ bool CNode::Misbehaving(int howmuch)
CloseSocketDisconnect();
return true;
} else
- printf("Misbehaving: %s (%d -> %d)\n", addr.ToString().c_str(), nMisbehavior-howmuch, nMisbehavior);
+ LogPrintf("Misbehaving: %s (%d -> %d)\n", addr.ToString().c_str(), nMisbehavior-howmuch, nMisbehavior);
return false;
}
@@ -731,7 +730,7 @@ void SocketSendData(CNode *pnode)
int nErr = WSAGetLastError();
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
{
- printf("socket send error %d\n", nErr);
+ LogPrintf("socket send error %d\n", nErr);
pnode->CloseSocketDisconnect();
}
}
@@ -891,7 +890,7 @@ void ThreadSocketHandler()
if (have_fds)
{
int nErr = WSAGetLastError();
- printf("socket select error %d\n", nErr);
+ LogPrintf("socket select error %d\n", nErr);
for (unsigned int i = 0; i <= hSocketMax; i++)
FD_SET(i, &fdsetRecv);
}
@@ -919,7 +918,7 @@ void ThreadSocketHandler()
if (hSocket != INVALID_SOCKET)
if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr))
- printf("Warning: Unknown socket family\n");
+ LogPrintf("Warning: Unknown socket family\n");
{
LOCK(cs_vNodes);
@@ -932,7 +931,7 @@ void ThreadSocketHandler()
{
int nErr = WSAGetLastError();
if (nErr != WSAEWOULDBLOCK)
- printf("socket error accept failed: %d\n", nErr);
+ LogPrintf("socket error accept failed: %d\n", nErr);
}
else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS)
{
@@ -944,12 +943,12 @@ void ThreadSocketHandler()
}
else if (CNode::IsBanned(addr))
{
- printf("connection from %s dropped (banned)\n", addr.ToString().c_str());
+ LogPrintf("connection from %s dropped (banned)\n", addr.ToString().c_str());
closesocket(hSocket);
}
else
{
- printf("accepted connection %s\n", addr.ToString().c_str());
+ LogPrint("net", "accepted connection %s\n", addr.ToString().c_str());
CNode* pnode = new CNode(hSocket, addr, "", true);
pnode->AddRef();
{
@@ -999,7 +998,7 @@ void ThreadSocketHandler()
{
// socket closed gracefully
if (!pnode->fDisconnect)
- printf("socket closed\n");
+ LogPrint("net", "socket closed\n");
pnode->CloseSocketDisconnect();
}
else if (nBytes < 0)
@@ -1009,7 +1008,7 @@ void ThreadSocketHandler()
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
{
if (!pnode->fDisconnect)
- printf("socket recv error %d\n", nErr);
+ LogPrintf("socket recv error %d\n", nErr);
pnode->CloseSocketDisconnect();
}
}
@@ -1038,17 +1037,17 @@ void ThreadSocketHandler()
{
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
{
- printf("socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0);
+ LogPrint("net", "socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0);
pnode->fDisconnect = true;
}
else if (GetTime() - pnode->nLastSend > 90*60 && GetTime() - pnode->nLastSendEmpty > 90*60)
{
- printf("socket not sending\n");
+ LogPrintf("socket not sending\n");
pnode->fDisconnect = true;
}
else if (GetTime() - pnode->nLastRecv > 90*60)
{
- printf("socket inactivity timeout\n");
+ LogPrintf("socket inactivity timeout\n");
pnode->fDisconnect = true;
}
}
@@ -1100,16 +1099,16 @@ void ThreadMapPort()
char externalIPAddress[40];
r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress);
if(r != UPNPCOMMAND_SUCCESS)
- printf("UPnP: GetExternalIPAddress() returned %d\n", r);
+ LogPrintf("UPnP: GetExternalIPAddress() returned %d\n", r);
else
{
if(externalIPAddress[0])
{
- printf("UPnP: ExternalIPAddress = %s\n", externalIPAddress);
+ LogPrintf("UPnP: ExternalIPAddress = %s\n", externalIPAddress);
AddLocal(CNetAddr(externalIPAddress), LOCAL_UPNP);
}
else
- printf("UPnP: GetExternalIPAddress failed.\n");
+ LogPrintf("UPnP: GetExternalIPAddress failed.\n");
}
}
@@ -1128,10 +1127,10 @@ void ThreadMapPort()
#endif
if(r!=UPNPCOMMAND_SUCCESS)
- printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
+ LogPrintf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
port.c_str(), port.c_str(), lanaddr, r, strupnperror(r));
else
- printf("UPnP Port Mapping successful.\n");;
+ LogPrintf("UPnP Port Mapping successful.\n");;
MilliSleep(20*60*1000); // Refresh every 20 minutes
}
@@ -1139,13 +1138,13 @@ void ThreadMapPort()
catch (boost::thread_interrupted)
{
r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0);
- printf("UPNP_DeletePortMapping() returned : %d\n", r);
+ LogPrintf("UPNP_DeletePortMapping() returned : %d\n", r);
freeUPNPDevlist(devlist); devlist = 0;
FreeUPNPUrls(&urls);
throw;
}
} else {
- printf("No valid UPnP IGDs found\n");
+ LogPrintf("No valid UPnP IGDs found\n");
freeUPNPDevlist(devlist); devlist = 0;
if (r != 0)
FreeUPNPUrls(&urls);
@@ -1190,7 +1189,7 @@ void ThreadDNSAddressSeed()
const vector<CDNSSeedData> &vSeeds = Params().DNSSeeds();
int found = 0;
- printf("Loading addresses from DNS seeds (could take a while)\n");
+ LogPrintf("Loading addresses from DNS seeds (could take a while)\n");
BOOST_FOREACH(const CDNSSeedData &seed, vSeeds) {
if (HaveNameProxy()) {
@@ -1213,7 +1212,7 @@ void ThreadDNSAddressSeed()
}
}
- printf("%d addresses found from DNS seeds\n", found);
+ LogPrintf("%d addresses found from DNS seeds\n", found);
}
@@ -1234,7 +1233,7 @@ void DumpAddresses()
CAddrDB adb;
adb.Write(addrman);
- printf("Flushed %d addresses to peers.dat %"PRI64d"ms\n",
+ LogPrint("net", "Flushed %d addresses to peers.dat %"PRI64d"ms\n",
addrman.size(), GetTimeMillis() - nStart);
}
@@ -1292,7 +1291,7 @@ void ThreadOpenConnections()
if (addrman.size() == 0 && (GetTime() - nStart > 60)) {
static bool done = false;
if (!done) {
- printf("Adding fixed seed nodes as DNS doesn't seem to be available.\n");
+ LogPrintf("Adding fixed seed nodes as DNS doesn't seem to be available.\n");
addrman.Add(Params().FixedSeeds(), CNetAddr("127.0.0.1"));
done = true;
}
@@ -1568,7 +1567,7 @@ bool BindListenPort(const CService &addrBind, string& strError)
if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len))
{
strError = strprintf("Error: bind address family for %s not supported", addrBind.ToString().c_str());
- printf("%s\n", strError.c_str());
+ LogPrintf("%s\n", strError.c_str());
return false;
}
@@ -1576,7 +1575,7 @@ bool BindListenPort(const CService &addrBind, string& strError)
if (hListenSocket == INVALID_SOCKET)
{
strError = strprintf("Error: Couldn't open socket for incoming connections (socket returned error %d)", WSAGetLastError());
- printf("%s\n", strError.c_str());
+ LogPrintf("%s\n", strError.c_str());
return false;
}
@@ -1600,7 +1599,7 @@ bool BindListenPort(const CService &addrBind, string& strError)
#endif
{
strError = strprintf("Error: Couldn't set properties on socket for incoming connections (error %d)", WSAGetLastError());
- printf("%s\n", strError.c_str());
+ LogPrintf("%s\n", strError.c_str());
return false;
}
@@ -1631,16 +1630,16 @@ bool BindListenPort(const CService &addrBind, string& strError)
strError = strprintf(_("Unable to bind to %s on this computer. Bitcoin is probably already running."), addrBind.ToString().c_str());
else
strError = strprintf(_("Unable to bind to %s on this computer (bind returned error %d, %s)"), addrBind.ToString().c_str(), nErr, strerror(nErr));
- printf("%s\n", strError.c_str());
+ LogPrintf("%s\n", strError.c_str());
return false;
}
- printf("Bound to %s\n", addrBind.ToString().c_str());
+ LogPrintf("Bound to %s\n", addrBind.ToString().c_str());
// Listen for incoming connections
if (listen(hListenSocket, SOMAXCONN) == SOCKET_ERROR)
{
strError = strprintf("Error: Listening for incoming connections failed (listen returned error %d)", WSAGetLastError());
- printf("%s\n", strError.c_str());
+ LogPrintf("%s\n", strError.c_str());
return false;
}
@@ -1687,7 +1686,7 @@ void static Discover()
struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr);
CNetAddr addr(s4->sin_addr);
if (AddLocal(addr, LOCAL_IF))
- printf("IPv4 %s: %s\n", ifa->ifa_name, addr.ToString().c_str());
+ LogPrintf("IPv4 %s: %s\n", ifa->ifa_name, addr.ToString().c_str());
}
#ifdef USE_IPV6
else if (ifa->ifa_addr->sa_family == AF_INET6)
@@ -1695,7 +1694,7 @@ void static Discover()
struct sockaddr_in6* s6 = (struct sockaddr_in6*)(ifa->ifa_addr);
CNetAddr addr(s6->sin6_addr);
if (AddLocal(addr, LOCAL_IF))
- printf("IPv6 %s: %s\n", ifa->ifa_name, addr.ToString().c_str());
+ LogPrintf("IPv6 %s: %s\n", ifa->ifa_name, addr.ToString().c_str());
}
#endif
}
@@ -1726,7 +1725,7 @@ void StartNode(boost::thread_group& threadGroup)
//
if (!GetBoolArg("-dnsseed", true))
- printf("DNS seeding disabled\n");
+ LogPrintf("DNS seeding disabled\n");
else
threadGroup.create_thread(boost::bind(&TraceThread<void (*)()>, "dnsseed", &ThreadDNSAddressSeed));
@@ -1753,7 +1752,7 @@ void StartNode(boost::thread_group& threadGroup)
bool StopNode()
{
- printf("StopNode()\n");
+ LogPrintf("StopNode()\n");
MapPort(false);
if (semOutbound)
for (int i=0; i<MAX_OUTBOUND_CONNECTIONS; i++)
@@ -1779,7 +1778,7 @@ public:
BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket)
if (hListenSocket != INVALID_SOCKET)
if (closesocket(hListenSocket) == SOCKET_ERROR)
- printf("closesocket(hListenSocket) failed with error %d\n", WSAGetLastError());
+ LogPrintf("closesocket(hListenSocket) failed with error %d\n", WSAGetLastError());
// clean up some globals (to help leak detection)
BOOST_FOREACH(CNode *pnode, vNodes)
diff --git a/src/net.h b/src/net.h
index 686861fbeb..49415f6502 100644
--- a/src/net.h
+++ b/src/net.h
@@ -372,8 +372,7 @@ public:
nRequestTime = it->second;
else
nRequestTime = 0;
- if (fDebugNet)
- printf("askfor %s %"PRI64d" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str());
+ LogPrint("net", "askfor %s %"PRI64d" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str());
// Make sure not to reuse time indexes to keep things in the same order
int64 nNow = (GetTime() - 1) * 1000000;
@@ -399,8 +398,7 @@ public:
ENTER_CRITICAL_SECTION(cs_vSend);
assert(ssSend.size() == 0);
ssSend << CMessageHeader(pszCommand, 0);
- if (fDebug)
- printf("sending: %s ", pszCommand);
+ LogPrint("net", "sending: %s ", pszCommand);
}
// TODO: Document the precondition of this function. Is cs_vSend locked?
@@ -410,8 +408,7 @@ public:
LEAVE_CRITICAL_SECTION(cs_vSend);
- if (fDebug)
- printf("(aborted)\n");
+ LogPrint("net", "(aborted)\n");
}
// TODO: Document the precondition of this function. Is cs_vSend locked?
@@ -419,7 +416,7 @@ public:
{
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
{
- printf("dropmessages DROPPING SEND MESSAGE\n");
+ LogPrint("net", "dropmessages DROPPING SEND MESSAGE\n");
AbortMessage();
return;
}
@@ -438,9 +435,7 @@ public:
assert(ssSend.size () >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
memcpy((char*)&ssSend[CMessageHeader::CHECKSUM_OFFSET], &nChecksum, sizeof(nChecksum));
- if (fDebug) {
- printf("(%d bytes)\n", nSize);
- }
+ LogPrint("net", "(%d bytes)\n", nSize);
std::deque<CSerializeData>::iterator it = vSendMsg.insert(vSendMsg.end(), CSerializeData());
ssSend.GetAndClear(*it);
diff --git a/src/netbase.cpp b/src/netbase.cpp
index d02490ad4a..acc2ae32aa 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -169,7 +169,7 @@ bool LookupNumeric(const char *pszName, CService& addr, int portDefault)
bool static Socks4(const CService &addrDest, SOCKET& hSocket)
{
- printf("SOCKS4 connecting %s\n", addrDest.ToString().c_str());
+ LogPrintf("SOCKS4 connecting %s\n", addrDest.ToString().c_str());
if (!addrDest.IsIPv4())
{
closesocket(hSocket);
@@ -204,16 +204,16 @@ bool static Socks4(const CService &addrDest, SOCKET& hSocket)
{
closesocket(hSocket);
if (pchRet[1] != 0x5b)
- printf("ERROR: Proxy returned error %d\n", pchRet[1]);
+ LogPrintf("ERROR: Proxy returned error %d\n", pchRet[1]);
return false;
}
- printf("SOCKS4 connected %s\n", addrDest.ToString().c_str());
+ LogPrintf("SOCKS4 connected %s\n", addrDest.ToString().c_str());
return true;
}
bool static Socks5(string strDest, int port, SOCKET& hSocket)
{
- printf("SOCKS5 connecting %s\n", strDest.c_str());
+ LogPrintf("SOCKS5 connecting %s\n", strDest.c_str());
if (strDest.size() > 255)
{
closesocket(hSocket);
@@ -309,7 +309,7 @@ bool static Socks5(string strDest, int port, SOCKET& hSocket)
closesocket(hSocket);
return error("Error reading from proxy");
}
- printf("SOCKS5 connected %s\n", strDest.c_str());
+ LogPrintf("SOCKS5 connected %s\n", strDest.c_str());
return true;
}
@@ -324,7 +324,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
#endif
socklen_t len = sizeof(sockaddr);
if (!addrConnect.GetSockAddr((struct sockaddr*)&sockaddr, &len)) {
- printf("Cannot connect to %s: unsupported network\n", addrConnect.ToString().c_str());
+ LogPrintf("Cannot connect to %s: unsupported network\n", addrConnect.ToString().c_str());
return false;
}
@@ -363,13 +363,13 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
int nRet = select(hSocket + 1, NULL, &fdset, NULL, &timeout);
if (nRet == 0)
{
- printf("connection timeout\n");
+ LogPrint("net", "connection timeout\n");
closesocket(hSocket);
return false;
}
if (nRet == SOCKET_ERROR)
{
- printf("select() for connection failed: %i\n",WSAGetLastError());
+ LogPrintf("select() for connection failed: %i\n",WSAGetLastError());
closesocket(hSocket);
return false;
}
@@ -380,13 +380,13 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == SOCKET_ERROR)
#endif
{
- printf("getsockopt() for connection failed: %i\n",WSAGetLastError());
+ LogPrintf("getsockopt() for connection failed: %i\n",WSAGetLastError());
closesocket(hSocket);
return false;
}
if (nRet != 0)
{
- printf("connect() failed after select(): %s\n",strerror(nRet));
+ LogPrintf("connect() failed after select(): %s\n",strerror(nRet));
closesocket(hSocket);
return false;
}
@@ -397,7 +397,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
else
#endif
{
- printf("connect() failed: %i\n",WSAGetLastError());
+ LogPrintf("connect() failed: %i\n",WSAGetLastError());
closesocket(hSocket);
return false;
}
@@ -893,7 +893,7 @@ uint64 CNetAddr::GetHash() const
void CNetAddr::print() const
{
- printf("CNetAddr(%s)\n", ToString().c_str());
+ LogPrintf("CNetAddr(%s)\n", ToString().c_str());
}
// private extensions to enum Network, only returned by GetExtNetwork,
@@ -1134,7 +1134,7 @@ std::string CService::ToString() const
void CService::print() const
{
- printf("CService(%s)\n", ToString().c_str());
+ LogPrintf("CService(%s)\n", ToString().c_str());
}
void CService::SetPort(unsigned short portIn)
diff --git a/src/noui.cpp b/src/noui.cpp
index c0e00c4715..67eac944c6 100644
--- a/src/noui.cpp
+++ b/src/noui.cpp
@@ -27,7 +27,7 @@ static bool noui_ThreadSafeMessageBox(const std::string& message, const std::str
strCaption += caption; // Use supplied caption (can be empty)
}
- printf("%s: %s\n", strCaption.c_str(), message.c_str());
+ LogPrintf("%s: %s\n", strCaption.c_str(), message.c_str());
fprintf(stderr, "%s: %s\n", strCaption.c_str(), message.c_str());
return false;
}
@@ -39,7 +39,7 @@ static bool noui_ThreadSafeAskFee(int64 /*nFeeRequired*/)
static void noui_InitMessage(const std::string &message)
{
- printf("init message: %s\n", message.c_str());
+ LogPrintf("init message: %s\n", message.c_str());
}
void noui_connect()
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 745b4338e4..ba254be3e1 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -67,7 +67,7 @@ bool CMessageHeader::IsValid() const
// Message size
if (nMessageSize > MAX_SIZE)
{
- printf("CMessageHeader::IsValid() : (%s, %u bytes) nMessageSize > MAX_SIZE\n", GetCommand().c_str(), nMessageSize);
+ LogPrintf("CMessageHeader::IsValid() : (%s, %u bytes) nMessageSize > MAX_SIZE\n", GetCommand().c_str(), nMessageSize);
return false;
}
@@ -146,6 +146,6 @@ std::string CInv::ToString() const
void CInv::print() const
{
- printf("CInv(%s)\n", ToString().c_str());
+ LogPrintf("CInv(%s)\n", ToString().c_str());
}
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index a4d589e167..f184fb9ef0 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -62,7 +62,7 @@ static bool ThreadSafeMessageBox(const std::string& message, const std::string&
}
else
{
- printf("%s: %s\n", caption.c_str(), message.c_str());
+ LogPrintf("%s: %s\n", caption.c_str(), message.c_str());
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
return false;
}
@@ -91,7 +91,7 @@ static void InitMessage(const std::string &message)
splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(55,55,55));
qApp->processEvents();
}
- printf("init message: %s\n", message.c_str());
+ LogPrintf("init message: %s\n", message.c_str());
}
/*
@@ -155,12 +155,12 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans
#if QT_VERSION < 0x050000
void DebugMessageHandler(QtMsgType type, const char * msg)
{
- OutputDebugStringF("Bitcoin-Qt: %s\n", msg);
+ LogPrint("qt", "Bitcoin-Qt: %s\n", msg);
}
#else
void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &msg)
{
- OutputDebugStringF("Bitcoin-Qt: %s\n", qPrintable(msg));
+ LogPrint("qt", "Bitcoin-Qt: %s\n", qPrintable(msg));
}
#endif
diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp
index e166f76bf1..842910c7e0 100644
--- a/src/rpcdump.cpp
+++ b/src/rpcdump.cpp
@@ -15,8 +15,6 @@
#include <boost/variant/get.hpp>
#include <boost/algorithm/string.hpp>
-#define printf OutputDebugStringF
-
using namespace json_spirit;
using namespace std;
@@ -147,7 +145,7 @@ Value importwallet(const Array& params, bool fHelp)
CPubKey pubkey = key.GetPubKey();
CKeyID keyid = pubkey.GetID();
if (pwalletMain->HaveKey(keyid)) {
- printf("Skipping import of %s (key already present)\n", CBitcoinAddress(keyid).ToString().c_str());
+ LogPrintf("Skipping import of %s (key already present)\n", CBitcoinAddress(keyid).ToString().c_str());
continue;
}
int64 nTime = DecodeDumpTime(vstr[1]);
@@ -165,7 +163,7 @@ Value importwallet(const Array& params, bool fHelp)
fLabel = true;
}
}
- printf("Importing %s...\n", CBitcoinAddress(keyid).ToString().c_str());
+ LogPrintf("Importing %s...\n", CBitcoinAddress(keyid).ToString().c_str());
if (!pwalletMain->AddKeyPubKey(key, pubkey)) {
fGood = false;
continue;
@@ -181,7 +179,7 @@ Value importwallet(const Array& params, bool fHelp)
while (pindex && pindex->pprev && pindex->nTime > nTimeBegin - 7200)
pindex = pindex->pprev;
- printf("Rescanning last %i blocks\n", pindexBest->nHeight - pindex->nHeight + 1);
+ LogPrintf("Rescanning last %i blocks\n", pindexBest->nHeight - pindex->nHeight + 1);
pwalletMain->ScanForWalletTransactions(pindex);
pwalletMain->ReacceptWalletTransactions();
pwalletMain->MarkDirty();
diff --git a/src/script.cpp b/src/script.cpp
index 3c3e9cf3bf..0fe2953548 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -977,7 +977,7 @@ uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int
{
if (nIn >= txTo.vin.size())
{
- printf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
+ LogPrintf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
return 1;
}
CTransaction txTmp(txTo);
@@ -1008,7 +1008,7 @@ uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int
unsigned int nOut = nIn;
if (nOut >= txTmp.vout.size())
{
- printf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut);
+ LogPrintf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut);
return 1;
}
txTmp.vout.resize(nOut+1);
diff --git a/src/script.h b/src/script.h
index 0ab47678e8..f5ed611548 100644
--- a/src/script.h
+++ b/src/script.h
@@ -560,7 +560,7 @@ public:
void PrintHex() const
{
- printf("CScript(%s)\n", HexStr(begin(), end(), true).c_str());
+ LogPrintf("CScript(%s)\n", HexStr(begin(), end(), true).c_str());
}
std::string ToString() const
@@ -588,7 +588,7 @@ public:
void print() const
{
- printf("%s\n", ToString().c_str());
+ LogPrintf("%s\n", ToString().c_str());
}
CScriptID GetID() const
diff --git a/src/sync.cpp b/src/sync.cpp
index 1ac4403beb..29a455f9b2 100644
--- a/src/sync.cpp
+++ b/src/sync.cpp
@@ -10,8 +10,8 @@
#ifdef DEBUG_LOCKCONTENTION
void PrintLockContention(const char* pszName, const char* pszFile, int nLine)
{
- printf("LOCKCONTENTION: %s\n", pszName);
- printf("Locker: %s:%d\n", pszFile, nLine);
+ LogPrintf("LOCKCONTENTION: %s\n", pszName);
+ LogPrintf("Locker: %s:%d\n", pszFile, nLine);
}
#endif /* DEBUG_LOCKCONTENTION */
@@ -56,20 +56,20 @@ static boost::thread_specific_ptr<LockStack> lockstack;
static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch, const LockStack& s1, const LockStack& s2)
{
- printf("POTENTIAL DEADLOCK DETECTED\n");
- printf("Previous lock order was:\n");
+ LogPrintf("POTENTIAL DEADLOCK DETECTED\n");
+ LogPrintf("Previous lock order was:\n");
BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, s2)
{
- if (i.first == mismatch.first) printf(" (1)");
- if (i.first == mismatch.second) printf(" (2)");
- printf(" %s\n", i.second.ToString().c_str());
+ if (i.first == mismatch.first) LogPrintf(" (1)");
+ if (i.first == mismatch.second) LogPrintf(" (2)");
+ LogPrintf(" %s\n", i.second.ToString().c_str());
}
- printf("Current lock order is:\n");
+ LogPrintf("Current lock order is:\n");
BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, s1)
{
- if (i.first == mismatch.first) printf(" (1)");
- if (i.first == mismatch.second) printf(" (2)");
- printf(" %s\n", i.second.ToString().c_str());
+ if (i.first == mismatch.first) LogPrintf(" (1)");
+ if (i.first == mismatch.second) LogPrintf(" (2)");
+ LogPrintf(" %s\n", i.second.ToString().c_str());
}
}
@@ -78,7 +78,7 @@ static void push_lock(void* c, const CLockLocation& locklocation, bool fTry)
if (lockstack.get() == NULL)
lockstack.reset(new LockStack);
- if (fDebug) printf("Locking: %s\n", locklocation.ToString().c_str());
+ if (fDebug) LogPrintf("Locking: %s\n", locklocation.ToString().c_str());
dd_mutex.lock();
(*lockstack).push_back(std::make_pair(c, locklocation));
@@ -108,7 +108,7 @@ static void pop_lock()
if (fDebug)
{
const CLockLocation& locklocation = (*lockstack).rbegin()->second;
- printf("Unlocked: %s\n", locklocation.ToString().c_str());
+ LogPrintf("Unlocked: %s\n", locklocation.ToString().c_str());
}
dd_mutex.lock();
(*lockstack).pop_back();
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 34836eaa97..0d2fdc2887 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -55,7 +55,7 @@ bool CCoinsViewDB::SetBestBlock(CBlockIndex *pindex) {
}
bool CCoinsViewDB::BatchWrite(const std::map<uint256, CCoins> &mapCoins, CBlockIndex *pindex) {
- printf("Committing %u changed transactions to coin database...\n", (unsigned int)mapCoins.size());
+ LogPrint("coindb", "Committing %u changed transactions to coin database...\n", (unsigned int)mapCoins.size());
CLevelDBBatch batch;
for (std::map<uint256, CCoins>::const_iterator it = mapCoins.begin(); it != mapCoins.end(); it++)
diff --git a/src/uint256.h b/src/uint256.h
index 2a252c94f3..45ab8abb5e 100644
--- a/src/uint256.h
+++ b/src/uint256.h
@@ -654,39 +654,39 @@ inline int Testuint256AdHoc(std::vector<std::string> vArg)
uint256 g(0);
- printf("%s\n", g.ToString().c_str());
- g--; printf("g--\n");
- printf("%s\n", g.ToString().c_str());
- g--; printf("g--\n");
- printf("%s\n", g.ToString().c_str());
- g++; printf("g++\n");
- printf("%s\n", g.ToString().c_str());
- g++; printf("g++\n");
- printf("%s\n", g.ToString().c_str());
- g++; printf("g++\n");
- printf("%s\n", g.ToString().c_str());
- g++; printf("g++\n");
- printf("%s\n", g.ToString().c_str());
+ LogPrintf("%s\n", g.ToString().c_str());
+ g--; LogPrintf("g--\n");
+ LogPrintf("%s\n", g.ToString().c_str());
+ g--; LogPrintf("g--\n");
+ LogPrintf("%s\n", g.ToString().c_str());
+ g++; LogPrintf("g++\n");
+ LogPrintf("%s\n", g.ToString().c_str());
+ g++; LogPrintf("g++\n");
+ LogPrintf("%s\n", g.ToString().c_str());
+ g++; LogPrintf("g++\n");
+ LogPrintf("%s\n", g.ToString().c_str());
+ g++; LogPrintf("g++\n");
+ LogPrintf("%s\n", g.ToString().c_str());
uint256 a(7);
- printf("a=7\n");
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("a=7\n");
+ LogPrintf("%s\n", a.ToString().c_str());
uint256 b;
- printf("b undefined\n");
- printf("%s\n", b.ToString().c_str());
+ LogPrintf("b undefined\n");
+ LogPrintf("%s\n", b.ToString().c_str());
int c = 3;
a = c;
a.pn[3] = 15;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
uint256 k(c);
a = 5;
a.pn[3] = 15;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
b = 1;
b <<= 52;
@@ -694,86 +694,86 @@ inline int Testuint256AdHoc(std::vector<std::string> vArg)
a ^= 0x500;
- printf("a %s\n", a.ToString().c_str());
+ LogPrintf("a %s\n", a.ToString().c_str());
a = a | b | (uint256)0x1000;
- printf("a %s\n", a.ToString().c_str());
- printf("b %s\n", b.ToString().c_str());
+ LogPrintf("a %s\n", a.ToString().c_str());
+ LogPrintf("b %s\n", b.ToString().c_str());
a = 0xfffffffe;
a.pn[4] = 9;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
a++;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
a++;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
a++;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
a++;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
a--;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
a--;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
a--;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
uint256 d = a--;
- printf("%s\n", d.ToString().c_str());
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", d.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
a--;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
a--;
- printf("%s\n", a.ToString().c_str());
+ LogPrintf("%s\n", a.ToString().c_str());
d = a;
- printf("%s\n", d.ToString().c_str());
- for (int i = uint256::WIDTH-1; i >= 0; i--) printf("%08x", d.pn[i]); printf("\n");
+ LogPrintf("%s\n", d.ToString().c_str());
+ for (int i = uint256::WIDTH-1; i >= 0; i--) LogPrintf("%08x", d.pn[i]); LogPrintf("\n");
uint256 neg = d;
neg = ~neg;
- printf("%s\n", neg.ToString().c_str());
+ LogPrintf("%s\n", neg.ToString().c_str());
uint256 e = uint256("0xABCDEF123abcdef12345678909832180000011111111");
- printf("\n");
- printf("%s\n", e.ToString().c_str());
+ LogPrintf("\n");
+ LogPrintf("%s\n", e.ToString().c_str());
- printf("\n");
+ LogPrintf("\n");
uint256 x1 = uint256("0xABCDEF123abcdef12345678909832180000011111111");
uint256 x2;
- printf("%s\n", x1.ToString().c_str());
+ LogPrintf("%s\n", x1.ToString().c_str());
for (int i = 0; i < 270; i += 4)
{
x2 = x1 << i;
- printf("%s\n", x2.ToString().c_str());
+ LogPrintf("%s\n", x2.ToString().c_str());
}
- printf("\n");
- printf("%s\n", x1.ToString().c_str());
+ LogPrintf("\n");
+ LogPrintf("%s\n", x1.ToString().c_str());
for (int i = 0; i < 270; i += 4)
{
x2 = x1;
x2 >>= i;
- printf("%s\n", x2.ToString().c_str());
+ LogPrintf("%s\n", x2.ToString().c_str());
}
for (int i = 0; i < 100; i++)
{
uint256 k = (~uint256(0) >> i);
- printf("%s\n", k.ToString().c_str());
+ LogPrintf("%s\n", k.ToString().c_str());
}
for (int i = 0; i < 100; i++)
{
uint256 k = (~uint256(0) << i);
- printf("%s\n", k.ToString().c_str());
+ LogPrintf("%s\n", k.ToString().c_str());
}
return (0);
diff --git a/src/util.cpp b/src/util.cpp
index 16c8f3fc17..281ced2fa9 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -166,7 +166,7 @@ void RandAddSeedPerfmon()
{
RAND_add(pdata, nSize, nSize/100.0);
OPENSSL_cleanse(pdata, nSize);
- printf("RandAddSeed() %lu bytes\n", nSize);
+ LogPrint("rand", "RandAddSeed() %lu bytes\n", nSize);
}
#endif
}
@@ -233,8 +233,16 @@ static void DebugPrintInit()
mutexDebugLog = new boost::mutex();
}
-int OutputDebugStringF(const char* pszFormat, ...)
+int LogPrint(const char* category, const char* pszFormat, ...)
{
+ if (category != NULL)
+ {
+ if (!fDebug) return 0;
+ const vector<string>& categories = mapMultiArgs["-debug"];
+ if (find(categories.begin(), categories.end(), string(category)) == categories.end())
+ return 0;
+ }
+
int ret = 0; // Returns total number of characters written
if (fPrintToConsole)
{
@@ -360,7 +368,7 @@ bool error(const char *format, ...)
va_start(arg_ptr, format);
std::string str = vstrprintf(format, arg_ptr);
va_end(arg_ptr);
- printf("ERROR: %s\n", str.c_str());
+ LogPrintf("ERROR: %s\n", str.c_str());
return false;
}
@@ -994,13 +1002,13 @@ static std::string FormatException(std::exception* pex, const char* pszThread)
void LogException(std::exception* pex, const char* pszThread)
{
std::string message = FormatException(pex, pszThread);
- printf("\n%s", message.c_str());
+ LogPrintf("\n%s", message.c_str());
}
void PrintException(std::exception* pex, const char* pszThread)
{
std::string message = FormatException(pex, pszThread);
- printf("\n\n************************\n%s\n", message.c_str());
+ LogPrintf("\n\n************************\n%s\n", message.c_str());
fprintf(stderr, "\n\n************************\n%s\n", message.c_str());
strMiscWarning = message;
throw;
@@ -1009,7 +1017,7 @@ void PrintException(std::exception* pex, const char* pszThread)
void PrintExceptionContinue(std::exception* pex, const char* pszThread)
{
std::string message = FormatException(pex, pszThread);
- printf("\n\n************************\n%s\n", message.c_str());
+ LogPrintf("\n\n************************\n%s\n", message.c_str());
fprintf(stderr, "\n\n************************\n%s\n", message.c_str());
strMiscWarning = message;
}
@@ -1322,7 +1330,7 @@ void AddTimeData(const CNetAddr& ip, int64 nTime)
// Add data
vTimeOffsets.input(nOffsetSample);
- printf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);
+ LogPrintf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
{
int64 nMedian = vTimeOffsets.median();
@@ -1350,17 +1358,17 @@ void AddTimeData(const CNetAddr& ip, int64 nTime)
fDone = true;
string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong Bitcoin will not work properly.");
strMiscWarning = strMessage;
- printf("*** %s\n", strMessage.c_str());
+ LogPrintf("*** %s\n", strMessage.c_str());
uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING);
}
}
}
if (fDebug) {
BOOST_FOREACH(int64 n, vSorted)
- printf("%+"PRI64d" ", n);
- printf("| ");
+ LogPrintf("%+"PRI64d" ", n);
+ LogPrintf("| ");
}
- printf("nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60);
+ LogPrintf("nTimeOffset = %+"PRI64d" (%+"PRI64d" minutes)\n", nTimeOffset, nTimeOffset/60);
}
}
@@ -1422,7 +1430,7 @@ boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate)
return fs::path(pszPath);
}
- printf("SHGetSpecialFolderPathA() failed, could not obtain requested path.\n");
+ LogPrintf("SHGetSpecialFolderPathA() failed, could not obtain requested path.\n");
return fs::path("");
}
#endif
@@ -1442,7 +1450,7 @@ boost::filesystem::path GetTempPath() {
path = boost::filesystem::path("/tmp");
#endif
if (path.empty() || !boost::filesystem::is_directory(path)) {
- printf("GetTempPath(): failed to find temp path\n");
+ LogPrintf("GetTempPath(): failed to find temp path\n");
return boost::filesystem::path("");
}
return path;
@@ -1453,7 +1461,7 @@ void runCommand(std::string strCommand)
{
int nErr = ::system(strCommand.c_str());
if (nErr)
- printf("runCommand error: system(%s) returned %d\n", strCommand.c_str(), nErr);
+ LogPrintf("runCommand error: system(%s) returned %d\n", strCommand.c_str(), nErr);
}
void RenameThread(const char* name)
diff --git a/src/util.h b/src/util.h
index d0bd16c1c9..a216aacdc9 100644
--- a/src/util.h
+++ b/src/util.h
@@ -153,7 +153,10 @@ extern volatile bool fReopenDebugLog;
void RandAddSeed();
void RandAddSeedPerfmon();
-int ATTR_WARN_PRINTF(1,2) OutputDebugStringF(const char* pszFormat, ...);
+
+// Print to debug.log if -debug=category switch is given OR category is NULL.
+int ATTR_WARN_PRINTF(2,3) LogPrint(const char* category, const char* pszFormat, ...);
+#define LogPrintf(...) LogPrint(NULL, __VA_ARGS__)
/*
Rationale for the real_strprintf / strprintf construction:
@@ -173,14 +176,6 @@ std::string vstrprintf(const char *format, va_list ap);
bool ATTR_WARN_PRINTF(1,2) error(const char *format, ...);
-/* Redefine printf so that it directs output to debug.log
- *
- * Do this *after* defining the other printf-like functions, because otherwise the
- * __attribute__((format(printf,X,Y))) gets expanded to __attribute__((format(OutputDebugStringF,X,Y)))
- * which confuses gcc.
- */
-#define printf OutputDebugStringF
-
void LogException(std::exception* pex, const char* pszThread);
void PrintException(std::exception* pex, const char* pszThread);
void PrintExceptionContinue(std::exception* pex, const char* pszThread);
@@ -317,12 +312,12 @@ inline std::string HexStr(const T& vch, bool fSpaces=false)
template<typename T>
void PrintHex(const T pbegin, const T pend, const char* pszFormat="%s", bool fSpaces=true)
{
- printf(pszFormat, HexStr(pbegin, pend, fSpaces).c_str());
+ LogPrintf(pszFormat, HexStr(pbegin, pend, fSpaces).c_str());
}
inline void PrintHex(const std::vector<unsigned char>& vch, const char* pszFormat="%s", bool fSpaces=true)
{
- printf(pszFormat, HexStr(vch, fSpaces).c_str());
+ LogPrintf(pszFormat, HexStr(vch, fSpaces).c_str());
}
inline int64 GetPerformanceCounter()
@@ -560,7 +555,7 @@ template <typename Callable> void LoopForever(const char* name, Callable func,
{
std::string s = strprintf("bitcoin-%s", name);
RenameThread(s.c_str());
- printf("%s thread start\n", name);
+ LogPrintf("%s thread start\n", name);
try
{
while (1)
@@ -571,7 +566,7 @@ template <typename Callable> void LoopForever(const char* name, Callable func,
}
catch (boost::thread_interrupted)
{
- printf("%s thread stop\n", name);
+ LogPrintf("%s thread stop\n", name);
throw;
}
catch (std::exception& e) {
@@ -588,13 +583,13 @@ template <typename Callable> void TraceThread(const char* name, Callable func)
RenameThread(s.c_str());
try
{
- printf("%s thread start\n", name);
+ LogPrintf("%s thread start\n", name);
func();
- printf("%s thread exit\n", name);
+ LogPrintf("%s thread exit\n", name);
}
catch (boost::thread_interrupted)
{
- printf("%s thread interrupt\n", name);
+ LogPrintf("%s thread interrupt\n", name);
throw;
}
catch (std::exception& e) {
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 54ede12a50..91de93da7a 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -159,7 +159,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
if (pMasterKey.second.nDeriveIterations < 25000)
pMasterKey.second.nDeriveIterations = 25000;
- printf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations);
+ LogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations);
if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
@@ -267,7 +267,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
if (kMasterKey.nDeriveIterations < 25000)
kMasterKey.nDeriveIterations = 25000;
- printf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations);
+ LogPrintf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations);
if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod))
return false;
@@ -368,10 +368,10 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx)
{
CWalletTx& wtx = (*mi).second;
if (txin.prevout.n >= wtx.vout.size())
- printf("WalletUpdateSpent: bad wtx %s\n", wtx.GetHash().ToString().c_str());
+ LogPrintf("WalletUpdateSpent: bad wtx %s\n", wtx.GetHash().ToString().c_str());
else if (!wtx.IsSpent(txin.prevout.n) && IsMine(wtx.vout[txin.prevout.n]))
{
- printf("WalletUpdateSpent found spent coin %sbc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
+ LogPrintf("WalletUpdateSpent found spent coin %sbc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
wtx.MarkSpent(txin.prevout.n);
wtx.WriteToDisk();
NotifyTransactionChanged(this, txin.prevout.hash, CT_UPDATED);
@@ -446,9 +446,9 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
wtx.nTimeSmart = std::max(latestEntry, std::min(blocktime, latestNow));
}
else
- printf("AddToWallet() : found %s in block %s not in index\n",
- wtxIn.GetHash().ToString().c_str(),
- wtxIn.hashBlock.ToString().c_str());
+ LogPrintf("AddToWallet() : found %s in block %s not in index\n",
+ wtxIn.GetHash().ToString().c_str(),
+ wtxIn.hashBlock.ToString().c_str());
}
}
@@ -476,7 +476,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
}
//// debug print
- printf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString().c_str(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : ""));
+ LogPrintf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString().c_str(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : ""));
// Write to disk
if (fInsertedNew || fUpdated)
@@ -677,8 +677,8 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64> >& listReceived,
vector<unsigned char> vchPubKey;
if (!ExtractDestination(txout.scriptPubKey, address))
{
- printf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
- this->GetHash().ToString().c_str());
+ LogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
+ this->GetHash().ToString().c_str());
}
// Don't report 'change' txouts
@@ -849,7 +849,7 @@ void CWallet::ReacceptWalletTransactions()
}
if (fUpdated)
{
- printf("ReacceptWalletTransactions found spent coin %sbc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
+ LogPrintf("ReacceptWalletTransactions found spent coin %sbc %s\n", FormatMoney(wtx.GetCredit()).c_str(), wtx.GetHash().ToString().c_str());
wtx.MarkDirty();
wtx.WriteToDisk();
}
@@ -882,7 +882,7 @@ void CWalletTx::RelayWalletTransaction()
{
if (GetDepthInMainChain() == 0) {
uint256 hash = GetHash();
- printf("Relaying wtx %s\n", hash.ToString().c_str());
+ LogPrintf("Relaying wtx %s\n", hash.ToString().c_str());
RelayTransaction((CTransaction)*this, hash);
}
}
@@ -905,7 +905,7 @@ void CWallet::ResendWalletTransactions()
nLastResend = GetTime();
// Rebroadcast any of our txes that aren't in a block yet
- printf("ResendWalletTransactions()\n");
+ LogPrintf("ResendWalletTransactions()\n");
{
LOCK(cs_wallet);
// Sort them in chronological order
@@ -1145,12 +1145,11 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe
nValueRet += vValue[i].first;
}
- //// debug print
- printf("SelectCoins() best subset: ");
+ LogPrintf("selectcoins", "SelectCoins() best subset: ");
for (unsigned int i = 0; i < vValue.size(); i++)
if (vfBest[i])
- printf("%s ", FormatMoney(vValue[i].first).c_str());
- printf("total %s\n", FormatMoney(nBest).c_str());
+ LogPrintf("selectcoins", "%s ", FormatMoney(vValue[i].first).c_str());
+ LogPrintf("selectcoins", "total %s\n", FormatMoney(nBest).c_str());
}
return true;
@@ -1336,7 +1335,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
{
{
LOCK2(cs_main, cs_wallet);
- printf("CommitTransaction:\n%s", wtxNew.ToString().c_str());
+ LogPrintf("CommitTransaction:\n%s", wtxNew.ToString().c_str());
{
// This is only to keep the database open to defeat the auto-flush for the
// duration of this scope. This is the only place where this optimization
@@ -1372,7 +1371,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
if (!wtxNew.AcceptToMemoryPool(false))
{
// This must not fail. The transaction has already been signed and recorded.
- printf("CommitTransaction() : Error: Transaction not valid");
+ LogPrintf("CommitTransaction() : Error: Transaction not valid");
return false;
}
wtxNew.RelayWalletTransaction();
@@ -1391,7 +1390,7 @@ string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew,
if (IsLocked())
{
string strError = _("Error: Wallet locked, unable to create transaction!");
- printf("SendMoney() : %s", strError.c_str());
+ LogPrintf("SendMoney() : %s", strError.c_str());
return strError;
}
string strError;
@@ -1399,7 +1398,7 @@ string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew,
{
if (nValue + nFeeRequired > GetBalance())
strError = strprintf(_("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!"), FormatMoney(nFeeRequired).c_str());
- printf("SendMoney() : %s\n", strError.c_str());
+ LogPrintf("SendMoney() : %s\n", strError.c_str());
return strError;
}
@@ -1490,10 +1489,10 @@ void CWallet::PrintWallet(const CBlock& block)
if (mapWallet.count(block.vtx[0].GetHash()))
{
CWalletTx& wtx = mapWallet[block.vtx[0].GetHash()];
- printf(" mine: %d %d %"PRI64d"", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit());
+ LogPrintf(" mine: %d %d %"PRI64d"", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit());
}
}
- printf("\n");
+ LogPrintf("\n");
}
bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx)
@@ -1552,7 +1551,7 @@ bool CWallet::NewKeyPool()
walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey()));
setKeyPool.insert(nIndex);
}
- printf("CWallet::NewKeyPool wrote %"PRI64d" new keys\n", nKeys);
+ LogPrintf("CWallet::NewKeyPool wrote %"PRI64d" new keys\n", nKeys);
}
return true;
}
@@ -1582,7 +1581,7 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey())))
throw runtime_error("TopUpKeyPool() : writing generated key failed");
setKeyPool.insert(nEnd);
- printf("keypool added key %"PRI64d", size=%"PRIszu"\n", nEnd, setKeyPool.size());
+ LogPrintf("keypool added key %"PRI64d", size=%"PRIszu"\n", nEnd, setKeyPool.size());
}
}
return true;
@@ -1611,7 +1610,7 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool)
if (!HaveKey(keypool.vchPubKey.GetID()))
throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool");
assert(keypool.vchPubKey.IsValid());
- printf("keypool reserve %"PRI64d"\n", nIndex);
+ LogPrintf("keypool reserve %"PRI64d"\n", nIndex);
}
}
@@ -1638,7 +1637,7 @@ void CWallet::KeepKey(int64 nIndex)
CWalletDB walletdb(strWalletFile);
walletdb.ErasePool(nIndex);
}
- printf("keypool keep %"PRI64d"\n", nIndex);
+ LogPrintf("keypool keep %"PRI64d"\n", nIndex);
}
void CWallet::ReturnKey(int64 nIndex)
@@ -1648,7 +1647,7 @@ void CWallet::ReturnKey(int64 nIndex)
LOCK(cs_wallet);
setKeyPool.insert(nIndex);
}
- printf("keypool return %"PRI64d"\n", nIndex);
+ LogPrintf("keypool return %"PRI64d"\n", nIndex);
}
bool CWallet::GetKeyFromPool(CPubKey& result)
@@ -1836,7 +1835,7 @@ bool CReserveKey::GetReservedKey(CPubKey& pubkey)
vchPubKey = keypool.vchPubKey;
else {
if (pwallet->vchDefaultKey.IsValid()) {
- printf("CReserveKey::GetReservedKey(): Warning: Using default key instead of a new key, top up your keypool!");
+ LogPrintf("CReserveKey::GetReservedKey(): Warning: Using default key instead of a new key, top up your keypool!");
vchPubKey = pwallet->vchDefaultKey;
} else
return false;
diff --git a/src/wallet.h b/src/wallet.h
index b529d5f28b..51bc9f67c4 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -745,7 +745,7 @@ public:
void print() const
{
- printf("%s\n", ToString().c_str());
+ LogPrintf("%s\n", ToString().c_str());
}
};
diff --git a/src/walletdb.cpp b/src/walletdb.cpp
index 554d140024..635fda1b42 100644
--- a/src/walletdb.cpp
+++ b/src/walletdb.cpp
@@ -271,8 +271,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
wss.fAnyUnordered = true;
//// debug print
- //printf("LoadWallet %s\n", wtx.GetHash().ToString().c_str());
- //printf(" %12"PRI64d" %s %s %s\n",
+ //LogPrintf("LoadWallet %s\n", wtx.GetHash().ToString().c_str());
+ //LogPrintf(" %12"PRI64d" %s %s %s\n",
// wtx.vout[0].nValue,
// DateTimeStrFormat("%Y-%m-%d %H:%M:%S", wtx.GetBlockTime()).c_str(),
// wtx.hashBlock.ToString().c_str(),
@@ -451,7 +451,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
Dbc* pcursor = GetCursor();
if (!pcursor)
{
- printf("Error getting wallet database cursor\n");
+ LogPrintf("Error getting wallet database cursor\n");
return DB_CORRUPT;
}
@@ -465,7 +465,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
break;
else if (ret != 0)
{
- printf("Error reading next record from wallet database\n");
+ LogPrintf("Error reading next record from wallet database\n");
return DB_CORRUPT;
}
@@ -487,7 +487,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
}
}
if (!strErr.empty())
- printf("%s\n", strErr.c_str());
+ LogPrintf("%s\n", strErr.c_str());
}
pcursor->close();
}
@@ -506,9 +506,9 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
if (result != DB_LOAD_OK)
return result;
- printf("nFileVersion = %d\n", wss.nFileVersion);
+ LogPrintf("nFileVersion = %d\n", wss.nFileVersion);
- printf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n",
+ LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n",
wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys);
// nTimeFirstKey is only reliable if all keys have metadata
@@ -576,7 +576,7 @@ void ThreadFlushWalletDB(const string& strFile)
map<string, int>::iterator mi = bitdb.mapFileUseCount.find(strFile);
if (mi != bitdb.mapFileUseCount.end())
{
- printf("Flushing wallet.dat\n");
+ LogPrint("db", "Flushing wallet.dat\n");
nLastFlushed = nWalletDBUpdated;
int64 nStart = GetTimeMillis();
@@ -585,7 +585,7 @@ void ThreadFlushWalletDB(const string& strFile)
bitdb.CheckpointLSN(strFile);
bitdb.mapFileUseCount.erase(mi++);
- printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart);
+ LogPrint("db", "Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart);
}
}
}
@@ -620,10 +620,10 @@ bool BackupWallet(const CWallet& wallet, const string& strDest)
#else
filesystem::copy_file(pathSrc, pathDest);
#endif
- printf("copied wallet.dat to %s\n", pathDest.string().c_str());
+ LogPrintf("copied wallet.dat to %s\n", pathDest.string().c_str());
return true;
} catch(const filesystem::filesystem_error &e) {
- printf("error copying wallet.dat to %s - %s\n", pathDest.string().c_str(), e.what());
+ LogPrintf("error copying wallet.dat to %s - %s\n", pathDest.string().c_str(), e.what());
return false;
}
}
@@ -651,10 +651,10 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
int result = dbenv.dbenv.dbrename(NULL, filename.c_str(), NULL,
newFilename.c_str(), DB_AUTO_COMMIT);
if (result == 0)
- printf("Renamed %s to %s\n", filename.c_str(), newFilename.c_str());
+ LogPrintf("Renamed %s to %s\n", filename.c_str(), newFilename.c_str());
else
{
- printf("Failed to rename %s to %s\n", filename.c_str(), newFilename.c_str());
+ LogPrintf("Failed to rename %s to %s\n", filename.c_str(), newFilename.c_str());
return false;
}
@@ -662,10 +662,10 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
bool allOK = dbenv.Salvage(newFilename, true, salvagedData);
if (salvagedData.empty())
{
- printf("Salvage(aggressive) found no records in %s.\n", newFilename.c_str());
+ LogPrintf("Salvage(aggressive) found no records in %s.\n", newFilename.c_str());
return false;
}
- printf("Salvage(aggressive) found %"PRIszu" records\n", salvagedData.size());
+ LogPrintf("Salvage(aggressive) found %"PRIszu" records\n", salvagedData.size());
bool fSuccess = allOK;
Db* pdbCopy = new Db(&dbenv.dbenv, 0);
@@ -677,7 +677,7 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
0);
if (ret > 0)
{
- printf("Cannot create database file %s\n", filename.c_str());
+ LogPrintf("Cannot create database file %s\n", filename.c_str());
return false;
}
CWallet dummyWallet;
@@ -697,7 +697,7 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
continue;
if (!fReadOK)
{
- printf("WARNING: CWalletDB::Recover skipping %s: %s\n", strType.c_str(), strErr.c_str());
+ LogPrintf("WARNING: CWalletDB::Recover skipping %s: %s\n", strType.c_str(), strErr.c_str());
continue;
}
}