Skip to content

Commit

Permalink
Modify addkey and project constructor to deal with auto greylist over…
Browse files Browse the repository at this point in the history
…ride
  • Loading branch information
jamescowens committed Jan 19, 2025
1 parent cf9fb42 commit 147252d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
21 changes: 19 additions & 2 deletions src/gridcoin/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,28 @@ Project::Project(uint32_t version, std::string name, std::string url, bool gdpr_
{
}

Project::Project(uint32_t version, std::string name, std::string url, bool gdpr_controls, bool manual_greylist)
Project::Project(uint32_t version, std::string name, std::string url, bool gdpr_controls, ProjectEntryStatus status)
: ProjectEntry(version, name, url, gdpr_controls, ProjectEntryStatus::UNKNOWN, int64_t {0})
{
if (manual_greylist) {
// The only two values that make sense for status using this constructor overload are MAN_GREYLISTED and
// AUTO_GREYLIST_OVERRIDE. The other are handled by the contract action context and the other overloads.
switch (status) {
case ProjectEntryStatus::MAN_GREYLISTED:
m_status = ProjectEntryStatus::MAN_GREYLISTED;
break;
case ProjectEntryStatus::AUTO_GREYLIST_OVERRIDE:
m_status = ProjectEntryStatus::AUTO_GREYLIST_OVERRIDE;
break;
case ProjectEntryStatus::ACTIVE:
break;
case ProjectEntryStatus::DELETED:
break;
case ProjectEntryStatus::AUTO_GREYLISTED:
break;
case ProjectEntryStatus::UNKNOWN:
break;
case ProjectEntryStatus::OUT_OF_BOUND:
break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gridcoin/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ class Project : public IContractPayload, public ProjectEntry
//! \param name Project name from contract message key.
//! \param url Project URL from contract message value.
//! \param gdpr_controls Boolean to indicate gdpr stats export controls enforced
//! \param manual_greylist Boolean to force manual greylisting of project
//! \param status ProjectEntryStatus to force project status.
//!
Project(uint32_t version, std::string name, std::string url, bool gdpr_controls, bool manual_greylist);
Project(uint32_t version, std::string name, std::string url, bool gdpr_controls, ProjectEntryStatus status);

//!
//! \brief Initialize a \c Project using data from the contract.
Expand Down
39 changes: 29 additions & 10 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2297,7 +2297,20 @@ UniValue addkey(const UniValue& params, bool fHelp)
if (fHelp || params.size() < required_param_count || params.size() > param_count_max) {
std::string error_string;

if (project_v2_enabled) {
if (block_v13_enabled) {
error_string = "addkey <action> <keytype> <keyname> <keyvalue> <gdpr_protection_bool> <status> \n"
"\n"
"<action> ---> Specify add or delete of key\n"
"<keytype> --> Specify keytype ex: project\n"
"<keyname> --> Specify keyname ex: milky\n"
"<keyvalue> -> Specify keyvalue ex: 1\n"
"\n"
"For project keytype only\n"
"<gdpr_protection_bool> -> true if GDPR stats export protection is enforced for project\n"
"<status> -> auto_greylist_override or man_greylist. Defaults to blank."
"\n"
"Add a key to the network";
} else if (project_v2_enabled) {
error_string = "addkey <action> <keytype> <keyname> <keyvalue> <gdpr_protection_bool>\n"
"\n"
"<action> ---> Specify add or delete of key\n"
Expand Down Expand Up @@ -2346,7 +2359,8 @@ UniValue addkey(const UniValue& params, bool fHelp)
{
if (action == GRC::ContractAction::ADD) {
bool gdpr_export_control = false;
bool manually_greylist = false;
//bool manually_greylist = false;
GRC::ProjectEntryStatus status = GRC::ProjectEntryStatus::UNKNOWN;

if (block_v13_enabled) {
// We must do our own conversion to boolean here, because the 5th parameter can either be
Expand All @@ -2360,8 +2374,13 @@ UniValue addkey(const UniValue& params, bool fHelp)
}

if (params.size() == 6) {
if (ToLower(params[4].get_str()) == "true") {
manually_greylist = true;
if (ToLower(params[4].get_str()) == "man_greylist") {
status = GRC::ProjectEntryStatus::MAN_GREYLISTED;
} else if (ToLower(params[4].get_str()) == "auto_greylist_override") {
status = GRC::ProjectEntryStatus::AUTO_GREYLIST_OVERRIDE;
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "project status specifier, if provided, must be either man_greylist "
"or auto_greylist_override");
}
}

Expand All @@ -2372,7 +2391,7 @@ UniValue addkey(const UniValue& params, bool fHelp)
params[2].get_str(), // Name
params[3].get_str(), // URL
gdpr_export_control, // GDPR stats export protection enforced boolean
manually_greylist); // manual greylist flag
status); // manual greylist flag

} else if (project_v2_enabled) {
// We must do our own conversion to boolean here, because the 5th parameter can either be
Expand Down Expand Up @@ -2405,11 +2424,11 @@ UniValue addkey(const UniValue& params, bool fHelp)
contract = GRC::MakeContract<GRC::Project>(
contract_version,
action,
uint32_t{3}, // Contract payload version number, 3
params[2].get_str(), // Name
std::string{}, // URL ignored
false, // GDPR status irrelevant
false); // manual greylisting irrelevant
uint32_t{3}, // Contract payload version number, 3
params[2].get_str(), // Name
std::string{}, // URL ignored
false, // GDPR status irrelevant
GRC::ProjectEntryStatus::UNKNOWN); // manual greylisting or auto greylist override irrelevant

} else if (project_v2_enabled) {
contract = GRC::MakeContract<GRC::Project>(
Expand Down

0 comments on commit 147252d

Please sign in to comment.