edilmedeiros / rust-bcli

Bitcoin CLI in Rust
GNU General Public License v3.0
6 stars 2 forks source link

info: How Bitcoin Core does the job #6

Open edilmedeiros opened 6 months ago

edilmedeiros commented 6 months ago

Putting this info here since we are interested in learning more about Core. I didn't know if we would use this information ourselves.

The RPC methods are defined using the RPCHelpMan class. For every method there's a call to the constructor

RPCHelpMan(std::string name, 
           std::string description, 
           std::vector<RPCArg> args, 
           RPCResults results, 
           RPCExamples examples, 
           RPCMethodImpl fun
           );

which includes the description and examples returned by the help command in the bitcoin-cli and the actual method implementation (usually passed as a lambda function. See decoderawtransaction for an example of its usage.

The interface is organized using a CTable class (this is where the methods are registered in the table which call this function that calls the others until the individual methods).

I still did not understand what the RPC methods actually return (and how, JSON?), but since we are going to change the user interface and this class manages part of the user interface, it seemed useful to put this info here.

itornaza commented 6 months ago

I believe the Bitcoin Core uses a json format RESTResponseFormat::JSON get results from REST service defined in the rest.cpp file.

On the other hand, bitcoincore_cli, utilizes json to interact with core but returns rust types as in this example here

edilmedeiros commented 6 months ago

It uses the UniValue class to represent values internally. Since this is compatible with JSON values, I believe it gets translated somewhere in the process.