Skip to content

Commit 3809ec4

Browse files
committed
Make all RPC commands use the same styling format
Added some missing help output, used EnsureWalletIsLocked where applicable (more in the next commit), and improved code readability for the help sections for each command.
1 parent 68f5017 commit 3809ec4

File tree

9 files changed

+750
-384
lines changed

9 files changed

+750
-384
lines changed

src/rpcblockchain.cpp

Lines changed: 76 additions & 29 deletions
Large diffs are not rendered by default.

src/rpcdump.cpp

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,25 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
8383
if (fHelp || params.size() < 1 || params.size() > 3)
8484
throw runtime_error(
8585
"importprivkey \"pivxprivkey\" ( \"label\" rescan )\n"
86-
"\nAdds a private key (as returned by dumpprivkey) to your wallet.\n"
86+
"\nAdds a private key (as returned by dumpprivkey) to your wallet.\n" +
87+
HelpRequiringPassphrase() + "\n"
88+
8789
"\nArguments:\n"
8890
"1. \"pivxprivkey\" (string, required) The private key (see dumpprivkey)\n"
8991
"2. \"label\" (string, optional, default=\"\") An optional label\n"
9092
"3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
93+
9194
"\nNote: This call can take minutes to complete if rescan is true.\n"
95+
9296
"\nExamples:\n"
9397
"\nDump a private key\n" +
9498
HelpExampleCli("dumpprivkey", "\"myaddress\"") +
95-
"\nImport the private key with rescan\n" + HelpExampleCli("importprivkey", "\"mykey\"") +
96-
"\nImport using a label and without rescan\n" + HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") +
97-
"\nAs a JSON-RPC call\n" + HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false"));
99+
"\nImport the private key with rescan\n" +
100+
HelpExampleCli("importprivkey", "\"mykey\"") +
101+
"\nImport using a label and without rescan\n" +
102+
HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") +
103+
"\nAs a JSON-RPC call\n" +
104+
HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false"));
98105

99106
LOCK2(cs_main, pwalletMain->cs_wallet);
100107

@@ -151,16 +158,21 @@ UniValue importaddress(const UniValue& params, bool fHelp)
151158
throw runtime_error(
152159
"importaddress \"address\" ( \"label\" rescan )\n"
153160
"\nAdds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend.\n"
161+
154162
"\nArguments:\n"
155163
"1. \"address\" (string, required) The address\n"
156164
"2. \"label\" (string, optional, default=\"\") An optional label\n"
157165
"3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
166+
158167
"\nNote: This call can take minutes to complete if rescan is true.\n"
168+
159169
"\nExamples:\n"
160170
"\nImport an address with rescan\n" +
161171
HelpExampleCli("importaddress", "\"myaddress\"") +
162-
"\nImport using a label without rescan\n" + HelpExampleCli("importaddress", "\"myaddress\" \"testing\" false") +
163-
"\nAs a JSON-RPC call\n" + HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false"));
172+
"\nImport using a label without rescan\n" +
173+
HelpExampleCli("importaddress", "\"myaddress\" \"testing\" false") +
174+
"\nAs a JSON-RPC call\n" +
175+
HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false"));
164176

165177
LOCK2(cs_main, pwalletMain->cs_wallet);
166178

@@ -216,14 +228,19 @@ UniValue importwallet(const UniValue& params, bool fHelp)
216228
if (fHelp || params.size() != 1)
217229
throw runtime_error(
218230
"importwallet \"filename\"\n"
219-
"\nImports keys from a wallet dump file (see dumpwallet).\n"
231+
"\nImports keys from a wallet dump file (see dumpwallet).\n" +
232+
HelpRequiringPassphrase() + "\n"
233+
220234
"\nArguments:\n"
221235
"1. \"filename\" (string, required) The wallet file\n"
236+
222237
"\nExamples:\n"
223238
"\nDump the wallet\n" +
224239
HelpExampleCli("dumpwallet", "\"test\"") +
225-
"\nImport the wallet\n" + HelpExampleCli("importwallet", "\"test\"") +
226-
"\nImport using the json rpc call\n" + HelpExampleRpc("importwallet", "\"test\""));
240+
"\nImport the wallet\n" +
241+
HelpExampleCli("importwallet", "\"test\"") +
242+
"\nImport using the json rpc call\n" +
243+
HelpExampleRpc("importwallet", "\"test\""));
227244

228245
LOCK2(cs_main, pwalletMain->cs_wallet);
229246

@@ -315,11 +332,15 @@ UniValue dumpprivkey(const UniValue& params, bool fHelp)
315332
throw runtime_error(
316333
"dumpprivkey \"pivxaddress\"\n"
317334
"\nReveals the private key corresponding to 'pivxaddress'.\n"
318-
"Then the importprivkey can be used with this output\n"
335+
"Then the importprivkey can be used with this output\n" +
336+
HelpRequiringPassphrase() + "\n"
337+
319338
"\nArguments:\n"
320339
"1. \"pivxaddress\" (string, required) The pivx address for the private key\n"
340+
321341
"\nResult:\n"
322342
"\"key\" (string) The private key\n"
343+
323344
"\nExamples:\n" +
324345
HelpExampleCli("dumpprivkey", "\"myaddress\"") + HelpExampleCli("importprivkey", "\"mykey\"") + HelpExampleRpc("dumpprivkey", "\"myaddress\""));
325346

@@ -346,9 +367,12 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
346367
if (fHelp || params.size() != 1)
347368
throw runtime_error(
348369
"dumpwallet \"filename\"\n"
349-
"\nDumps all wallet keys in a human-readable format.\n"
370+
"\nDumps all wallet keys in a human-readable format.\n" +
371+
HelpRequiringPassphrase() + "\n"
372+
350373
"\nArguments:\n"
351374
"1. \"filename\" (string, required) The filename\n"
375+
352376
"\nExamples:\n" +
353377
HelpExampleCli("dumpwallet", "\"test\"") + HelpExampleRpc("dumpwallet", "\"test\""));
354378

@@ -405,14 +429,20 @@ UniValue bip38encrypt(const UniValue& params, bool fHelp)
405429
{
406430
if (fHelp || params.size() != 2)
407431
throw runtime_error(
408-
"bip38encrypt \"pivxaddress\"\n"
409-
"\nEncrypts a private key corresponding to 'pivxaddress'.\n"
432+
"bip38encrypt \"pivxaddress\" \"passphrase\"\n"
433+
"\nEncrypts a private key corresponding to 'pivxaddress'.\n" +
434+
HelpRequiringPassphrase() + "\n"
435+
410436
"\nArguments:\n"
411437
"1. \"pivxaddress\" (string, required) The pivx address for the private key (you must hold the key already)\n"
412438
"2. \"passphrase\" (string, required) The passphrase you want the private key to be encrypted with - Valid special chars: !#$%&'()*+,-./:;<=>?`{|}~ \n"
439+
413440
"\nResult:\n"
414441
"\"key\" (string) The encrypted private key\n"
415-
"\nExamples:\n");
442+
443+
"\nExamples:\n" +
444+
HelpExampleCli("bip38encrypt", "\"DMJRSsuU9zfyrvxVaAEFQqK4MxZg6vgeS6\" \"mypasphrase\"") +
445+
HelpExampleRpc("bip38encrypt", "\"DMJRSsuU9zfyrvxVaAEFQqK4MxZg6vgeS6\" \"mypasphrase\""));
416446

417447
LOCK2(cs_main, pwalletMain->cs_wallet);
418448

@@ -445,15 +475,20 @@ UniValue bip38decrypt(const UniValue& params, bool fHelp)
445475
{
446476
if (fHelp || params.size() != 2)
447477
throw runtime_error(
448-
"bip38decrypt \"pivxaddress\"\n"
449-
"\nDecrypts and then imports password protected private key.\n"
478+
"bip38decrypt \"pivxaddress\" \"passphrase\"\n"
479+
"\nDecrypts and then imports password protected private key.\n" +
480+
HelpRequiringPassphrase() + "\n"
481+
450482
"\nArguments:\n"
451483
"1. \"encryptedkey\" (string, required) The encrypted private key\n"
452484
"2. \"passphrase\" (string, required) The passphrase you want the private key to be encrypted with\n"
453485

454486
"\nResult:\n"
455487
"\"key\" (string) The decrypted private key\n"
456-
"\nExamples:\n");
488+
489+
"\nExamples:\n" +
490+
HelpExampleCli("bip38decrypt", "\"encryptedkey\" \"mypassphrase\"") +
491+
HelpExampleRpc("bip38decrypt", "\"encryptedkey\" \"mypassphrase\""));
457492

458493
LOCK2(cs_main, pwalletMain->cs_wallet);
459494

src/rpcmasternode-budget.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@ UniValue preparebudget(const UniValue& params, bool fHelp)
171171

172172
"\nResult:\n"
173173
"\"xxxx\" (string) proposal fee hash (if successful) or error message (if failed)\n"
174+
174175
"\nExamples:\n" +
175176
HelpExampleCli("preparebudget", "\"test-proposal\" \"https://forum.pivx.org/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500") +
176177
HelpExampleRpc("preparebudget", "\"test-proposal\" \"https://forum.pivx.org/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500"));
177178

