From 4c317d89e9d980328028ff01cd9a0465cc22bb7e Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Thu, 15 Mar 2018 16:37:57 -0400 Subject: [PATCH] Document RPC method aliasing Suggested by Sjors Provoost in https://github.com/bitcoin/bitcoin/pull/11536#issuecomment-372820660 --- doc/developer-notes.md | 11 +++++++++++ src/rpc/server.h | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/doc/developer-notes.md b/doc/developer-notes.md index a5468c3be..8f06ee4ec 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -710,3 +710,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. diff --git a/src/rpc/server.h b/src/rpc/server.h index 8b32924fb..d25268a8a 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -165,8 +165,17 @@ public: /** * Appends a CRPCCommand 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 CRPCCommand* pcmd); };