20#include <xrpld/rpc/detail/Handler.h>
21#include <xrpld/rpc/detail/RPCHelpers.h>
22#include <xrpld/rpc/handlers/Handlers.h>
23#include <xrpld/rpc/handlers/Version.h>
24#include <xrpl/basics/contract.h>
33template <
typename Function>
34Handler::Method<Json::Value>
35byRef(Function
const& f)
37 return [f](JsonContext& context,
Json::Value& result) {
41 UNREACHABLE(
"ripple::RPC::byRef : result is object");
49template <
class Object,
class HandlerImpl>
51handle(JsonContext& context, Object&
object)
54 context.apiVersion >= HandlerImpl::minApiVer &&
55 context.apiVersion <= HandlerImpl::maxApiVer,
56 "ripple::RPC::handle : valid API version");
57 HandlerImpl handler(context);
59 auto status = handler.check();
63 handler.writeResult(
object);
67template <
typename HandlerImpl>
73 &handle<Json::Value, HandlerImpl>,
75 HandlerImpl::condition,
76 HandlerImpl::minApiVer,
77 HandlerImpl::maxApiVer};
80Handler
const handlerArray[]{
84 {
"account_currencies",
103 {
"deposit_authorized",
112 {
"get_aggregate_price",
147 {
"peer_reservations_add",
151 {
"peer_reservations_del",
155 {
"peer_reservations_list",
160 {
"server_definitions",
170 {
"submit_multisigned",
179 {
"validation_create",
184 {
"validator_list_sites",
203 overlappingApiVersion(
210 "ripple::RPC::HandlerTable : valid API version range");
213 "ripple::RPC::HandlerTable : valid max API version");
218 [minVer, maxVer](
auto const& item) {
219 return item.second.minApiVer_ <= maxVer &&
220 item.second.maxApiVer_ >= minVer;
224 template <std::
size_t N>
225 explicit HandlerTable(
const Handler (&entries)[N])
227 for (
auto const& entry : entries)
229 if (overlappingApiVersion(
235 " overlaps with an existing handler");
237 table_.
insert({entry.name_, entry});
241 addHandler<LedgerHandler>();
242 addHandler<VersionHandler>();
246 static HandlerTable
const&
249 static HandlerTable
const handlerTable(handlerArray);
253 [[nodiscard]] Handler
const*
264 range.first,
range.second, [version](
auto const& entry) {
265 return entry.second.minApiVer_ <= version &&
266 version <= entry.second.maxApiVer_;
269 return i ==
range.second ? nullptr : &i->second;
276 for (
auto const& i : table_)
277 ret.
insert(i.second.name_);
283 handler_table_t table_;
285 template <
class HandlerImpl>
289 static_assert(HandlerImpl::minApiVer <= HandlerImpl::maxApiVer);
294 if (overlappingApiVersion(
296 HandlerImpl::minApiVer,
297 HandlerImpl::maxApiVer))
300 " overlaps with an existing handler");
302 table_.
insert({HandlerImpl::name, handlerFrom<HandlerImpl>()});
311 return HandlerTable::instance().getHandler(version, betaEnabled, name);
317 return HandlerTable::instance().getHandlerNames();
@ objectValue
object value (collection of name/value pairs).
Status
Return codes from Backend operations.
@ NEEDS_NETWORK_CONNECTION
static constexpr auto apiMaximumSupportedVersion
std::set< char const * > getHandlerNames()
Return names of all methods.
Json::Value makeObjectValue(Value const &value, Json::StaticString const &field=jss::message)
Return a Json::objectValue with a single entry.
static constexpr auto apiMaximumValidVersion
static constexpr auto apiBetaVersion
Handler const * getHandler(unsigned version, bool betaEnabled, std::string const &name)
static constexpr auto apiMinimumSupportedVersion
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Json::Value doPeers(RPC::JsonContext &)
Json::Value doTxHistory(RPC::JsonContext &)
Json::Value doLedgerAccept(RPC::JsonContext &)
Json::Value doUnsubscribe(RPC::JsonContext &)
Json::Value doTxReduceRelay(RPC::JsonContext &)
Json::Value doServerState(RPC::JsonContext &)
Json::Value doChannelVerify(RPC::JsonContext &)
Json::Value doValidationCreate(RPC::JsonContext &)
Json::Value doGetAggregatePrice(RPC::JsonContext &context)
oracles: array of {account, oracle_document_id} base_asset: is the asset to be priced quote_asset: is...
Json::Value doSubmitMultiSigned(RPC::JsonContext &)
Json::Value doLedgerEntry(RPC::JsonContext &)
Json::Value doNFTBuyOffers(RPC::JsonContext &)
Json::Value doChannelAuthorize(RPC::JsonContext &)
Json::Value doNoRippleCheck(RPC::JsonContext &)
Json::Value doTransactionEntry(RPC::JsonContext &)
Json::Value doConsensusInfo(RPC::JsonContext &context)
Json::Value doBookChanges(RPC::JsonContext &context)
Json::Value doLedgerRequest(RPC::JsonContext &)
Json::Value doPeerReservationsAdd(RPC::JsonContext &)
Json::Value doLedgerCleaner(RPC::JsonContext &)
Json::Value doSign(RPC::JsonContext &)
Json::Value doAccountTxJson(RPC::JsonContext &context)
Json::Value doAccountLines(RPC::JsonContext &context)
Json::Value doTxJson(RPC::JsonContext &)
Json::Value doAMMInfo(RPC::JsonContext &context)
Json::Value doPeerReservationsList(RPC::JsonContext &)
Json::Value doServerInfo(RPC::JsonContext &)
Json::Value doFee(RPC::JsonContext &context)
Json::Value doConnect(RPC::JsonContext &context)
Json::Value doNFTSellOffers(RPC::JsonContext &)
Json::Value doDepositAuthorized(RPC::JsonContext &context)
Json::Value doStop(RPC::JsonContext &)
Json::Value doLedgerClosed(RPC::JsonContext &)
Json::Value doLogLevel(RPC::JsonContext &)
Json::Value doSubmit(RPC::JsonContext &)
Json::Value doServerDefinitions(RPC::JsonContext &)
Json::Value doSubscribe(RPC::JsonContext &)
Json::Value doAccountObjects(RPC::JsonContext &context)
Json::Value doFeature(RPC::JsonContext &context)
Json::Value doAccountNFTs(RPC::JsonContext &context)
General RPC command that can retrieve objects in the account root.
Json::Value doFetchInfo(RPC::JsonContext &context)
Json::Value doLedgerHeader(RPC::JsonContext &)
Json::Value doRandom(RPC::JsonContext &)
Json::Value doManifest(RPC::JsonContext &)
Json::Value doGetCounts(RPC::JsonContext &context)
Json::Value doPing(RPC::JsonContext &)
Json::Value doBlackList(RPC::JsonContext &context)
Json::Value doLedgerData(RPC::JsonContext &)
Json::Value doValidatorListSites(RPC::JsonContext &)
Json::Value doSignFor(RPC::JsonContext &)
Json::Value doLedgerCurrent(RPC::JsonContext &)
Json::Value doAccountOffers(RPC::JsonContext &context)
Json::Value doValidatorInfo(RPC::JsonContext &)
Json::Value doGatewayBalances(RPC::JsonContext &context)
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Json::Value doRipplePathFind(RPC::JsonContext &)
Json::Value doBookOffers(RPC::JsonContext &context)
Json::Value doAccountCurrencies(RPC::JsonContext &context)
Json::Value doAccountInfo(RPC::JsonContext &context)
Json::Value doLogRotate(RPC::JsonContext &)
Json::Value doCanDelete(RPC::JsonContext &context)
Json::Value doWalletPropose(RPC::JsonContext &)
Json::Value doAccountChannels(RPC::JsonContext &context)
Json::Value doPeerReservationsDel(RPC::JsonContext &)
Json::Value doValidators(RPC::JsonContext &)
Json::Value doOwnerInfo(RPC::JsonContext &)
Json::Value doPrint(RPC::JsonContext &)
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
Json::Value doUnlList(RPC::JsonContext &)
Json::Value doPathFind(RPC::JsonContext &)