Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.cpp
// Copyright (c) 2017 The Bitcoin Core developers | // Copyright (c) 2017-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <keystore.h> | #include <keystore.h> | ||||
#include <pubkey.h> | #include <pubkey.h> | ||||
#include <rpc/protocol.h> | #include <rpc/protocol.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
▲ Show 20 Lines • Show All 417 Lines • ▼ Show 20 Lines | std::string RPCResults::ToDescriptionString() const { | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
std::string RPCExamples::ToDescriptionString() const { | std::string RPCExamples::ToDescriptionString() const { | ||||
return m_examples.empty() ? m_examples : "\nExamples:\n" + m_examples; | return m_examples.empty() ? m_examples : "\nExamples:\n" + m_examples; | ||||
} | } | ||||
bool RPCHelpMan::IsValidNumArgs(size_t num_args) const { | |||||
size_t num_required_args = 0; | |||||
for (size_t n = m_args.size(); n > 0; --n) { | |||||
if (!m_args.at(n - 1).IsOptional()) { | |||||
num_required_args = n; | |||||
break; | |||||
} | |||||
} | |||||
return num_required_args <= num_args && num_args <= m_args.size(); | |||||
} | |||||
std::string RPCHelpMan::ToString() const { | std::string RPCHelpMan::ToString() const { | ||||
std::string ret; | std::string ret; | ||||
// Oneline summary | // Oneline summary | ||||
ret += m_name; | ret += m_name; | ||||
bool was_optional{false}; | bool was_optional{false}; | ||||
for (const auto &arg : m_args) { | for (const auto &arg : m_args) { | ||||
bool optional; | const bool optional = arg.IsOptional(); | ||||
if (arg.m_fallback.which() == 1) { | |||||
optional = true; | |||||
} else { | |||||
optional = RPCArg::Optional::NO != | |||||
boost::get<RPCArg::Optional>(arg.m_fallback); | |||||
} | |||||
ret += " "; | ret += " "; | ||||
if (optional) { | if (optional) { | ||||
if (!was_optional) { | if (!was_optional) { | ||||
ret += "( "; | ret += "( "; | ||||
} | } | ||||
was_optional = true; | was_optional = true; | ||||
} else { | } else { | ||||
if (was_optional) { | if (was_optional) { | ||||
Show All 36 Lines | std::string RPCHelpMan::ToString() const { | ||||
ret += m_results.ToDescriptionString(); | ret += m_results.ToDescriptionString(); | ||||
// Examples | // Examples | ||||
ret += m_examples.ToDescriptionString(); | ret += m_examples.ToDescriptionString(); | ||||
return ret; | return ret; | ||||
} | } | ||||
bool RPCArg::IsOptional() const { | |||||
if (m_fallback.which() == 1) { | |||||
return true; | |||||
} else { | |||||
return RPCArg::Optional::NO != boost::get<RPCArg::Optional>(m_fallback); | |||||
} | |||||
} | |||||
std::string RPCArg::ToDescriptionString() const { | std::string RPCArg::ToDescriptionString() const { | ||||
std::string ret; | std::string ret; | ||||
ret += "("; | ret += "("; | ||||
if (m_type_str.size() != 0) { | if (m_type_str.size() != 0) { | ||||
ret += m_type_str.at(1); | ret += m_type_str.at(1); | ||||
} else { | } else { | ||||
switch (m_type) { | switch (m_type) { | ||||
case Type::STR_HEX: | case Type::STR_HEX: | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |