0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

Avoid callback when -blocknotify is empty

This commit is contained in:
João Barbosa 2020-08-30 17:27:22 +01:00
parent 4631dc5c57
commit 413e0d1d31

View file

@ -1828,20 +1828,15 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
} }
#if HAVE_SYSTEM #if HAVE_SYSTEM
if (args.IsArgSet("-blocknotify")) { const std::string block_notify = args.GetArg("-blocknotify", "");
const std::string block_notify = args.GetArg("-blocknotify", ""); if (!block_notify.empty()) {
const auto BlockNotifyCallback = [block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) { uiInterface.NotifyBlockTip_connect([block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) return;
return; std::string command = block_notify;
boost::replace_all(command, "%s", pBlockIndex->GetBlockHash().GetHex());
std::string strCmd = block_notify; std::thread t(runCommand, command);
if (!strCmd.empty()) { t.detach(); // thread runs free
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex()); });
std::thread t(runCommand, strCmd);
t.detach(); // thread runs free
}
};
uiInterface.NotifyBlockTip_connect(BlockNotifyCallback);
} }
#endif #endif