aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@bitpay.com>2014-08-14 12:32:34 -0400
committerJeff Garzik <jgarzik@bitpay.com>2014-08-14 12:32:34 -0400
commitc7b6117debf4ebabc464a55b840bdd7bdeb94fa3 (patch)
treef0a46587349bba3bb5ab0a3a01e589e9c8e18502
parentbeb36e800c393da3c5857a8f1e5959748ac0f96b (diff)
downloadbitcoin-c7b6117debf4ebabc464a55b840bdd7bdeb94fa3.tar.xz
Create new signal for notification of new blocks. Use w/ -blocknotify
-rw-r--r--src/init.cpp11
-rw-r--r--src/main.cpp8
-rw-r--r--src/ui_interface.h3
3 files changed, 17 insertions, 5 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 8ae228bbbe..494342c693 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -367,6 +367,14 @@ std::string LicenseInfo()
"\n";
}
+static void BlockNotifyCallback(const uint256& hashNewTip)
+{
+ std::string strCmd = GetArg("-blocknotify", "");
+
+ boost::replace_all(strCmd, "%s", hashNewTip.GetHex());
+ boost::thread t(runCommand, strCmd); // thread runs free
+}
+
struct CImportingNow
{
CImportingNow() {
@@ -1184,6 +1192,9 @@ bool AppInit2(boost::thread_group& threadGroup)
#endif // !ENABLE_WALLET
// ********************************************************* Step 9: import blocks
+ if (mapArgs.count("-blocknotify"))
+ uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
+
// scan for better chains in the block chain database, that are not yet connected in the active best chain
CValidationState state;
if (!ActivateBestChain(state))
diff --git a/src/main.cpp b/src/main.cpp
index e73942d7e0..841cc1952f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2162,16 +2162,14 @@ bool ActivateBestChain(CValidationState &state) {
uint256 hashNewTip = pindexNewTip->GetBlockHash();
// Relay inventory, but don't relay old inventory during initial block download.
int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate();
+ {
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate))
pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip));
-
- std::string strCmd = GetArg("-blocknotify", "");
- if (!strCmd.empty()) {
- boost::replace_all(strCmd, "%s", hashNewTip.GetHex());
- boost::thread t(runCommand, strCmd); // thread runs free
}
+
+ uiInterface.NotifyBlockTip(hashNewTip);
}
} while(pindexMostWork != chainActive.Tip());
diff --git a/src/ui_interface.h b/src/ui_interface.h
index a073a32828..bbc8a203c9 100644
--- a/src/ui_interface.h
+++ b/src/ui_interface.h
@@ -92,6 +92,9 @@ public:
/** Show progress e.g. for verifychain */
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
+
+ /** New block has been accepted */
+ boost::signals2::signal<void (const uint256& hash)> NotifyBlockTip;
};
extern CClientUIInterface uiInterface;