Skip to content

Commit 1d56dff

Browse files
authored
Unify help display logic for various "complex" rpc commands (#2415)
* Unify help display logic for various "complex" rpc commands * add [[ noreturn ]] attribute and drop dummy returns
1 parent bea5909 commit 1d56dff

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

src/rpc/governance.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ UniValue gobject_getcurrentvotes(const JSONRPCRequest& request)
945945
return bResult;
946946
}
947947

948-
void gobject_help()
948+
[[ noreturn ]] void gobject_help()
949949
{
950950
throw std::runtime_error(
951951
"gobject \"command\"...\n"
@@ -975,15 +975,9 @@ UniValue gobject(const JSONRPCRequest& request)
975975
if (request.params.size() >= 1)
976976
strCommand = request.params[0].get_str();
977977

978-
if ((request.fHelp && strCommand.empty()) ||
979-
(
980-
#ifdef ENABLE_WALLET
981-
strCommand != "prepare" &&
982-
#endif // ENABLE_WALLET
983-
strCommand != "vote-many" && strCommand != "vote-conf" && strCommand != "vote-alias" && strCommand != "submit" && strCommand != "count" &&
984-
strCommand != "deserialize" && strCommand != "get" && strCommand != "getvotes" && strCommand != "getcurrentvotes" && strCommand != "list" && strCommand != "diff" &&
985-
strCommand != "check" ))
986-
gobject_help();
978+
if (request.fHelp || strCommand.empty()) {
979+
gobject_help();
980+
}
987981

988982
if (strCommand == "count") {
989983
return gobject_count(request);
@@ -1026,9 +1020,9 @@ UniValue gobject(const JSONRPCRequest& request)
10261020
} else if (strCommand == "getcurrentvotes") {
10271021
// GETVOTES FOR SPECIFIC GOVERNANCE OBJECT
10281022
return gobject_getcurrentvotes(request);
1023+
} else {
1024+
gobject_help();
10291025
}
1030-
1031-
throw std::runtime_error("invalid command: " + strCommand);
10321026
}
10331027

10341028
UniValue voteraw(const JSONRPCRequest& request)

src/rpc/masternode.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ UniValue masternode_check(const JSONRPCRequest& request)
757757
return obj;
758758
}
759759

760-
void masternode_help()
760+
[[ noreturn ]] void masternode_help()
761761
{
762762
throw std::runtime_error(
763763
"masternode \"command\"...\n"
@@ -794,7 +794,7 @@ UniValue masternode(const JSONRPCRequest& request)
794794
throw JSONRPCError(RPC_INVALID_PARAMETER, "DEPRECATED, please use start-all instead");
795795
#endif // ENABLE_WALLET
796796

797-
if (request.fHelp && strCommand.empty()) {
797+
if (request.fHelp || strCommand.empty()) {
798798
masternode_help();
799799
}
800800

@@ -834,7 +834,6 @@ UniValue masternode(const JSONRPCRequest& request)
834834
return masternode_check(request);
835835
} else {
836836
masternode_help();
837-
return UniValue::VNULL; // avoid compiler warnings
838837
}
839838
}
840839

src/rpc/rpcevo.cpp

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -819,28 +819,32 @@ UniValue protx_diff(const JSONRPCRequest& request)
819819
return ret;
820820
}
821821

822+
[[ noreturn ]] void protx_help()
823+
{
824+
throw std::runtime_error(
825+
"protx \"command\" ...\n"
826+
"Set of commands to execute ProTx related actions.\n"
827+
"To get help on individual commands, use \"help protx command\".\n"
828+
"\nArguments:\n"
829+
"1. \"command\" (string, required) The command to execute\n"
830+
"\nAvailable commands:\n"
831+
" register - Create and send ProTx to network\n"
832+
" register_fund - Fund, create and send ProTx to network\n"
833+
" register_prepare - Create an unsigned ProTx\n"
834+
" register_submit - Sign and submit a ProTx\n"
835+
" list - List ProTxs\n"
836+
" info - Return information about a ProTx\n"
837+
" update_service - Create and send ProUpServTx to network\n"
838+
" update_registrar - Create and send ProUpRegTx to network\n"
839+
" revoke - Create and send ProUpRevTx to network\n"
840+
" diff - Calculate a diff and a proof between two masternode lists\n"
841+
);
842+
}
822843

823844
UniValue protx(const JSONRPCRequest& request)
824845
{
825-
if (request.params.empty()) {
826-
throw std::runtime_error(
827-
"protx \"command\" ...\n"
828-
"Set of commands to execute ProTx related actions.\n"
829-
"To get help on individual commands, use \"help protx command\".\n"
830-
"\nArguments:\n"
831-
"1. \"command\" (string, required) The command to execute\n"
832-
"\nAvailable commands:\n"
833-
" register - Create and send ProTx to network\n"
834-
" register_fund - Fund, create and send ProTx to network\n"
835-
" register_prepare - Create an unsigned ProTx\n"
836-
" register_submit - Sign and submit a ProTx\n"
837-
" list - List ProTxs\n"
838-
" info - Return information about a ProTx\n"
839-
" update_service - Create and send ProUpServTx to network\n"
840-
" update_registrar - Create and send ProUpRegTx to network\n"
841-
" revoke - Create and send ProUpRevTx to network\n"
842-
" diff - Calculate a diff and a proof between two masternode lists\n"
843-
);
846+
if (request.fHelp || request.params.empty()) {
847+
protx_help();
844848
}
845849

846850
std::string command = request.params[0].get_str();
@@ -862,7 +866,7 @@ UniValue protx(const JSONRPCRequest& request)
862866
} else if (command == "diff") {
863867
return protx_diff(request);
864868
} else {
865-
throw std::runtime_error("invalid command: " + command);
869+
protx_help();
866870
}
867871
}
868872
#endif//ENABLE_WALLET
@@ -897,7 +901,7 @@ UniValue bls_generate(const JSONRPCRequest& request)
897901
return ret;
898902
}
899903

900-
void bls_help()
904+
[[ noreturn ]] void bls_help()
901905
{
902906
throw std::runtime_error(
903907
"bls \"command\" ...\n"
@@ -912,7 +916,7 @@ void bls_help()
912916

913917
UniValue _bls(const JSONRPCRequest& request)
914918
{
915-
if (request.params.empty()) {
919+
if (request.fHelp || request.params.empty()) {
916920
bls_help();
917921
}
918922

0 commit comments

Comments
 (0)