Skip to content

Commit a71c347

Browse files
author
MarcoFalke
committed
Merge #17809: rpc: Auto-format RPCResult
fa6b061 rpc: Auto-format RPCResult (MarcoFalke) fa7d050 rpc: Move OuterType enum to header (MarcoFalke) Pull request description: This enforces most syntax rules of the RPCResult at compile time (or some at run time during unit and functional tests) Apart from normalizing the syntax, by separating stylistic formatting from the structure, we could in theory directly generate the html for e.g. https://bitcoincore.org/en/doc/0.19.0/rpc/wallet/importmulti/ ACKs for top commit: Sjors: Indeed, re-ACK fa6b061 ajtowns: ACK fa6b061 -- skimmed code changes and differences to rpc help output Tree-SHA512: 5b510b3aa0b7c7b9189a48c77593159409069f939145b9a00c5478e894cf65f994d44d633eb7bb7dbea40ee820645a2930976c24772379d96929002b120efa28
2 parents 0886042 + fa6b061 commit a71c347

File tree

11 files changed

+1515
-1248
lines changed

11 files changed

+1515
-1248
lines changed

src/rpc/blockchain.cpp

Lines changed: 298 additions & 322 deletions
Large diffs are not rendered by default.

src/rpc/mining.cpp

Lines changed: 119 additions & 100 deletions
Large diffs are not rendered by default.

