Skip to content

Commit ebdf84c

Browse files
committed
Merge #12700: Document RPC method aliasing
4c317d8 Document RPC method aliasing (Russell Yanofsky) Pull request description: Suggested by @Sjors in bitcoin/bitcoin#11536 (comment) Tree-SHA512: 7bf16238e41b6c6c078e9103d8eac2ac76739a2c16b4f964be49bfde1f20f31a1fb30badf1faaa6ddc301a74f0d785d19567069b50de78c502144479143cb38c
2 parents 93634f2 + 4c317d8 commit ebdf84c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

doc/developer-notes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,3 +710,14 @@ A few guidelines for introducing and reviewing new RPC interfaces:
710710
client may be aware of prior to entering a wallet RPC call, we must block
711711
until the wallet is caught up to the chainstate as of the RPC call's entry.
712712
This also makes the API much easier for RPC clients to reason about.
713+
714+
- Be aware of RPC method aliases and generally avoid registering the same
715+
callback function pointer for different RPCs.
716+
717+
- *Rationale*: RPC methods registered with the same function pointer will be
718+
considered aliases and only the first method name will show up in the
719+
`help` rpc command list.
720+
721+
- *Exception*: Using RPC method aliases may be appropriate in cases where a
722+
new RPC is replacing a deprecated RPC, to avoid both RPCs confusingly
723+
showing up in the command list.

src/rpc/server.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,17 @@ class CRPCTable
165165

166166
/**
167167
* Appends a CRPCCommand to the dispatch table.
168+
*
168169
* Returns false if RPC server is already running (dump concurrency protection).
170+
*
169171
* Commands cannot be overwritten (returns false).
172+
*
173+
* Commands with different method names but the same callback function will
174+
* be considered aliases, and only the first registered method name will
175+
* show up in the help text command listing. Aliased commands do not have
176+
* to have the same behavior. Server and client code can distinguish
177+
* between calls based on method name, and aliased commands can also
178+
* register different names, types, and numbers of parameters.
170179
*/
171180
bool appendCommand(const std::string& name, const CRPCCommand* pcmd);
172181
};

0 commit comments

Comments
 (0)