diff options
| author | Gavin Andresen <[email protected]> | 2012-01-12 06:31:25 -0800 |
|---|---|---|
| committer | Gavin Andresen <[email protected]> | 2012-01-12 06:31:25 -0800 |
| commit | 3f64fa1369bde45034e451c4093e0852e59a1cdf (patch) | |
| tree | 2660c3cdcb6153cacf7524e13dc46dd0564b5b4f /src/main.cpp | |
| parent | Merge pull request #649 from sipa/comprpubkey (diff) | |
| parent | -blocknotify=command argument, implemented using system() and boost::thread (diff) | |
| download | discoin-3f64fa1369bde45034e451c4093e0852e59a1cdf.tar.xz discoin-3f64fa1369bde45034e451c4093e0852e59a1cdf.zip | |
Merge pull request #743 from gavinandresen/blocknotify
-blocknotify : run a command when best-block changes
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index 9a3ce6539..2d5e9a181 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; } |