handshake-org / hsd

Handshake Daemon & Full Node
Other
1.94k stars 281 forks source link

API unification. #543

Open randomlogin opened 3 years ago

randomlogin commented 3 years ago

There are several kinds of APIs, the RPC, the http. From what I know, the rpc was created for the 'backward compatibility' with bitcoin core.

The outputs have different sets of fields presented, different names for the same fields, and even different naming conventions (camelCase vs lowcase).

For example, here is the output of rpc curl 127.0.0.1:12037/ -X POST -d '{ "method": "getblockbyheight", "params": [ 1, true, true ] }.

And here is the output of curl 127.0.0.1:12037/block/1.

The outputs use these functions: RPC: https://github.com/handshake-org/hsd/blob/1a086e44b5b60e1ebb01955b0e1b2a0ebd00b42d/lib/node/rpc.js#L2819 HTTP: https://github.com/handshake-org/hsd/blob/1a086e44b5b60e1ebb01955b0e1b2a0ebd00b42d/lib/primitives/tx.js#L1726 and their analogues for the block presentation.

From what I think, the http api (which is stateless) is more useful and important and should contain full information.

So the questions/suggestions:

  1. Is it really needed to have RPC api?
  2. If rpc is still needed, change the 'main' api to the http and set rpc to use the same output as http.
  3. Some kind of unification, say name the hash of the tx field as txid, etc.
pinheadmz commented 3 years ago

related: https://github.com/handshake-org/hsd/pull/470

Maybe we should plan a big API cleanup for hsd v3.0.0 that drops this forced compatibility with Bitcoin Core