Passing the rpc result and rpc examples through RPCHelpMan makes it clear in what order they appear in the stringified version. Future improvements could then autoformat or autogenerate them.
RPCHelpMan: Pass through Result and Examples #14987
pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:Mf1812-rpcResultFlat changing 11 files +1011 −759-
MarcoFalke commented at 9:29 PM on December 17, 2018: member
- MarcoFalke added the label RPC/REST/ZMQ on Dec 17, 2018
- MarcoFalke added the label Docs on Dec 17, 2018
- MarcoFalke added the label Refactoring on Dec 17, 2018
- MarcoFalke removed the label Refactoring on Dec 17, 2018
- MarcoFalke force-pushed on Dec 17, 2018
- MarcoFalke force-pushed on Dec 17, 2018
-
MarcoFalke commented at 9:48 PM on December 17, 2018: member
<details><summary>Resulting diff for faa1522e5ec5ec53b2b2b1ed36c11e84939bbb13</summary>
diff --git a/abandontransaction b/abandontransaction index 4ce0ab0..4727471 100644 --- a/abandontransaction +++ b/abandontransaction @@ -9,8 +9,6 @@ It has no effect on transactions which are already abandoned. Arguments: 1. txid (string, required) The transaction id -Result: - Examples: > bitcoin-cli abandontransaction "1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d" > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "abandontransaction", "params": ["1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/ diff --git a/estimaterawfee b/estimaterawfee index 300ff13..8284dcf 100644 --- a/estimaterawfee +++ b/estimaterawfee @@ -39,5 +39,5 @@ Result: Results are returned for any horizon which tracks blocks up to the confirmation target. -Example: +Examples: > bitcoin-cli estimaterawfee 6 0.9 diff --git a/estimatesmartfee b/estimatesmartfee index 3cad235..b787d02 100644 --- a/estimatesmartfee +++ b/estimatesmartfee @@ -29,5 +29,5 @@ fee estimation is able to return based on how long it has been running. An error is returned if not enough transactions and blocks have been observed to make an estimate for any number of blocks. -Example: +Examples: > bitcoin-cli estimatesmartfee 6 diff --git a/getrawmempool b/getrawmempool index e995089..7050878 100644 --- a/getrawmempool +++ b/getrawmempool @@ -7,7 +7,7 @@ Hint: use getmempoolentry to fetch a specific transaction from the mempool. Arguments: 1. verbose (boolean, optional, default=false) True for a json object, false for array of transaction ids -Result: (for verbose = false): +Result (for verbose = false): [ (json array of string) "transactionid" (string) The transaction id ,... diff --git a/importaddress b/importaddress index e0f1865..9c15eea 100644 --- a/importaddress +++ b/importaddress @@ -2,12 +2,6 @@ importaddress "address" ( "label" rescan p2sh ) Adds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup. -Arguments: -1. address (string, required) The Bitcoin address (or hex-encoded script) -2. label (string, optional, default="") An optional label -3. rescan (boolean, optional, default=true) Rescan the wallet for transactions -4. p2sh (boolean, optional, default=false) Add the P2SH version of the script as well - Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls may report that the imported address exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes. If you have the full public key, you should call importpubkey instead of this. @@ -15,6 +9,12 @@ If you have the full public key, you should call importpubkey instead of this. Note: If you import a non-standard raw script in hex form, outputs sending to it will be treated as change, and not show up in many RPCs. +Arguments: +1. address (string, required) The Bitcoin address (or hex-encoded script) +2. label (string, optional, default="") An optional label +3. rescan (boolean, optional, default=true) Rescan the wallet for transactions +4. p2sh (boolean, optional, default=false) Add the P2SH version of the script as well + Examples: Import an address with rescan diff --git a/importmulti b/importmulti index 51a6f51..a6afbb2 100644 --- a/importmulti +++ b/importmulti @@ -4,6 +4,9 @@ Import addresses/scripts (with private or public keys, redeem script (P2SH)), op If an address/script is imported without all of the private keys required to spend from that address, it will be watchonly. The 'watchonly' option must be set to true in this case or a warning will be returned. Conversely, if all the private keys are provided and the address/script is spendable, the watchonly option must be set to false, or a warning will be returned. +Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls +may report that the imported keys, addresses or scripts exists but related transactions are still missing. + Arguments: 1. requests (json array, required) Data to be imported [ @@ -36,12 +39,11 @@ Arguments: "rescan": bool, (boolean, optional, default=true) Stating if should rescan the blockchain after all imports } -Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls -may report that the imported keys, addresses or scripts exists but related transactions are still missing. +Result: + +Response is an array with the same size as the input that has the execution result : + [{"success": true}, {"success": true, "warnings": ["Ignoring irrelevant private key"]}, {"success": false, "error": {"code": -1, "message": "Internal Server Error"}}, ...] Examples: > bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "<my address>" }, "timestamp":1455191478 }, { "scriptPubKey": { "address": "<my 2nd address>" }, "label": "example 2", "timestamp": 1455191480 }]' > bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "<my address>" }, "timestamp":1455191478 }]' '{ "rescan": false}' - -Response is an array with the same size as the input that has the execution result : - [{"success": true}, {"success": true, "warnings": ["Ignoring irrelevant private key"]}, {"success": false, "error": {"code": -1, "message": "Internal Server Error"}}, ...] diff --git a/importprivkey b/importprivkey index d083a48..01793fd 100644 --- a/importprivkey +++ b/importprivkey @@ -3,14 +3,14 @@ importprivkey "privkey" ( "label" rescan ) Adds a private key (as returned by dumpprivkey) to your wallet. Requires a new wallet backup. Hint: use importmulti to import more than one private key. +Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls +may report that the imported key exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes. + Arguments: 1. privkey (string, required) The private key (see dumpprivkey) 2. label (string, optional, default=current label if address exists, otherwise "") An optional label 3. rescan (boolean, optional, default=true) Rescan the wallet for transactions -Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls -may report that the imported key exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes. - Examples: Dump a private key diff --git a/importpubkey b/importpubkey index 3c79e07..54354e1 100644 --- a/importpubkey +++ b/importpubkey @@ -2,14 +2,14 @@ importpubkey "pubkey" ( "label" rescan ) Adds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup. +Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls +may report that the imported pubkey exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes. + Arguments: 1. pubkey (string, required) The hex-encoded public key 2. label (string, optional, default="") An optional label 3. rescan (boolean, optional, default=true) Rescan the wallet for transactions -Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls -may report that the imported pubkey exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes. - Examples: Import a public key with rescan diff --git a/invalidateblock b/invalidateblock index bb1513e..6d22805 100644 --- a/invalidateblock +++ b/invalidateblock @@ -5,8 +5,6 @@ Permanently marks a block as invalid, as if it violated a consensus rule. Arguments: 1. blockhash (string, required) the hash of the block to mark as invalid -Result: - Examples: > bitcoin-cli invalidateblock "blockhash" > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "invalidateblock", "params": ["blockhash"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/ diff --git a/listunspent b/listunspent index b068fc6..0960a1c 100644 --- a/listunspent +++ b/listunspent @@ -22,7 +22,7 @@ Arguments: "minimumSumAmount": amount, (numeric or string, optional, default=unlimited) Minimum sum value of all UTXOs in BTC } -Result +Result: [ (array of json object) { "txid" : "txid", (string) the transaction id @@ -43,7 +43,7 @@ Result ,... ] -Examples +Examples: > bitcoin-cli listunspent > bitcoin-cli listunspent 6 9999999 "[\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\",\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\"]" > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listunspent", "params": [6, 9999999 "[\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\",\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\"]"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/ diff --git a/listwalletdir b/listwalletdir index 54ea06a..9a3c26e 100644 --- a/listwalletdir +++ b/listwalletdir @@ -1,5 +1,7 @@ listwalletdir Returns a list of wallets in the wallet directory. + +Result: { "wallets" : [ (json array of objects) { diff --git a/preciousblock b/preciousblock index 786992d..2135eee 100644 --- a/preciousblock +++ b/preciousblock @@ -9,8 +9,6 @@ The effects of preciousblock are not retained across restarts. Arguments: 1. blockhash (string, required) the hash of the block to mark as precious -Result: - Examples: > bitcoin-cli preciousblock "blockhash" > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "preciousblock", "params": ["blockhash"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/ diff --git a/reconsiderblock b/reconsiderblock index f3ee35b..c1dc5bd 100644 --- a/reconsiderblock +++ b/reconsiderblock @@ -6,8 +6,6 @@ This can be used to undo the effects of invalidateblock. Arguments: 1. blockhash (string, required) the hash of the block to reconsider -Result: - Examples: > bitcoin-cli reconsiderblock "blockhash" > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "reconsiderblock", "params": ["blockhash"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/ diff --git a/resendwallettransactions b/resendwallettransactions index d349b7e..865257b 100644 --- a/resendwallettransactions +++ b/resendwallettransactions @@ -2,5 +2,7 @@ resendwallettransactions Immediately re-broadcast unconfirmed wallet transactions to all peers. Intended only for testing; the wallet code periodically re-broadcasts automatically. + +Result: Returns an RPC error if -walletbroadcast is set to false. Returns array of transaction ids that were re-broadcast. diff --git a/settxfee b/settxfee index 579448a..bb72205 100644 --- a/settxfee +++ b/settxfee @@ -5,7 +5,7 @@ Set the transaction fee per kB for this wallet. Overrides the global -paytxfee c Arguments: 1. amount (numeric or string, required) The transaction fee in BTC/kB -Result +Result: true|false (boolean) Returns true if successful Examples: diff --git a/submitblock b/submitblock index f0602ae..9141363 100644 --- a/submitblock +++ b/submitblock @@ -7,8 +7,6 @@ Arguments: 1. hexdata (string, required) the hex-encoded block data to submit 2. dummy (string, optional, default=ignored) dummy value, for compatibility with BIP22. This value is ignored. -Result: - Examples: > bitcoin-cli submitblock "mydata" > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "submitblock", "params": ["mydata"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/ diff --git a/walletpassphrase b/walletpassphrase index 8cf7ba3..40002fd 100644 --- a/walletpassphrase +++ b/walletpassphrase @@ -3,14 +3,14 @@ walletpassphrase "passphrase" timeout Stores the wallet decryption key in memory for 'timeout' seconds. This is needed prior to performing transactions related to private keys such as sending bitcoins -Arguments: -1. passphrase (string, required) The wallet passphrase -2. timeout (numeric, required) The time to keep the decryption key in seconds; capped at 100000000 (~3 years). - Note: Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock time that overrides the old one. +Arguments: +1. passphrase (string, required) The wallet passphrase +2. timeout (numeric, required) The time to keep the decryption key in seconds; capped at 100000000 (~3 years). + Examples: Unlock the wallet for 60 seconds</details>
-
DrahtBot commented at 12:47 AM on December 18, 2018: member
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #15279 (wallet: Clarify rescanblockchain doc by MarcoFalke)
- #15272 (doc: correct logging return type and RPC example by fanquake)
- #15245 (remove deprecated mentions of signrawtransaction from fundraw help by instagibbs)
- #15226 (Allow creating blank (empty) wallets (alternative) by achow101)
- #15157 (rpc: Bumpfee units change, satoshis to BTC by benthecarman)
- #15006 (Add option to create an encrypted wallet by achow101)
- #14918 (RPCHelpMan: Check default values are given at compile-time by MarcoFalke)
- #14898 (nextpagepointer flag for listtransactions by hosseinamin)
- #14707 ([RPC] Include coinbase transactions in receivedby RPCs by andrewtoth)
- #14459 (docs: Consistent type names in RPC help descriptions by ch4ot1c)
- #13756 (wallet: "avoid_reuse" wallet flag for improved privacy by kallewoof)
- #13541 (wallet/rpc: sendrawtransaction maxfeerate by kallewoof)
- #11413 ([wallet] [rpc] sendtoaddress/sendmany: Add explicit feerate option by kallewoof)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
-
in src/rpc/mining.cpp:98 in fa97fbe423 outdated
93 | @@ -94,10 +94,11 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request) 94 | { 95 | {"nblocks", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "120", "The number of blocks, or -1 for blocks since last difficulty change."}, 96 | {"height", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "-1", "To estimate at the time of the given height."}, 97 | - }} 98 | - .ToString() + 99 | - "\nResult:\n" 100 | + }, 101 | + RPCResult{
promag commented at 3:01 PM on December 18, 2018:Drop
RPCResult?
MarcoFalke commented at 5:05 PM on December 18, 2018:I think it is better to label the sections instead of having a jungle of
{}
promag commented at 5:50 PM on December 18, 2018:It's pretty obviously what always comes after args but ok.
in src/rpc/util.h:112 in fa97fbe423 outdated
105 | @@ -106,17 +106,33 @@ struct RPCArg { 106 | std::string ToDescriptionString(bool implicitly_required = false) const; 107 | }; 108 | 109 | +struct RPCResult { 110 | + const std::string m_result; 111 | + 112 | + RPCResult(
practicalswift commented at 3:55 PM on December 18, 2018:Should be
explicit? :-)All reviewers of this PR: please review PR #14505 and make the
explicitchecking an automatic Travis check :-)
promag commented at 4:00 PM on December 18, 2018:IMO we could ignore explicit here, this is utility code, nothing to worry about..
practicalswift commented at 7:08 AM on December 21, 2018:IMO we should follow the explicit recommendation in our developer notes:
- By default, declare single-argument constructors
explicit.- Rationale: This is a precaution to avoid unintended conversions that might arise when single-argument constructors are used as implicit conversion functions.
:-)
MarcoFalke force-pushed on Dec 21, 2018MarcoFalke renamed this:[rcp] RPCHelpMan: Require documentation of return value at compile time
RPCHelpMan: Pass through Result and Examples
on Dec 21, 2018MarcoFalke force-pushed on Dec 21, 2018DrahtBot added the label Needs rebase on Dec 24, 2018MarcoFalke force-pushed on Dec 24, 2018DrahtBot removed the label Needs rebase on Dec 24, 2018MarcoFalke force-pushed on Jan 15, 2019MarcoFalke force-pushed on Jan 15, 2019laanwj commented at 11:52 AM on January 16, 2019: memberutACK faa90fe9d5e688fdd311a819721f6e911cc441a5
DrahtBot added the label Needs rebase on Jan 16, 2019MarcoFalke force-pushed on Jan 16, 2019DrahtBot removed the label Needs rebase on Jan 16, 2019DrahtBot added the label Needs rebase on Jan 21, 2019MarcoFalke force-pushed on Jan 25, 2019DrahtBot removed the label Needs rebase on Jan 25, 2019ajtowns commented at 3:24 PM on January 25, 2019: memberA bunch of the changes add redundant "Result:" headers when there were conditional results, eg for
getblockheader:+Result: + Result (for verbose = true):Could be worth doing:
struct RPCResult { std::string m_cond; std::string m_result; explicit RPCResult(std::string result) : m_result{result} { } explicit RPCResult(std::string cond, std::string result) : m_cond{cond}, m_result{result} { } } struct RPCResults { std::vector<RPCResult> m_results; RPCResults(RPCResult result) : m_results{{result}} { } RPCResults(std::initializer_list<RPCResult> results) : m_results{results} { } std::string ToDescription() const; }and changing
RPCHelpMan()to takeRPCResultsinstead. Then you can supply eitherRPCResult("foo")for unconditional results, or{ RPCResult{"for verbose=true", "...results..."}, RPCResult{"for verbose=false"}, "...other results..."} }for conditional results, orRPCResults{}if you're not giving any result examples.Patch at https://github.com/ajtowns/bitcoin/commit/1ca7fb3f00b95a04133018a431853a75f790c02e (feel free to include it as a fixup if you like it)
MarcoFalke force-pushed on Jan 25, 2019RPCHelpMan: Pass through Result and Examples faa1522e5eMarcoFalke force-pushed on Jan 25, 2019MarcoFalke commented at 7:21 PM on January 25, 2019: memberThanks. I stole your changes and squashed them with some minor fixups. Hope you don't mind.
ajtowns commented at 7:21 AM on January 29, 2019: memberACK faa1522e5ec5ec53b2b2b1ed36c11e84939bbb13
Help differences checked with:
mkdir BEFORE AFTER git checkout faa1522e^ && make && make check && ./bitcoind -regtest for a in $(./bitcoin-cli -regtest help | grep '^[^=]' | sed 's/ .*//') estimaterawfee setmocktime echo echojson signrawtransaction invalidateblock reconsiderblock waitfornewblock waitforblock waitforblockheight syncwithvalidationinterfacequeue resendwallettransactions; do ./bitcoin-cli -regtest help $a > BEFORE/$a.txt; done git checkout faa1522e && make && make check && ./bitcoind -regtest for a in $(./bitcoin-cli -regtest help | grep '^[^=]' | sed 's/ .*//') estimaterawfee setmocktime echo echojson signrawtransaction invalidateblock reconsiderblock waitfornewblock waitforblock waitforblockheight syncwithvalidationinterfacequeue resendwallettransactions; do ./bitcoin-cli -regtest help $a > AFTER/$a.txt; done git diff --color-moved=dimmed_zebra --no-index BEFORE/ AFTER/(there isn't a way to just list all the RPC commands including hidden ones?)
MarcoFalke referenced this in commit 7275365c9b on Jan 29, 2019MarcoFalke commented at 2:57 PM on January 29, 2019: member@ajtowns I modified
CRPCTable::helpto print even hidden ones to get the diff in #14987 (comment)Anyway, this has two ACKs, three upvotes (which I count as Concept ACK) and only conflicts with prs that have review and are mine, so I am going to merge this.
Sorry for the merge conflicts :(
MarcoFalke merged this on Jan 29, 2019MarcoFalke closed this on Jan 29, 2019MarcoFalke deleted the branch on Jan 29, 2019deadalnix referenced this in commit e6cc692608 on Apr 23, 2020deadalnix referenced this in commit ae8d0e0ef6 on Apr 23, 2020deadalnix referenced this in commit 6cc4213706 on Apr 24, 2020deadalnix referenced this in commit 8cc917edc1 on Apr 27, 2020deadalnix referenced this in commit 9f1d09d793 on Apr 27, 2020deadalnix referenced this in commit 22f5cdd265 on Apr 27, 2020deadalnix referenced this in commit f2d4686b93 on Apr 28, 2020deadalnix referenced this in commit 4bc2f9217b on Apr 29, 2020deadalnix referenced this in commit c03c766cf3 on Apr 29, 2020deadalnix referenced this in commit 499a480840 on May 1, 2020deadalnix referenced this in commit df9019c008 on May 1, 2020deadalnix referenced this in commit 69f5edb690 on May 1, 2020deadalnix referenced this in commit 50beb5f36a on May 1, 2020deadalnix referenced this in commit a65bffe62f on May 1, 2020deadalnix referenced this in commit 70ba2634e1 on May 1, 2020deadalnix referenced this in commit fa91619ce8 on May 4, 2020deadalnix referenced this in commit e55251f432 on May 4, 2020ftrader referenced this in commit aecbde56fa on Apr 14, 2021ftrader referenced this in commit d1bf6d0d71 on Apr 14, 2021ftrader referenced this in commit abf3302a15 on Apr 14, 2021ftrader referenced this in commit 383becdcbd on Apr 14, 2021ftrader referenced this in commit c4f396d8ad on Apr 14, 2021dzutto referenced this in commit 8697e58b49 on Oct 25, 2021dzutto referenced this in commit 0005764589 on Oct 26, 2021vijaydasmp referenced this in commit 09e84bf1c6 on Oct 30, 2021dzutto referenced this in commit 12b4454271 on Nov 5, 2021dzutto referenced this in commit 57841be492 on Nov 9, 2021PastaPastaPasta referenced this in commit 4bf6dc07d4 on Nov 13, 2021pravblockc referenced this in commit ecf7178a2e on Nov 18, 2021DrahtBot locked this on Dec 16, 2021Labels
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC
More mirrored repositories can be found on mirror.b10c.me