Skip to content

JSON parsing in QT debug window #1831

Closed

Description

@gavinandresen

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?

Activity

  1. laanwj commented on Sep 18, 2012

    @laanwj
    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.

  2. laanwj commented on Sep 18, 2012

    @laanwj
    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?

  3. gavinandresen commented on Sep 18, 2012

    @gavinandresen
    ContributorAuthor

    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...

  4. laanwj commented on Sep 19, 2012

    @laanwj
    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.

  5. added a commit that references this issue on Dec 5, 2020
  6. locked as resolved and limited conversation to collaborators on Sep 8, 2021
  7. added a commit that references this issue on Jun 19, 2026
    1f3f0a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions