aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoão Barbosa <joao.paulo.barbosa@gmail.com>2020-08-30 17:27:22 +0100
committerJoão Barbosa <joao.paulo.barbosa@gmail.com>2020-08-30 17:38:27 +0100
commit413e0d1d31ede6a9b539d63ec814b6e8044e35e2 (patch)
tree7cc76ca02692f5f5915e1598c4c9f49c9337b8d0 /src
parent4631dc5c578475fd3ca7a91676f7daf788a11192 (diff)
Avoid callback when -blocknotify is empty
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/init.cpp b/src/init.cpp
index ecd57960ad..4bb98b1eb2 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1828,20 +1828,15 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
}
#if HAVE_SYSTEM
- if (args.IsArgSet("-blocknotify")) {
- const std::string block_notify = args.GetArg("-blocknotify", "");
- const auto BlockNotifyCallback = [block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
- if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex)
- return;
-
- std::string strCmd = block_notify;
- if (!strCmd.empty()) {
- boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
- std::thread t(runCommand, strCmd);
- t.detach(); // thread runs free
- }
- };
- uiInterface.NotifyBlockTip_connect(BlockNotifyCallback);
+ const std::string block_notify = args.GetArg("-blocknotify", "");
+ if (!block_notify.empty()) {
+ uiInterface.NotifyBlockTip_connect([block_notify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
+ if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) return;
+ std::string command = block_notify;
+ boost::replace_all(command, "%s", pBlockIndex->GetBlockHash().GetHex());
+ std::thread t(runCommand, command);
+ t.detach(); // thread runs free
+ });
}
#endif