mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
RPC: refactor spork
rpc
This commit is contained in:
parent
564b3d68fe
commit
e8febda363
@ -139,7 +139,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "setnetworkactive", 0, "state" },
|
||||
{ "getmempoolancestors", 1, "verbose" },
|
||||
{ "getmempooldescendants", 1, "verbose" },
|
||||
{ "spork", 1, "datetime" },
|
||||
{ "spork", 1, "value" },
|
||||
{ "voteraw", 1, "tx_index" },
|
||||
{ "voteraw", 5, "time" },
|
||||
{ "getblockhashes", 0, "high"},
|
||||
|
@ -224,14 +224,17 @@ public:
|
||||
*/
|
||||
UniValue spork(const JSONRPCRequest& request)
|
||||
{
|
||||
if(request.params.size() == 1 && request.params[0].get_str() == "show"){
|
||||
if (request.params.size() == 1) {
|
||||
// basic mode, show info
|
||||
std:: string strCommand = request.params[0].get_str();
|
||||
if (strCommand == "show") {
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
for(int nSporkID = SPORK_START; nSporkID <= SPORK_END; nSporkID++){
|
||||
if(sporkManager.GetSporkNameByID(nSporkID) != "Unknown")
|
||||
ret.push_back(Pair(sporkManager.GetSporkNameByID(nSporkID), sporkManager.GetSporkValue(nSporkID)));
|
||||
}
|
||||
return ret;
|
||||
} else if(request.params.size() == 1 && request.params[0].get_str() == "active"){
|
||||
} else if(strCommand == "active"){
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
for(int nSporkID = SPORK_START; nSporkID <= SPORK_END; nSporkID++){
|
||||
if(sporkManager.GetSporkNameByID(nSporkID) != "Unknown")
|
||||
@ -239,13 +242,35 @@ UniValue spork(const JSONRPCRequest& request)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#ifdef ENABLE_WALLET
|
||||
else if (request.params.size() == 2){
|
||||
int nSporkID = sporkManager.GetSporkIDByName(request.params[0].get_str());
|
||||
if(nSporkID == -1){
|
||||
return "Invalid spork name";
|
||||
}
|
||||
|
||||
if (request.fHelp || request.params.size() != 2) {
|
||||
// default help, for basic mode
|
||||
throw std::runtime_error(
|
||||
"spork \"command\"\n"
|
||||
"\nShows information about current state of sporks\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"command\" (string, required) 'show' to show all current spork values, 'active' to show which sporks are active\n"
|
||||
"\nResult:\n"
|
||||
"For 'show':\n"
|
||||
"{\n"
|
||||
" \"SPORK_NAME\" : spork_value, (number) The value of the specific spork with the name SPORK_NAME\n"
|
||||
" ...\n"
|
||||
"}\n"
|
||||
"For 'active':\n"
|
||||
"{\n"
|
||||
" \"SPORK_NAME\" : true|false, (boolean) 'true' for time-based sporks if spork is active and 'false' otherwise\n"
|
||||
" ...\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("spork", "show")
|
||||
+ HelpExampleRpc("spork", "\"show\""));
|
||||
} else {
|
||||
// advanced mode, update spork values
|
||||
int nSporkID = sporkManager.GetSporkIDByName(request.params[0].get_str());
|
||||
if(nSporkID == -1)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid spork name");
|
||||
|
||||
if (!g_connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
@ -257,21 +282,20 @@ UniValue spork(const JSONRPCRequest& request)
|
||||
sporkManager.ExecuteSpork(nSporkID, nValue);
|
||||
return "success";
|
||||
} else {
|
||||
return "failure";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
"spork <name> [<value>]\n"
|
||||
"<name> is the corresponding spork name, or 'show' to show all current spork settings, 'active' to show which sporks are active\n"
|
||||
"<value> is a epoch datetime to enable or disable spork\n"
|
||||
"spork \"name\" value\n"
|
||||
"\nUpdate the value of the specific spork. Requires \"-sporkkey\" to be set to sign the message.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"name\" (string, required) The name of the spork to update\n"
|
||||
"2. value (number, required) The new desired value of the spork\n"
|
||||
"\nResult:\n"
|
||||
" result (string) \"success\" if spork value was updated or this help otherwise\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("spork", "SPORK_2_INSTANTSEND_ENABLED 4070908800")
|
||||
+ HelpExampleRpc("spork", "\"SPORK_2_INSTANTSEND_ENABLED\", 4070908800")
|
||||
+ HelpRequiringPassphrase());
|
||||
#else // ENABLE_WALLET
|
||||
throw std::runtime_error(
|
||||
"spork <name>\n"
|
||||
"<name> is the corresponding spork name, or 'show' to show all current spork settings, 'active' to show which sporks are active\n");
|
||||
#endif // ENABLE_WALLET
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1129,7 +1153,7 @@ static const CRPCCommand commands[] =
|
||||
|
||||
/* Dash features */
|
||||
{ "dash", "mnsync", &mnsync, true, {} },
|
||||
{ "dash", "spork", &spork, true, {"datetime"} },
|
||||
{ "dash", "spork", &spork, true, {"value"} },
|
||||
|
||||
/* Not shown in help */
|
||||
{ "hidden", "setmocktime", &setmocktime, true, {"timestamp"}},
|
||||
|
Loading…
Reference in New Issue
Block a user