-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
QoL improvements for accounts_frontiers
& accounts_representatives
RPC
#4223
QoL improvements for accounts_frontiers
& accounts_representatives
RPC
#4223
Conversation
would this return an empty object |
checked this, is is returning an empty string when the |
can't check {
"action": "accounts_frontiers",
"accounts": ["nano_1hrts7hcoozxccnffoq9hqhngnn9jz783usapejm57ejtqcyz9dpso1bibuy"]
} {
"frontiers": ""
} with this in mind, I have no idea which option would be the least breaking for existing implementations. this cursed javascript code works because it iterates characters of the string rather than keys of the set: const response = {
frontiers: '',
}
for(const accountID in response.frontiers) {
console.log(accountID)
} the one below doesn't seem to produce any errors either, but that might be different in other programming languages, so it depends if the implementations check for the presence of field const response = {}
for(const accountID in response.frontiers) {
console.log(accountID)
}
{
"error": "Bad account number"
} and #4228 proposes changing it to {
"errors": {
"nano_36uccgpjzhjsdbj44wm1y5hyz8gefx3wjpp1jircxt84nopxkxti5bzq1rnz": "Bad account number"
}
} which is different, but likely fine for an improper configuration error that shouldn't occur on production code (?) |
nano/node/json_handler.cpp
Outdated
@@ -989,10 +996,15 @@ void nano::json_handler::accounts_frontiers () | |||
ec = nano::error_common::account_not_found; | |||
} | |||
} | |||
frontiers.put (account_from_request.second.data (), boost::str (boost::format ("error: %1%") % ec.message ())); | |||
debug_assert (ec); | |||
errors.put (account_from_request.second.data (), ec.message ()); | |||
ec = {}; | |||
} | |||
response_l.add_child ("frontiers", frontiers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only add frontiers
if it is not empty.
nano/node/json_handler.cpp
Outdated
@@ -937,10 +938,15 @@ void nano::json_handler::accounts_representatives () | |||
continue; | |||
} | |||
} | |||
representatives.put (account_from_request.second.data (), boost::format ("error: %1%") % ec.message ()); | |||
debug_assert (ec); | |||
errors.put (account_from_request.second.data (), ec.message ()); | |||
ec = {}; | |||
} | |||
response_l.add_child ("representatives", representatives); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only add representatives
if it is not empty.
ec = {}; | ||
} | ||
response_l.add_child ("representatives", representatives); | ||
if (!representatives.empty ()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the ptree issue with serialising empty arrays as empty strings, I think this is the less-wrong way to do it. RPC users can test if the array member exists before iterating. In the future when the serialisation is fully conformant, the check could be removed. Otherwise they need to handle different types which is undesirable.
Issue nanocurrency/nano-docs#665 complained that "[...], if your code expects a valid hash like it always used to return, the RPC now provides an unexpected string for newly created accounts:", which was caused by
#3791 that changed RPC API to return errors in a pretty unexpected, non standard way. This PR changes
accounts_frontiers
&accounts_representatives
RPCs to instead return any errors in anerrors
subfield, which avoids encoding errors in a field that should always contain valid hash or account number (according to documentation). It should also simplify checking for errors client side, as checking if the account was queried successfully can be accomplished by simpleif account in response
condition, instead of needing to parse error strings.accounts_frontiers
Request:
Response:
accounts_representatives
Request:
Response: