Skip to content

Commit

Permalink
Implement NotifyProjectChanged core signal
Browse files Browse the repository at this point in the history
Also implement corresponding -projectnotify startup parameter that
provides the ability to run a cmd based on a change to the whitelist.
  • Loading branch information
jamescowens committed Nov 25, 2024
1 parent de00a19 commit b72bc83
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/gridcoin/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,32 @@ void Whitelist::AddDelete(const ContractContext& ctx)
historical.m_hash.GetHex());
}

auto project_iter = m_project_db.find(ctx.m_tx.GetHash());

// Finally, insert the new project entry (payload) smart pointer into the m_project_entries map.
m_project_entries[payload.m_name] = m_project_db.find(ctx.m_tx.GetHash())->second;
m_project_entries[payload.m_name] = project_iter->second;

ChangeType status;

if (project_iter->second->m_status == ProjectEntryStatus::DELETED) {
status = CT_DELETED;
} else if (current_project_entry_present) {
status = CT_UPDATED;
} else {
status = CT_NEW;
}

NotifyProjectChanged(project_iter->second, status);

// notify an external script when a project is added to the whitelist, or a project status changes.
#if HAVE_SYSTEM
std::string cmd = gArgs.GetArg("-projectnotify", "");

if (!cmd.empty()) {
std::thread t(runCommand, cmd);
t.detach(); // thread runs free
}
#endif

return;

Expand Down
6 changes: 6 additions & 0 deletions src/gridcoin/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "serialize.h"
#include "pubkey.h"
#include "sync.h"
#include "node/ui_interface.h"

#include <memory>
#include <vector>
Expand Down Expand Up @@ -667,6 +668,11 @@ class Whitelist : public IContractHandler
std::set<ProjectEntry>,
HistoricalProjectEntryMap> ProjectEntryDB;

//!
//! \brief Core signal to indicate that a project status has changed.
//!
boost::signals2::signal<void (const ProjectEntry_ptr project, ChangeType status)> NotifyProjectChanged;

private:
//!
//! \brief Protects the registry with multithreaded access. This is implemented INTERNAL to the registry class.
Expand Down

0 comments on commit b72bc83

Please sign in to comment.