Skip to content

Conversation

@jgarzik
Copy link
Contributor

@jgarzik jgarzik commented Apr 15, 2012

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).

@laanwj
Copy link
Member

laanwj commented Apr 15, 2012

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.

@sipa
Copy link
Member

sipa commented Apr 15, 2012

You could have an RPCDIspatcher class with a singleton object, which uses RegisterRPCCommands as constructor.

@laanwj
Copy link
Member

laanwj commented Apr 15, 2012

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?

@sipa
Copy link
Member

sipa commented Apr 15, 2012

Oh right - I confused safe mode with "requires extra locking". I removed the part of the comment about that.

@jgarzik
Copy link
Contributor Author

jgarzik commented Apr 15, 2012

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.

@laanwj
Copy link
Member

laanwj commented Apr 15, 2012

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.

  • The server logic is a box that accepts JSON and produces JSON data structures. It knows nothing of argument parsing, formatting, just handles commands.
  • The client logic takes a command name and list of (string) arguments, and produces a string message and error code as output. The conversion from argument list to JSON internally is dependent on the command. It can either communicate with the server through the network (as JSON client) or by passing the JSON object in and out in memory (UI console).

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)

@jgarzik
Copy link
Contributor Author

jgarzik commented Apr 15, 2012

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 :)

@gavinandresen
Copy link
Contributor

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.

@sipa
Copy link
Member

sipa commented Apr 18, 2012

I've extended the encapsulation a bit further (while fixing the initialization issue) in #1124.

sipa added a commit that referenced this pull request Apr 21, 2012
extension of #1103: encapsulate mapCommands in CRPCTable
@sipa
Copy link
Member

sipa commented Apr 21, 2012

Included in #1124

@sipa sipa closed this Apr 21, 2012
coblee pushed a commit to litecoin-project/litecoin that referenced this pull request Jul 17, 2012
extension of bitcoin#1103: encapsulate mapCommands in CRPCTable
suprnurd pushed a commit to chaincoin-legacy/chaincoin that referenced this pull request Dec 5, 2017
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Jan 22, 2019
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Dec 25, 2019
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
Bushstar pushed a commit to Bushstar/omnicore that referenced this pull request Apr 21, 2020
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants