1#include <xrpld/rpc/detail/Handler.h>
3#include <xrpld/rpc/Context.h>
4#include <xrpld/rpc/MethodNames.h>
5#include <xrpld/rpc/Role.h>
6#include <xrpld/rpc/detail/SpecBridge.hpp>
7#include <xrpld/rpc/handlers/Handlers.h>
8#include <xrpld/rpc/handlers/account/AccountChannels.h>
9#include <xrpld/rpc/handlers/account/AccountCurrencies.h>
10#include <xrpld/rpc/handlers/account/AccountInfo.h>
11#include <xrpld/rpc/handlers/account/AccountLines.h>
12#include <xrpld/rpc/handlers/account/AccountNFTs.h>
13#include <xrpld/rpc/handlers/account/AccountOffers.h>
14#include <xrpld/rpc/handlers/ledger/Ledger.h>
15#include <xrpld/rpc/handlers/orderbook/BookChanges.h>
16#include <xrpld/rpc/handlers/orderbook/DepositAuthorized.h>
17#include <xrpld/rpc/handlers/orderbook/NFTBuyOffers.h>
18#include <xrpld/rpc/handlers/orderbook/NFTSellOffers.h>
19#include <xrpld/rpc/handlers/server_info/Version.h>
20#include <xrpld/rpc/handlers/transaction/TransactionEntry.h>
22#include <xrpl/basics/StringUtilities.h>
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/json/json_value.h>
25#include <xrpl/protocol/ApiVersion.h>
27#include <rpcspec/Errors.hpp>
28#include <rpcspec/Types.hpp>
51template <auto Function>
55 result = Function(context);
59 UNREACHABLE(
"xrpl::rpc::byRef : result is object");
64 return ::rpc::Status::kOK;
67template <
typename HandlerImpl>
68concept SpecBasedHandler = std::derived_from<HandlerImpl, HandlerFor<typename HandlerImpl::Input>>;
70template <
typename HandlerImpl>
73template <
class HandlerImpl,
class Output>
76 HandlerImpl
const& handler,
78 std::expected<Output, ::rpc::Status>
const& output,
79 ::rpc::spec::Warnings
const& warnings)
81 if (not output.has_value())
83 injectSpecError(
object, output.error());
84 return output.error();
88 handler.writeResult(result, *output);
89 injectSpecWarnings(result, warnings);
90 object = std::move(result);
92 return ::rpc::Status::kOK;
95template <
class HandlerImpl>
98 requires SpecBasedHandler<HandlerImpl> or InputlessHandler<HandlerImpl>
100 if constexpr (SpecBasedHandler<HandlerImpl>)
102 auto const input = HandlerImpl::parseInput(context.params, context.apiVersion);
103 if (not input.has_value())
105 injectSpecError(
object, input.error());
106 return input.error();
109 HandlerImpl handler(context);
110 auto const output = handler.process(*input);
111 auto const warnings = output.has_value()
112 ? HandlerImpl::spec(context.apiVersion).check(context.params)
113 : ::rpc::spec::Warnings{};
114 return respond(handler,
object, output, warnings);
118 HandlerImpl handler(context);
119 return respond(handler,
object, handler.process(), {});
123constexpr auto kHandlerArray = std::to_array<Handler>({
127 .valueMethod = Method::of<&handle<AccountInfoHandler>>(),
133 .valueMethod = Method::of<&handle<AccountCurrenciesHandler>>(),
139 .valueMethod = Method::of<&handle<AccountLinesHandler>>(),
145 .valueMethod = Method::of<&handle<AccountChannelsHandler>>(),
151 .valueMethod = Method::of<&handle<AccountNFTsHandler>>(),
157 .valueMethod = Method::of<&byRef<&doAccountObjects>>(),
163 .valueMethod = Method::of<&handle<AccountOffersHandler>>(),
169 .valueMethod = Method::of<&byRef<&doAccountTx>>(),
175 .valueMethod = Method::of<&byRef<&doAMMInfo>>(),
181 .valueMethod = Method::of<&byRef<&doBlackList>>(),
184 .hasCommandLineForm =
false,
188 .valueMethod = Method::of<&handle<BookChangesHandler>>(),
194 .valueMethod = Method::of<&byRef<&doBookOffers>>(),
200 .valueMethod = Method::of<&byRef<&doCanDelete>>(),
206 .valueMethod = Method::of<&byRef<&doChannelAuthorize>>(),
212 .valueMethod = Method::of<&byRef<&doChannelVerify>>(),
218 .valueMethod = Method::of<&byRef<&doConnect>>(),
224 .valueMethod = Method::of<&byRef<&doConsensusInfo>>(),
230 .valueMethod = Method::of<&handle<DepositAuthorizedHandler>>(),
236 .valueMethod = Method::of<&byRef<&doFeature>>(),
242 .valueMethod = Method::of<&byRef<&doFee>>(),
245 .hasCommandLineForm =
false,
249 .valueMethod = Method::of<&byRef<&doFetchInfo>>(),
255 .valueMethod = Method::of<&byRef<&doGatewayBalances>>(),
261 .valueMethod = Method::of<&byRef<&doGetCounts>>(),
267 .valueMethod = Method::of<&byRef<&doGetAggregatePrice>>(),
270 .hasCommandLineForm =
false,
274 .valueMethod = Method::of<&handle<LedgerHandler>>(),
280 .valueMethod = Method::of<&byRef<&doLedgerAccept>>(),
286 .valueMethod = Method::of<&byRef<&doLedgerCleaner>>(),
289 .hasCommandLineForm =
false,
293 .valueMethod = Method::of<&byRef<&doLedgerClosed>>(),
299 .valueMethod = Method::of<&byRef<&doLedgerCurrent>>(),
305 .valueMethod = Method::of<&byRef<&doLedgerData>>(),
308 .hasCommandLineForm =
false,
312 .valueMethod = Method::of<&byRef<&doLedgerEntry>>(),
318 .valueMethod = Method::of<&byRef<&doLedgerHeader>>(),
326 .valueMethod = Method::of<&byRef<&doLedgerRequest>>(),
332 .valueMethod = Method::of<&byRef<&doLogLevel>>(),
338 .valueMethod = Method::of<&byRef<&doLogRotate>>(),
344 .valueMethod = Method::of<&byRef<&doManifest>>(),
350 .valueMethod = Method::of<&handle<NFTBuyOffersHandler>>(),
353 .hasCommandLineForm =
false,
357 .valueMethod = Method::of<&handle<NFTSellOffersHandler>>(),
360 .hasCommandLineForm =
false,
364 .valueMethod = Method::of<&byRef<&doNoRippleCheck>>(),
367 .hasCommandLineForm =
false,
371 .valueMethod = Method::of<&byRef<&doOwnerInfo>>(),
377 .valueMethod = Method::of<&byRef<&doPeers>>(),
383 .valueMethod = Method::of<&byRef<&doPathFind>>(),
389 .valueMethod = Method::of<&byRef<&doPing>>(),
395 .valueMethod = Method::of<&byRef<&doPrint>>(),
401 .valueMethod = Method::of<&byRef<&doRandom>>(),
407 .valueMethod = Method::of<&byRef<&doPeerReservationsAdd>>(),
413 .valueMethod = Method::of<&byRef<&doPeerReservationsDel>>(),
419 .valueMethod = Method::of<&byRef<&doPeerReservationsList>>(),
425 .valueMethod = Method::of<&byRef<&doRipplePathFind>>(),
431 .valueMethod = Method::of<&byRef<&doServerDefinitions>>(),
437 .valueMethod = Method::of<&byRef<&doServerInfo>>(),
443 .valueMethod = Method::of<&byRef<&doServerState>>(),
449 .valueMethod = Method::of<&byRef<&doSign>>(),
455 .valueMethod = Method::of<&byRef<&doSignFor>>(),
461 .valueMethod = Method::of<&byRef<&doSimulate>>(),
467 .valueMethod = Method::of<&byRef<&doStop>>(),
473 .valueMethod = Method::of<&byRef<&doSubmit>>(),
479 .valueMethod = Method::of<&byRef<&doSubmitMultiSigned>>(),
485 .valueMethod = Method::of<&handle<TransactionEntryHandler>>(),
491 .valueMethod = Method::of<&byRef<&doTxJson>>(),
497 .valueMethod = Method::of<&byRef<&doTxHistory>>(),
505 .valueMethod = Method::of<&byRef<&doTxReduceRelay>>(),
508 .hasCommandLineForm =
false,
512 .valueMethod = Method::of<&byRef<&doUnlList>>(),
518 .valueMethod = Method::of<&byRef<&doValidationCreate>>(),
524 .valueMethod = Method::of<&byRef<&doValidators>>(),
527 .hasCommandLineForm =
false,
531 .valueMethod = Method::of<&byRef<&doValidatorListSites>>(),
534 .hasCommandLineForm =
false,
538 .valueMethod = Method::of<&byRef<&doValidatorInfo>>(),
544 .valueMethod = Method::of<&byRef<&doVaultInfo>>(),
550 .valueMethod = Method::of<&handle<VersionHandler>>(),
556 .valueMethod = Method::of<&byRef<&doWalletPropose>>(),
563 .valueMethod = Method::of<&byRef<&doSubscribe>>(),
569 .valueMethod = Method::of<&byRef<&doUnsubscribe>>(),
576constexpr auto kHandlers = [] {
577 auto all = kHandlerArray;
588 "xrpl::rpc : kHandlers must be sorted by name");
599 for (std::size_t i = 0; i < kHandlers.size(); ++i)
601 auto const& h = kHandlers[i];
602 if (h.name.empty() || h.minApiVer > h.maxApiVer ||
608 if (i > 0 && kHandlers[i - 1].name == h.name)
613 "xrpl::rpc : every handler needs a unique name and a valid API version range");
625template <std::size_t... I>
627checkedHandlerNames(std::index_sequence<I...>)
629 return std::array<NullTerminatedView,
sizeof...(I)>{NullTerminatedView{kHandlers[I].name}...};
633constexpr auto kHandlerNames = checkedHandlerNames(std::make_index_sequence<kHandlers.size()>{});
647 if (i == kHandlers.end() || i->name != name)
650 if (i->minApiVer <= version && version <= i->maxApiVer)
659 return kHandlerNames;
The function a handler dispatches to.
@ Object
object value (collection of name/value pairs).
constexpr std::string_view kAccountNfts
constexpr std::string_view kPing
constexpr std::string_view kAccountLines
constexpr std::string_view kBookOffers
constexpr std::string_view kNftSellOffers
constexpr std::string_view kAccountOffers
constexpr std::string_view kNorippleCheck
constexpr std::string_view kConnect
constexpr std::string_view kRipplePathFind
constexpr std::string_view kAccountCurrencies
constexpr std::string_view kLedgerCurrent
constexpr std::string_view kPeerReservationsAdd
constexpr std::string_view kChannelAuthorize
constexpr std::string_view kAccountChannels
Names of the RPC methods the server accepts.
constexpr std::string_view kPeerReservationsDel
constexpr std::string_view kLogLevel
constexpr std::string_view kSubmitMultisigned
constexpr std::string_view kWalletPropose
constexpr std::string_view kLedgerAccept
constexpr std::string_view kLedger
constexpr std::string_view kAccountTx
constexpr std::string_view kBookChanges
constexpr std::string_view kValidationCreate
constexpr std::string_view kConsensusInfo
constexpr std::string_view kOwnerInfo
constexpr std::string_view kDepositAuthorized
constexpr std::string_view kServerDefinitions
constexpr std::string_view kTxReduceRelay
constexpr std::string_view kAmmInfo
constexpr std::string_view kCanDelete
constexpr std::string_view kFee
constexpr std::string_view kLogrotate
constexpr std::string_view kLedgerData
constexpr std::string_view kLedgerEntry
constexpr std::string_view kChannelVerify
constexpr std::string_view kPeers
constexpr std::string_view kSign
constexpr std::string_view kGetCounts
constexpr std::string_view kValidatorListSites
constexpr std::string_view kVersion
constexpr std::string_view kPathFind
constexpr std::string_view kServerInfo
constexpr std::string_view kAccountObjects
constexpr std::string_view kManifest
constexpr std::string_view kLedgerHeader
constexpr std::string_view kNftBuyOffers
constexpr std::string_view kSubmit
constexpr std::string_view kStop
constexpr std::string_view kValidators
constexpr std::string_view kLedgerClosed
constexpr std::string_view kFetchInfo
constexpr std::string_view kTxHistory
constexpr std::string_view kSubscribe
constexpr std::string_view kValidatorInfo
constexpr std::string_view kTx
constexpr std::string_view kPrint
constexpr std::string_view kGetAggregatePrice
constexpr std::string_view kTransactionEntry
constexpr std::string_view kVaultInfo
constexpr std::string_view kSimulate
constexpr std::string_view kSignFor
constexpr std::string_view kBlacklist
constexpr std::string_view kPeerReservationsList
constexpr std::string_view kFeature
constexpr std::string_view kLedgerRequest
constexpr std::string_view kUnlList
constexpr std::string_view kLedgerCleaner
constexpr std::string_view kRandom
constexpr std::string_view kServerState
constexpr std::string_view kAccountInfo
constexpr std::string_view kUnsubscribe
constexpr std::string_view kGatewayBalances
The api_version numbers this server serves.
std::span< NullTerminatedView const > getHandlerNames()
Return the names of all methods, sorted and without duplicates.
static constexpr auto kApiMaximumSupportedVersion
json::Value makeObjectValue(Value const &value, json::StaticString const &field=jss::message)
Return a json::ValueType::Object with a single entry.
Handler const * getHandler(unsigned version, bool betaEnabled, std::string_view name)
static constexpr auto kApiMaximumValidVersion
static constexpr auto kApiMinimumSupportedVersion
static constexpr auto kApiBetaVersion