JSON parsing in QT debug window #1831

issue gavinandresen opened this issue on September 18, 2012
  1. gavinandresen commented at 4:52 PM on September 18, 2012: contributor

    Bug #1 : spaces inside single quotes are not preserved for method arguments.

    E.g. run listunspent, then try to copy and paste one of the unspent inputs into a createrawtransaction '[...unspent...]' '{"...address...":1}'

    You have to delete all of the spaces in the listunspent output for it to work.

    Bug #2 : you have to put JSON arrays/objects inside single quotes. It would be really nice if the QT debug window was smart enough to not require that. Can the json spirit code read from a stream?

  2. laanwj commented at 5:36 PM on September 18, 2012: member

    #1 sounds like a bug, #2 is not a bug though: the console emulates a 'bash' console with bitcoind, which also needs JSON arrays/objects quoted.

    I'm sure it's possible to switch to "JSON objects separated by spaces", or even full javascript syntax (Qt has a js interpreter, QtScript), but that would be a complete break from what we've done until now.

  3. laanwj commented at 5:58 PM on September 18, 2012: member

    I'm not able to reproduce #1. To check space handling, I've temporarily added a command test that simply prints the first argument:

    19:53:45 test " 1234 " 19:53:45 " 1234 " 19:53:49 test ' 1234 ' 19:53:49 " 1234 "

    Spaces inside both single and double quotes seem to be handled as expected, at least by the console code. There might be something deeper in RPCConvertValues that causes the problem, but then you'd expect it as well when you use bitcoind as RPC client on the command line.

    Can you give exact input that produces the problem?

  4. gavinandresen commented at 9:26 PM on September 18, 2012: contributor

    Weird... I cannot reproduce #1 now with a fresh build, I'll verify on a 0.7.0 release binary.

    Input that was causing my trouble before:

    createrawtransaction '[{ "txid" : "f28346bb47465584cfe65c1bf72b5a2f66ac40a4565a45d33b6e0b87ffd57637", "vout" : 0}]' '{"19DtwBKG7YHYTVraX6QWTv4Lb6nBxfWWSf":0.925}'

    UPDATED: verified, works great on 0.7.0 final, maybe I was running an old release candidate Bitcoin-Qt by accident...

  5. laanwj commented at 6:08 AM on September 19, 2012: member

    That leaves "JSON objects directly on the command line".

    • I think it could be done unambiguously by detecting unquoted arguments that start with '[' or '{' as the beginning of a JSON object, and then attempting to read a full JSON object using json_spirit, and continuing at the position where it stopped parsing (if that's available somewhere). It would mess up the pretty little state machine in parseCommandLine though...
    • Either that, or go all the way and integrate a Javascript interpreter using QScript. One could use normal function calls, ie createrawtransaction([{...}], "test"). You could even store the return values and use them in a next call, or run them through a script first. But I'm somewhat wary of pulling in a script interpreter, as it will increase the attack surface.

    Nah... this is very low priority, the console is already useful and I'm not sure that we need to make it even more developer friendly :-) Hmm... Or maybe that's the future niche of Bitcoin-Qt, "the debug client", as Sipa is talking about directing normal users to faster lightweight clients already.

  6. gavinandresen closed this on Jan 21, 2013

  7. KolbyML referenced this in commit 28509bf9e8 on Dec 5, 2020
  8. 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-16 21:16 UTC

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