Create new signal for notification of new blocks. Use w/ -blocknotify
This commit is contained in:
parent
beb36e800c
commit
c7b6117deb
11
src/init.cpp
11
src/init.cpp
@ -367,6 +367,14 @@ std::string LicenseInfo()
|
|||||||
"\n";
|
"\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
|
struct CImportingNow
|
||||||
{
|
{
|
||||||
CImportingNow() {
|
CImportingNow() {
|
||||||
@ -1184,6 +1192,9 @@ bool AppInit2(boost::thread_group& threadGroup)
|
|||||||
#endif // !ENABLE_WALLET
|
#endif // !ENABLE_WALLET
|
||||||
// ********************************************************* Step 9: import blocks
|
// ********************************************************* 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
|
// scan for better chains in the block chain database, that are not yet connected in the active best chain
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
if (!ActivateBestChain(state))
|
if (!ActivateBestChain(state))
|
||||||
|
@ -2162,16 +2162,14 @@ bool ActivateBestChain(CValidationState &state) {
|
|||||||
uint256 hashNewTip = pindexNewTip->GetBlockHash();
|
uint256 hashNewTip = pindexNewTip->GetBlockHash();
|
||||||
// Relay inventory, but don't relay old inventory during initial block download.
|
// Relay inventory, but don't relay old inventory during initial block download.
|
||||||
int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate();
|
int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate();
|
||||||
|
{
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||||
if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate))
|
if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate))
|
||||||
pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip));
|
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());
|
} while(pindexMostWork != chainActive.Tip());
|
||||||
|
|
||||||
|
@ -92,6 +92,9 @@ public:
|
|||||||
|
|
||||||
/** Show progress e.g. for verifychain */
|
/** Show progress e.g. for verifychain */
|
||||||
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
|
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;
|
extern CClientUIInterface uiInterface;
|
||||||
|
Loading…
Reference in New Issue
Block a user