178179
LOCK2(cs_main, pwalletMain->cs_wallet);
179180

180-
if (pwalletMain->IsLocked())
181-
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first.");
181+
EnsureWalletIsUnlocked();
182182

183183
std::string strProposalName = SanitizeString(params[0].get_str());
184184
if (strProposalName.size() > 20)
@@ -267,6 +267,7 @@ UniValue submitbudget(const UniValue& params, bool fHelp)
267267

268268
"\nResult:\n"
269269
"\"xxxx\" (string) proposal hash (if successful) or error message (if failed)\n"
270+
270271
"\nExamples:\n" +
271272
HelpExampleCli("submitbudget", "\"test-proposal\" \"https://forum.pivx.org/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500") +
272273
HelpExampleRpc("submitbudget", "\"test-proposal\" \"https://forum.pivx.org/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500"));
@@ -619,6 +620,7 @@ UniValue getbudgetvotes(const UniValue& params, bool fHelp)
619620
" }\n"
620621
" ,...\n"
621622
"]\n"
623+
622624
"\nExamples:\n" +
623625
HelpExampleCli("getbudgetvotes", "\"test-proposal\"") + HelpExampleRpc("getbudgetvotes", "\"test-proposal\""));
624626

@@ -656,6 +658,7 @@ UniValue getnextsuperblock(const UniValue& params, bool fHelp)
656658

