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
| errors.put (account_from_request.second.data (), ec.message ()); | ||
| ec = {}; | ||
| } | ||
| response_l.add_child ("frontiers", frontiers); |
There was a problem hiding this comment.
Only add frontiers if it is not empty.
nano/node/json_handler.cpp
Outdated
| errors.put (account_from_request.second.data (), ec.message ()); | ||
| ec = {}; | ||
| } | ||
| response_l.add_child ("representatives", representatives); |
There was a problem hiding this comment.
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.
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_representativesRPCs to instead return any errors in anerrorssubfield, 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 responsecondition, instead of needing to parse error strings.accounts_frontiers
Request:
Response:
accounts_representatives
Request:
Response: