getaddednodeinfo RPC call returns JSON object with duplicate keys #3581

issue davecgh opened this issue on January 24, 2014
  1. davecgh commented at 9:59 PM on January 24, 2014: contributor

    As the title states, the getaddednodeinfo RPC call, when invoked with the dns flag set to false, returns a JSON object with duplicate keys:

    bitcoind getaddednodeinfo false { "addednode" : "1.2.3.4", "addednode" : "5.6.7.8" }

    Most parsers will not handle this correctly. For example, paste {"addednode":"1.2.3.4","addednode":"5.6.7.8"} into http://jsonlint.com/ and look at the result.

    I would suggest that is changed to an array of strings ["1.2.3.4","5.6.7.8"].

    15:48 < gavinandresen> davec: can you file a bug?  That should definitely get fixed.
    15:49 < davec> gavinandresen: will do
    15:51 < gavinandresen> davec: you sure it is broken?  According to the help, getaddednodeinfo returns an array of objects
    15:54 < davec> > bitcoind getaddednodeinfo false
    15:54 < davec> > {
    15:54 < davec> >    "addednode" : "1.2.3.4",
    15:54 < davec> >    "addednode" : "5.6.7.8"
    15:54 < davec> > }
    15:54 < davec> gavinandresen: with the dns flag set to true, it is an array of objs
    15:55 < gavinandresen> davec: ah, yeah.  Definitely file a bug, getaddednodeinfo false should just return an aray of IP strings.
    
  2. laanwj commented at 9:28 AM on January 27, 2014: member

    According to the help https://github.com/bitcoin/bitcoin/blob/master/src/rpcnet.cpp#L202 it's supposed to return a record per node with at least an IP address so

    [
    {"addednode" : "1.2.3.4"},
    {"addednode" : "5.6.7.8"}
    ]
    

    But it somehow creates one object with multiple keys. This is indeed a bug.

  3. laanwj referenced this in commit b829815a57 on Jan 27, 2014
  4. laanwj commented at 9:34 AM on January 27, 2014: member

    See #3586

  5. davecgh commented at 7:34 PM on January 27, 2014: contributor

    I'm glad to see this addressed so quickly, but I would like to point out I don't think the change is quite right.

    Perhaps I read the help differently, but I see "If false, only a list of added nodes will be provided," meaning it should be an array of IP address strings. Also, returning an array of single entry objects is inconsistent with the rest of the RPC methods. For example, look at the addresses field of decoderawtransaction and decodescript. In all other cases where there is only a single entry, the JSON is just an array of the entries versus an array of objects containing a single entry.

    Finally, per the quoted conversation above with Gavin quoted he indicated it should "return an aray of IP strings".

    Edit:

    To make it clear what I think the final JSON should look like: ["1.2.3.4", "5.6.7.8"]

  6. laanwj commented at 8:31 PM on January 27, 2014: member

    This is how I interpreted it. Keeps the output format in both cases consistent and makes it possible to add fields later.

    Anyway, you know how to change it now feel free to do it differently.

  7. laanwj referenced this in commit 4412c5a759 on Jan 29, 2014
  8. laanwj closed this on Jan 29, 2014

  9. luke-jr referenced this in commit a41825be57 on Feb 12, 2014
  10. pooler referenced this in commit f8704fb36d on Mar 26, 2014
  11. wtogami referenced this in commit 77e59c0dc6 on Mar 27, 2014
  12. wtogami referenced this in commit c1c35358fb on Apr 4, 2014
  13. MathyV referenced this in commit 0316d50ee7 on May 9, 2014
  14. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 21:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me