Skip to content

Commit

Permalink
Document RPC method aliasing
Browse files Browse the repository at this point in the history
Summary:
Suggested by Sjors Provoost <sjors@sprovoost.nl> in
bitcoin/bitcoin#11536 (comment)

This is a backport of Core PR12700

Test Plan:
  make

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D4169
  • Loading branch information
ryanofsky authored and jonspock committed Dec 26, 2019
1 parent 6c6044d commit f84d9c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,14 @@ A few guidelines for introducing and reviewing new RPC interfaces:
client may be aware of prior to entering a wallet RPC call, we must block
until the wallet is caught up to the chainstate as of the RPC call's entry.
This also makes the API much easier for RPC clients to reason about.

- Be aware of RPC method aliases and generally avoid registering the same
callback function pointer for different RPCs.

- *Rationale*: RPC methods registered with the same function pointer will be
considered aliases and only the first method name will show up in the
`help` rpc command list.

- *Exception*: Using RPC method aliases may be appropriate in cases where a
new RPC is replacing a deprecated RPC, to avoid both RPCs confusingly
showing up in the command list.
9 changes: 9 additions & 0 deletions src/rpc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,18 @@ class CRPCTable {

/**
* Appends a ContextFreeRPCCommand to the dispatch table.
*
* Returns false if RPC server is already running (dump concurrency
* protection).
*
* Commands cannot be overwritten (returns false).
*
* Commands with different method names but the same callback function will
* be considered aliases, and only the first registered method name will
* show up in the help text command listing. Aliased commands do not have
* to have the same behavior. Server and client code can distinguish
* between calls based on method name, and aliased commands can also
* register different names, types, and numbers of parameters.
*/
bool appendCommand(const std::string &name,
const ContextFreeRPCCommand *pcmd);
Expand Down

0 comments on commit f84d9c2

Please sign in to comment.