Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.h
// 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. | ||||
#ifndef BITCOIN_RPC_UTIL_H | #ifndef BITCOIN_RPC_UTIL_H | ||||
#define BITCOIN_RPC_UTIL_H | #define BITCOIN_RPC_UTIL_H | ||||
#include <node/transaction.h> | #include <node/transaction.h> | ||||
#include <rpc/protocol.h> | #include <rpc/protocol.h> | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | enum class Type { | ||||
//! Special type that is a STR with only hex chars | //! Special type that is a STR with only hex chars | ||||
STR_HEX, | STR_HEX, | ||||
}; | }; | ||||
enum class Optional { | enum class Optional { | ||||
/** Required arg */ | /** Required arg */ | ||||
NO, | NO, | ||||
/** | /** | ||||
* Optinal arg that is a named argument and has a default value of | * Optional arg that is a named argument and has a default value of | ||||
* `null`. When possible, the default value should be specified. | * `null`. When possible, the default value should be specified. | ||||
*/ | */ | ||||
OMITTED_NAMED_ARG, | OMITTED_NAMED_ARG, | ||||
/** | /** | ||||
* Optional argument with default value omitted because they are | * Optional argument with default value omitted because they are | ||||
* implicitly clear. That is, elements in an array or object may not | * implicitly clear. That is, elements in an array or object may not | ||||
* exist by default. | * exist by default. | ||||
* When possible, the default value should be specified. | * When possible, the default value should be specified. | ||||
Show All 37 Lines | RPCArg(const std::string &name, const Type &type, const Fallback &fallback, | ||||
const std::string &oneline_description = "", | const std::string &oneline_description = "", | ||||
const std::vector<std::string> &type_str = {}) | const std::vector<std::string> &type_str = {}) | ||||
: m_name{name}, m_type{type}, m_inner{inner}, m_fallback{fallback}, | : m_name{name}, m_type{type}, m_inner{inner}, m_fallback{fallback}, | ||||
m_description{description}, | m_description{description}, | ||||
m_oneline_description{oneline_description}, m_type_str{type_str} { | m_oneline_description{oneline_description}, m_type_str{type_str} { | ||||
CHECK_NONFATAL(type == Type::ARR || type == Type::OBJ); | CHECK_NONFATAL(type == Type::ARR || type == Type::OBJ); | ||||
} | } | ||||
bool IsOptional() const; | |||||
/** | /** | ||||
* Return the type string of the argument. | * Return the type string of the argument. | ||||
* Set oneline to allow it to be overridden by a custom oneline type string | * Set oneline to allow it to be overridden by a custom oneline type string | ||||
* (m_oneline_description). | * (m_oneline_description). | ||||
*/ | */ | ||||
std::string ToString(bool oneline) const; | std::string ToString(bool oneline) const; | ||||
/** | /** | ||||
* Return the type string of the argument when it is in an object (dict). | * Return the type string of the argument when it is in an object (dict). | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
class RPCHelpMan { | class RPCHelpMan { | ||||
public: | public: | ||||
RPCHelpMan(std::string name, std::string description, | RPCHelpMan(std::string name, std::string description, | ||||
std::vector<RPCArg> args, RPCResults results, | std::vector<RPCArg> args, RPCResults results, | ||||
RPCExamples examples); | RPCExamples examples); | ||||
std::string ToString() const; | std::string ToString() const; | ||||
/** If the supplied number of args is neither too small nor too high */ | |||||
bool IsValidNumArgs(size_t num_args) const; | |||||
private: | private: | ||||
const std::string m_name; | const std::string m_name; | ||||
const std::string m_description; | const std::string m_description; | ||||
const std::vector<RPCArg> m_args; | const std::vector<RPCArg> m_args; | ||||
const RPCResults m_results; | const RPCResults m_results; | ||||
const RPCExamples m_examples; | const RPCExamples m_examples; | ||||
}; | }; | ||||
#endif // BITCOIN_RPC_UTIL_H | #endif // BITCOIN_RPC_UTIL_H |