diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-04-19 09:04:05 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-04-19 09:04:31 +0200 |
commit | d4300a10ddd67ceb06f0a2a27d11b556bc6e4dda (patch) | |
tree | 0a3845635ce31be135f64ac755dbe3f898c537d4 /src/rpc/util.h | |
parent | 17b51cd5cb9c5e02caf04d25423313392f7f81fb (diff) | |
parent | bee56c78e94417f89b1f48682404e2821b57bdec (diff) |
Merge #21679: rpc: Keep default argument value in correct type
bee56c78e94417f89b1f48682404e2821b57bdec rpc: Check default value type againts argument type (João Barbosa)
f81ef4303e057e85aa24772c865287c17ffa4350 rpc: Keep default argument value in correct type (João Barbosa)
Pull request description:
Store default values of RPC arguments in the corresponding type instead of a string. The value is then serialized when the help output is needed. This change simplifies #20017.
The following examples illustrates how to use the new `RPCArg::Default` and `RPCArg::DefaultHint`:
```diff
- {"verbose", RPCArg::Type::BOOL, /* default */ "false", "True for a json object, false for array of transaction ids"}
+ {"verbose", RPCArg::Type::BOOL, RPCArg::Default(false), "True for a json object, false for array of transaction ids"}
```
```diff
- {"nblocks", RPCArg::Type::NUM, /* default */ "one month", "Size of the window in number of blocks"}
+ {"nblocks", RPCArg::Type::NUM, RPCArg::DefaultHint("one month"), "Size of the window in number of blocks"}
```
No behavior change is expected.
ACKs for top commit:
LarryRuane:
ACK bee56c78e94417f89b1f48682404e2821b57bdec
MarcoFalke:
ACK bee56c78e94417f89b1f48682404e2821b57bdec 🦅
Tree-SHA512: c47d78c918e996d36631d4ad3c933b270a34c5b446b8d736be94cf4a0a7b8c0e33d954149ec786cf9550639865b79deb6a130ad044de6030f95aac33f524293a
Diffstat (limited to 'src/rpc/util.h')
-rw-r--r-- | src/rpc/util.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/rpc/util.h b/src/rpc/util.h index 6e783e19fb..8ec18b2f35 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -145,7 +145,9 @@ struct RPCArg { */ OMITTED, }; - using Fallback = std::variant<Optional, /* default value for optional args */ std::string>; + using DefaultHint = std::string; + using Default = UniValue; + using Fallback = std::variant<Optional, /* hint for default value */ DefaultHint, /* default constant value */ Default>; const std::string m_names; //!< The name of the arg (can be empty for inner args, can contain multiple aliases separated by | for named request arguments) const Type m_type; const bool m_hidden; |