aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/util.cpp
AgeCommit message (Collapse)Author
2020-10-29wallet: fundrawtx fee rate coverage, fixup ParseConfirmTarget()Jon Atack
2020-08-14Merge #19528: rpc: Assert that RPCArg names are equal to CRPCCommand ones (misc)MarcoFalke
fa77de2baa40ee828c850ef4068c76cc3619e87b rpc: Assert that RPCArg names are equal to CRPCCommand ones (misc) (MarcoFalke) fa50bdc755489b2e291ea5ba0e39e44a20c6c6de rpc: Limit echo to 10 args (MarcoFalke) fa89ca9b5bd334813fd7e7edb202c56b35076e8d refactor: Use C++11 range based for loops to simplify rpc code (MarcoFalke) fa459bdc87bbb050ca1c8d469023a96ed798540e rpc: Treat all args after a hidden arg as hidden as well (MarcoFalke) Pull request description: This is split out from #18531 to just touch the RPC methods in misc. Description from the main pr: ### Motivation RPCArg names in the rpc help are currently only used for documentation. However, in the future they could be used to teach the server the named arguments. Named arguments are currently registered by the `CRPCCommand`s and duplicate the RPCArg names from the documentation. This redundancy is fragile, and has lead to errors in the past (despite having linters to catch those kind of errors). See section "bugs found" for a list of bugs that have been found as a result of the changes here. ### Changes The changes here add an assert in the `CRPCCommand` constructor that the RPCArg names are identical to the ones in the `CRPCCommand`. ### Future work > Here or follow up, makes sense to also assert type of returned UniValue? Sure, but let's not get ahead of ourselves. I am going to submit any further works as follow-ups, including: * Removing the CRPCCommand arguments, now that they are asserted to be equal and thus redundant * Removing all python regex linters on the args, now that RPCMan can be used to generate any output, including the cli.cpp table * Auto-formatting and sanity checking the RPCExamples with RPCMan * Checking passed-in json in self-check. Removing redundant checks * Checking returned json against documentation to avoid regressions or false documentation * Compile the RPC documentation at compile-time to ensure it doesn't change at runtime and is completely static ### Bugs found * The assert identified issue #18607 * The changes itself fixed bug #19250 ACKs for top commit: laanwj: Code review ACK fa77de2baa40ee828c850ef4068c76cc3619e87b fjahr: tested ACK fa77de2baa40ee828c850ef4068c76cc3619e87b theStack: ACK https://github.com/bitcoin/bitcoin/pull/19528/commits/fa77de2baa40ee828c850ef4068c76cc3619e87b ryanofsky: Code review ACK fa77de2baa40ee828c850ef4068c76cc3619e87b. Pretty straightfoward changes Tree-SHA512: badae1606518c0b55ce2c0bb9025d14f05556532375eb20fd6f3bfadae1e5e6568860bff8599d037e655bf1d23f1f464ca17f4db10a6ab3d502b6e9e61c7b3d3
2020-08-06refactor: Make HexStr take a spanWladimir J. van der Laan
Make HexStr take a span of bytes, instead of an awkward pair of templated iterators.
2020-08-02rpc: Treat all args after a hidden arg as hidden as wellMarcoFalke
This commit has no effect right now, but hardens the code for the future
2020-07-15Merge #19386: rpc: Assert that RPCArg names are equal to CRPCCommand ones ↵MarcoFalke
(server) fa7592bfa8691eb0289b21da3571709a18391b0f rpc: Update server to use new RPCHelpMan (MarcoFalke) aaaaad562790cd4dce1568ae193f5393aacacedf rpc: Add option to hide RPCArg (MarcoFalke) fa9708f94c01cb8bf2971bdf404af38c38fa341b rpc: Assert that passed arg names are equal to hardcoded ones (MarcoFalke) faaeb2b0b347b40ce456a951eec5e820587e5b02 rpc: Add CRPCCommand constructor which takes RPCHelpMan (MarcoFalke) fa8ec00061567e56333bb69c5623919d45a9a92d rpc: Check that left section is not multiline (MarcoFalke) Pull request description: This is split out from #18531 to just touch the RPC methods in server. Description from the main pr: ### Motivation RPCArg names in the rpc help are currently only used for documentation. However, in the future they could be used to teach the server the named arguments. Named arguments are currently registered by the `CRPCCommand`s and duplicate the RPCArg names from the documentation. This redundancy is fragile, and has lead to errors in the past (despite having linters to catch those kind of errors). See section "bugs found" for a list of bugs that have been found as a result of the changes here. ### Changes The changes here add an assert in the `CRPCCommand` constructor that the RPCArg names are identical to the ones in the `CRPCCommand`. ### Future work > Here or follow up, makes sense to also assert type of returned UniValue? Sure, but let's not get ahead of ourselves. I am going to submit any further works as follow-ups, including: * Removing the CRPCCommand arguments, now that they are asserted to be equal and thus redundant * Removing all python regex linters on the args, now that RPCMan can be used to generate any output, including the cli.cpp table * Auto-formatting and sanity checking the RPCExamples with RPCMan * Checking passed-in json in self-check. Removing redundant checks * Checking returned json against documentation to avoid regressions or false documentation * Compile the RPC documentation at compile-time to ensure it doesn't change at runtime and is completely static ### Bugs found * The assert identified issue #18607 * The changes itself fixed bug #19250 ACKs for top commit: laanwj: ACK fa7592bfa8691eb0289b21da3571709a18391b0f ryanofsky: Code review ACK fa7592bfa8691eb0289b21da3571709a18391b0f. Looks great! Just some hidden arg and Check() and comment cleanups since last review Tree-SHA512: e64b6a212f4a3aeedeee47557559bde104d5fd40cdc1746b27eb2f3d4c8885d5e6e4dd287595ea11cdbc6a939654fe103cae765fd505875444d851f0abb11308
2020-07-06Merge #19328: Add gettxoutsetinfo hash_type optionMarcoFalke
40506bf93f955adfbc446c4d5fee4fa8bcfd7d9a test: Test gettxouttsetinfo hash_type option (Fabian Jahr) f17a4d1c4ddce6935a353004898fb4e8618a213e rpc: Add hash_type NONE to gettxoutsetinfo (Fabian Jahr) a712cf6f6801157667fcf36d1c498b6fff6d328a rpc: gettxoutsetinfo can specify hash_type (only legacy option for now) (Fabian Jahr) 605884ef21318fc3f326dbdf4901cb353ba63fab refactor: Extract GetBogoSize function (Fabian Jahr) Pull request description: This is another intermediate part of the Coinstats Index (tracked in #18000). Sjors suggested [here](https://github.com/bitcoin/bitcoin/pull/18000#issuecomment-641423019) that the part of the changes in #19145 that don't rely on the new `hash_type` muhash, i.e. that are for `hash_type=none`, could be merged separately from everything involving muhash. So these changes are extracted from #19145 here and can be merged without any other requirements. Building the index with no UTXO set hash is still valuable because `gettxoutsetinfo` can still be used to audit the `total_amount` for example. By itself this PR is not a huge improvement, `hash_type=none` is speeding up `gettxoutsetinfo` by about 10%, but it enables the implementation of an index on top of it in a follow-up and that means large parts of the index code of Coinstats Index can be merged while reviews for the hashing algorithm might take longer. ACKs for top commit: MarcoFalke: ACK 40506bf93f955adfbc446c4d5fee4fa8bcfd7d9a 🖨 Sjors: tACK 40506bf93f955adfbc446c4d5fee4fa8bcfd7d9a Tree-SHA512: 3964c2b8eed427511b1aa9b2ef285dff27dc4d1537d72c3911e435b6e6b40912232da4acb3a09bd19a0372ddffa44103388d8a650169d95a4a727b970d210add
2020-07-03rpc: Add option to hide RPCArgMarcoFalke
Also, update switch statments to our style guide
2020-06-30rpc: Add CRPCCommand constructor which takes RPCHelpManMarcoFalke
This allows the constructor to ask the rpc manager for the name of the rpc method or the rpc argument names instead of having it manually passed in.
2020-06-26rpc: Check that left section is not multilineMarcoFalke
2020-06-24refactor: Replace HexStr(o.begin(), o.end()) with HexStr(o)Wladimir J. van der Laan
HexStr can be called with anything that bas `begin()` and `end()` functions, so clean up the redundant calls.
2020-06-22rpc: Add hash_type NONE to gettxoutsetinfoFabian Jahr
2020-06-22rpc: gettxoutsetinfo can specify hash_type (only legacy option for now)Fabian Jahr
2020-06-09refactor: Error message bilingual_str consistencyWladimir J. van der Laan
- Move the decision whether to translate an error message to where it is defined. This simplifies call sites: no more `InitError(Untranslated(...))`. - Make all functions in `util/error.h` consistently return a `bilingual_str`. We've decided to use this as error message type so let's roll with it. This has no functional changes: no messages are changed, no new translation messages are defined.
2020-05-29util: dedup code in callers of serviceFlagToStr()Vasil Dimov
Introduce `serviceFlagsToStr()` which hides the internals of the bitmask and simplifies callers of `serviceFlagToStr()`.
2020-05-29util: simplify the interface of serviceFlagToStr()Vasil Dimov
Don't take two redundant arguments in `serviceFlagToStr()`. As a side effect this fixes an issue introduced in https://github.com/bitcoin/bitcoin/pull/18165 due to which the GUI could print something like `UNKNOWN[1033] & UNKNOWN[1033] & UNKNOWN[2^10]` instead of `NETWORK & WITNESS`.
2020-05-29Merge #18165: Consolidate service flag bit-to-name conversion to a shared ↵Jonas Schnelli
serviceFlagToStr function c31bc5bcfddf440e9a1713f7ba2ca2bf9cfa8e2e Consolidate service flag bit-to-name conversion to a shared serviceFlagToStr function (Luke Dashjr) cea91a1e40e12029140ebfba969ce3ef2965029c Bugfix: GUI: Use unsigned long long type to avoid implicit conversion of MSB check (Luke Dashjr) Pull request description: Side effect: this results in the RPC showing unknown service bits as "UNKNOWN[n]" like the GUI. Note that there is no common mask-to-`vector<string>` function because both GUI and RPC would need to iterate through it to convert to their desired target formats. ACKs for top commit: jonasschnelli: utACK ~~cea91a1e40e12029140ebfba969ce3ef2965029c~~ c31bc5bcfddf440e9a1713f7ba2ca2bf9cfa8e2e Tree-SHA512: 32c7ba8ac7ef2d4087f4f317447ae93a328ec9fb9ad81301df2fbaeeb21a3db7a503187a369552b05a9414251b7cf8e15bcde74c1ea2ef36591ea7ffb6721f60
2020-04-17Merge #18607: rpc: Fix named arguments in documentationMarcoFalke
fa168d754221a83cab0d2984a02c41cf6819e873 rpc: Document all aliases for first arg of listtransactions (MarcoFalke) fa5b1f067fcf8bebb23455dd8a16cde5068e79cd rpc: Document all aliases for second arg of getblock (MarcoFalke) fa86a4bbfc000593ae4ad9dcdaec3fd0c0406086 rpc: Rename first arg of generateblock RPC to "output" (MarcoFalke) Pull request description: This fixes a bug found with #18531: * Currently the named argument for `generateblock` is documented as `address/descriptor`, but the server only accepts a named argument of `address`. Fix it by changing the name to `output` for both the documentation and the server code. Also, add tests to prove the server understands the new name `output`. * Unrelated to that, there have been a bunch of aliases in the server code that are not present in the source code of the documentation. Fix that by adding the alias to the source code of the documentation. Only the first alias is displayed in the rendered documentation. Also, add tests to prove the server actually understands all aliases. ACKs for top commit: pierreN: Tested ACK fa168d7 tests, help messages Tree-SHA512: 05e15628e3a667b296f3783d20f764b450b959451b5360c7eaf5993156582d47a0f5882330ca2493b851eb46324d504953b90c875bc88a15c9e8c89eb3ef8d92
2020-04-16scripted-diff: Bump copyright headersMarcoFalke
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT-
2020-04-16rpc: Document all aliases for second arg of getblockMarcoFalke
2020-04-02Bugfix: RPC: JSON null is not "None"Luke Dashjr
2020-04-02Bugfix: RPC: Don't use a continuation elipsis after an elision elipsisLuke Dashjr
2020-04-02Bugfix: RPC: Add missing commas and correct indentation of explicit ELISIONLuke Dashjr
2020-03-28Merge #18444: RPC: Remove final comma for last entry of fixed-size ↵MarcoFalke
arrays/objects in RPCResult c34164896c62fc6307b4cc72c060a277263590bb Bugfix: RPC: Remove final comma for last entry of fixed-size Arrays and Objects in RPCResult (Luke Dashjr) Pull request description: JSON doesn't allow a trailing comma in arrays Top commit has no ACKs. Tree-SHA512: 761502a05f447afc09c120f13bf23abd2aee83a7f5e5dadaf54c7e1c0c1280d83ee041ca6ca45998fb561e41b32d01067ec52a187c3bcc9d53303ea813bc212c
2020-03-28Bugfix: RPC: Remove final comma for last entry of fixed-size Arrays and ↵Luke Dashjr
Objects in RPCResult JSON doesn't allow a trailing comma in Arrays/Objects
2020-03-25Merge #18134: Replace std::to_string with locale-independent alternativeWladimir J. van der Laan
d056df033a1e88554f7cc39dd709a87b17cb49df Replace std::to_string with locale-independent alternative (Ben Woosley) Pull request description: Addresses #17866 following practicalswift's suggestion: https://github.com/bitcoin/bitcoin/issues/17866#issuecomment-584287299 ~Used ::ToString to avoid aliasing issues. Left uses in QT and test.~ ACKs for top commit: practicalswift: ACK d056df033a1e88554f7cc39dd709a87b17cb49df laanwj: ACK d056df033a1e88554f7cc39dd709a87b17cb49df Tree-SHA512: 9e6966a9cdd14f4a1a40d9f0fa7c402aed22b2f1ad8681708e22b050d51a91c5d62220a9ec4c425be2d57acf5c964fca87a5e981b5cbff048bc3b6720dae92b7
2020-03-14Replace std::to_string with locale-independent alternativeBen Woosley
2020-03-13Merge #18316: util: HelpExampleRpc formattingfanquake
a33cffbeabcc42137c4a66aa19b7dd1d300e6d73 util: HelpExampleRpc formatting fixup (Jon Atack) Pull request description: Minor visual fixup of the HelpExampleRpc template; conforms to the JSON-RPC spec as per https://www.jsonrpc.org/specification#examples. (I'm... somewhat embarassed to open such a minor change, but this is what is shown in all the CLI/RPC help docs.) ACKs for top commit: laanwj: ACK a33cffbeabcc42137c4a66aa19b7dd1d300e6d73 Tree-SHA512: 8f1dee080c224742fff60a33fec6f5fb1d59c9fa51f3f2a67bf2e1837dbfa25f12a69e34518936588940013b0e61f55378b4f1a571c47c3cb081ca5b245e1091
2020-03-11Merge #18208: rpc: Change RPCExamples to bech32MarcoFalke
3e32499909ca8127baaa9b40ad113b25ee151bbd Change example addresses to bech32 (Yusuf Sahin HAMZA) Pull request description: This is a follow-up PR to #18197 that fixes RPCExamples. Fixes #18185. ACKs for top commit: MarcoFalke: ACK 3e32499909ca8127baaa9b40ad113b25ee151bbd jonatack: ACK 3e32499 Tree-SHA512: c7a6410ef8b6e169016c2c5eac3e6b9501caabd0e8a0871ec31e56bfc44589f056d3f5cb55b5a13bba36f6c15136c2352f883e30e4dcc0997ffd36b27f9173b9
2020-03-11util: HelpExampleRpc formatting fixupJon Atack
to conform to json-rpc spec as per https://www.jsonrpc.org/specification#examples
2020-03-01Change example addresses to bech32Yusuf Sahin HAMZA
2020-02-25rpc: Auto-format RPCResultMarcoFalke
2020-02-25rpc: Move OuterType enum to headerMarcoFalke
This is needed so that it can be used by RPCResult Also, * rename NAMED_ARG to NONE for generalization. * change RPCArg constructors to initialize the members by moving values
2020-02-21Consolidate service flag bit-to-name conversion to a shared serviceFlagToStr ↵Luke Dashjr
function Side effect: this results in the RPC showing unknown service bits as "UNKNOWN[n]" like the GUI. Note that there is no common mask-to-vector<string> function because both GUI and RPC would need to iterate through it to convert to their desired target formats.
2020-02-13rpc: update validateaddress RPCExamples to bech32Sebastian Falbesoner
also contains the following changes: - rpc: factor out example bech32 address for RPCExamples - doc: update developer notes wrt RPCExamples addresses (mention the EXAMPLE_ADDRESS constant as an example for an invalid bech32 address suitable for RPCExamples help documentation)
2019-12-13qa: unify unix epoch time descriptionsJon Atack
to "UNIX epoch time". Call sites updated: ``` mocktime getblockheader getblock pruneblockchain getchaintxstats getblocktemplate setmocktime getpeerinfo setban getnodeaddresses getrawtransaction importmulti listtransactions listsinceblock gettransaction getwalletinfo getaddressinfo ```
2019-11-24wallet: replace raw pointer with const reference in AddrToPubKeyHarris
2019-10-30replace asserts in RPC code with CHECK_NONFATAL and add linterAdam Jonas
2019-10-28Avoid using g_rpc_node global in wallet codeRussell Yanofsky
Wallet code should use interfaces::Chain and not directly access to node state. Add a g_rpc_chain replacement global for wallet code to use, and move g_rpc_node definition to a libbitcoin_server source file so there are link errors if wallet code tries to access it.
2019-10-28scripted-diff: Rename InitInterfaces to NodeContextRussell Yanofsky
-BEGIN VERIFY SCRIPT- s() { git grep -l "$1" src | xargs sed -i "s/$1/$2/g"; } s 'struct InitInterfaces' 'struct NodeContext' s 'InitInterfaces interfaces' 'NodeContext node' s 'InitInterfaces& interfaces' 'NodeContext\& node' s 'InitInterfaces m_interfaces' 'NodeContext m_context' s 'InitInterfaces\* g_rpc_interfaces' 'NodeContext* g_rpc_node' s 'g_rpc_interfaces = &interfaces' 'g_rpc_node = \&node' s 'g_rpc_interfaces' 'g_rpc_node' s 'm_interfaces' 'm_context' s 'interfaces\.chain' 'node.chain' s '\(AppInitMain\|Shutdown\|Construct\)(interfaces)' '\1(node)' s 'init interfaces' 'chain clients' -END VERIFY SCRIPT-
2019-09-05rpc/net: decode the services flags in a new entrydarosior
2019-08-20rpc: Use Join helper in rpc/utilMarcoFalke
2019-08-16Give more errors for specific failure conditionsAndrew Chow
Some failure conditions implicitly fail by failing some other check. But the error messages are more helpful if they say explicitly what actually caused the failure, so add those as failure conditions and errors.
2019-08-16Return an error from descriptor Parse that gives more information about what ↵Andrew Chow
failed
2019-07-09Move various SigningProviders to signingprovider.{cpp,h}Andrew Chow
Moves all of the various SigningProviders out of sign.{cpp,h} and keystore.{cpp,h}. As such, keystore.{cpp,h} is also removed. Includes and the Makefile are updated to reflect this. Includes were largely changed using: git grep -l "keystore.h" | xargs sed -i -e 's;keystore.h;script/signingprovider.h;g'
2019-07-09scripted-diff: rename CBasicKeyStore to FillableSigningProviderAndrew Chow
-BEGIN VERIFY SCRIPT- git grep -l "CBasicKeyStore" | xargs sed -i -e 's/CBasicKeyStore/FillableSigningProvider/g' -END VERIFY SCRIPT-
2019-07-09Remove CKeyStore and squash into CBasicKeyStoreAndrew Chow
2019-07-02Merge #15427: Add support for descriptors to utxoupdatepsbtWladimir J. van der Laan
26fe9b990995f9cb5eee21d40b4daaad19f7181f Add support for descriptors to utxoupdatepsbt (Pieter Wuille) 3135c1a2d2e2fb31bc362c848bd2456d576e408b Abstract out UpdatePSBTOutput from FillPSBT (Pieter Wuille) fb90ec3c33e824f5abb6a68452c683d6ce8b3e4a Abstract out EvalDescriptorStringOrObject from scantxoutset (Pieter Wuille) eaf4f887348a08c620732125ad4430e1a133d434 Abstract out IsSegWitOutput from utxoupdatepsbt (Pieter Wuille) Pull request description: This adds a descriptors argument to the `utxoupdatepsbt` RPC. This means: * Input and output scripts and keys will be filled in when known. * P2SH-witness inputs will be filled in from the UTXO set when a descriptor is provided that shows they're spending segwit outputs. This also moves some (newly) shared code to separate functions: `UpdatePSBTOutput` (an analogue to `SignPSBTInput`), `IsSegWitOutput`, and `EvalDescriptorStringOrObject` (implementing the string or object notation parsing used in `scantxoutset`). ACKs for top commit: jnewbery: utACK 26fe9b990995f9cb5eee21d40b4daaad19f7181f laanwj: utACK 26fe9b990995f9cb5eee21d40b4daaad19f7181f (will hold merging until response to promag's comments) promag: ACK 26fe9b9, checked refactors and tests look comprehensive. Still missing a release note but can be added later. Tree-SHA512: 1d833b7351b59d6c5ded6da399ff371a8a2a6ad04c0a8f90e6e46105dc737fa6f2740b1e5340280d59e01f42896c40b720c042f44417e38dfbee6477b894b245
2019-06-20Make and get the multisig redeemscript and destination in one function ↵Andrew Chow
instead of two Instead of creating a redeemScript with CreateMultisigRedeemscript and then getting the destination with AddAndGetDestinationForScript, do both in the same function. CreateMultisigRedeemscript is changed to AddAndGetMultisigDestination. It creates the redeemScript and returns it via an output parameter. Then it calls AddAndGetDestinationForScript to add the destination to the keystore and get the proper destination. This allows us to inspect the public keys in the redeemScript before creating the destination so that the correct destination is used when uncompressed pubkeys are in the multisig.
2019-05-10Abstract out EvalDescriptorStringOrObject from scantxoutsetPieter Wuille
2019-05-10Merge #15744: refactor: Extract ParseDescriptorRangeMarcoFalke
510c6532ba Extract ParseDescriptorRange (Ben Woosley) Pull request description: So as to be consistently informative when the checks fail, and to protect against unintentional divergence among the checks. ACKs for commit 510c65: meshcollider: Oh apologies, yes. Thanks :) utACK https://github.com/bitcoin/bitcoin/pull/15744/commits/510c6532bae9abc5beda1c126c945923a64680cb MarcoFalke: utACK 510c6532bae9abc5beda1c126c945923a64680cb sipa: utACK 510c6532bae9abc5beda1c126c945923a64680cb Tree-SHA512: b1f0792bfaa163890a20654a0fc2c4c4a996659916bf5f4a495662436b39326692a1a0c825caafd859e48c05f5dd1865c4f7c28092be5074edda3c94f94f9f8b