Skip to content

Commit fa33bc2

Browse files
author
MarcoFalke
committed
init: Capture copy of blocknotify setting for BlockNotifyCallback
Can be reviewed with --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
1 parent fa40017 commit fa33bc2

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/init.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -600,21 +600,6 @@ std::string LicenseInfo()
600600
"\n";
601601
}
602602

603-
#if HAVE_SYSTEM
604-
static void BlockNotifyCallback(SynchronizationState sync_state, const CBlockIndex* pBlockIndex)
605-
{
606-
if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex)
607-
return;
608-
609-
std::string strCmd = gArgs.GetArg("-blocknotify", "");
610-
if (!strCmd.empty()) {
611-
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
612-
std::thread t(runCommand, strCmd);
613-
t.detach(); // thread runs free
614-
}
615-
}
616-
#endif
617-
618603
static bool fHaveGenesis = false;
619604
static Mutex g_genesis_wait_mutex;
620605
static std::condition_variable g_genesis_wait_cv;
@@ -1847,8 +1832,21 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
18471832
}
18481833

18491834
#if HAVE_SYSTEM
1850-
if (gArgs.IsArgSet("-blocknotify"))
1835+
if (args.IsArgSet("-blocknotify")) {
1836+
const std::string block_notify = args.GetArg("-blocknotify", "");
1837+
const auto BlockNotifyCallback = [block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
1838+
if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex)
1839+
return;
1840+
1841+
std::string strCmd = block_notify;
1842+
if (!strCmd.empty()) {
1843+
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
1844+
std::thread t(runCommand, strCmd);
1845+
t.detach(); // thread runs free
1846+
}
1847+
};
18511848
uiInterface.NotifyBlockTip_connect(BlockNotifyCallback);
1849+
}
18521850
#endif
18531851

18541852
std::vector<fs::path> vImportFiles;

0 commit comments

Comments
 (0)