fixes #20246
This documents the two JSON-RPC endpoints available, details when they are active, specifies when they can or must be used, and outlines some known behaviour quirks.
fixes #20246
This documents the two JSON-RPC endpoints available, details when they are active, specifies when they can or must be used, and outlines some known behaviour quirks.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--021abf342d371248e50ceaed478a90ca-->
See the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
Concept ACK
4 | @@ -5,6 +5,36 @@ The headless daemon `bitcoind` has the JSON-RPC API enabled by default, the GUI 5 | option. In the GUI it is possible to execute RPC methods in the Debug Console 6 | Dialog. 7 | 8 | +## Endpoints 9 | + 10 | +There are two JSON-RPC endpoints on the server: 11 | + 12 | +1. `/` 13 | +2. `/wallet/<walletname>/`
A few ideas about these:
http://localhost:{port}//wallet/:walletname, at least for REST APIs. I dunno if there is otherwise a convention for thatPersonally I feel it's clearer just to use the endpoints themselves, rather than cluttering with hosts and ports.
Also, we have examples now!
13 | +2. `/wallet/<walletname>/` 14 | + 15 | +### `/` endpoint 16 | + 17 | +This endpoint is always active and can service both wallet and non-wallet 18 | +requests when there are zero or one wallets loaded.
This endpoint is always active for non-wallet requests, and can service wallet requests when exactly one wallet is loaded.
I see your point here, but I was also trying to distinguish: active=enabled, services=wallet/non-wallet.
How about:
This endpoint is always active. It can always service non-wallet requests and can service wallet requests when exactly one wallet is loaded.
👍
Done
17 | +This endpoint is always active and can service both wallet and non-wallet 18 | +requests when there are zero or one wallets loaded. 19 | + 20 | +### `/wallet/<walletname>/` endpoint 21 | + 22 | +This endpoint is only activated when the wallet component has been compiled in
It is also always active for non-wallet requests before any wallets are loaded.
(but only when the wallet is compiled in).
Also I think i've covered that it handles both types of request when no wallet is loaded in the Quirks section?
21 | + 22 | +This endpoint is only activated when the wallet component has been compiled in 23 | +and can service both wallet and non-wallet requests. It MUST be used for wallet 24 | +requests when two or more wallets are loaded. 25 | + 26 | +This endpoint is equivalent to using bitcoin-cli with the `-rpcwallet=` parameter.
This is the endpoint used by bitcoin-cli when a `-rpcwallet=` parameter is passed in.
Agree with this.
Done
24 | +requests when two or more wallets are loaded. 25 | + 26 | +This endpoint is equivalent to using bitcoin-cli with the `-rpcwallet=` parameter. 27 | + 28 | +Best practice would dictate using the `/wallet/<walletname>/` endpoint for ALL 29 | +requests when multiple wallets are in use.
actually seems like its the right endpoint to use for all requests all the time! For non wallet requests you can still use /wallet with no wallet name
$ curl http://u:p@localhost:18443/wallet/ --data '{"method":"getblockcount"}'
{"result":206,"error":null,"id":null}
Oh, I didn't know you could use the endpoint without a wallet name at all!
IMO it makes sense to specify that it should be used with the wallet/<walletname>/ syntax for multiwallet (as designed?)
yeah i dunno whats best to reccomend. I think personally Id use / for node requests and /wallet/walletname for any wallet request no matter how many wallets are loaded.
Leaving this for now, as using the bare /wallet/ endpoint could be considered unsupported behaviour.
31 | +### Quirks: 32 | + 33 | +* With more than one wallet loaded the `/` endpoint will still be able to 34 | +service non-wallet requests. 35 | +* When active the `/wallet/<walletname>/` endpoint can still be used when no 36 | +wallet is loaded by providing a dummy `walletname`.
I think these can be folded in above if you like my suggestions.
I think a few curl examples might be appropriate here as well since this document is covering raw endpoint stuff
Again I think I agree here, especially seeing as there are no /wallet/ examples given in RPCHelp
Removed quirks
ACK https://github.com/bitcoin/bitcoin/pull/27225/commits/86cff0ee0cb78f5eb2568e7e863eb72baa571a53
Error is also helpful if someone is unaware of this and tries to use / endpoint with 2 or more wallets for wallet based RPC commands.
{
"result": null,
"error": {
"code": -19,
"message": "Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path)."
},
"id": "test"
}
concept ACK
34 | +```sh 35 | +# Get block count from the / endpoint when rpcuser=alice and rpcport=38332 36 | +$ curl --user alice --data-binary '{"jsonrpc": "1.0", "id": "0", "method": "getblockcount", "params": []}' -H 'content-type: text/plain;' localhost:38332/ 37 | + 38 | +# Get balance from the /wallet/walletname endpoint when rpcuser=alice, rpcport=38332 and rpcwallet=desc-wallet 39 | +$ curl --user alice --data-binary '{"jsonrpc": "1.0", "id": "0", "method": "getbalance", "params": []}' -H 'content-type: text/plain;' localhost:38332/wallet/desc-wallet
Why are the examples using signet port? I think we should use mainnet port (8332) same as all the RPC examples.
I'm happy to be persuaded either way here, no particular reason for using signet (other than I was using it for testing). Although I personally don't think it matters much as the comment for each shows which variables are being used
Concept ACK
Nit - there is typo in commit message / PR title (s/docment/document/).
fixes #20246
Document both JSON-RPC endpoints, when they are active and which types
of requests they are able to service.
Adds two example curl requests, one for each endpoint.
Nit - there is typo in commit message / PR title (s/docment/document/).
Thanks, i've updated this in 65e3abcbf
Nit - there is typo in commit message / PR title (s/docment/document/).
Thanks, i've updated this in 65e3abcbf
You should also edit PR title. It is used by github-merge.py.
Thanks, I thought that updated from the force push, but apparently not. Now also done :)
ACK 65e3abcbf2b9e818f3b9f1ba35f3cfe7df5e3811 - Seems fine. Can be improved if need be.