rpc: fix data optionality for RPC calls. #27829

pull miketwenty1 wants to merge 1 commits into bitcoin:master from miketwenty1:fix-rpc-data-optional changing 2 files +12 −9
  1. miketwenty1 commented at 4:21 pm on June 5, 2023: contributor

    The “data” field without outputs was marked as “required” in the help docs when using bitcoin-cli. This field when left off worked as an intended optional OP_RETURN. closes #27828.

    Motivation: It is hard to understand that “data” is actually optional for commands like createpsbt and walletcreatefundedpsbt.

  2. DrahtBot commented at 4:21 pm on June 5, 2023: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK Sjors, achow101
    Stale ACK sipa

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    No conflicts as of last run.

  3. DrahtBot added the label RPC/REST/ZMQ on Jun 5, 2023
  4. sipa commented at 4:24 pm on June 5, 2023: member

    I get that this is confusing, but this change isn’t correct.

    The "data" field itself is required when the object is present (as in [{"address": amount, ..., {}] would not be valid). What’s optional is the object (the { ... } around it), which is at a higher level.

    Maybe it’s worth elaborating in the prose text above?

  5. miketwenty1 commented at 4:44 pm on June 5, 2023: contributor

    I get that this is confusing, but this change isn’t correct.

    The "data" field itself is required when the object is present (as in [{"address": amount, ..., {}] would not be valid). What’s optional is the object (the { ... } around it), which is at a higher level.

    Maybe it’s worth elaborating in the prose text above?

    Understood you’re saying the change isn’t correct. How would someone properly indicate the “data” is optional if not specifying it as optional? The parent output is required and some of it’s children elements are optional. From my perspective what I would expect to see is a required “outputs” and within outputs there being required and optional fields.

    For instance: "address": amount, (numeric or string, required makes sense as address and amount are necessary. But "data": "hex", (string, required) seems like a bug because this is not required and can be left out. If you specify “data” then of course there will be a required value for it, but this is implied with how json works.

    Full text of for outputs as reference:

     02. outputs                            (json array, required) The outputs (key-value pairs), where none of the keys are duplicated.
     1                                      That is, each address can only appear once and there can only be one 'data' object.
     2                                      For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also
     3                                      accepted as second parameter.
     4     [
     5       {                              (json object)
     6         "address": amount,           (numeric or string, required) A key-value pair. The key (string) is the bitcoin address,
     7                                      the value (float or string) is the amount in BTC
     8         ...
     9       },
    10       {                              (json object)
    11         "data": "hex",               (string, required) A key-value pair. The key must be "data", the value is hex-encoded data
    12       },
    13       ...
    14     ]
    
  6. sipa commented at 4:52 pm on June 5, 2023: member
    The "data": ... part cannot be left out. It’s the {"data": ...} that can be left out.
  7. miketwenty1 commented at 4:56 pm on June 5, 2023: contributor

    The "data": ... part cannot be left out. It’s the {"data": ...} that can be left out.

    Let me rephrase my question: How would someone know {"data" ...} is optional if not specifying it as optional? If every field is optional within an obj maybe it’s implied the obj itself is optional?

    Does there need to be a new idea of specifying whether the (json object) itself is optional?

    Edit: Is this what “prose text” means?

  8. DrahtBot added the label CI failed on Jun 5, 2023
  9. miketwenty1 renamed this:
    rpc: fix data optionality for RPC calls.
    DRAFT: rpc: fix data optionality for RPC calls.
    on Jun 5, 2023
  10. miketwenty1 force-pushed on Jun 5, 2023
  11. miketwenty1 commented at 9:14 pm on June 5, 2023: contributor
    @sipa, edited the commit. Something like this look good?
  12. sipa commented at 9:32 pm on June 5, 2023: member
    ACK 30acffa32023838d7b0c3f48d2a3688fae15490a
  13. DrahtBot removed the label CI failed on Jun 5, 2023
  14. miketwenty1 renamed this:
    DRAFT: rpc: fix data optionality for RPC calls.
    rpc: fix data optionality for RPC calls.
    on Jun 5, 2023
  15. in src/rpc/rawtransaction.cpp:152 in 30acffa320 outdated
    148@@ -149,6 +149,7 @@ static std::vector<RPCArg> CreateTxDoc()
    149         },
    150         {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The outputs (key-value pairs), where none of the keys are duplicated.\n"
    151                 "That is, each address can only appear once and there can only be one 'data' object.\n"
    152+                "Either {\"data\"} or {\"address\"}, are required, but specifying both is optional.\n"
    


    Sjors commented at 7:55 am on June 6, 2023:

    I find this wording confusing. Do you mean to say that the user can combine data and address entries? Or that you can provide data or an address directly without putting “data” or “address” in front of it? (but then how it does it know the difference?)

    Examples can be helpful. Maybe say “see send RPC for examples” and then expand the send RPC docs with said examples.


    miketwenty1 commented at 3:16 pm on June 6, 2023:

    Do you mean to say that the user can combine data and address entries?

    The outputs array, outputs [], must contain at minimum either an obj containing {"address" ".."} or an obj containing {"data": ".."}. You can also specify both, but you must have at least one.

    I’m reading over this block of help text again.

    0(json array, required) The outputs (key-value pairs), where none of the keys are duplicated.
    1                                      That is, each address can only appear once and there can only be one 'data' object.
    2                                      For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also
    3                                      accepted as second parameter.
    

    just using separate objs

     0[
     1    {
     2        "bc1address1":"0.01",
     3    },
     4    {
     5        "bc1address2":"0.02",
     6    },
     7    {
     8        "data":"ff00ff00ff"
     9    }
    10]
    

    or… Also note: a dictionary, which holds the key-value pairs directly, is also accepted as second parameter. I believe this is saying you can also do something like:

    0[
    1    {
    2        "bc1address1":"0.01",
    3        "bc1address2":"0.02",
    4        "data":"ff00ff00ff"
    5    }
    6]
    

    I think this style is for compatibility reasons per docs, so I’m guessing it’s preferred/future proof to break everything out into individual objects. Please correct me if I’m wrong!

    Current: "Either {\"data\"} or {\"address\"}, are required, but specifying both is optional.\n" Something like this be better?: "At least one object containing the key \"data\" or \"address\" is required.\n"


    murchandamus commented at 7:01 pm on July 11, 2023:

    How about:

    0        {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The outputs specified as key-value pairs.\n"
    1                "Each key may only appear once, i.e. there can only be one 'data' output, and no address may be duplicated.\n"
    2                "At least one output of either type must be specified.\n"
    
  16. miketwenty1 commented at 1:09 am on June 28, 2023: contributor
    @Sjors Not sure if you saw my response above, let me know what you think, we can close this out if there’s no appetite for this small change.
  17. murchandamus commented at 7:02 pm on July 11, 2023: contributor

    @Sjors Not sure if you saw my response above, let me know what you think, we can close this out if there’s no appetite for this small change.

    I think you have correctly identified that this text could be improved and we should move forward with the PR.

  18. DrahtBot added the label Needs rebase on Jul 20, 2023
  19. jonatack commented at 3:39 pm on July 20, 2023: member
    @miketwenty1 Needs rebase. Are you still working on this?
  20. miketwenty1 force-pushed on Aug 23, 2023
  21. miketwenty1 force-pushed on Aug 23, 2023
  22. DrahtBot added the label CI failed on Aug 23, 2023
  23. DrahtBot removed the label Needs rebase on Aug 23, 2023
  24. miketwenty1 commented at 2:15 am on August 23, 2023: contributor
    @jonatack thanks for the bump. Open for feedback. I took @murchandamus suggestions where it seemed appropriate.
  25. Update help text for spend and rawtransaction rpcs
    fixing typo
    27b168b81f
  26. miketwenty1 force-pushed on Aug 23, 2023
  27. Sjors commented at 8:57 am on August 23, 2023: member
    I think the CI failure is unrelated to your change (see #28027).
  28. Sjors approved
  29. Sjors commented at 9:14 am on August 23, 2023: member

    tACK 27b168b81f3959f5376a4176673187a71c7b25e1

    I didn’t think about it very deeply, but the new text is an improvement in clarity.

    I think the CI failure is unrelated to your change (see #28027, cc @achow101).

  30. DrahtBot requested review from sipa on Aug 23, 2023
  31. achow101 commented at 8:26 pm on August 23, 2023: member
    ACK 27b168b81f3959f5376a4176673187a71c7b25e1
  32. achow101 merged this on Aug 23, 2023
  33. achow101 closed this on Aug 23, 2023

  34. miketwenty1 deleted the branch on Aug 24, 2023
  35. Frank-GER referenced this in commit 950247f9de on Sep 8, 2023
  36. bitcoin locked this on Aug 23, 2024

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: 2024-09-28 22:12 UTC

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