mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 07:39:08 +01:00
rpc: add named arg helper
Overload the Arg and MaybeArg helpers to allow accessing arguments by name as well. Also update the docs to document Arg and MaybeArg separately
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
#include <util/string.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
|
||||
@@ -728,6 +730,16 @@ std::vector<std::pair<std::string, bool>> RPCHelpMan::GetArgNames() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t RPCHelpMan::GetParamIndex(std::string_view key) const
|
||||
{
|
||||
auto it{std::find_if(
|
||||
m_args.begin(), m_args.end(), [&key](const auto& arg) { return arg.GetName() == key;}
|
||||
)};
|
||||
|
||||
CHECK_NONFATAL(it != m_args.end()); // TODO: ideally this is checked at compile time
|
||||
return std::distance(m_args.begin(), it);
|
||||
}
|
||||
|
||||
std::string RPCHelpMan::ToString() const
|
||||
{
|
||||
std::string ret;
|
||||
|
||||
Reference in New Issue
Block a user