Skip to content

Conversation

@kallewoof
Copy link
Contributor

@kallewoof kallewoof commented Sep 15, 2020

Introduce a new "check alias" helper for RPC commands, which checks and moves the values into the "primary" key.

The first commit simply pushKV's the value from the alias, if set, whereas the second commit const-casts the keys vector in UniValue and modifies that directly, i.e. "rename". Some people (cough sipa cough) might object to the approach, so I'm splitting into two commits.

This is partially also a cleanup of #16378.

@kallewoof kallewoof force-pushed the 202009-rpc-alias branch 2 times, most recently from e01eaff to 97e383e Compare September 15, 2020 06:56
@Sjors
Copy link
Member

Sjors commented Sep 15, 2020

Concept ACK

@ryanofsky ryanofsky requested a review from maflcko September 15, 2020 14:45
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.

Looks good. No strong opinion on handwaving away the constness in 97e383ef829523130f192aebf67c71cc7e10d975

@Sjors Sjors mentioned this pull request Sep 17, 2020
3 tasks
@kallewoof kallewoof force-pushed the 202009-rpc-alias branch 4 times, most recently from 6828ba5 to 06dca23 Compare September 18, 2020 00:23
@Sjors
Copy link
Member

Sjors commented Sep 18, 2020

ACK 9056b07

Travis failure should go away after #19971.

@promag
Copy link
Contributor

promag commented Sep 22, 2020

Concept ACK, not sure about the approach.

I think that we could improve consistency if internally all keys are transformed like lower(key.replace('_', '')) This way alias aren't necessary. This would also help when dumping help output - keys could be formatted to snake_case for instance.

@kallewoof
Copy link
Contributor Author

@promag That sounds like a good idea but people pointed out that it could be potentially riskful (use the fun-draw-transaction command on this innocent transaction and send it off and it should give you a free lottery ticket where you can potentially win a bitcoin!!). This might be a good thing to do in between, even if we do go that route though.

@maflcko
Copy link
Member

maflcko commented Sep 23, 2020

I am wondering if the aliases can be passed in via RPCArg and the merging be done by RPCHelpMan before dispatching the request to the method.

@kallewoof
Copy link
Contributor Author

@MarcoFalke That sounds like a good idea. I can think of a number of ways to do that:

  1. Add an alias string var to RPCArg, and two new constructors which include alias
  2. Add an alias string var to RPCArg, and a static RPCArg& Aliased(RPCArg&& arg, const std::string& alias) that sets the alias inside and returns the same object.
  3. Make RPCArgs have new type "alias" and use e.g. 'description' to indicate the primary name.

I'm leaning towards number 2 on that list but may change my mind if it turns out to be ugly.

@kallewoof
Copy link
Contributor Author

One issue with doing it in RPCArg is that it requires duplication e.g. for callers of FundTransaction().

RPCTypeCheckAliases(options, {
{"change_address", "changeAddress"},
{"change_position", "changePosition"},
{"include_watching", "includeWatching"},
{"lock_unspents", "lockUnspents"},
{"subtract_fee_from_outputs", "subtractFeeFromOutputs"},
});

@maflcko
Copy link
Member

maflcko commented Sep 23, 2020

Oh it looks like RPCArg already has m_names (separated by |). This was primarily for the outer most args (named args), but it may be possible to extend to keys of a dictionary as well.

it requires duplication

The PRCArg vector or initializer list is a C++ struct, so it can be easily deduplicated and re-used. Even parts of it, which can be concatenated with our Cat vector util helper.

@kallewoof
Copy link
Contributor Author

@MarcoFalke The way I understood it was that you'd provide the arguments before the RPCHelper cleaned up. In the FundTransaction case, the RPCHelper has already cleaned once, so you'd have to do it twice. Which sounds kind of similar to what I'm doing here already.

@promag
Copy link
Contributor

promag commented Sep 24, 2020

@promag That sounds like a good idea but people pointed out that it could be potentially riskful (use the fun-draw-transaction command on this innocent transaction and send it off and it should give you a free lottery ticket where you can potentially win a bitcoin!!). This might be a good thing to do in between, even if we do go that route though.

The suggestion is to just transform args and json keys, not command names or arg values.

@kallewoof
Copy link
Contributor Author

@promag Ah, right.

@kallewoof
Copy link
Contributor Author

See #20013 -- I believe that one is better, and it initiates what @promag suggests we do. Unless people say they prefer this approach, I will be closing this one.

@kallewoof kallewoof closed this Sep 25, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
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.

5 participants