Skip to content

Commit

Permalink
Merge bitcoin#19840: Avoid callback when -blocknotify is empty
Browse files Browse the repository at this point in the history
413e0d1 Avoid callback when -blocknotify is empty (João Barbosa)

Pull request description:

ACKs for top commit:
  MarcoFalke:
    ACK 413e0d1
  practicalswift:
    ACK 413e0d1 -- patch looks correct
  laanwj:
    Code review ACK 413e0d1

Tree-SHA512: 915e796666b4e74dbb029ba5436e5573a4b881aad9e118f737bcff4024528b7ff3b00dd035138f63d30963cfd66195f6e53a2dbe429ee28cb6f0b9cc47218ecf
  • Loading branch information
laanwj committed Sep 2, 2020
2 parents 8845b38 + 413e0d1 commit c157a50
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1833,20 +1833,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

Expand Down

0 comments on commit c157a50

Please sign in to comment.