657659
"\nResult:\n"
658660
"n (numeric) Block height of the next super block\n"
661+
659662
"\nExamples:\n" +
660663
HelpExampleCli("getnextsuperblock", "") + HelpExampleRpc("getnextsuperblock", ""));
661664

@@ -700,6 +703,7 @@ UniValue getbudgetprojection(const UniValue& params, bool fHelp)
700703
" }\n"
701704
" ,...\n"
702705
"]\n"
706+
703707
"\nExamples:\n" +
704708
HelpExampleCli("getbudgetprojection", "") + HelpExampleRpc("getbudgetprojection", ""));
705709

@@ -761,6 +765,7 @@ UniValue getbudgetinfo(const UniValue& params, bool fHelp)
761765
" }\n"
762766
" ,...\n"
763767
"]\n"
768+
764769
"\nExamples:\n" +
765770
HelpExampleCli("getbudgetprojection", "") + HelpExampleRpc("getbudgetprojection", ""));
766771

@@ -807,6 +812,7 @@ UniValue mnbudgetrawvote(const UniValue& params, bool fHelp)
807812

808813
"\nResult:\n"
809814
"\"status\" (string) Vote status or error message\n"
815+
810816
"\nExamples:\n" +
811817
HelpExampleCli("mnbudgetrawvote", "") + HelpExampleRpc("mnbudgetrawvote", ""));
812818

@@ -863,7 +869,8 @@ UniValue mnfinalbudget(const UniValue& params, bool fHelp)
863869
(strCommand != "suggest" && strCommand != "vote-many" && strCommand != "vote" && strCommand != "show" && strCommand != "getvotes"))
864870
throw runtime_error(
865871
"mnfinalbudget \"command\"... ( \"passphrase\" )\n"
866-
"Vote or show current budgets\n"
872+
"\nVote or show current budgets\n"
873+
867874
"\nAvailable commands:\n"
868875
" vote-many - Vote on a finalized budget\n"
869876
" vote - Vote on a finalized budget\n"
@@ -1037,6 +1044,7 @@ UniValue checkbudgets(const UniValue& params, bool fHelp)
10371044
throw runtime_error(
10381045
"checkbudgets\n"
10391046
"\nInitiates a buddget check cycle manually\n"
1047+
10401048
"\nExamples:\n" +
10411049
HelpExampleCli("checkbudgets", "") + HelpExampleRpc("checkbudgets", ""));
10421050

0 commit comments

Comments
 (0)