src/rpc/misc.cpp

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ static UniValue validateaddress(const JSONRPCRequest& request)
3333
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to validate"},
3434
},
3535
RPCResult{
36-
"{\n"
37-
" \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n"
38-
" \"address\" : \"address\", (string) The bitcoin address validated\n"
39-
" \"scriptPubKey\" : \"hex\", (string) The hex-encoded scriptPubKey generated by the address\n"
40-
" \"isscript\" : true|false, (boolean) If the key is a script\n"
41-
" \"iswitness\" : true|false, (boolean) If the address is a witness address\n"
42-
" \"witness_version\" : version (numeric, optional) The version number of the witness program\n"
43-
" \"witness_program\" : \"hex\" (string, optional) The hex value of the witness program\n"
44-
"}\n"
36+
RPCResult::Type::OBJ, "", "",
37+
{
38+
{RPCResult::Type::BOOL, "isvalid", "If the address is valid or not. If not, this is the only property returned."},
39+
{RPCResult::Type::STR, "address", "The bitcoin address validated"},
40+
{RPCResult::Type::STR_HEX, "scriptPubKey", "The hex-encoded scriptPubKey generated by the address"},
41+
{RPCResult::Type::BOOL, "isscript", "If the key is a script"},
42+
{RPCResult::Type::BOOL, "iswitness", "If the address is a witness address"},
43+
{RPCResult::Type::NUM, "witness_version", /* optional */ true, "The version number of the witness program"},
44+
{RPCResult::Type::STR_HEX, "witness_program", /* optional */ true, "The hex value of the witness program"},
45+
}
4546
},
4647
RPCExamples{
4748
HelpExampleCli("validateaddress", EXAMPLE_ADDRESS) +
@@ -82,11 +83,12 @@ static UniValue createmultisig(const JSONRPCRequest& request)
8283
{"address_type", RPCArg::Type::STR, /* default */ "legacy", "The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
8384
},
8485
RPCResult{
85-
"{\n"
86-
" \"address\" : \"multisigaddress\", (string) The value of the new multisig address.\n"
87-
" \"redeemScript\" : \"script\" (string) The string value of the hex-encoded redemption script.\n"
88-
" \"descriptor\" : \"descriptor\" (string) The descriptor for this multisig\n"
89-
"}\n"
86+
RPCResult::Type::OBJ, "", "",
87+
{
88+
{RPCResult::Type::STR, "address", "The value of the new multisig address."},
89+
{RPCResult::Type::STR_HEX, "redeemScript", "The string value of the hex-encoded redemption script."},
90+
{RPCResult::Type::STR, "descriptor", "The descriptor for this multisig"},
91+
}
9092
},
9193
RPCExamples{
9294
"\nCreate a multisig address from 2 public keys\n"
@@ -141,13 +143,14 @@ UniValue getdescriptorinfo(const JSONRPCRequest& request)
141143
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor."},
142144
},
143145
RPCResult{
144-
"{\n"
145-
" \"descriptor\" : \"desc\", (string) The descriptor in canonical form, without private keys\n"
146-
" \"checksum\" : \"chksum\", (string) The checksum for the input descriptor\n"
147-
" \"isrange\" : true|false, (boolean) Whether the descriptor is ranged\n"
148-
" \"issolvable\" : true|false, (boolean) Whether the descriptor is solvable\n"
149-
" \"hasprivatekeys\" : true|false, (boolean) Whether the input descriptor contained at least one private key\n"
150-
"}\n"
146+
RPCResult::Type::OBJ, "", "",
147+
{
148+
{RPCResult::Type::STR, "descriptor", "The descriptor in canonical form, without private keys"},
149+
{RPCResult::Type::STR, "checksum", "The checksum for the input descriptor"},
150+
{RPCResult::Type::BOOL, "isrange", "Whether the descriptor is ranged"},
151+
{RPCResult::Type::BOOL, "issolvable", "Whether the descriptor is solvable"},
152+
{RPCResult::Type::BOOL, "hasprivatekeys", "Whether the input descriptor contained at least one private key"},
153+
}
151154
},
152155
RPCExamples{
153156
"Analyse a descriptor\n" +
@@ -189,7 +192,10 @@ UniValue deriveaddresses(const JSONRPCRequest& request)
189192
{"range", RPCArg::Type::RANGE, RPCArg::Optional::OMITTED_NAMED_ARG, "If a ranged descriptor is used, this specifies the end or the range (in [begin,end] notation) to derive."},
190193
},
191194
RPCResult{
192-
"[ address ] (json array) the derived addresses\n"
195+
RPCResult::Type::ARR, "", "",
196+
{
197+
{RPCResult::Type::STR, "address", "the derived addresses"},
198+
}
193199
},
194200
RPCExamples{
195201
"First three native segwit receive addresses\n" +
@@ -258,7 +264,7 @@ static UniValue verifymessage(const JSONRPCRequest& request)
258264
{"message", RPCArg::Type::STR, RPCArg::Optional::NO, "The message that was signed."},
259265
},
260266
RPCResult{
261-
"true|false (boolean) If the signature is verified or not.\n"
267+
RPCResult::Type::BOOL, "", "If the signature is verified or not."
262268
},
263269
RPCExamples{
264270
"\nUnlock the wallet for 30 seconds\n"
@@ -304,7 +310,7 @@ static UniValue signmessagewithprivkey(const JSONRPCRequest& request)
304310
{"message", RPCArg::Type::STR, RPCArg::Optional::NO, "The message to create a signature of."},
305311
},
306312
RPCResult{
307-
"\"signature\" (string) The signature of the message encoded in base 64\n"
313+
RPCResult::Type::STR, "signature", "The signature of the message encoded in base 64"
308314
},
309315
RPCExamples{
310316
"\nCreate the signature\n"
@@ -437,19 +443,21 @@ static UniValue getmemoryinfo(const JSONRPCRequest& request)
437443
},
438444
{
439445
RPCResult{"mode \"stats\"",
440-
"{\n"
441-
" \"locked\" : { (json object) Information about locked memory manager\n"
442-
" \"used\" : xxxxx, (numeric) Number of bytes used\n"
443-
" \"free\" : xxxxx, (numeric) Number of bytes available in current arenas\n"
444-
" \"total\" : xxxxxxx, (numeric) Total number of bytes managed\n"
445-
" \"locked\" : xxxxxx, (numeric) Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk.\n"
446-
" \"chunks_used\" : xxxxx, (numeric) Number allocated chunks\n"
447-
" \"chunks_free\" : xxxxx, (numeric) Number unused chunks\n"
448-
" }\n"
449-
"}\n"
446+
RPCResult::Type::OBJ, "", "",
447+
{
448+
{RPCResult::Type::OBJ, "locked", "Information about locked memory manager",
449+
{
450+
{RPCResult::Type::NUM, "used", "Number of bytes used"},
451+
{RPCResult::Type::NUM, "free", "Number of bytes available in current arenas"},
452+
{RPCResult::Type::NUM, "total", "Total number of bytes managed"},
453+
{RPCResult::Type::NUM, "locked", "Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk."},
454+
{RPCResult::Type::NUM, "chunks_used", "Number allocated chunks"},
455+
{RPCResult::Type::NUM, "chunks_free", "Number unused chunks"},
456+
}},
457+
}
450458
},
451459
RPCResult{"mode \"mallocinfo\"",
452-
"\"<malloc version=\"1\">...\"\n"
460+
RPCResult::Type::STR, "", "\"<malloc version=\"1\">...\""
453461
},
454462
},
455463
RPCExamples{
@@ -516,10 +524,10 @@ UniValue logging(const JSONRPCRequest& request)
516524
}},
517525
},
518526
RPCResult{
519-
"{ (json object where keys are the logging categories, and values indicates its status\n"
520-
" \"category\" : true|false, (boolean) if being debug logged or not. false:inactive, true:active\n"
521-
" ...\n"
522-
"}\n"
527+
RPCResult::Type::OBJ_DYN, "", "keys are the logging categories, and values indicates its status",
528+
{
529+
{RPCResult::Type::BOOL, "category", "if being debug logged or not. false:inactive, true:active"},
530+
}
523531
},
524532
RPCExamples{
525533
HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")

0 commit comments

Comments
 (0)