Skip to content

Conversation

miketwenty1
Copy link
Contributor

@miketwenty1 miketwenty1 commented Jun 5, 2023

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 5, 2023

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.

@sipa
Copy link
Member

sipa commented Jun 5, 2023

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?

@miketwenty1
Copy link
Contributor Author

miketwenty1 commented Jun 5, 2023

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:

2. outputs                            (json array, required) The outputs (key-value pairs), where none of the keys are duplicated.
                                      That is, each address can only appear once and there can only be one 'data' object.
                                      For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also
                                      accepted as second parameter.
     [
       {                              (json object)
         "address": amount,           (numeric or string, required) A key-value pair. The key (string) is the bitcoin address,
                                      the value (float or string) is the amount in BTC
         ...
       },
       {                              (json object)
         "data": "hex",               (string, required) A key-value pair. The key must be "data", the value is hex-encoded data
       },
       ...
     ]

@sipa
Copy link
Member

sipa commented Jun 5, 2023

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

@miketwenty1
Copy link
Contributor Author

miketwenty1 commented Jun 5, 2023

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?

@miketwenty1 miketwenty1 changed the title rpc: fix data optionality for RPC calls. DRAFT: rpc: fix data optionality for RPC calls. Jun 5, 2023
@miketwenty1 miketwenty1 force-pushed the fix-rpc-data-optional branch from 9235d06 to 30acffa Compare June 5, 2023 21:12
@miketwenty1
Copy link
Contributor Author

@sipa, edited the commit. Something like this look good?

@sipa
Copy link
Member

sipa commented Jun 5, 2023

ACK 30acffa

@DrahtBot DrahtBot removed the CI failed label Jun 5, 2023
@miketwenty1 miketwenty1 changed the title DRAFT: rpc: fix data optionality for RPC calls. rpc: fix data optionality for RPC calls. Jun 5, 2023
@@ -149,6 +149,7 @@ static std::vector<RPCArg> CreateTxDoc()
},
{"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The outputs (key-value pairs), where none of the keys are duplicated.\n"
"That is, each address can only appear once and there can only be one 'data' object.\n"
"Either {\"data\"} or {\"address\"}, are required, but specifying both is optional.\n"
Copy link
Member

@Sjors Sjors Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@miketwenty1 miketwenty1 Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

just using separate objs

[
    {
        "bc1address1":"0.01",
    },
    {
        "bc1address2":"0.02",
    },
    {
        "data":"ff00ff00ff"
    }
]

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:

[
    {
        "bc1address1":"0.01",
        "bc1address2":"0.02",
        "data":"ff00ff00ff"
    }
]

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"

@miketwenty1
Copy link
Contributor Author

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

@murchandamus
Copy link
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.

@jonatack
Copy link
Member

@miketwenty1 Needs rebase. Are you still working on this?

@miketwenty1 miketwenty1 force-pushed the fix-rpc-data-optional branch 2 times, most recently from 79dc796 to aaddf50 Compare August 23, 2023 02:05
@miketwenty1
Copy link
Contributor Author

@jonatack thanks for the bump. Open for feedback. I took @murchandamus suggestions where it seemed appropriate.

@miketwenty1 miketwenty1 force-pushed the fix-rpc-data-optional branch from aaddf50 to 27b168b Compare August 23, 2023 02:29
@Sjors
Copy link
Member

Sjors commented Aug 23, 2023

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

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 27b168b

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

@DrahtBot DrahtBot requested a review from sipa August 23, 2023 09:14
@achow101
Copy link
Member

ACK 27b168b

@achow101 achow101 merged commit 23f3f40 into bitcoin:master Aug 23, 2023
@miketwenty1 miketwenty1 deleted the fix-rpc-data-optional branch August 24, 2023 18:06
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Sep 8, 2023
27b168b Update help text for spend and rawtransaction rpcs (Michael Tidwell)

Pull request description:

  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 bitcoin#27828.

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

ACKs for top commit:
  achow101:
    ACK 27b168b
  Sjors:
    tACK 27b168b

Tree-SHA512: 235e7ed4af69880880c04015b3f7de72c8f31ae035485c4c64c483e282948f3ea3f1eef16f15e260a1aaf21114150713516ba6a99967ccad9ecd91ff67cb0450
@bitcoin bitcoin locked and limited conversation to collaborators Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bitcoin-cli output help text - (json object) not utilizing RPCArg::Optional value
7 participants