nanocurrency / nano-node

Nano is digital currency. Its ticker is: XNO and its currency symbol is: Ӿ
https://nano.org
BSD 3-Clause "New" or "Revised" License
3.48k stars 786 forks source link

Return proper types in RPC #3348

Open shryder opened 3 years ago

shryder commented 3 years ago

Summary

I think this is a really breaking change and unneeded right now but just wondering what you guys think about RPCs returning an empty string instead of an empty array/object.

Example RPC request: If the account was opened, the history field will be a populated array: https://node.shrynode.me/api?action=account_history&account=nano_1nk9zdf1otddxhxfqimjdkmbtq17yzf3z6giz1as7x1huyug8er1ukeqpqpe&count=20

If the account was not opened, the history field will be an empty string: https://node.shrynode.me/api?action=account_history&account=nano_3ikcyn5rn5erjyx53wa9ejmu3o7853rwbhbucrkp57xuzxurqj486aascn4x&count=20

What problem would be solved by this feature?

Clients having to do weird checks & just better imo

Are there any previous requests for this feature?

I don't think so

Do you have a suggested solution?

My suggested solution would be to not use Boost's Property Tree entirely and instead move to something like nlohmann or Boost.JSON

With nlohmann, we can specify the type by simply using one of the standard types (int, bool, std::vector, std::map, std::string).

For example: This is how it roughly works currently:

boost::property_tree::ptree accounts;

// Add item to array
boost::property_tree::ptree entry;
entry.put ("", nano::account (0).to_account ());
accounts.push_back (std::make_pair ("", entry));

With a special JSON library it would look like this:

std::vector<std::string> accounts;
accounts.push_back (nano::account (0).to_account ());

Serializing with nlohmann will always return an array even when empty, unlike boost::property_tree::write_json.

If this feature is approved, would you be willing to submit a pull request with the solution?

I am willing to collaborate

Possible solution

No response

Supporting files

No response

shryder commented 3 years ago

Just found an old issue, this is apparently planned as part of RPC 2.0: https://github.com/nanocurrency/nano-node/issues/1871