Skip to content

Commit 413e0d1

Browse files
committed
Avoid callback when -blocknotify is empty
1 parent 4631dc5 commit 413e0d1

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/init.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,20 +1828,15 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
18281828
}
18291829

18301830
#if HAVE_SYSTEM
1831-
if (args.IsArgSet("-blocknotify")) {
1832-
const std::string block_notify = args.GetArg("-blocknotify", "");
1833-
const auto BlockNotifyCallback = [block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
1834-
if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex)
1835-
return;
1836-
1837-
std::string strCmd = block_notify;
1838-
if (!strCmd.empty()) {
1839-
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
1840-
std::thread t(runCommand, strCmd);
1841-
t.detach(); // thread runs free
1842-
}
1843-
};
1844-
uiInterface.NotifyBlockTip_connect(BlockNotifyCallback);
1831+
const std::string block_notify = args.GetArg("-blocknotify", "");
1832+
if (!block_notify.empty()) {
1833+
uiInterface.NotifyBlockTip_connect([block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
1834+
if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) return;
1835+
std::string command = block_notify;
1836+
boost::replace_all(command, "%s", pBlockIndex->GetBlockHash().GetHex());
1837+
std::thread t(runCommand, command);
1838+
t.detach(); // thread runs free
1839+
});
18451840
}
18461841
#endif
18471842

0 commit comments

Comments
 (0)