aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-01-03 15:24:28 -0500
committerGavin Andresen <gavinandresen@gmail.com>2012-01-03 15:48:59 -0500
commitd237f62c2360107235fc75f4533711e98c70e2aa (patch)
treecc91ec15cbefb109bc0506f12733a03f173c60a1 /src/main.cpp
parent96d3bcb99690726d4c0e28355cc87c25e14f4c8d (diff)
downloadbitcoin-d237f62c2360107235fc75f4533711e98c70e2aa.tar.xz
-blocknotify=command argument, implemented using system() and boost::thread
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 15f047bf7b..52a3c3fde5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,6 +7,7 @@
#include "db.h"
#include "net.h"
#include "init.h"
+#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
@@ -1278,6 +1279,14 @@ bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew)
}
+static 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);
+}
+
bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
{
uint256 hash = GetHash();
@@ -1321,7 +1330,8 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
}
// Update best block in wallet (so we can detect restored wallets)
- if (!IsInitialBlockDownload())
+ bool fIsInitialDownload = IsInitialBlockDownload();
+ if (!fIsInitialDownload)
{
const CBlockLocator locator(pindexNew);
::SetBestChain(locator);
@@ -1336,6 +1346,14 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
nTransactionsUpdated++;
printf("SetBestChain: new best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());
+ std::string strCmd = GetArg("-blocknotify", "");
+
+ if (!fIsInitialDownload && !strCmd.empty())
+ {
+ boost::replace_all(strCmd, "%s", hashBestChain.GetHex());
+ boost::thread t(runCommand, strCmd); // thread runs free
+ }
+
return true;
}