-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Encapsulate RPC command dispatch in an array of CRPCCommand's #1103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
IMO this is less ugly instead of more ugly than #1102. All non-implementation information about RPC commands is conveniently in one place, in table vRpcCommands. You could in principle add the help message as well. And there's no long registration function that has to be kept up to date when new commands added, just a simple one. One remark though: can you move the RegisterRPCCommands() call to AppInit2() instead? This make sure that the RPC commands data structure is initialized even if the RPC thread is not started. #1075 makes use of this for executing local "RPC" commands without -server. |
|
You could have an RPCDIspatcher class with a singleton object, which uses RegisterRPCCommands as constructor. |
|
As I understand it we currently simply take both mutexes for all RPC commands? (which is inefficient, but very safe) Did that change with this commit? |
|
Oh right - I confused safe mode with "requires extra locking". I removed the part of the comment about that. |
|
BTW, I am looking for suggestions on how to best encapsulate the parameter parsing in CommandLineRPC(). That is the last area where there is a long "if command==foo, do X" decision table, containing per-RPC-command logic. It would be nice to move that parameter parsing into the vRPCCommand table. |
|
I'm not entirely sure about that. IMO it would be nice to separate client and server concerns as far as possible, even into separate implementation files.
There's some network code and such that exists in limbo between the two. (I have nothing against making the "convert argument strings to JSON" data-driven as well, but I'm not convinced it belongs in the same place) |
|
RE @laanwj "And there's no long registration function that has to be kept up to date when new commands added, just a simple one" Well, the long registration function is replaced with a long table. As the saying goes, "six of one, half-dozen of the other" In both this pull request and #1102, there is one (1) place that contains a master list of RPC commands. In this pull request it is vRPCCommands[], and in #1102 it is RegisterRPCCommands(). I do lean towards this pull request too, because it is smaller and more compact. However, the continued use of 'rpcfn_type' would probably be ugly to C++ purists :) |
|
ACK. I like this one better. I like data-driven programming, so describing argument types in a std::map<string method, std::map<int argNumber, ...something... argType> > or something instead of the current big long "if/else..." appeals to me. But that's such a low priority I probably wouldn't bother. |
|
I've extended the encapsulation a bit further (while fixing the initialization issue) in #1124. |
extension of #1103: encapsulate mapCommands in CRPCTable
|
Included in #1124 |
extension of bitcoin#1103: encapsulate mapCommands in CRPCTable
Fix clang warnings
48a4a3c [Bug] Coded properly the URI from file read.. (furszy) Pull request description: Re coded the URI from file read. Can be easily tested parsing a file with the following text pattern: `pivx:%address%?amount=%number%?label=%text%?message=%text%` About the code that was here before, really no comments.. This solves bitcoin#1103 ACKs for top commit: Warrows: ACK 48a4a3c random-zebra: utACK 48a4a3c Tree-SHA512: 2597ef7db91c2eed012d2ec27dc6192ac82e383392254ae8cd301546ebadd661b8316e807dd8c24944614aa1916d4ff7f79b94f53c8c6d141ceef8d51bb93610
9dfa58f Fix typo: depreciated -> deprecated (Sean Gilligan) Pull request description: See https://www.merriam-webster.com/dictionary/deprecate This change only affects comments, documentation, and RPC Help messages. Tree-SHA512: 4b65f1911e428e20b1f02a10eb27452d90b16dab1fa8e33a895e786dee47e46a4ac7b141c4531116cadcd1414987de22b9028835632de1e08a8ee37b895dabbf
This is an alternate version of pull request #1102, which uses function pointers ("ugly" and less extensible from C++ standpoint, but perhaps cleaner from bitcoin's perspective).