Merge pull request #1238 from rnicoll/1.10-block-notify-height

Add block height to block notification
This commit is contained in:
Max K. 2015-08-13 18:41:49 +02:00
commit 1027b821df
3 changed files with 6 additions and 4 deletions

View File

@ -44,6 +44,7 @@
#include <boost/filesystem.hpp>
#include <boost/function.hpp>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
@ -269,7 +270,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-?", _("This help message"));
strUsage += HelpMessageOpt("-alerts", strprintf(_("Receive and display P2P network alerts (default: %u)"), DEFAULT_ALERTS));
strUsage += HelpMessageOpt("-alertnotify=<cmd>", _("Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)"));
strUsage += HelpMessageOpt("-blocknotify=<cmd>", _("Execute command when the best block changes (%s in cmd is replaced by block hash)"));
strUsage += HelpMessageOpt("-blocknotify=<cmd>", _("Execute command when the best block changes (%s in cmd is replaced by block hash, %i is replaced by block number)"));
strUsage += HelpMessageOpt("-checkblocks=<n>", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), 288));
strUsage += HelpMessageOpt("-checklevel=<n>", strprintf(_("How thorough the block verification of -checkblocks is (0-4, default: %u)"), 3));
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), "bitcoin.conf"));
@ -452,11 +453,12 @@ std::string LicenseInfo()
"\n";
}
static void BlockNotifyCallback(const uint256& hashNewTip)
static void BlockNotifyCallback(const uint256& hashNewTip, const int nHeight)
{
std::string strCmd = GetArg("-blocknotify", "");
boost::replace_all(strCmd, "%s", hashNewTip.GetHex());
boost::replace_all(strCmd, "%i", boost::lexical_cast<std::string>(chainActive.Height()));
boost::thread t(runCommand, strCmd); // thread runs free
}

View File

@ -2424,7 +2424,7 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) {
pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip));
}
// Notify external listeners about the new tip.
uiInterface.NotifyBlockTip(hashNewTip);
uiInterface.NotifyBlockTip(hashNewTip, pindexNewTip->nHeight);
}
} while(pindexMostWork != chainActive.Tip());
CheckBlockIndex();

View File

@ -94,7 +94,7 @@ public:
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
/** New block has been accepted */
boost::signals2::signal<void (const uint256& hash)> NotifyBlockTip;
boost::signals2::signal<void (const uint256& hash, const int nHeight)> NotifyBlockTip;
};
extern CClientUIInterface uiInterface;