From 5403fbf19cdaea888f0dfd5424c40841eef39394 Mon Sep 17 00:00:00 2001 From: Alex Kremer Date: Mon, 28 Sep 2026 18:07:23 +0100 Subject: [PATCH] chore: Conform to latest rpc-spec 0.1.19 (#3233) --- conan.lock | 2 +- conanfile.py | 2 +- src/app/WebHandlers.cpp | 2 +- src/app/WebHandlers.hpp | 2 +- src/rpc/CMakeLists.txt | 6 +- src/rpc/CredentialHelpers.cpp | 10 +- src/rpc/Errors.cpp | 25 +++-- src/rpc/Errors.hpp | 4 +- src/rpc/Factories.cpp | 3 +- src/rpc/README.md | 11 ++- src/rpc/RPCEngine.hpp | 18 ++-- src/rpc/RPCHelpers.cpp | 94 +++++++++---------- src/rpc/common/Concepts.hpp | 10 +- src/rpc/common/SpecBackend.hpp | 26 +++++ src/rpc/common/impl/Processors.hpp | 2 +- src/rpc/handlers/AMMInfo.cpp | 12 +-- src/rpc/handlers/AMMInfo.hpp | 4 +- src/rpc/handlers/AccountChannels.cpp | 2 +- src/rpc/handlers/AccountChannels.hpp | 4 +- src/rpc/handlers/AccountCurrencies.cpp | 2 +- src/rpc/handlers/AccountCurrencies.hpp | 4 +- src/rpc/handlers/AccountInfo.cpp | 8 +- src/rpc/handlers/AccountInfo.hpp | 4 +- src/rpc/handlers/AccountLines.cpp | 2 +- src/rpc/handlers/AccountLines.hpp | 5 +- src/rpc/handlers/AccountMPTokenIssuances.cpp | 2 +- src/rpc/handlers/AccountMPTokenIssuances.hpp | 4 +- src/rpc/handlers/AccountMPTokens.cpp | 2 +- src/rpc/handlers/AccountMPTokens.hpp | 4 +- src/rpc/handlers/AccountNFTs.cpp | 6 +- src/rpc/handlers/AccountNFTs.hpp | 4 +- src/rpc/handlers/AccountObjects.cpp | 2 +- src/rpc/handlers/AccountObjects.hpp | 5 +- src/rpc/handlers/AccountOffers.cpp | 2 +- src/rpc/handlers/AccountOffers.hpp | 5 +- src/rpc/handlers/AccountTx.cpp | 10 +- src/rpc/handlers/AccountTx.hpp | 4 +- src/rpc/handlers/BookChanges.hpp | 4 +- src/rpc/handlers/BookOffers.hpp | 4 +- src/rpc/handlers/DepositAuthorized.cpp | 10 +- src/rpc/handlers/DepositAuthorized.hpp | 4 +- src/rpc/handlers/Feature.cpp | 2 +- src/rpc/handlers/Feature.hpp | 4 +- src/rpc/handlers/GatewayBalances.cpp | 2 +- src/rpc/handlers/GatewayBalances.hpp | 4 +- src/rpc/handlers/GetAggregatePrice.hpp | 4 +- src/rpc/handlers/Ledger.hpp | 4 +- src/rpc/handlers/LedgerData.cpp | 6 +- src/rpc/handlers/LedgerData.hpp | 4 +- src/rpc/handlers/LedgerEntry.cpp | 16 ++-- src/rpc/handlers/LedgerEntry.hpp | 4 +- src/rpc/handlers/LedgerIndex.cpp | 2 +- src/rpc/handlers/LedgerIndex.hpp | 4 +- src/rpc/handlers/MPTHolders.cpp | 6 +- src/rpc/handlers/MPTHolders.hpp | 4 +- src/rpc/handlers/MPTokenIssuanceHistory.cpp | 10 +- src/rpc/handlers/MPTokenIssuanceHistory.hpp | 4 +- src/rpc/handlers/NFTHistory.cpp | 8 +- src/rpc/handlers/NFTHistory.hpp | 4 +- src/rpc/handlers/NFTInfo.cpp | 2 +- src/rpc/handlers/NFTInfo.hpp | 4 +- src/rpc/handlers/NFTOffersCommon.cpp | 4 +- src/rpc/handlers/NFTOffersCommon.hpp | 5 +- src/rpc/handlers/NFTsByIssuer.cpp | 2 +- src/rpc/handlers/NFTsByIssuer.hpp | 5 +- src/rpc/handlers/NoRippleCheck.cpp | 2 +- src/rpc/handlers/NoRippleCheck.hpp | 5 +- src/rpc/handlers/ServerInfo.hpp | 9 +- src/rpc/handlers/Subscribe.hpp | 4 +- src/rpc/handlers/TransactionEntry.cpp | 2 +- src/rpc/handlers/TransactionEntry.hpp | 4 +- src/rpc/handlers/Tx.hpp | 25 +++-- src/rpc/handlers/Unsubscribe.hpp | 4 +- src/rpc/handlers/VaultInfo.cpp | 6 +- src/rpc/handlers/VaultInfo.hpp | 4 +- src/web/LoadWarning.hpp | 1 + src/web/RPCServerHandler.hpp | 1 + src/web/impl/ErrorHandling.hpp | 10 +- src/web/impl/HttpBase.hpp | 4 +- src/web/impl/WsBase.hpp | 6 +- src/web/ng/RPCServerHandler.hpp | 3 +- src/web/ng/impl/ErrorHandling.cpp | 16 ++-- src/web/ng/impl/ErrorHandling.hpp | 2 +- tests/common/rpc/FakesAndMocks.cpp | 6 +- tests/common/rpc/FakesAndMocks.hpp | 6 +- tests/unit/app/WebHandlersTests.cpp | 2 +- tests/unit/rpc/ErrorTests.cpp | 45 +++++---- tests/unit/rpc/RPCEngineTests.cpp | 10 +- tests/unit/rpc/RPCHelpersTests.cpp | 22 ++--- .../rpc/handlers/AccountCurrenciesTests.cpp | 2 +- tests/unit/rpc/handlers/AccountInfoTests.cpp | 2 +- tests/unit/rpc/handlers/AccountLinesTests.cpp | 2 +- .../unit/rpc/handlers/AccountOffersTests.cpp | 2 +- .../rpc/handlers/CredentialHelpersTests.cpp | 2 +- tests/unit/rpc/handlers/LedgerDataTests.cpp | 2 +- tests/unit/rpc/handlers/LedgerEntryTests.cpp | 2 +- tests/unit/rpc/handlers/LedgerTests.cpp | 6 +- tests/unit/rpc/handlers/SubscribeTests.cpp | 2 +- tests/unit/rpc/handlers/TestHandlerTests.cpp | 2 +- tests/unit/rpc/handlers/TxTests.cpp | 2 +- tests/unit/rpc/handlers/UnsubscribeTests.cpp | 2 +- tests/unit/rpc/handlers/VaultInfoTests.cpp | 6 +- tests/unit/web/RPCServerHandlerTests.cpp | 8 +- tests/unit/web/impl/ErrorHandlingTests.cpp | 6 +- tests/unit/web/ng/RPCServerHandlerTests.cpp | 10 +- tests/unit/web/ng/impl/ErrorHandlingTests.cpp | 8 +- 106 files changed, 370 insertions(+), 345 deletions(-) create mode 100644 src/rpc/common/SpecBackend.hpp diff --git a/conan.lock b/conan.lock index ba3034e03..ff828c988 100644 --- a/conan.lock +++ b/conan.lock @@ -3,7 +3,7 @@ "requires": [ "zlib/1.3.2#1cb806da49011867778ffb6ac7190fcb%1782392402.122708", "xxhash/0.8.3#681d36a0a6111fc56e5e45ea182c19cc%1782392402.420688", - "xrpl-rpc-spec/0.1.17#ddfbc1f89da7797b6506fb9ee9488e17%1790136770.803908", + "xrpl-rpc-spec/0.1.19#870b2d3abcfbbf13b61c2d3c69495060%1790348286.187549", "xrpl/3.4.0#e06b127b3ba92806a43fc7a53fc05fd3%1789577552.219154", "sqlite3/3.53.0#324ada52333108388a9a6108bfa96734%1782392403.185447", "spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c%1782736610.443882", diff --git a/conanfile.py b/conanfile.py index 339b0ade5..7a0887db3 100644 --- a/conanfile.py +++ b/conanfile.py @@ -17,7 +17,7 @@ class ClioConan(ConanFile): "fmt/12.1.0", "libbacktrace/cci.20210118", "spdlog/1.17.0", - "xrpl-rpc-spec/0.1.17", + "xrpl-rpc-spec/0.1.19", "xrpl/3.4.0", ] diff --git a/src/app/WebHandlers.cpp b/src/app/WebHandlers.cpp index a320927b5..fbcf97520 100644 --- a/src/app/WebHandlers.cpp +++ b/src/app/WebHandlers.cpp @@ -106,7 +106,7 @@ MetricsHandler::operator()( if (!postSuccessful) { return web::ng::Response{ boost::beast::http::status::too_many_requests, - rpc::makeError(rpc::RippledError::RpcTooBusy), + rpc::makeError(rpc::XrpldError::RpcTooBusy), request }; } diff --git a/src/app/WebHandlers.hpp b/src/app/WebHandlers.hpp index aba547a69..6a4d99752 100644 --- a/src/app/WebHandlers.hpp +++ b/src/app/WebHandlers.hpp @@ -241,7 +241,7 @@ public: } catch (std::exception const&) { return web::ng::Response{ boost::beast::http::status::internal_server_error, - rpc::makeError(rpc::RippledError::RpcInternal), + rpc::makeError(rpc::XrpldError::RpcInternal), request }; } diff --git a/src/rpc/CMakeLists.txt b/src/rpc/CMakeLists.txt index 2daf99925..8e1b95fab 100644 --- a/src/rpc/CMakeLists.txt +++ b/src/rpc/CMakeLists.txt @@ -58,7 +58,11 @@ target_sources( handlers/VaultInfo.cpp ) -rpcspec_generate_instantiations(OUT_VAR rpcspec_instantiations) +rpcspec_generate_instantiations( + OUT_VAR rpcspec_instantiations + VALUE_TYPE "boost::json::value" + VIEW_HEADER "rpcspec/backends/BoostJson.hpp" +) target_sources(clio_rpc PRIVATE ${rpcspec_instantiations}) target_link_libraries(clio_rpc PUBLIC clio_util clio_data rpcspec::rpcspec) diff --git a/src/rpc/CredentialHelpers.cpp b/src/rpc/CredentialHelpers.cpp index be54bb244..3772f9fa1 100644 --- a/src/rpc/CredentialHelpers.cpp +++ b/src/rpc/CredentialHelpers.cpp @@ -109,27 +109,27 @@ fetchCredentialArray( std::unordered_set seen; for (auto const& credHash : credIDs) { if (seen.contains(credHash)) - return Error{Status{RippledError::RpcBadCredentials, "duplicates in credentials."}}; + return Error{Status{XrpldError::RpcBadCredentials, "duplicates in credentials."}}; seen.insert(credHash); auto const credKeylet = xrpl::keylet::credential(credHash).key; auto const credLedgerObject = backend.fetchLedgerObject(credKeylet, info.seq, yield); if (!credLedgerObject) - return Error{Status{RippledError::RpcBadCredentials, "credentials don't exist."}}; + return Error{Status{XrpldError::RpcBadCredentials, "credentials don't exist."}}; auto credIt = xrpl::SerialIter{credLedgerObject->data(), credLedgerObject->size()}; auto const sleCred = xrpl::SLE{credIt, credKeylet}; if ((sleCred.getType() != xrpl::ltCREDENTIAL) || ((sleCred.getFieldU32(xrpl::sfFlags) & xrpl::lsfAccepted) == 0u)) - return Error{Status{RippledError::RpcBadCredentials, "credentials aren't accepted"}}; + return Error{Status{XrpldError::RpcBadCredentials, "credentials aren't accepted"}}; if (credentials::checkExpired(sleCred, info)) - return Error{Status{RippledError::RpcBadCredentials, "credentials are expired"}}; + return Error{Status{XrpldError::RpcBadCredentials, "credentials are expired"}}; if (sleCred.getAccountID(xrpl::sfSubject) != srcAcc) { return Error{Status{ - RippledError::RpcBadCredentials, "credentials don't belong to the root account" + XrpldError::RpcBadCredentials, "credentials don't belong to the root account" }}; } diff --git a/src/rpc/Errors.cpp b/src/rpc/Errors.cpp index 7f9487cdb..cd5f59fe8 100644 --- a/src/rpc/Errors.cpp +++ b/src/rpc/Errors.cpp @@ -24,6 +24,19 @@ using namespace std; namespace rpc { +namespace { + +boost::json::object +extraInfoToJson(ExtraInfo const& extra) +{ + boost::json::object out; + for (auto const& [key, value] : extra) + std::visit([&out, &key](auto const& held) { out[key] = held; }, value); + return out; +} + +} // namespace + /** * @brief Stream a Status in human readable form. * @@ -39,8 +52,8 @@ operator<<(std::ostream& stream, Status const& status) { std::visit( util::OverloadSet{ - [&stream, &status](RippledError err) { - stream << "Code: " << static_cast>(err); + [&stream, &status](XrpldError err) { + stream << "Code: " << static_cast>(err); if (!status.error.empty()) stream << ", Error: " << status.error; if (!status.message.empty()) { @@ -64,7 +77,7 @@ operator<<(std::ostream& stream, Status const& status) ); if (status.extraInfo.has_value()) - stream << ", Extra Info: " << *status.extraInfo; + stream << ", Extra Info: " << extraInfoToJson(*status.extraInfo); return stream; } @@ -170,7 +183,7 @@ getErrorInfo(ClioError code) boost::json::object makeError( - RippledError err, + XrpldError err, std::optional customError, std::optional customMessage ) @@ -215,7 +228,7 @@ makeError(Status const& status) auto res = visit( util::OverloadSet{ - [&status, &wrapOptional](RippledError err) { + [&status, &wrapOptional](XrpldError err) { if (err == xrpl::RpcUnknown) { return boost::json::object{ {"error", status.message}, {"type", "response"}, {"status", "error"} @@ -232,7 +245,7 @@ makeError(Status const& status) ); if (status.extraInfo) { - for (auto& [key, value] : *status.extraInfo) + for (auto& [key, value] : extraInfoToJson(*status.extraInfo)) res[key] = value; } diff --git a/src/rpc/Errors.hpp b/src/rpc/Errors.hpp index c5bb2e3f9..44d2e1618 100644 --- a/src/rpc/Errors.hpp +++ b/src/rpc/Errors.hpp @@ -42,7 +42,7 @@ boost::json::object makeError(Status const& status); /** - * @brief Generate JSON from a rpc::RippledError. + * @brief Generate JSON from a rpc::XrpldError. * * @param err The rippled error * @param customError A custom error @@ -51,7 +51,7 @@ makeError(Status const& status); */ boost::json::object makeError( - RippledError err, + XrpldError err, std::optional customError = std::nullopt, std::optional customMessage = std::nullopt ); diff --git a/src/rpc/Factories.cpp b/src/rpc/Factories.cpp index 22c4aa996..09f0fb338 100644 --- a/src/rpc/Factories.cpp +++ b/src/rpc/Factories.cpp @@ -83,8 +83,7 @@ makeHttpContext( if (command == "subscribe" || command == "unsubscribe") { return Error{ - {RippledError::RpcBadSyntax, - "Subscribe and unsubscribe are only allowed for websocket."} + {XrpldError::RpcBadSyntax, "Subscribe and unsubscribe are only allowed for websocket."} }; } diff --git a/src/rpc/README.md b/src/rpc/README.md index 424b9daa6..1d6571760 100644 --- a/src/rpc/README.md +++ b/src/rpc/README.md @@ -20,9 +20,10 @@ See the [common](https://github.com/XRPLF/clio/blob/develop/src/rpc/common) subf From the spec library: -- **`rpc::spec::HandlerFor`**: Base class supplying the static `parseInput` and `spec` - entry points a handler needs. It resolves the versioned spec for `Input` through ADL, so a - handler names only its `Input` type. +- **`rpc::spec::HandlerFor`**: Base class supplying the static `parseInput` and + `spec` entry points a handler needs. It resolves the versioned spec for `Input` through ADL, so a + handler names only its `Input` type. Handlers do not inherit it directly; they use the + `rpc::HandlerFor` alias from `rpc/common/SpecBackend.hpp`, which binds the JSON backend. - **`rpcspec/handlers//Types.hpp`**: The strongly-typed `Input` struct for a method (`xrpl::AccountID`, `xrpl::uint256`, `LedgerSpecifier`, ... rather than `std::string`). - **`rpcspec/handlers//Spec.hpp`**: The consteval spec declaring that method's fields, @@ -36,14 +37,14 @@ for examples; `NFTInfo` is a small one. Handlers need to fulfil the requirements specified by the `SomeHandler` concept (see `rpc/common/Concepts.hpp`): -- Derive from `rpc::spec::HandlerFor::Input>`. This supplies: +- Derive from `rpc::HandlerFor::Input>` (see `rpc/common/SpecBackend.hpp`). This supplies: - `Input` — the strongly-typed input struct, owned by the spec library rather than declared here - `static parseInput(boost::json::value const&, uint32_t apiVersion)` — validates and deserialises in one pass, returning `std::expected` - - `static spec(uint32_t apiVersion)` — returns a type-erased `rpc::spec::RpcSpecView` + - `static spec(uint32_t apiVersion)` — returns a type-erased `rpc::SpecView` If the method takes no input at all, skip the base class and expose only `process(Context const&)`. diff --git a/src/rpc/RPCEngine.hpp b/src/rpc/RPCEngine.hpp index a44f33707..d2235cc0a 100644 --- a/src/rpc/RPCEngine.hpp +++ b/src/rpc/RPCEngine.hpp @@ -135,7 +135,7 @@ public: if (forwardingProxy_.shouldForward(ctx)) { // Disallow forwarding of the admin api, only user api is allowed for security reasons. if (isAdminCmd(ctx.method, ctx.params)) - return Result{Status{RippledError::RpcNoPermission}}; + return Result{Status{XrpldError::RpcNoPermission}}; return forwardingProxy_.forward(ctx); } @@ -148,13 +148,13 @@ public: if (backend_->isTooBusy()) { LOG(log_.error()) << "Database is too busy. Rejecting request"; notifyTooBusy(); // TODO: should we add ctx.method if we have it? - return Result{Status{RippledError::RpcTooBusy}}; + return Result{Status{XrpldError::RpcTooBusy}}; } auto const method = handlerProvider_->getHandler(ctx.method); if (!method) { notifyUnknownCommand(); - return Result{Status{RippledError::RpcUnknownCommand}}; + return Result{Status{XrpldError::RpcUnknownCommand}}; } try { @@ -182,12 +182,12 @@ public: LOG(log_.error()) << "Database error: " << t.what(); notifyTooBusy(); - return Result{Status{RippledError::RpcTooBusy}}; + return Result{Status{XrpldError::RpcTooBusy}}; } catch (std::exception const& ex) { LOG(log_.error()) << ctx.tag() << "Caught exception: " << ex.what(); notifyInternalError(); - return Result{Status{RippledError::RpcInternal}}; + return Result{Status{XrpldError::RpcInternal}}; } } @@ -333,13 +333,13 @@ private: if (backend_->isTooBusy()) { LOG(log_.error()) << "Database is too busy. Rejecting request"; notifyTooBusy(); // TODO: should we add ctx.method if we have it? - return Result{Status{RippledError::RpcTooBusy}}; + return Result{Status{XrpldError::RpcTooBusy}}; } auto const method = handlerProvider_->getHandler(ctx.method); if (!method) { notifyUnknownCommand(); - return Result{Status{RippledError::RpcUnknownCommand}}; + return Result{Status{XrpldError::RpcUnknownCommand}}; } try { @@ -365,12 +365,12 @@ private: LOG(log_.error()) << "Database error: " << t.what(); notifyTooBusy(); - return Result{Status{RippledError::RpcTooBusy}}; + return Result{Status{XrpldError::RpcTooBusy}}; } catch (std::exception const& ex) { LOG(log_.error()) << ctx.tag() << "Caught exception: " << ex.what(); notifyInternalError(); - return Result{Status{RippledError::RpcInternal}}; + return Result{Status{XrpldError::RpcInternal}}; } } }; diff --git a/src/rpc/RPCHelpers.cpp b/src/rpc/RPCHelpers.cpp index b8d36f5e2..e76a43cf2 100644 --- a/src/rpc/RPCHelpers.cpp +++ b/src/rpc/RPCHelpers.cpp @@ -472,16 +472,16 @@ ledgerHeaderFromRequest( if (!hashValue.is_null()) { if (!hashValue.is_string()) - return std::unexpected{Status{RippledError::RpcInvalidParams, "ledgerHashNotString"}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "ledgerHashNotString"}}; xrpl::uint256 ledgerHash; if (!ledgerHash.parseHex(boost::json::value_to(hashValue))) - return std::unexpected{Status{RippledError::RpcInvalidParams, "ledgerHashMalformed"}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "ledgerHashMalformed"}}; auto lgrInfo = backend->fetchLedgerByHash(ledgerHash, ctx.yield); if (!lgrInfo || lgrInfo->seq > ctx.range.maxSequence) - return std::unexpected{Status{RippledError::RpcLgrNotFound, "ledgerNotFound"}}; + return std::unexpected{Status{XrpldError::RpcLgrNotFound, "ledgerNotFound"}}; return *lgrInfo; } @@ -505,12 +505,12 @@ ledgerHeaderFromRequest( } if (!ledgerSequence) - return std::unexpected{Status{RippledError::RpcInvalidParams, "ledgerIndexMalformed"}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "ledgerIndexMalformed"}}; auto lgrInfo = backend->fetchLedgerBySequence(*ledgerSequence, ctx.yield); if (!lgrInfo || lgrInfo->seq > ctx.range.maxSequence) - return std::unexpected{Status{RippledError::RpcLgrNotFound, "ledgerNotFound"}}; + return std::unexpected{Status{XrpldError::RpcLgrNotFound, "ledgerNotFound"}}; return *lgrInfo; } @@ -526,7 +526,7 @@ getLedgerHeaderFromHashOrSeq( ) { std::optional lgrInfo; - auto const err = std::unexpected{Status{RippledError::RpcLgrNotFound, "ledgerNotFound"}}; + auto const err = std::unexpected{Status{XrpldError::RpcLgrNotFound, "ledgerNotFound"}}; if (ledgerHash) { // invoke uint256's constructor to parse the hex string , instead of // copying buffer @@ -557,7 +557,7 @@ getLedgerHeaderFromLedgerSpecifier( uint32_t maxSeq ) { - auto const err = std::unexpected{Status{RippledError::RpcLgrNotFound, "ledgerNotFound"}}; + auto const err = std::unexpected{Status{XrpldError::RpcLgrNotFound, "ledgerNotFound"}}; auto const resolved = ledger.resolved(); if (resolved.isHash()) { @@ -574,7 +574,7 @@ getLedgerHeaderFromLedgerSpecifier( if (resolved.isShortcut() and std::get(resolved.value) != rpc::spec::LedgerShortcut::Validated) { - return std::unexpected{Status{RippledError::RpcInvalidParams, "ledgerIndexMalformed"}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "ledgerIndexMalformed"}}; } auto const ledgerSequence = resolved.isSequence() ? std::get(resolved.value) : maxSeq; @@ -644,7 +644,7 @@ traverseNFTObjects( // check if nextPage is valid if (nextPage != beast::kZero and firstNFTPage.key != (nextPage & ~xrpl::nft::kPageMask)) - return std::unexpected{Status{RippledError::RpcInvalidParams, "Invalid marker."}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "Invalid marker."}}; // no marker, start from the last page xrpl::uint256 const currentPage = nextPage == beast::kZero ? lastNFTPage.key : nextPage; @@ -657,7 +657,7 @@ traverseNFTObjects( return AccountCursor{.index = beast::kZero, .hint = 0}; } // marker is in the right range, but still invalid - return std::unexpected{Status{RippledError::RpcInvalidParams, "Invalid marker."}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "Invalid marker."}}; } // the object exists and the key is in right range, must be nft page @@ -697,7 +697,7 @@ traverseOwnedNodes( auto const maybeCursor = parseAccountCursor(jsonCursor); if (!maybeCursor) - return std::unexpected{Status{RippledError::RpcInvalidParams, "Malformed cursor."}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "Malformed cursor."}}; // the format is checked in RPC framework level auto [hexCursor, startHint] = *maybeCursor; @@ -1501,7 +1501,7 @@ parseBook( { auto const checkIssuer = [](xrpl::Asset const& asset, std::string_view field, - RippledError error) -> std::optional { + XrpldError error) -> std::optional { if (!asset.holds()) return std::nullopt; @@ -1520,10 +1520,10 @@ parseBook( return std::nullopt; }; - if (auto const err = checkIssuer(pays, JS(taker_pays), RippledError::RpcSrcIsrMalformed)) + if (auto const err = checkIssuer(pays, JS(taker_pays), XrpldError::RpcSrcIsrMalformed)) return std::unexpected{*err}; - if (auto const err = checkIssuer(gets, JS(taker_gets), RippledError::RpcDstIsrMalformed)) + if (auto const err = checkIssuer(gets, JS(taker_gets), XrpldError::RpcDstIsrMalformed)) return std::unexpected{*err}; std::optional domainID = std::nullopt; @@ -1531,14 +1531,14 @@ parseBook( xrpl::uint256 dom; if (!dom.parseHex(*domain)) { return std::unexpected{ - Status{RippledError::RpcDomainMalformed, "Unable to parse domain."} + Status{XrpldError::RpcDomainMalformed, "Unable to parse domain."} }; } domainID = dom; } if (pays == gets) - return std::unexpected{Status{RippledError::RpcBadMarket}}; + return std::unexpected{Status{XrpldError::RpcBadMarket}}; return xrpl::Book{pays, gets, domainID}; } @@ -1547,92 +1547,88 @@ std::expected parseBook(boost::json::object const& request) { if (!request.contains("taker_pays")) { - return std::unexpected{ - Status{RippledError::RpcInvalidParams, "Missing field 'taker_pays'"} - }; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "Missing field 'taker_pays'"}}; } if (!request.contains("taker_gets")) { - return std::unexpected{ - Status{RippledError::RpcInvalidParams, "Missing field 'taker_gets'"} - }; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "Missing field 'taker_gets'"}}; } if (!request.at("taker_pays").is_object()) { return std::unexpected{ - Status{RippledError::RpcInvalidParams, "Field 'taker_pays' is not an object"} + Status{XrpldError::RpcInvalidParams, "Field 'taker_pays' is not an object"} }; } if (!request.at("taker_gets").is_object()) { return std::unexpected{ - Status{RippledError::RpcInvalidParams, "Field 'taker_gets' is not an object"} + Status{XrpldError::RpcInvalidParams, "Field 'taker_gets' is not an object"} }; } auto takerPays = request.at("taker_pays").as_object(); if (!takerPays.contains("currency")) - return std::unexpected{Status{RippledError::RpcSrcCurMalformed}}; + return std::unexpected{Status{XrpldError::RpcSrcCurMalformed}}; if (!takerPays.at("currency").is_string()) - return std::unexpected{Status{RippledError::RpcSrcCurMalformed}}; + return std::unexpected{Status{XrpldError::RpcSrcCurMalformed}}; auto takerGets = request.at("taker_gets").as_object(); if (!takerGets.contains("currency")) - return std::unexpected{Status{RippledError::RpcDstAmtMalformed}}; + return std::unexpected{Status{XrpldError::RpcDstAmtMalformed}}; if (!takerGets.at("currency").is_string()) { return std::unexpected{Status{ - RippledError::RpcDstAmtMalformed, + XrpldError::RpcDstAmtMalformed, }}; } if (request.contains("domain") && !request.at("domain").is_string()) - return std::unexpected{Status{RippledError::RpcDomainMalformed}}; + return std::unexpected{Status{XrpldError::RpcDomainMalformed}}; xrpl::Currency payCurrency; if (!xrpl::toCurrency( payCurrency, boost::json::value_to(takerPays.at("currency")) )) - return std::unexpected{Status{RippledError::RpcSrcCurMalformed}}; + return std::unexpected{Status{XrpldError::RpcSrcCurMalformed}}; xrpl::Currency getCurrency; if (!xrpl::toCurrency(getCurrency, boost::json::value_to(takerGets["currency"]))) - return std::unexpected{Status{RippledError::RpcDstAmtMalformed}}; + return std::unexpected{Status{XrpldError::RpcDstAmtMalformed}}; xrpl::AccountID payIssuer; if (takerPays.contains("issuer")) { if (!takerPays.at("issuer").is_string()) { return std::unexpected{ - Status{RippledError::RpcInvalidParams, "takerPaysIssuerNotString"} + Status{XrpldError::RpcInvalidParams, "takerPaysIssuerNotString"} }; } if (!xrpl::toIssuer(payIssuer, boost::json::value_to(takerPays.at("issuer")))) - return std::unexpected{Status{RippledError::RpcSrcIsrMalformed}}; + return std::unexpected{Status{XrpldError::RpcSrcIsrMalformed}}; if (payIssuer == xrpl::noAccount()) - return std::unexpected{Status{RippledError::RpcSrcIsrMalformed}}; + return std::unexpected{Status{XrpldError::RpcSrcIsrMalformed}}; } else { payIssuer = xrpl::xrpAccount(); } if (isXRP(payCurrency) && !isXRP(payIssuer)) { return std::unexpected{Status{ - RippledError::RpcSrcIsrMalformed, + XrpldError::RpcSrcIsrMalformed, "Unneeded field 'taker_pays.issuer' for XRP currency specification." }}; } if (!isXRP(payCurrency) && isXRP(payIssuer)) { return std::unexpected{Status{ - RippledError::RpcSrcIsrMalformed, + XrpldError::RpcSrcIsrMalformed, "Invalid field 'taker_pays.issuer', expected non-XRP issuer." }}; } if ((!isXRP(payCurrency)) && (!takerPays.contains("issuer"))) { - return std::unexpected{Status{RippledError::RpcSrcIsrMalformed, "Missing non-XRP issuer."}}; + return std::unexpected{Status{XrpldError::RpcSrcIsrMalformed, "Missing non-XRP issuer."}}; } xrpl::AccountID getIssuer; @@ -1640,7 +1636,7 @@ parseBook(boost::json::object const& request) if (takerGets.contains("issuer")) { if (!takerGets["issuer"].is_string()) { return std::unexpected{ - Status{RippledError::RpcInvalidParams, "taker_gets.issuer should be string"} + Status{XrpldError::RpcInvalidParams, "taker_gets.issuer should be string"} }; } @@ -1648,13 +1644,13 @@ parseBook(boost::json::object const& request) getIssuer, boost::json::value_to(takerGets.at("issuer")) )) { return std::unexpected{Status{ - RippledError::RpcDstIsrMalformed, "Invalid field 'taker_gets.issuer', bad issuer." + XrpldError::RpcDstIsrMalformed, "Invalid field 'taker_gets.issuer', bad issuer." }}; } if (getIssuer == xrpl::noAccount()) { return std::unexpected{Status{ - RippledError::RpcDstIsrMalformed, + XrpldError::RpcDstIsrMalformed, "Invalid field 'taker_gets.issuer', bad issuer account one." }}; } @@ -1664,26 +1660,26 @@ parseBook(boost::json::object const& request) if (xrpl::isXRP(getCurrency) && !xrpl::isXRP(getIssuer)) { return std::unexpected{Status{ - RippledError::RpcDstIsrMalformed, + XrpldError::RpcDstIsrMalformed, "Unneeded field 'taker_gets.issuer' for XRP currency specification." }}; } if (!xrpl::isXRP(getCurrency) && xrpl::isXRP(getIssuer)) { return std::unexpected{Status{ - RippledError::RpcDstIsrMalformed, + XrpldError::RpcDstIsrMalformed, "Invalid field 'taker_gets.issuer', expected non-XRP issuer." }}; } if (payCurrency == getCurrency && payIssuer == getIssuer) - return std::unexpected{Status{RippledError::RpcBadMarket}}; + return std::unexpected{Status{XrpldError::RpcBadMarket}}; std::optional domainID; if (request.contains("domain")) { xrpl::uint256 dom; if (!dom.parseHex(boost::json::value_to(request.at("domain")))) - return std::unexpected{Status{RippledError::RpcDomainMalformed}}; + return std::unexpected{Status{XrpldError::RpcDomainMalformed}}; domainID = dom; } @@ -1697,12 +1693,12 @@ parseTaker(boost::json::value const& taker) { std::optional takerID = {}; if (!taker.is_string()) - return std::unexpected{Status{RippledError::RpcInvalidParams, "takerNotString"}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "takerNotString"}}; takerID = accountFromStringStrict(boost::json::value_to(taker)); if (!takerID) - return std::unexpected{Status{RippledError::RpcBadIssuer, "invalidTakerAccount"}}; + return std::unexpected{Status{XrpldError::RpcBadIssuer, "invalidTakerAccount"}}; return *takerID; } @@ -1762,14 +1758,14 @@ std::expected getNFTID(boost::json::object const& request) { if (!request.contains(JS(nft_id))) - return std::unexpected{Status{RippledError::RpcInvalidParams, "missingTokenID"}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "missingTokenID"}}; if (!request.at(JS(nft_id)).is_string()) - return std::unexpected{Status{RippledError::RpcInvalidParams, "tokenIDNotString"}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "tokenIDNotString"}}; xrpl::uint256 tokenid; if (!tokenid.parseHex(boost::json::value_to(request.at(JS(nft_id))))) - return std::unexpected{Status{RippledError::RpcInvalidParams, "malformedTokenID"}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "malformedTokenID"}}; return tokenid; } diff --git a/src/rpc/common/Concepts.hpp b/src/rpc/common/Concepts.hpp index 05dceaf30..44e523116 100644 --- a/src/rpc/common/Concepts.hpp +++ b/src/rpc/common/Concepts.hpp @@ -1,13 +1,13 @@ #pragma once #include "rpc/Errors.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include #include -#include #include #include @@ -37,15 +37,15 @@ concept SomeContextProcessWithoutInput = requires(T a, T::Output out, Context co /** * @brief Specifies what a Handler validated by the shared consteval spec must provide. * - * Such a handler inherits @c rpc::spec::HandlerFor from the spec library, which - * supplies a static @c parseInput (validate and deserialise in one pass) and a static - * @c spec returning a type-erased @c RpcSpecView. + * Such a handler inherits @c rpc::HandlerFor, which binds the shared spec base to + * Clio JSON type and supplies a static @c parseInput (validate and deserialise in one pass) + * and a static @c spec returning a type-erased view of the spec. */ template concept SomeHandlerWithTypedInput = requires(uint32_t version, boost::json::value jv) { typename T::Input; { T::parseInput(jv, version) } -> std::same_as>; - { T::spec(version) } -> std::same_as; + { T::spec(version) } -> std::same_as; } and SomeContextProcessWithInput; /** diff --git a/src/rpc/common/SpecBackend.hpp b/src/rpc/common/SpecBackend.hpp new file mode 100644 index 000000000..1b4ec841b --- /dev/null +++ b/src/rpc/common/SpecBackend.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include +#include + +namespace rpc { + +/** + * @brief A type-erased view of a handler's spec, uniform across API versions. + */ +using SpecView = spec::RpcSpecView; + +/** + * @brief The spec-driven base every typed handler inherits. + * + * Binding the backend here, once, is what keeps handlers and call sites free of it: + * @c Handler::parseInput and @c Handler::spec are ordinary static members. + * + * @tparam InputT The handler's request Input struct. + */ +template +using HandlerFor = spec::HandlerFor; + +} // namespace rpc diff --git a/src/rpc/common/impl/Processors.hpp b/src/rpc/common/impl/Processors.hpp index e9595d136..9f332ae20 100644 --- a/src/rpc/common/impl/Processors.hpp +++ b/src/rpc/common/impl/Processors.hpp @@ -4,7 +4,7 @@ #include "rpc/common/Types.hpp" #include -#include +#include #include diff --git a/src/rpc/handlers/AMMInfo.cpp b/src/rpc/handlers/AMMInfo.cpp index 6d955cd91..efe43426e 100644 --- a/src/rpc/handlers/AMMInfo.cpp +++ b/src/rpc/handlers/AMMInfo.cpp @@ -67,7 +67,7 @@ AMMInfoHandler::process(AMMInfoHandler::Input const& input, Context const& ctx) }(); if (hasInvalidParams) - return Error{Status{RippledError::RpcInvalidParams}}; + return Error{Status{XrpldError::RpcInvalidParams}}; auto const range = sharedPtrBackend_->fetchLedgerRange(); ASSERT(range.has_value(), "AMMInfo's ledger range must be available"); @@ -87,7 +87,7 @@ AMMInfoHandler::process(AMMInfoHandler::Input const& input, Context const& ctx) if (input.accountID) { auto keylet = keylet::account(*input.accountID); if (not sharedPtrBackend_->fetchLedgerObject(keylet.key, lgrInfo.seq, ctx.yield)) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; } xrpl::uint256 ammID; @@ -96,13 +96,13 @@ AMMInfoHandler::process(AMMInfoHandler::Input const& input, Context const& ctx) auto const accountLedgerObject = sharedPtrBackend_->fetchLedgerObject(accountKeylet.key, lgrInfo.seq, ctx.yield); if (not accountLedgerObject) - return Error{Status{RippledError::RpcActMalformed}}; + return Error{Status{XrpldError::RpcActMalformed}}; xrpl::STLedgerEntry const sle{ xrpl::SerialIter{accountLedgerObject->data(), accountLedgerObject->size()}, accountKeylet.key }; if (not sle.isFieldPresent(xrpl::sfAMMID)) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; ammID = sle.getFieldH256(xrpl::sfAMMID); } @@ -113,7 +113,7 @@ AMMInfoHandler::process(AMMInfoHandler::Input const& input, Context const& ctx) sharedPtrBackend_->fetchLedgerObject(ammKeylet.key, lgrInfo.seq, ctx.yield); if (not ammBlob) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; auto const amm = SLE{SerialIter{ammBlob->data(), ammBlob->size()}, ammKeylet.key}; auto const ammAccountID = amm.getAccountID(sfAccount); @@ -121,7 +121,7 @@ AMMInfoHandler::process(AMMInfoHandler::Input const& input, Context const& ctx) keylet::account(ammAccountID).key, lgrInfo.seq, ctx.yield ); if (not accBlob) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; // If the issue1 and issue2 are not specified, we need to get them from the AMM. // Otherwise we preserve the mapping of asset1 -> issue1 and asset2 -> issue2 as requested by diff --git a/src/rpc/handlers/AMMInfo.hpp b/src/rpc/handlers/AMMInfo.hpp index bb35374dc..f15b0c355 100644 --- a/src/rpc/handlers/AMMInfo.hpp +++ b/src/rpc/handlers/AMMInfo.hpp @@ -2,12 +2,12 @@ #include "data/AmendmentCenterInterface.hpp" #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include -#include #include #include @@ -23,7 +23,7 @@ namespace rpc { * * For more info see: https://xrpl.org/amm_info.html */ -class AMMInfoHandler : public rpc::spec::HandlerFor { +class AMMInfoHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; std::shared_ptr amendmentCenter_; diff --git a/src/rpc/handlers/AccountChannels.cpp b/src/rpc/handlers/AccountChannels.cpp index c905003f0..3b2b28c55 100644 --- a/src/rpc/handlers/AccountChannels.cpp +++ b/src/rpc/handlers/AccountChannels.cpp @@ -88,7 +88,7 @@ AccountChannelsHandler::process( ); if (!accountLedgerObject) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; auto const& destAccountID = input.destinationAccount; diff --git a/src/rpc/handlers/AccountChannels.hpp b/src/rpc/handlers/AccountChannels.hpp index d80f59245..c309f96a5 100644 --- a/src/rpc/handlers/AccountChannels.hpp +++ b/src/rpc/handlers/AccountChannels.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -26,7 +26,7 @@ namespace rpc { * For more details see: https://xrpl.org/account_channels.html */ class AccountChannelsHandler - : public rpc::spec::HandlerFor { + : public rpc::HandlerFor { // dependencies std::shared_ptr const sharedPtrBackend_; diff --git a/src/rpc/handlers/AccountCurrencies.cpp b/src/rpc/handlers/AccountCurrencies.cpp index 913fb373c..0cf70b607 100644 --- a/src/rpc/handlers/AccountCurrencies.cpp +++ b/src/rpc/handlers/AccountCurrencies.cpp @@ -48,7 +48,7 @@ AccountCurrenciesHandler::process( xrpl::keylet::account(accountID).key, lgrInfo.seq, ctx.yield ); if (!accountLedgerObject) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; Output response; auto const addToResponse = [&](xrpl::SLE const sle) { diff --git a/src/rpc/handlers/AccountCurrencies.hpp b/src/rpc/handlers/AccountCurrencies.hpp index eecac4fff..4f49c990c 100644 --- a/src/rpc/handlers/AccountCurrencies.hpp +++ b/src/rpc/handlers/AccountCurrencies.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -22,7 +22,7 @@ namespace rpc { * For more details see: https://xrpl.org/account_currencies.html */ class AccountCurrenciesHandler - : public rpc::spec::HandlerFor { + : public rpc::HandlerFor { // dependencies std::shared_ptr sharedPtrBackend_; diff --git a/src/rpc/handlers/AccountInfo.cpp b/src/rpc/handlers/AccountInfo.cpp index 5b7951f38..d2408be5b 100644 --- a/src/rpc/handlers/AccountInfo.cpp +++ b/src/rpc/handlers/AccountInfo.cpp @@ -37,7 +37,7 @@ AccountInfoHandler::process(AccountInfoHandler::Input const& input, Context cons if (!input.account && !input.ident) { return Error{ - Status{RippledError::RpcInvalidParams, xrpl::rpc::missingFieldMessage(JS(account))} + Status{XrpldError::RpcInvalidParams, xrpl::rpc::missingFieldMessage(JS(account))} }; } @@ -60,7 +60,7 @@ AccountInfoHandler::process(AccountInfoHandler::Input const& input, Context cons sharedPtrBackend_->fetchLedgerObject(accountKeylet.key, lgrInfo.seq, ctx.yield); if (!accountLedgerObject) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; xrpl::STLedgerEntry const sle{ xrpl::SerialIter{accountLedgerObject->data(), accountLedgerObject->size()}, @@ -68,7 +68,7 @@ AccountInfoHandler::process(AccountInfoHandler::Input const& input, Context cons }; if (!accountKeylet.check(sle)) - return Error{Status{RippledError::RpcDbDeserialization}}; + return Error{Status{XrpldError::RpcDbDeserialization}}; auto isEnabled = [this, &ctx, seq = lgrInfo.seq](auto key) { return amendmentCenter_->isEnabled(ctx.yield, key, seq); @@ -107,7 +107,7 @@ AccountInfoHandler::process(AccountInfoHandler::Input const& input, Context cons }; if (!signersKey.check(sleSigners)) - return Error{Status{RippledError::RpcDbDeserialization}}; + return Error{Status{XrpldError::RpcDbDeserialization}}; out.signerLists->push_back(sleSigners); } diff --git a/src/rpc/handlers/AccountInfo.hpp b/src/rpc/handlers/AccountInfo.hpp index 08196c054..a44a021ce 100644 --- a/src/rpc/handlers/AccountInfo.hpp +++ b/src/rpc/handlers/AccountInfo.hpp @@ -2,11 +2,11 @@ #include "data/AmendmentCenterInterface.hpp" #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -24,7 +24,7 @@ namespace rpc { * * For more details see: https://xrpl.org/account_info.html */ -class AccountInfoHandler : public rpc::spec::HandlerFor { +class AccountInfoHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; std::shared_ptr amendmentCenter_; diff --git a/src/rpc/handlers/AccountLines.cpp b/src/rpc/handlers/AccountLines.cpp index ea867fe85..b3b5cd301 100644 --- a/src/rpc/handlers/AccountLines.cpp +++ b/src/rpc/handlers/AccountLines.cpp @@ -136,7 +136,7 @@ AccountLinesHandler::process(AccountLinesHandler::Input const& input, Context co ); if (not accountLedgerObject) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; auto const& peerAccountID = input.peer; diff --git a/src/rpc/handlers/AccountLines.hpp b/src/rpc/handlers/AccountLines.hpp index 28f244371..6a2ed1d1d 100644 --- a/src/rpc/handlers/AccountLines.hpp +++ b/src/rpc/handlers/AccountLines.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include #include @@ -25,8 +25,7 @@ namespace rpc { * * For more details see: https://xrpl.org/account_lines.html */ -class AccountLinesHandler - : public rpc::spec::HandlerFor { +class AccountLinesHandler : public rpc::HandlerFor { // dependencies std::shared_ptr const sharedPtrBackend_; diff --git a/src/rpc/handlers/AccountMPTokenIssuances.cpp b/src/rpc/handlers/AccountMPTokenIssuances.cpp index 61ab0696c..aa82c0606 100644 --- a/src/rpc/handlers/AccountMPTokenIssuances.cpp +++ b/src/rpc/handlers/AccountMPTokenIssuances.cpp @@ -139,7 +139,7 @@ AccountMPTokenIssuancesHandler::process( ); if (not accountLedgerObject.has_value()) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; Output response; response.issuances.reserve(input.limit); diff --git a/src/rpc/handlers/AccountMPTokenIssuances.hpp b/src/rpc/handlers/AccountMPTokenIssuances.hpp index 9222ab621..f06aebb52 100644 --- a/src/rpc/handlers/AccountMPTokenIssuances.hpp +++ b/src/rpc/handlers/AccountMPTokenIssuances.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include #include @@ -24,7 +24,7 @@ namespace rpc { * the account has created. */ class AccountMPTokenIssuancesHandler - : public rpc::spec::HandlerFor { + : public rpc::HandlerFor { // dependencies std::shared_ptr sharedPtrBackend_; diff --git a/src/rpc/handlers/AccountMPTokens.cpp b/src/rpc/handlers/AccountMPTokens.cpp index 6de41d7e1..852633ee8 100644 --- a/src/rpc/handlers/AccountMPTokens.cpp +++ b/src/rpc/handlers/AccountMPTokens.cpp @@ -103,7 +103,7 @@ AccountMPTokensHandler::process( ); if (not accountLedgerObject.has_value()) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; Output response; response.mpts.reserve(input.limit); diff --git a/src/rpc/handlers/AccountMPTokens.hpp b/src/rpc/handlers/AccountMPTokens.hpp index 2755c4df4..743736a02 100644 --- a/src/rpc/handlers/AccountMPTokens.hpp +++ b/src/rpc/handlers/AccountMPTokens.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -23,7 +23,7 @@ namespace rpc { * holds. */ class AccountMPTokensHandler - : public rpc::spec::HandlerFor { + : public rpc::HandlerFor { // dependencies std::shared_ptr sharedPtrBackend_; diff --git a/src/rpc/handlers/AccountNFTs.cpp b/src/rpc/handlers/AccountNFTs.cpp index bded73ccd..576bb3701 100644 --- a/src/rpc/handlers/AccountNFTs.cpp +++ b/src/rpc/handlers/AccountNFTs.cpp @@ -50,7 +50,7 @@ AccountNFTsHandler::process(AccountNFTsHandler::Input const& input, Context cons ); if (!accountLedgerObject) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; auto response = Output{}; response.account = xrpl::to_string(accountID); @@ -65,7 +65,7 @@ AccountNFTsHandler::process(AccountNFTsHandler::Input const& input, Context cons if (!blob) { if (input.marker.has_value()) { return Error{Status{ - RippledError::RpcInvalidParams, "Marker field does not match any valid Page ID" + XrpldError::RpcInvalidParams, "Marker field does not match any valid Page ID" }}; } return response; @@ -77,7 +77,7 @@ AccountNFTsHandler::process(AccountNFTsHandler::Input const& input, Context cons if (page->getType() != xrpl::ltNFTOKEN_PAGE) { return Error{ - Status{RippledError::RpcInvalidParams, "Marker matches Page ID from another Account"} + Status{XrpldError::RpcInvalidParams, "Marker matches Page ID from another Account"} }; } diff --git a/src/rpc/handlers/AccountNFTs.hpp b/src/rpc/handlers/AccountNFTs.hpp index 92d9e03a4..104127e89 100644 --- a/src/rpc/handlers/AccountNFTs.hpp +++ b/src/rpc/handlers/AccountNFTs.hpp @@ -1,12 +1,12 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include -#include #include #include @@ -22,7 +22,7 @@ namespace rpc { * * For more details see: https://xrpl.org/account_nfts.html */ -class AccountNFTsHandler : public rpc::spec::HandlerFor { +class AccountNFTsHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/AccountObjects.cpp b/src/rpc/handlers/AccountObjects.cpp index 13a250e7b..9c21c4d41 100644 --- a/src/rpc/handlers/AccountObjects.cpp +++ b/src/rpc/handlers/AccountObjects.cpp @@ -53,7 +53,7 @@ AccountObjectsHandler::process(AccountObjectsHandler::Input const& input, Contex ); if (!accountLedgerObject) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; auto typeFilter = std::optional>{}; diff --git a/src/rpc/handlers/AccountObjects.hpp b/src/rpc/handlers/AccountObjects.hpp index ca7e17519..f9549d3be 100644 --- a/src/rpc/handlers/AccountObjects.hpp +++ b/src/rpc/handlers/AccountObjects.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -25,8 +25,7 @@ namespace rpc { * * For more details see: https://xrpl.org/account_objects.html */ -class AccountObjectsHandler - : public rpc::spec::HandlerFor { +class AccountObjectsHandler : public rpc::HandlerFor { // dependencies std::shared_ptr sharedPtrBackend_; diff --git a/src/rpc/handlers/AccountOffers.cpp b/src/rpc/handlers/AccountOffers.cpp index 17787d50a..a94826d5b 100644 --- a/src/rpc/handlers/AccountOffers.cpp +++ b/src/rpc/handlers/AccountOffers.cpp @@ -66,7 +66,7 @@ AccountOffersHandler::process(AccountOffersHandler::Input const& input, Context ); if (!accountLedgerObject) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; Output response; response.account = xrpl::to_string(accountID); diff --git a/src/rpc/handlers/AccountOffers.hpp b/src/rpc/handlers/AccountOffers.hpp index 1d79d97e9..21f1c2903 100644 --- a/src/rpc/handlers/AccountOffers.hpp +++ b/src/rpc/handlers/AccountOffers.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include #include @@ -24,8 +24,7 @@ namespace rpc { * * For more details see: https://xrpl.org/account_offers.html */ -class AccountOffersHandler - : public rpc::spec::HandlerFor { +class AccountOffersHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/AccountTx.cpp b/src/rpc/handlers/AccountTx.cpp index 08b9d3f7f..ea53b35b3 100644 --- a/src/rpc/handlers/AccountTx.cpp +++ b/src/rpc/handlers/AccountTx.cpp @@ -48,7 +48,7 @@ AccountTxHandler::process(AccountTxHandler::Input const& input, Context const& c if (ctx.apiVersion > 1u && (input.ledgerIndexMin > range->maxSequence || input.ledgerIndexMin < range->minSequence)) { - return Error{Status{RippledError::RpcLgrIdxMalformed, "ledgerSeqMinOutOfRange"}}; + return Error{Status{XrpldError::RpcLgrIdxMalformed, "ledgerSeqMinOutOfRange"}}; } // NOLINTEND(bugprone-unchecked-optional-access) @@ -61,7 +61,7 @@ AccountTxHandler::process(AccountTxHandler::Input const& input, Context const& c if (ctx.apiVersion > 1u && (input.ledgerIndexMax > range->maxSequence || input.ledgerIndexMax < range->minSequence)) { - return Error{Status{RippledError::RpcLgrIdxMalformed, "ledgerSeqMaxOutOfRange"}}; + return Error{Status{XrpldError::RpcLgrIdxMalformed, "ledgerSeqMaxOutOfRange"}}; } // NOLINTEND(bugprone-unchecked-optional-access) @@ -71,14 +71,14 @@ AccountTxHandler::process(AccountTxHandler::Input const& input, Context const& c if (minIndex > maxIndex) { if (ctx.apiVersion == 1u) - return Error{Status{RippledError::RpcLgrIdxsInvalid}}; + return Error{Status{XrpldError::RpcLgrIdxsInvalid}}; - return Error{Status{RippledError::RpcInvalidLgrRange}}; + return Error{Status{XrpldError::RpcInvalidLgrRange}}; } if (not input.ledger.isUnspecified()) { if (ctx.apiVersion > 1u && (input.ledgerIndexMax || input.ledgerIndexMin)) { - return Error{Status{RippledError::RpcInvalidParams, "containsLedgerSpecifierAndRange"}}; + return Error{Status{XrpldError::RpcInvalidParams, "containsLedgerSpecifierAndRange"}}; } if (!input.ledgerIndexMax && !input.ledgerIndexMin) { diff --git a/src/rpc/handlers/AccountTx.hpp b/src/rpc/handlers/AccountTx.hpp index 60f6d5190..98ab8a9a9 100644 --- a/src/rpc/handlers/AccountTx.hpp +++ b/src/rpc/handlers/AccountTx.hpp @@ -2,6 +2,7 @@ #include "data/BackendInterface.hpp" #include "etl/ETLServiceInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include "util/log/Logger.hpp" @@ -9,7 +10,6 @@ #include #include #include -#include #include #include @@ -27,7 +27,7 @@ namespace rpc { * * For more details see: https://xrpl.org/account_tx.html */ -class AccountTxHandler : public rpc::spec::HandlerFor { +class AccountTxHandler : public rpc::HandlerFor { util::Logger log_{"RPC"}; std::shared_ptr sharedPtrBackend_; std::shared_ptr etl_; diff --git a/src/rpc/handlers/BookChanges.hpp b/src/rpc/handlers/BookChanges.hpp index fa09a51c7..57bc6c8ff 100644 --- a/src/rpc/handlers/BookChanges.hpp +++ b/src/rpc/handlers/BookChanges.hpp @@ -2,11 +2,11 @@ #include "data/BackendInterface.hpp" #include "rpc/BookChangesHelper.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -22,7 +22,7 @@ namespace rpc { * * This API is not documented in the rippled API documentation. */ -class BookChangesHandler : public rpc::spec::HandlerFor { +class BookChangesHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/BookOffers.hpp b/src/rpc/handlers/BookOffers.hpp index dcbeb5685..aa47f8b0e 100644 --- a/src/rpc/handlers/BookOffers.hpp +++ b/src/rpc/handlers/BookOffers.hpp @@ -2,13 +2,13 @@ #include "data/AmendmentCenterInterface.hpp" #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include #include -#include #include #include @@ -24,7 +24,7 @@ namespace rpc { * * For more details see: https://xrpl.org/book_offers.html */ -class BookOffersHandler : public rpc::spec::HandlerFor { +class BookOffersHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; std::shared_ptr amendmentCenter_; diff --git a/src/rpc/handlers/DepositAuthorized.cpp b/src/rpc/handlers/DepositAuthorized.cpp index e23a9b7ff..eb54184c6 100644 --- a/src/rpc/handlers/DepositAuthorized.cpp +++ b/src/rpc/handlers/DepositAuthorized.cpp @@ -59,14 +59,14 @@ DepositAuthorizedHandler::process( ); if (!srcAccountLedgerObject) - return Error{Status{RippledError::RpcSrcActNotFound, "source_accountNotFound"}}; + return Error{Status{XrpldError::RpcSrcActNotFound, "source_accountNotFound"}}; auto const dstKeylet = xrpl::keylet::account(destinationAccountID).key; auto const dstAccountLedgerObject = sharedPtrBackend_->fetchLedgerObject(dstKeylet, lgrInfo.seq, ctx.yield); if (!dstAccountLedgerObject) - return Error{Status{RippledError::RpcDstActNotFound, "destination_accountNotFound"}}; + return Error{Status{XrpldError::RpcDstActNotFound, "destination_accountNotFound"}}; Output response; @@ -80,12 +80,10 @@ DepositAuthorizedHandler::process( xrpl::STArray authCreds; if (credentialsPresent) { if (creds->empty()) { - return Error{ - Status{RippledError::RpcInvalidParams, "credential array has no elements."} - }; + return Error{Status{XrpldError::RpcInvalidParams, "credential array has no elements."}}; } if (creds->size() > xrpl::kMaxCredentialsArraySize) { - return Error{Status{RippledError::RpcInvalidParams, "credential array too long."}}; + return Error{Status{XrpldError::RpcInvalidParams, "credential array too long."}}; } auto const credArray = credentials::fetchCredentialArray( *creds, sourceAccountID, *sharedPtrBackend_, lgrInfo, ctx.yield diff --git a/src/rpc/handlers/DepositAuthorized.hpp b/src/rpc/handlers/DepositAuthorized.hpp index 8907a49de..75dfe949b 100644 --- a/src/rpc/handlers/DepositAuthorized.hpp +++ b/src/rpc/handlers/DepositAuthorized.hpp @@ -1,12 +1,12 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include -#include #include #include #include @@ -31,7 +31,7 @@ namespace rpc { * For more details see: https://xrpl.org/deposit_authorized.html */ class DepositAuthorizedHandler - : public rpc::spec::HandlerFor { + : public rpc::HandlerFor { // dependencies std::shared_ptr const sharedPtrBackend_; diff --git a/src/rpc/handlers/Feature.cpp b/src/rpc/handlers/Feature.cpp index 09d0f6c7a..ba9141aa5 100644 --- a/src/rpc/handlers/Feature.cpp +++ b/src/rpc/handlers/Feature.cpp @@ -66,7 +66,7 @@ FeatureHandler::process(FeatureHandler::Input const& input, Context const& ctx) ); if (filtered.empty()) - return Error{Status{RippledError::RpcBadFeature}}; + return Error{Status{XrpldError::RpcBadFeature}}; std::vector names; rg::transform(filtered, std::back_inserter(names), [](auto const& feature) { diff --git a/src/rpc/handlers/Feature.hpp b/src/rpc/handlers/Feature.hpp index 02ea0c6ba..79927e0fc 100644 --- a/src/rpc/handlers/Feature.hpp +++ b/src/rpc/handlers/Feature.hpp @@ -2,11 +2,11 @@ #include "data/AmendmentCenterInterface.hpp" #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -20,7 +20,7 @@ namespace rpc { /** * @brief Contains common functionality for handling the `server_info` command */ -class FeatureHandler : public rpc::spec::HandlerFor { +class FeatureHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; std::shared_ptr amendmentCenter_; diff --git a/src/rpc/handlers/GatewayBalances.cpp b/src/rpc/handlers/GatewayBalances.cpp index 1d93575d6..9843b92dc 100644 --- a/src/rpc/handlers/GatewayBalances.cpp +++ b/src/rpc/handlers/GatewayBalances.cpp @@ -61,7 +61,7 @@ GatewayBalancesHandler::process( ); if (!accountLedgerObject) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; auto output = GatewayBalancesHandler::Output{}; diff --git a/src/rpc/handlers/GatewayBalances.hpp b/src/rpc/handlers/GatewayBalances.hpp index 4385d41f8..c765e23dc 100644 --- a/src/rpc/handlers/GatewayBalances.hpp +++ b/src/rpc/handlers/GatewayBalances.hpp @@ -1,12 +1,12 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include -#include #include #include #include @@ -30,7 +30,7 @@ namespace rpc { * For more details see: https://xrpl.org/gateway_balances.html#gateway_balances */ class GatewayBalancesHandler - : public rpc::spec::HandlerFor { + : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/GetAggregatePrice.hpp b/src/rpc/handlers/GetAggregatePrice.hpp index 577e2247c..12f44764c 100644 --- a/src/rpc/handlers/GetAggregatePrice.hpp +++ b/src/rpc/handlers/GetAggregatePrice.hpp @@ -2,13 +2,13 @@ #include "data/BackendInterface.hpp" #include "rpc/Errors.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include #include -#include #include #include #include @@ -31,7 +31,7 @@ namespace rpc { *@brief The get_aggregate_price method. */ class GetAggregatePriceHandler - : public rpc::spec::HandlerFor { + : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/Ledger.hpp b/src/rpc/handlers/Ledger.hpp index 95227b275..7d33cd6ac 100644 --- a/src/rpc/handlers/Ledger.hpp +++ b/src/rpc/handlers/Ledger.hpp @@ -2,12 +2,12 @@ #include "data/AmendmentCenterInterface.hpp" #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include -#include #include #include @@ -22,7 +22,7 @@ namespace rpc { * * For more details see: https://xrpl.org/ledger.html */ -class LedgerHandler : public rpc::spec::HandlerFor { +class LedgerHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; std::shared_ptr amendmentCenter_; diff --git a/src/rpc/handlers/LedgerData.cpp b/src/rpc/handlers/LedgerData.cpp index 3a2435328..bb4459bef 100644 --- a/src/rpc/handlers/LedgerData.cpp +++ b/src/rpc/handlers/LedgerData.cpp @@ -42,10 +42,10 @@ LedgerDataHandler::process(Input const& input, Context const& ctx) const auto const* diffMarker = input.marker ? std::get_if(&*input.marker) : nullptr; if (input.outOfOrder && uint256Marker != nullptr) - return Error{Status{RippledError::RpcInvalidParams, "outOfOrderMarkerNotInt"}}; + return Error{Status{XrpldError::RpcInvalidParams, "outOfOrderMarkerNotInt"}}; if (!input.outOfOrder && diffMarker != nullptr) - return Error{Status{RippledError::RpcInvalidParams, "markerNotString"}}; + return Error{Status{XrpldError::RpcInvalidParams, "markerNotString"}}; auto const range = sharedPtrBackend_->fetchLedgerRange(); ASSERT(range.has_value(), "LedgerData's ledger range must be available"); @@ -70,7 +70,7 @@ LedgerDataHandler::process(Input const& input, Context const& ctx) const } else { if (uint256Marker != nullptr && !sharedPtrBackend_->fetchLedgerObject(*uint256Marker, lgrInfo.seq, ctx.yield)) - return Error{Status{RippledError::RpcInvalidParams, "markerDoesNotExist"}}; + return Error{Status{XrpldError::RpcInvalidParams, "markerDoesNotExist"}}; } output.ledgerHash = xrpl::strHex(lgrInfo.hash); diff --git a/src/rpc/handlers/LedgerData.hpp b/src/rpc/handlers/LedgerData.hpp index 85bb0c7fc..87ffd2a33 100644 --- a/src/rpc/handlers/LedgerData.hpp +++ b/src/rpc/handlers/LedgerData.hpp @@ -2,6 +2,7 @@ #include "data/BackendInterface.hpp" #include "rpc/Errors.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include "util/log/Logger.hpp" @@ -9,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -29,7 +29,7 @@ namespace rpc { * * For more details see: https://xrpl.org/ledger_data.html */ -class LedgerDataHandler : public rpc::spec::HandlerFor { +class LedgerDataHandler : public rpc::HandlerFor { // dependencies std::shared_ptr sharedPtrBackend_; util::Logger log_{"RPC"}; diff --git a/src/rpc/handlers/LedgerEntry.cpp b/src/rpc/handlers/LedgerEntry.cpp index 934294913..fdf72d829 100644 --- a/src/rpc/handlers/LedgerEntry.cpp +++ b/src/rpc/handlers/LedgerEntry.cpp @@ -123,12 +123,12 @@ directoryLocator(le::DirectoryEntry const& entry) // This should be unified after xrpld is migrated to rpc-spec. if (entry.dirRoot.has_value() and entry.owner.has_value()) { return std::unexpected{ - Status{RippledError::RpcInvalidParams, "mayNotSpecifyBothDirRootAndOwner"} + Status{XrpldError::RpcInvalidParams, "mayNotSpecifyBothDirRootAndOwner"} }; } if (not entry.dirRoot.has_value() and not entry.owner.has_value()) - return std::unexpected{Status{RippledError::RpcInvalidParams, "missingOwnerOrDirRoot"}}; + return std::unexpected{Status{XrpldError::RpcInvalidParams, "missingOwnerOrDirRoot"}}; auto const subIndex = entry.subIndex.value_or(0); if (entry.dirRoot.has_value()) @@ -224,7 +224,7 @@ resolveLocator(Input const& input, uint32_t apiVersion) if (input.index.has_value()) { // A raw key names no entry type, so nothing is verified after the read. if (input.index->isZero()) - return std::unexpected{Status{RippledError::RpcEntryNotFound}}; + return std::unexpected{Status{XrpldError::RpcEntryNotFound}}; return Locator{.key = *input.index}; } @@ -409,7 +409,7 @@ resolveLocator(Input const& input, uint32_t apiVersion) return std::unexpected{Status{ClioError::RpcUnknownOption}}; return std::unexpected{ - Status{RippledError::RpcInvalidParams, "No ledger_entry params provided."} + Status{XrpldError::RpcInvalidParams, "No ledger_entry params provided."} }; } @@ -443,14 +443,14 @@ LedgerEntryHandler::process(LedgerEntryHandler::Input const& input, Context cons if (not ledgerObject.has_value() or ledgerObject->empty()) { if (not input.includeDeleted) - return Error{Status{RippledError::RpcEntryNotFound}}; + return Error{Status{XrpldError::RpcEntryNotFound}}; auto const deletedSeq = sharedPtrBackend_->fetchLedgerObjectSeq(key, lgrInfo.seq, ctx.yield); if (not deletedSeq.has_value()) - return Error{Status{RippledError::RpcEntryNotFound}}; + return Error{Status{XrpldError::RpcEntryNotFound}}; ledgerObject = sharedPtrBackend_->fetchLedgerObject(key, *deletedSeq - 1, ctx.yield); if (not ledgerObject.has_value() or ledgerObject->empty()) - return Error{Status{RippledError::RpcEntryNotFound}}; + return Error{Status{XrpldError::RpcEntryNotFound}}; output.deletedLedgerIndex = deletedSeq; } @@ -459,7 +459,7 @@ LedgerEntryHandler::process(LedgerEntryHandler::Input const& input, Context cons }; if (expectedType != xrpl::ltANY && sle.getType() != expectedType) - return Error{Status{RippledError::RpcUnexpectedLedgerType}}; + return Error{Status{XrpldError::RpcUnexpectedLedgerType}}; output.index = xrpl::strHex(key); output.ledgerIndex = lgrInfo.seq; diff --git a/src/rpc/handlers/LedgerEntry.hpp b/src/rpc/handlers/LedgerEntry.hpp index 9ed608e84..ea9987439 100644 --- a/src/rpc/handlers/LedgerEntry.hpp +++ b/src/rpc/handlers/LedgerEntry.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -22,7 +22,7 @@ namespace rpc { * * For more details see: https://xrpl.org/ledger_entry.html */ -class LedgerEntryHandler : public rpc::spec::HandlerFor { +class LedgerEntryHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/LedgerIndex.cpp b/src/rpc/handlers/LedgerIndex.cpp index 917cde0f7..97a5a120d 100644 --- a/src/rpc/handlers/LedgerIndex.cpp +++ b/src/rpc/handlers/LedgerIndex.cpp @@ -51,7 +51,7 @@ LedgerIndexHandler::process(LedgerIndexHandler::Input const& input, Context cons // If the given date is earlier than the first valid ledger, return lgrNotFound if (earlierThan(minIndex)) - return Error{Status{RippledError::RpcLgrNotFound, "ledgerNotInRange"}}; + return Error{Status{XrpldError::RpcLgrNotFound, "ledgerNotInRange"}}; auto const view = std::ranges::iota_view{minIndex, maxIndex + 1}; diff --git a/src/rpc/handlers/LedgerIndex.hpp b/src/rpc/handlers/LedgerIndex.hpp index bde2ec687..fc953ab8b 100644 --- a/src/rpc/handlers/LedgerIndex.hpp +++ b/src/rpc/handlers/LedgerIndex.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -19,7 +19,7 @@ namespace rpc { * @brief The ledger_index method fetches the latest closed ledger before the given date. * */ -class LedgerIndexHandler : public rpc::spec::HandlerFor { +class LedgerIndexHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/MPTHolders.cpp b/src/rpc/handlers/MPTHolders.cpp index 90d49f1ff..12af696bf 100644 --- a/src/rpc/handlers/MPTHolders.cpp +++ b/src/rpc/handlers/MPTHolders.cpp @@ -100,9 +100,9 @@ MPTHoldersHandler::process(MPTHoldersHandler::Input const& input, Context const& // alongside it. if (input.accounts) { if (input.marker.has_value()) - return Error{Status{RippledError::RpcInvalidParams, "accountsWithMarker"}}; + return Error{Status{XrpldError::RpcInvalidParams, "accountsWithMarker"}}; if (input.limit.has_value()) - return Error{Status{RippledError::RpcInvalidParams, "accountsWithLimit"}}; + return Error{Status{XrpldError::RpcInvalidParams, "accountsWithLimit"}}; } auto const range = sharedPtrBackend_->fetchLedgerRange(); @@ -125,7 +125,7 @@ MPTHoldersHandler::process(MPTHoldersHandler::Input const& input, Context const& xrpl::keylet::mptokenIssuance(mptID).key, lgrInfo.seq, ctx.yield ); if (!issuanceLedgerObject) - return Error{Status{RippledError::RpcObjectNotFound, "objectNotFound"}}; + return Error{Status{XrpldError::RpcObjectNotFound, "objectNotFound"}}; auto output = MPTHoldersHandler::Output{}; output.mptID = to_string(mptID); diff --git a/src/rpc/handlers/MPTHolders.hpp b/src/rpc/handlers/MPTHolders.hpp index a899f7110..13768410d 100644 --- a/src/rpc/handlers/MPTHolders.hpp +++ b/src/rpc/handlers/MPTHolders.hpp @@ -1,12 +1,12 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include -#include #include #include @@ -26,7 +26,7 @@ namespace rpc { * collapsed in first-seen order and non-holders are omitted. This filtered mode is * not paginated, so `marker` and `limit` are rejected. */ -class MPTHoldersHandler : public rpc::spec::HandlerFor { +class MPTHoldersHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/MPTokenIssuanceHistory.cpp b/src/rpc/handlers/MPTokenIssuanceHistory.cpp index 5b0d4196a..e22a52625 100644 --- a/src/rpc/handlers/MPTokenIssuanceHistory.cpp +++ b/src/rpc/handlers/MPTokenIssuanceHistory.cpp @@ -89,7 +89,7 @@ MPTokenIssuanceHistoryHandler::verifyHistoryAvailable(Context const& ctx) const // Fail closed: partial history must never be served. return Error{Status{ - RippledError::RpcNotReady, + XrpldError::RpcNotReady, "mptoken_issuance_history is not available on this server because the required " "transaction-history backfill has not completed." }}; @@ -106,25 +106,25 @@ MPTokenIssuanceHistoryHandler::resolveSequenceRange(Input const& input, Context if (input.ledgerIndexMin.has_value()) { if (dbMaxSeq < input.ledgerIndexMin || dbMinSeq > input.ledgerIndexMin) - return Error{Status{RippledError::RpcLgrIdxMalformed, "ledgerSeqMinOutOfRange"}}; + return Error{Status{XrpldError::RpcLgrIdxMalformed, "ledgerSeqMinOutOfRange"}}; resolved.min = *input.ledgerIndexMin; } if (input.ledgerIndexMax.has_value()) { if (dbMaxSeq < input.ledgerIndexMax || dbMinSeq > input.ledgerIndexMax) - return Error{Status{RippledError::RpcLgrIdxMalformed, "ledgerSeqMaxOutOfRange"}}; + return Error{Status{XrpldError::RpcLgrIdxMalformed, "ledgerSeqMaxOutOfRange"}}; resolved.max = *input.ledgerIndexMax; } if (resolved.min > resolved.max) - return Error{Status{RippledError::RpcLgrIdxsInvalid}}; + return Error{Status{XrpldError::RpcLgrIdxsInvalid}}; if (not input.ledger.isUnspecified()) { // rippled does not have this check if (input.ledgerIndexMax.has_value() || input.ledgerIndexMin.has_value()) - return Error{Status{RippledError::RpcInvalidParams, "containsLedgerSpecifierAndRange"}}; + return Error{Status{XrpldError::RpcInvalidParams, "containsLedgerSpecifierAndRange"}}; auto const expectedLgrInfo = getLedgerHeaderFromLedgerSpecifier( *sharedPtrBackend_, ctx.yield, input.ledger, dbMaxSeq diff --git a/src/rpc/handlers/MPTokenIssuanceHistory.hpp b/src/rpc/handlers/MPTokenIssuanceHistory.hpp index ae33144f8..d30180e8d 100644 --- a/src/rpc/handlers/MPTokenIssuanceHistory.hpp +++ b/src/rpc/handlers/MPTokenIssuanceHistory.hpp @@ -2,6 +2,7 @@ #include "data/BackendInterface.hpp" #include "data/Types.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include "util/log/Logger.hpp" @@ -9,7 +10,6 @@ #include #include #include -#include #include #include @@ -31,7 +31,7 @@ namespace rpc { * backfill reports `Migrated`, so partial history is never served. */ class MPTokenIssuanceHistoryHandler - : public rpc::spec::HandlerFor { + : public rpc::HandlerFor { util::Logger log_{"RPC"}; std::shared_ptr sharedPtrBackend_; diff --git a/src/rpc/handlers/NFTHistory.cpp b/src/rpc/handlers/NFTHistory.cpp index 22edb5c4d..4746ef1a7 100644 --- a/src/rpc/handlers/NFTHistory.cpp +++ b/src/rpc/handlers/NFTHistory.cpp @@ -41,7 +41,7 @@ NFTHistoryHandler::process(NFTHistoryHandler::Input const& input, Context const& if (input.ledgerIndexMin) { // NOLINTBEGIN(bugprone-unchecked-optional-access) if (range->maxSequence < input.ledgerIndexMin || range->minSequence > input.ledgerIndexMin) - return Error{Status{RippledError::RpcLgrIdxMalformed, "ledgerSeqMinOutOfRange"}}; + return Error{Status{XrpldError::RpcLgrIdxMalformed, "ledgerSeqMinOutOfRange"}}; // NOLINTEND(bugprone-unchecked-optional-access) minIndex = static_cast(*input.ledgerIndexMin); @@ -50,19 +50,19 @@ NFTHistoryHandler::process(NFTHistoryHandler::Input const& input, Context const& if (input.ledgerIndexMax) { // NOLINTBEGIN(bugprone-unchecked-optional-access) if (range->maxSequence < input.ledgerIndexMax || range->minSequence > input.ledgerIndexMax) - return Error{Status{RippledError::RpcLgrIdxMalformed, "ledgerSeqMaxOutOfRange"}}; + return Error{Status{XrpldError::RpcLgrIdxMalformed, "ledgerSeqMaxOutOfRange"}}; // NOLINTEND(bugprone-unchecked-optional-access) maxIndex = static_cast(*input.ledgerIndexMax); } if (minIndex > maxIndex) - return Error{Status{RippledError::RpcLgrIdxsInvalid}}; + return Error{Status{XrpldError::RpcLgrIdxsInvalid}}; if (not input.ledger.isUnspecified()) { // rippled does not have this check if (input.ledgerIndexMax || input.ledgerIndexMin) { - return Error{Status{RippledError::RpcInvalidParams, "containsLedgerSpecifierAndRange"}}; + return Error{Status{XrpldError::RpcInvalidParams, "containsLedgerSpecifierAndRange"}}; } auto const expectedLgrInfo = getLedgerHeaderFromLedgerSpecifier( diff --git a/src/rpc/handlers/NFTHistory.hpp b/src/rpc/handlers/NFTHistory.hpp index c0cd5a106..048fb65a9 100644 --- a/src/rpc/handlers/NFTHistory.hpp +++ b/src/rpc/handlers/NFTHistory.hpp @@ -2,6 +2,7 @@ #include "data/BackendInterface.hpp" #include "rpc/Errors.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include "util/log/Logger.hpp" @@ -9,7 +10,6 @@ #include #include #include -#include #include #include @@ -27,7 +27,7 @@ namespace rpc { * * For more details see: https://xrpl.org/nft_history.html#nft_history */ -class NFTHistoryHandler : public rpc::spec::HandlerFor { +class NFTHistoryHandler : public rpc::HandlerFor { util::Logger log_{"RPC"}; std::shared_ptr sharedPtrBackend_; diff --git a/src/rpc/handlers/NFTInfo.cpp b/src/rpc/handlers/NFTInfo.cpp index cc416cdea..8fd5f1109 100644 --- a/src/rpc/handlers/NFTInfo.cpp +++ b/src/rpc/handlers/NFTInfo.cpp @@ -42,7 +42,7 @@ NFTInfoHandler::process(NFTInfoHandler::Input const& input, Context const& ctx) auto const maybeNft = sharedPtrBackend_->fetchNFT(tokenID, lgrInfo.seq, ctx.yield); if (not maybeNft.has_value()) - return Error{Status{RippledError::RpcObjectNotFound, "NFT not found"}}; + return Error{Status{XrpldError::RpcObjectNotFound, "NFT not found"}}; // TODO - this formatting is exactly the same and SHOULD REMAIN THE SAME // for each element of the `nfts_by_issuer` API. We should factor this out diff --git a/src/rpc/handlers/NFTInfo.hpp b/src/rpc/handlers/NFTInfo.hpp index 02fffc86c..2a1c84f36 100644 --- a/src/rpc/handlers/NFTInfo.hpp +++ b/src/rpc/handlers/NFTInfo.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -20,7 +20,7 @@ namespace rpc { * * For more details see: https://xrpl.org/nft_info.html */ -class NFTInfoHandler : public rpc::spec::HandlerFor { +class NFTInfoHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/NFTOffersCommon.cpp b/src/rpc/handlers/NFTOffersCommon.cpp index 40a8f4788..a1a584b11 100644 --- a/src/rpc/handlers/NFTOffersCommon.cpp +++ b/src/rpc/handlers/NFTOffersCommon.cpp @@ -87,7 +87,7 @@ NFTOffersHandlerBase::iterateOfferDirectory( // TODO: just check for existence without pulling if (not sharedPtrBackend_->fetchLedgerObject(directory.key, lgrInfo.seq, yield)) - return Error{Status{RippledError::RpcObjectNotFound, "notFound"}}; + return Error{Status{XrpldError::RpcObjectNotFound, "notFound"}}; auto output = Output{.nftID = xrpl::strHex(input.nftID), .offers = {}, .limit = {}, .marker = {}}; @@ -113,7 +113,7 @@ NFTOffersHandlerBase::iterateOfferDirectory( if (!sle || sle->getFieldU16(xrpl::sfLedgerEntryType) != xrpl::ltNFTOKEN_OFFER || tokenID != sle->getFieldH256(xrpl::sfNFTokenID)) { - return Error{Status{RippledError::RpcInvalidParams}}; + return Error{Status{XrpldError::RpcInvalidParams}}; } startHint = sle->getFieldU64(xrpl::sfNFTokenOfferNode); diff --git a/src/rpc/handlers/NFTOffersCommon.hpp b/src/rpc/handlers/NFTOffersCommon.hpp index 69f749e11..46edc3048 100644 --- a/src/rpc/handlers/NFTOffersCommon.hpp +++ b/src/rpc/handlers/NFTOffersCommon.hpp @@ -1,12 +1,12 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include -#include #include #include #include @@ -24,8 +24,7 @@ namespace rpc { /** * @brief Contains common functionality for handling the `nft_offers` command */ -class NFTOffersHandlerBase - : public rpc::spec::HandlerFor { +class NFTOffersHandlerBase : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/NFTsByIssuer.cpp b/src/rpc/handlers/NFTsByIssuer.cpp index 43f620e19..18fd0bbfc 100644 --- a/src/rpc/handlers/NFTsByIssuer.cpp +++ b/src/rpc/handlers/NFTsByIssuer.cpp @@ -48,7 +48,7 @@ NFTsByIssuerHandler::process(NFTsByIssuerHandler::Input const& input, Context co ); if (!accountLedgerObject) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; auto const cursor = input.marker; diff --git a/src/rpc/handlers/NFTsByIssuer.hpp b/src/rpc/handlers/NFTsByIssuer.hpp index 59209d72a..a4168c633 100644 --- a/src/rpc/handlers/NFTsByIssuer.hpp +++ b/src/rpc/handlers/NFTsByIssuer.hpp @@ -1,12 +1,12 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include -#include #include #include @@ -20,8 +20,7 @@ namespace rpc { /** * @brief Handler for the `nfts_by_issuer` command */ -class NFTsByIssuerHandler - : public rpc::spec::HandlerFor { +class NFTsByIssuerHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/NoRippleCheck.cpp b/src/rpc/handlers/NoRippleCheck.cpp index 7602153d5..75647808e 100644 --- a/src/rpc/handlers/NoRippleCheck.cpp +++ b/src/rpc/handlers/NoRippleCheck.cpp @@ -56,7 +56,7 @@ NoRippleCheckHandler::process(NoRippleCheckHandler::Input const& input, Context auto const accountObj = sharedPtrBackend_->fetchLedgerObject(keylet, lgrInfo.seq, ctx.yield); if (!accountObj) - return Error{Status{RippledError::RpcActNotFound}}; + return Error{Status{XrpldError::RpcActNotFound}}; auto it = xrpl::SerialIter{accountObj->data(), accountObj->size()}; auto sle = xrpl::SLE{it, keylet}; diff --git a/src/rpc/handlers/NoRippleCheck.hpp b/src/rpc/handlers/NoRippleCheck.hpp index f32088271..116511163 100644 --- a/src/rpc/handlers/NoRippleCheck.hpp +++ b/src/rpc/handlers/NoRippleCheck.hpp @@ -1,12 +1,12 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include -#include #include #include @@ -26,8 +26,7 @@ namespace rpc { * * For more details see: https://xrpl.org/noripple_check.html */ -class NoRippleCheckHandler - : public rpc::spec::HandlerFor { +class NoRippleCheckHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/ServerInfo.hpp b/src/rpc/handlers/ServerInfo.hpp index e5982f4e1..b8a7ff574 100644 --- a/src/rpc/handlers/ServerInfo.hpp +++ b/src/rpc/handlers/ServerInfo.hpp @@ -6,6 +6,7 @@ #include "etl/LoadBalancerInterface.hpp" #include "feed/SubscriptionManagerInterface.hpp" #include "rpc/JS.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include "util/Assert.hpp" #include "util/Concepts.hpp" @@ -16,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -47,8 +47,7 @@ namespace rpc { * @tparam ClockType Clock used for the output time and the ledger age */ template -class BaseServerInfoHandler - : public rpc::spec::HandlerFor { +class BaseServerInfoHandler : public rpc::HandlerFor { static constexpr auto kBackendCountersKey = "backend_counters"; std::shared_ptr backend_; @@ -166,11 +165,11 @@ public: ctx.yield ); if (not lgrInfo.has_value()) - return Error{Status{RippledError::RpcInternal}}; + return Error{Status{XrpldError::RpcInternal}}; auto const fees = backend_->fetchFees(lgrInfo->seq, ctx.yield); if (not fees.has_value()) - return Error{Status{RippledError::RpcInternal}}; + return Error{Status{XrpldError::RpcInternal}}; auto output = Output{}; auto const sinceEpoch = duration_cast(output.info.time.time_since_epoch()).count(); diff --git a/src/rpc/handlers/Subscribe.hpp b/src/rpc/handlers/Subscribe.hpp index 9d9e4c61f..e8885a85d 100644 --- a/src/rpc/handlers/Subscribe.hpp +++ b/src/rpc/handlers/Subscribe.hpp @@ -4,6 +4,7 @@ #include "data/BackendInterface.hpp" #include "feed/SubscriptionManagerInterface.hpp" #include "feed/Types.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include @@ -11,7 +12,6 @@ #include #include #include -#include #include #include @@ -29,7 +29,7 @@ namespace rpc { * For more details see: https://xrpl.org/subscribe.html */ -class SubscribeHandler : public rpc::spec::HandlerFor { +class SubscribeHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; std::shared_ptr amendmentCenter_; std::shared_ptr subscriptions_; diff --git a/src/rpc/handlers/TransactionEntry.cpp b/src/rpc/handlers/TransactionEntry.cpp index 6e0f09de0..895c0b015 100644 --- a/src/rpc/handlers/TransactionEntry.cpp +++ b/src/rpc/handlers/TransactionEntry.cpp @@ -52,7 +52,7 @@ TransactionEntryHandler::process( // is in a different ledger than the one specified. if (!dbRet || dbRet->ledgerSequence != output.ledgerHeader->seq) { return Error{ - Status{RippledError::RpcTxnNotFound, "transactionNotFound", "Transaction not found."} + Status{XrpldError::RpcTxnNotFound, "transactionNotFound", "Transaction not found."} }; } diff --git a/src/rpc/handlers/TransactionEntry.hpp b/src/rpc/handlers/TransactionEntry.hpp index 4d48453a2..2d782cd76 100644 --- a/src/rpc/handlers/TransactionEntry.hpp +++ b/src/rpc/handlers/TransactionEntry.hpp @@ -1,12 +1,12 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include #include -#include #include #include @@ -24,7 +24,7 @@ namespace rpc { * For more details see: https://xrpl.org/transaction_entry.html */ class TransactionEntryHandler - : public rpc::spec::HandlerFor { + : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/rpc/handlers/Tx.hpp b/src/rpc/handlers/Tx.hpp index 5c45c1f90..63fb6d20a 100644 --- a/src/rpc/handlers/Tx.hpp +++ b/src/rpc/handlers/Tx.hpp @@ -5,6 +5,7 @@ #include "etl/ETLServiceInterface.hpp" #include "rpc/JS.hpp" #include "rpc/RPCHelpers.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include "util/Assert.hpp" @@ -15,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -35,7 +35,7 @@ namespace rpc { * * For more details see: https://xrpl.org/tx.html */ -class TxHandler : public rpc::spec::HandlerFor { +class TxHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; std::shared_ptr etl_; @@ -91,20 +91,20 @@ public: process(Input const& input, Context const& ctx) const { if (input.ctid && input.transaction) // ambiguous identifier - return Error{Status{RippledError::RpcInvalidParams}}; + return Error{Status{XrpldError::RpcInvalidParams}}; if (!input.ctid && !input.transaction) // at least one identifier must be supplied - return Error{Status{RippledError::RpcInvalidParams}}; + return Error{Status{XrpldError::RpcInvalidParams}}; static constexpr auto kMaxLedgerRange = 1000u; auto const rangeSupplied = input.minLedger && input.maxLedger; if (rangeSupplied) { if (*input.minLedger > *input.maxLedger) - return Error{Status{RippledError::RpcInvalidLgrRange}}; + return Error{Status{XrpldError::RpcInvalidLgrRange}}; if (*input.maxLedger - *input.minLedger > kMaxLedgerRange) - return Error{Status{RippledError::RpcExcessiveLgrRange}}; + return Error{Status{XrpldError::RpcExcessiveLgrRange}}; } std::optional currentNetId = std::nullopt; @@ -116,13 +116,13 @@ public: if (input.ctid) { auto const ctid = rpc::decodeCTID(*input.ctid); if (!ctid) - return Error{Status{RippledError::RpcInvalidParams}}; + return Error{Status{XrpldError::RpcInvalidParams}}; auto const [lgrSeq, txnIdx, netId] = *ctid; // when current network id is available, let us check the network id from parameter if (currentNetId && netId != *currentNetId) { return Error{Status{ - RippledError::RpcWrongNetwork, + XrpldError::RpcWrongNetwork, fmt::format( "Wrong network. You should submit this request to a node running on " "NetworkID: {}", @@ -149,13 +149,12 @@ public: range->minSequence <= *input.minLedger; // NOLINTEND(bugprone-unchecked-optional-access) - boost::json::object extra; - extra["searched_all"] = searchedAll; - - return Error{Status{RippledError::RpcTxnNotFound, std::move(extra)}}; + return Error{ + Status{XrpldError::RpcTxnNotFound, ExtraInfo{{"searched_all", searchedAll}}} + }; } - return Error{Status{RippledError::RpcTxnNotFound}}; + return Error{Status{XrpldError::RpcTxnNotFound}}; } auto const [txn, meta] = diff --git a/src/rpc/handlers/Unsubscribe.hpp b/src/rpc/handlers/Unsubscribe.hpp index 4ab9c43be..84de91f42 100644 --- a/src/rpc/handlers/Unsubscribe.hpp +++ b/src/rpc/handlers/Unsubscribe.hpp @@ -2,9 +2,9 @@ #include "feed/SubscriptionManagerInterface.hpp" #include "feed/Types.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" -#include #include #include @@ -22,7 +22,7 @@ namespace rpc { * For more details see: https://xrpl.org/unsubscribe.html */ -class UnsubscribeHandler : public rpc::spec::HandlerFor { +class UnsubscribeHandler : public rpc::HandlerFor { std::shared_ptr subscriptions_; public: diff --git a/src/rpc/handlers/VaultInfo.cpp b/src/rpc/handlers/VaultInfo.cpp index 9449ee880..05578d9a4 100644 --- a/src/rpc/handlers/VaultInfo.cpp +++ b/src/rpc/handlers/VaultInfo.cpp @@ -88,7 +88,7 @@ VaultInfoHandler::process(VaultInfoHandler::Input const& input, Context const& c sharedPtrBackend_->fetchLedgerObject(accountKeylet.key, lgrInfo.seq, ctx.yield); if (!accountLedgerObject) - return std::unexpected{Status{RippledError::RpcEntryNotFound}}; + return std::unexpected{Status{XrpldError::RpcEntryNotFound}}; } return xrpl::keylet::vault(accountID, xrpl::SeqProxy::rawSequence(*input.tnxSequence)); @@ -105,7 +105,7 @@ VaultInfoHandler::process(VaultInfoHandler::Input const& input, Context const& c sharedPtrBackend_->fetchLedgerObject(vaultKeylet->key, lgrInfo.seq, ctx.yield); if (not vaultLedgerObject) - return Error{Status{RippledError::RpcEntryNotFound, "vault object not found."}}; + return Error{Status{XrpldError::RpcEntryNotFound, "vault object not found."}}; xrpl::STLedgerEntry const vaultSle{ xrpl::SerialIter{vaultLedgerObject->data(), vaultLedgerObject->size()}, vaultKeylet->key @@ -116,7 +116,7 @@ VaultInfoHandler::process(VaultInfoHandler::Input const& input, Context const& c sharedPtrBackend_->fetchLedgerObject(issuanceKeylet, lgrInfo.seq, ctx.yield); if (not issuanceObject) - return Error{Status{RippledError::RpcEntryNotFound, "issuance object not found."}}; + return Error{Status{XrpldError::RpcEntryNotFound, "issuance object not found."}}; xrpl::STLedgerEntry const issuanceSle{ xrpl::SerialIter{issuanceObject->data(), issuanceObject->size()}, issuanceKeylet diff --git a/src/rpc/handlers/VaultInfo.hpp b/src/rpc/handlers/VaultInfo.hpp index 9a7a3a2b4..28c743673 100644 --- a/src/rpc/handlers/VaultInfo.hpp +++ b/src/rpc/handlers/VaultInfo.hpp @@ -1,11 +1,11 @@ #pragma once #include "data/BackendInterface.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include #include -#include #include #include @@ -16,7 +16,7 @@ namespace rpc { /** * @brief The vault_info command retrieves information about a vault, currency, shares etc. */ -class VaultInfoHandler : public rpc::spec::HandlerFor { +class VaultInfoHandler : public rpc::HandlerFor { std::shared_ptr sharedPtrBackend_; public: diff --git a/src/web/LoadWarning.hpp b/src/web/LoadWarning.hpp index 189a08244..25e858fb6 100644 --- a/src/web/LoadWarning.hpp +++ b/src/web/LoadWarning.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include diff --git a/src/web/RPCServerHandler.hpp b/src/web/RPCServerHandler.hpp index f4c1520e2..78ddd8849 100644 --- a/src/web/RPCServerHandler.hpp +++ b/src/web/RPCServerHandler.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/src/web/impl/ErrorHandling.hpp b/src/web/impl/ErrorHandling.hpp index f14e6131c..11d56b397 100644 --- a/src/web/impl/ErrorHandling.hpp +++ b/src/web/impl/ErrorHandling.hpp @@ -102,7 +102,7 @@ public: sendInternalError() const { connection_->send( - boost::json::serialize(composeError(rpc::RippledError::RpcInternal)), + boost::json::serialize(composeError(rpc::XrpldError::RpcInternal)), boost::beast::http::status::internal_server_error ); } @@ -111,7 +111,7 @@ public: sendNotReadyError() const { connection_->send( - boost::json::serialize(composeError(rpc::RippledError::RpcNotReady)), + boost::json::serialize(composeError(rpc::XrpldError::RpcNotReady)), boost::beast::http::status::ok ); } @@ -121,12 +121,12 @@ public: { if (connection_->upgraded) { connection_->send( - boost::json::serialize(rpc::makeError(rpc::RippledError::RpcTooBusy)), + boost::json::serialize(rpc::makeError(rpc::XrpldError::RpcTooBusy)), boost::beast::http::status::ok ); } else { connection_->send( - boost::json::serialize(rpc::makeError(rpc::RippledError::RpcTooBusy)), + boost::json::serialize(rpc::makeError(rpc::XrpldError::RpcTooBusy)), boost::beast::http::status::service_unavailable ); } @@ -137,7 +137,7 @@ public: { if (connection_->upgraded) { connection_->send( - boost::json::serialize(rpc::makeError(rpc::RippledError::RpcBadSyntax)) + boost::json::serialize(rpc::makeError(rpc::XrpldError::RpcBadSyntax)) ); } else { connection_->send( diff --git a/src/web/impl/HttpBase.hpp b/src/web/impl/HttpBase.hpp index a21af1738..a08639e61 100644 --- a/src/web/impl/HttpBase.hpp +++ b/src/web/impl/HttpBase.hpp @@ -294,7 +294,7 @@ public: return sender_(httpResponse( http::status::internal_server_error, "application/json", - boost::json::serialize(rpc::makeError(rpc::RippledError::RpcInternal)) + boost::json::serialize(rpc::makeError(rpc::XrpldError::RpcInternal)) )); } } @@ -305,7 +305,7 @@ public: sender_(httpResponse( http::status::service_unavailable, "text/plain", - boost::json::serialize(rpc::makeError(rpc::RippledError::RpcSlowDown)) + boost::json::serialize(rpc::makeError(rpc::XrpldError::RpcSlowDown)) )); } diff --git a/src/web/impl/WsBase.hpp b/src/web/impl/WsBase.hpp index 4022b2a9e..87ddef2bc 100644 --- a/src/web/impl/WsBase.hpp +++ b/src/web/impl/WsBase.hpp @@ -152,7 +152,7 @@ public: void sendSlowDown(std::string const& request) override { - sendError(rpc::RippledError::RpcSlowDown, request); + sendError(rpc::XrpldError::RpcSlowDown, request); } /** @@ -282,7 +282,7 @@ public: try { (*handler_)(requestStr, shared_from_this()); } catch (std::exception const&) { - sendError(rpc::RippledError::RpcInternal, std::move(requestStr)); + sendError(rpc::XrpldError::RpcInternal, std::move(requestStr)); } doRead(); @@ -290,7 +290,7 @@ public: private: void - sendError(rpc::RippledError error, std::string requestStr) + sendError(rpc::XrpldError error, std::string requestStr) { auto e = rpc::makeError(error); diff --git a/src/web/ng/RPCServerHandler.hpp b/src/web/ng/RPCServerHandler.hpp index ac50f46ef..afc9e612d 100644 --- a/src/web/ng/RPCServerHandler.hpp +++ b/src/web/ng/RPCServerHandler.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -347,7 +348,7 @@ private: static Response makeSlowDownResponse(Request const& request, std::optional requestJson) { - auto error = rpc::makeError(rpc::RippledError::RpcSlowDown); + auto error = rpc::makeError(rpc::XrpldError::RpcSlowDown); if (not request.isHttp()) { try { diff --git a/src/web/ng/impl/ErrorHandling.cpp b/src/web/ng/impl/ErrorHandling.cpp index a1b5bebe3..496c29817 100644 --- a/src/web/ng/impl/ErrorHandling.cpp +++ b/src/web/ng/impl/ErrorHandling.cpp @@ -111,16 +111,14 @@ Response ErrorHelper::makeInternalError() const { return Response{ - http::status::internal_server_error, - composeError(rpc::RippledError::RpcInternal), - rawRequest_ + http::status::internal_server_error, composeError(rpc::XrpldError::RpcInternal), rawRequest_ }; } Response ErrorHelper::makeNotReadyError() const { - return Response{http::status::ok, composeError(rpc::RippledError::RpcNotReady), rawRequest_}; + return Response{http::status::ok, composeError(rpc::XrpldError::RpcNotReady), rawRequest_}; } Response @@ -129,15 +127,13 @@ ErrorHelper::makeTooBusyError() const if (not rawRequest_.get().isHttp()) { return Response{ http::status::too_many_requests, - rpc::makeError(rpc::RippledError::RpcTooBusy), + rpc::makeError(rpc::XrpldError::RpcTooBusy), rawRequest_ }; } return Response{ - http::status::service_unavailable, - rpc::makeError(rpc::RippledError::RpcTooBusy), - rawRequest_ + http::status::service_unavailable, rpc::makeError(rpc::XrpldError::RpcTooBusy), rawRequest_ }; } @@ -146,7 +142,7 @@ ErrorHelper::makeJsonParsingError() const { if (not rawRequest_.get().isHttp()) { return Response{ - http::status::bad_request, rpc::makeError(rpc::RippledError::RpcBadSyntax), rawRequest_ + http::status::bad_request, rpc::makeError(rpc::XrpldError::RpcBadSyntax), rawRequest_ }; } @@ -162,7 +158,7 @@ ErrorHelper::composeError(rpc::Status const& error) const } boost::json::object -ErrorHelper::composeError(rpc::RippledError error) const +ErrorHelper::composeError(rpc::XrpldError error) const { return composeErrorImpl(error, rawRequest_, request_); } diff --git a/src/web/ng/impl/ErrorHandling.hpp b/src/web/ng/impl/ErrorHandling.hpp index ab7667649..4882eb4b9 100644 --- a/src/web/ng/impl/ErrorHandling.hpp +++ b/src/web/ng/impl/ErrorHandling.hpp @@ -92,7 +92,7 @@ public: * @return The composed json object. */ [[nodiscard]] boost::json::object - composeError(rpc::RippledError error) const; + composeError(rpc::XrpldError error) const; }; } // namespace web::ng::impl diff --git a/tests/common/rpc/FakesAndMocks.cpp b/tests/common/rpc/FakesAndMocks.cpp index 62a824527..aa860ebb9 100644 --- a/tests/common/rpc/FakesAndMocks.cpp +++ b/tests/common/rpc/FakesAndMocks.cpp @@ -1,6 +1,8 @@ #include "rpc/FakesAndMocks.hpp" +#include #include -#include // IWYU pragma: keep +#include // IWYU pragma: keep +#include // IWYU pragma: keep -template struct rpc::spec::HandlerFor; +template struct rpc::spec::HandlerFor; diff --git a/tests/common/rpc/FakesAndMocks.hpp b/tests/common/rpc/FakesAndMocks.hpp index 5505502c8..9a5e8042d 100644 --- a/tests/common/rpc/FakesAndMocks.hpp +++ b/tests/common/rpc/FakesAndMocks.hpp @@ -1,6 +1,7 @@ #pragma once #include "rpc/Errors.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include @@ -12,7 +13,6 @@ #include #include #include -#include #include #include @@ -112,7 +112,7 @@ specFor(TypedInput const*) noexcept } // namespace typed_fake -class TypedHandlerFake : public rpc::spec::HandlerFor { +class TypedHandlerFake : public rpc::HandlerFor { public: using Output = TestOutput; using Result = rpc::HandlerReturnType; @@ -124,7 +124,7 @@ public: } }; -class FailingTypedHandlerFake : public rpc::spec::HandlerFor { +class FailingTypedHandlerFake : public rpc::HandlerFor { public: using Output = TestOutput; using Result = rpc::HandlerReturnType; diff --git a/tests/unit/app/WebHandlersTests.cpp b/tests/unit/app/WebHandlersTests.cpp index 5377ef479..974d72a20 100644 --- a/tests/unit/app/WebHandlersTests.cpp +++ b/tests/unit/app/WebHandlersTests.cpp @@ -211,7 +211,7 @@ TEST_F(RequestHandlerTest, RpcHandlerThrows) auto const body = boost::json::parse(httpResponse.body()).as_object(); EXPECT_EQ(body.at("error").as_string(), "internal"); - EXPECT_EQ(body.at("error_code").as_int64(), rpc::RippledError::RpcInternal); + EXPECT_EQ(body.at("error_code").as_int64(), rpc::XrpldError::RpcInternal); EXPECT_EQ(body.at("status").as_string(), "error"); }); } diff --git a/tests/unit/rpc/ErrorTests.cpp b/tests/unit/rpc/ErrorTests.cpp index 5952069aa..eff670a21 100644 --- a/tests/unit/rpc/ErrorTests.cpp +++ b/tests/unit/rpc/ErrorTests.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -50,17 +51,17 @@ check( TEST(RPCErrorsTest, StatusAsBool) { // Only RpcSuccess status should return false - EXPECT_FALSE(Status{RippledError::RpcSuccess}); + EXPECT_FALSE(Status{XrpldError::RpcSuccess}); // true should be returned for any error state, we just test a few CombinedError const errors[]{ - RippledError::RpcInvalidParams, - RippledError::RpcUnknownCommand, - RippledError::RpcTooBusy, - RippledError::RpcNoNetwork, - RippledError::RpcWrongNetwork, - RippledError::RpcActMalformed, - RippledError::RpcBadMarket, + XrpldError::RpcInvalidParams, + XrpldError::RpcUnknownCommand, + XrpldError::RpcTooBusy, + XrpldError::RpcNoNetwork, + XrpldError::RpcWrongNetwork, + XrpldError::RpcActMalformed, + XrpldError::RpcBadMarket, ClioError::RpcMalformedCurrency, }; @@ -70,22 +71,20 @@ TEST(RPCErrorsTest, StatusAsBool) TEST(RPCErrorsTest, StatusEquals) { - EXPECT_EQ(Status{RippledError::RpcUnknown}, Status{RippledError::RpcUnknown}); - EXPECT_NE(Status{RippledError::RpcUnknown}, Status{RippledError::RpcInternal}); + EXPECT_EQ(Status{XrpldError::RpcUnknown}, Status{XrpldError::RpcUnknown}); + EXPECT_NE(Status{XrpldError::RpcUnknown}, Status{XrpldError::RpcInternal}); } TEST(RPCErrorsTest, SuccessToJSON) { - auto const status = Status{RippledError::RpcSuccess}; - check(makeError(status), "unknown", RippledError::RpcSuccess, "An unknown error code."); + auto const status = Status{XrpldError::RpcSuccess}; + check(makeError(status), "unknown", XrpldError::RpcSuccess, "An unknown error code."); } TEST(RPCErrorsTest, RippledErrorToJSON) { - auto const status = Status{RippledError::RpcInvalidParams}; - check( - makeError(status), "invalidParams", RippledError::RpcInvalidParams, "Invalid parameters." - ); + auto const status = Status{XrpldError::RpcInvalidParams}; + check(makeError(status), "invalidParams", XrpldError::RpcInvalidParams, "Invalid parameters."); } TEST(RPCErrorsTest, RippledErrorFromStringToJSON) @@ -96,14 +95,14 @@ TEST(RPCErrorsTest, RippledErrorFromStringToJSON) TEST(RPCErrorsTest, RippledErrorToJSONCustomMessage) { - auto const status = Status{RippledError::RpcInvalidParams, "custom"}; - check(makeError(status), "invalidParams", RippledError::RpcInvalidParams, "custom"); + auto const status = Status{XrpldError::RpcInvalidParams, "custom"}; + check(makeError(status), "invalidParams", XrpldError::RpcInvalidParams, "custom"); } TEST(RPCErrorsTest, RippledErrorToJSONCustomStrCodeAndMessage) { - auto const status = Status{RippledError::RpcInvalidParams, "customCode", "customMessage"}; - check(makeError(status), "customCode", RippledError::RpcInvalidParams, "customMessage"); + auto const status = Status{XrpldError::RpcInvalidParams, "customCode", "customMessage"}; + check(makeError(status), "customCode", XrpldError::RpcInvalidParams, "customMessage"); } TEST(RPCErrorsTest, ClioErrorToJSON) @@ -224,7 +223,7 @@ INSTANTIATE_TEST_SUITE_P( }, StatusStreamTestBundle{ .testName = "StatusWithRippledError", - .status = Status{RippledError::RpcSuccess}, + .status = Status{XrpldError::RpcSuccess}, .expectedOutput = "Code: 0, Message: An unknown error code." }, StatusStreamTestBundle{ @@ -235,7 +234,7 @@ INSTANTIATE_TEST_SUITE_P( }, StatusStreamTestBundle{ .testName = "StatusWithCodeAndExtraInfo", - .status = Status{ClioError::RpcForwardingConnectionError, boost::json::object{}}, + .status = Status{ClioError::RpcForwardingConnectionError, ExtraInfo{}}, .expectedOutput = "Code: 7000, Message: Couldn't connect to rippled., Extra Info: {}" }, StatusStreamTestBundle{ @@ -245,7 +244,7 @@ INSTANTIATE_TEST_SUITE_P( }, StatusStreamTestBundle{ .testName = "StatusWithRippledErrorAndMessage", - .status = Status{RippledError::RpcSuccess, "test message."}, + .status = Status{XrpldError::RpcSuccess, "test message."}, .expectedOutput = "Code: 0, Message: test message." }, StatusStreamTestBundle{ diff --git a/tests/unit/rpc/RPCEngineTests.cpp b/tests/unit/rpc/RPCEngineTests.cpp index 0bfae0b62..8c21d4d53 100644 --- a/tests/unit/rpc/RPCEngineTests.cpp +++ b/tests/unit/rpc/RPCEngineTests.cpp @@ -128,7 +128,7 @@ generateTestValuesForParametersTest() .isTooBusy = neverCalled, .isUnknownCmd = neverCalled, .handlerReturnError = false, - .status = rpc::Status{RippledError::RpcNoPermission}, + .status = rpc::Status{XrpldError::RpcNoPermission}, .response = std::nullopt}, {.testName = "BackendTooBusy", .isAdmin = false, @@ -138,7 +138,7 @@ generateTestValuesForParametersTest() .isTooBusy = true, .isUnknownCmd = neverCalled, .handlerReturnError = false, - .status = rpc::Status{RippledError::RpcTooBusy}, + .status = rpc::Status{XrpldError::RpcTooBusy}, .response = std::nullopt}, {.testName = "HandlerUnknown", .isAdmin = false, @@ -148,7 +148,7 @@ generateTestValuesForParametersTest() .isTooBusy = false, .isUnknownCmd = true, .handlerReturnError = false, - .status = rpc::Status{RippledError::RpcUnknownCommand}, + .status = rpc::Status{XrpldError::RpcUnknownCommand}, .response = std::nullopt}, {.testName = "HandlerReturnError", .isAdmin = false, @@ -281,7 +281,7 @@ TEST_F(RPCEngineTest, ThrowDatabaseError) auto const res = engine->buildResponse(ctx); ASSERT_FALSE(res.response.has_value()); - EXPECT_EQ(res.response.error(), Status{RippledError::RpcTooBusy}); + EXPECT_EQ(res.response.error(), Status{XrpldError::RpcTooBusy}); }); } @@ -313,7 +313,7 @@ TEST_F(RPCEngineTest, ThrowException) auto const res = engine->buildResponse(ctx); ASSERT_FALSE(res.response.has_value()); - EXPECT_EQ(res.response.error(), Status{RippledError::RpcInternal}); + EXPECT_EQ(res.response.error(), Status{XrpldError::RpcInternal}); }); } diff --git a/tests/unit/rpc/RPCHelpersTests.cpp b/tests/unit/rpc/RPCHelpersTests.cpp index f1ace39a2..982020603 100644 --- a/tests/unit/rpc/RPCHelpersTests.cpp +++ b/tests/unit/rpc/RPCHelpersTests.cpp @@ -638,7 +638,7 @@ TEST_F(RPCHelpersTest, ParseBookIssuerErrors) xrpl::Asset{xrpl::Issue{xrpl::xrpCurrency(), account}}, validGets, std::nullopt ); ASSERT_FALSE(book.has_value()); - EXPECT_TRUE(book.error().code == CombinedError{RippledError::RpcSrcIsrMalformed}); + EXPECT_TRUE(book.error().code == CombinedError{XrpldError::RpcSrcIsrMalformed}); EXPECT_EQ( book.error().message, "Unneeded field 'taker_pays.issuer' for XRP currency specification." @@ -653,7 +653,7 @@ TEST_F(RPCHelpersTest, ParseBookIssuerErrors) std::nullopt ); ASSERT_FALSE(book.has_value()); - EXPECT_TRUE(book.error().code == CombinedError{RippledError::RpcSrcIsrMalformed}); + EXPECT_TRUE(book.error().code == CombinedError{XrpldError::RpcSrcIsrMalformed}); EXPECT_EQ( book.error().message, "Invalid field 'taker_pays.issuer', expected non-XRP issuer." ); @@ -665,7 +665,7 @@ TEST_F(RPCHelpersTest, ParseBookIssuerErrors) validPays, xrpl::Asset{xrpl::Issue{xrpl::xrpCurrency(), account}}, std::nullopt ); ASSERT_FALSE(book.has_value()); - EXPECT_TRUE(book.error().code == CombinedError{RippledError::RpcDstIsrMalformed}); + EXPECT_TRUE(book.error().code == CombinedError{XrpldError::RpcDstIsrMalformed}); EXPECT_EQ( book.error().message, "Unneeded field 'taker_gets.issuer' for XRP currency specification." @@ -680,7 +680,7 @@ TEST_F(RPCHelpersTest, ParseBookIssuerErrors) std::nullopt ); ASSERT_FALSE(book.has_value()); - EXPECT_TRUE(book.error().code == CombinedError{RippledError::RpcDstIsrMalformed}); + EXPECT_TRUE(book.error().code == CombinedError{XrpldError::RpcDstIsrMalformed}); EXPECT_EQ( book.error().message, "Invalid field 'taker_gets.issuer', expected non-XRP issuer." ); @@ -705,7 +705,7 @@ TEST_F(RPCHelpersTest, ParseBookBadMarket) { auto const book = rpc::parseBook(usd, usd, std::nullopt); ASSERT_FALSE(book.has_value()); - EXPECT_TRUE(book.error().code == CombinedError{RippledError::RpcBadMarket}); + EXPECT_TRUE(book.error().code == CombinedError{XrpldError::RpcBadMarket}); EXPECT_EQ(rpc::makeError(book.error()).at("error_message").as_string(), "No such market."); } @@ -716,7 +716,7 @@ TEST_F(RPCHelpersTest, ParseBookBadMarket) auto const mpt = xrpl::Asset{xrpl::MPTIssue{mptId}}; auto const book = rpc::parseBook(mpt, mpt, std::nullopt); ASSERT_FALSE(book.has_value()); - EXPECT_TRUE(book.error().code == CombinedError{RippledError::RpcBadMarket}); + EXPECT_TRUE(book.error().code == CombinedError{XrpldError::RpcBadMarket}); EXPECT_EQ(rpc::makeError(book.error()).at("error_message").as_string(), "No such market."); } } @@ -729,7 +729,7 @@ TEST_F(RPCHelpersTest, ParseBookDomainMalformed) auto const book = rpc::parseBook(usd, xrp, std::string{"notavalidhex"}); ASSERT_FALSE(book.has_value()); - EXPECT_TRUE(book.error().code == CombinedError{RippledError::RpcDomainMalformed}); + EXPECT_TRUE(book.error().code == CombinedError{XrpldError::RpcDomainMalformed}); EXPECT_EQ(book.error().message, "Unable to parse domain."); } @@ -742,7 +742,7 @@ TEST_F(RPCHelpersTest, ParseBookDomainCheckedBeforeBadMarket) // domain before the "taker_gets same as taker_pays" check, so the domain error wins. auto const book = rpc::parseBook(usd, usd, std::string{"notavalidhex"}); ASSERT_FALSE(book.has_value()); - EXPECT_TRUE(book.error().code == CombinedError{RippledError::RpcDomainMalformed}); + EXPECT_TRUE(book.error().code == CombinedError{XrpldError::RpcDomainMalformed}); EXPECT_EQ(book.error().message, "Unable to parse domain."); } @@ -768,7 +768,7 @@ TEST_F(RPCHelpersTest, ParseBookCurrencyOverloadDelegates) xrpl::toCurrency("USD"), account, xrpl::toCurrency("USD"), account, std::nullopt ); ASSERT_FALSE(book.has_value()); - EXPECT_TRUE(book.error().code == CombinedError{RippledError::RpcBadMarket}); + EXPECT_TRUE(book.error().code == CombinedError{XrpldError::RpcBadMarket}); EXPECT_EQ(rpc::makeError(book.error()).at("error_message").as_string(), "No such market."); } } @@ -2059,7 +2059,7 @@ TEST_F(RPCHelpersTest, LedgerHeaderFromSpecifierCurrentRejected) kSpecifierRangeMax ); ASSERT_FALSE(res.has_value()); - EXPECT_EQ(res.error().code, rpc::CombinedError{rpc::RippledError::RpcInvalidParams}); + EXPECT_EQ(res.error().code, rpc::CombinedError{rpc::XrpldError::RpcInvalidParams}); EXPECT_EQ(res.error().message, "ledgerIndexMalformed"); }); } @@ -2076,7 +2076,7 @@ TEST_F(RPCHelpersTest, LedgerHeaderFromSpecifierClosedRejected) kSpecifierRangeMax ); ASSERT_FALSE(res.has_value()); - EXPECT_EQ(res.error().code, rpc::CombinedError{rpc::RippledError::RpcInvalidParams}); + EXPECT_EQ(res.error().code, rpc::CombinedError{rpc::XrpldError::RpcInvalidParams}); EXPECT_EQ(res.error().message, "ledgerIndexMalformed"); }); } diff --git a/tests/unit/rpc/handlers/AccountCurrenciesTests.cpp b/tests/unit/rpc/handlers/AccountCurrenciesTests.cpp index f48a8c5f3..85c3d3ea9 100644 --- a/tests/unit/rpc/handlers/AccountCurrenciesTests.cpp +++ b/tests/unit/rpc/handlers/AccountCurrenciesTests.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/unit/rpc/handlers/AccountInfoTests.cpp b/tests/unit/rpc/handlers/AccountInfoTests.cpp index ef08161f0..ade189ff2 100644 --- a/tests/unit/rpc/handlers/AccountInfoTests.cpp +++ b/tests/unit/rpc/handlers/AccountInfoTests.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/unit/rpc/handlers/AccountLinesTests.cpp b/tests/unit/rpc/handlers/AccountLinesTests.cpp index 5a63192a0..e53598c9b 100644 --- a/tests/unit/rpc/handlers/AccountLinesTests.cpp +++ b/tests/unit/rpc/handlers/AccountLinesTests.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/unit/rpc/handlers/AccountOffersTests.cpp b/tests/unit/rpc/handlers/AccountOffersTests.cpp index ce3a63af1..961634679 100644 --- a/tests/unit/rpc/handlers/AccountOffersTests.cpp +++ b/tests/unit/rpc/handlers/AccountOffersTests.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/unit/rpc/handlers/CredentialHelpersTests.cpp b/tests/unit/rpc/handlers/CredentialHelpersTests.cpp index e10482746..1aadb5614 100644 --- a/tests/unit/rpc/handlers/CredentialHelpersTests.cpp +++ b/tests/unit/rpc/handlers/CredentialHelpersTests.cpp @@ -112,7 +112,7 @@ TEST_F(CredentialHelperTest, GetInvalidCredentialArray) ); ASSERT_FALSE(ret.has_value()); auto const status = ret.error(); - EXPECT_EQ(status, RippledError::RpcBadCredentials); + EXPECT_EQ(status, XrpldError::RpcBadCredentials); EXPECT_EQ(status.message, "credentials don't exist."); }); ctx_.run(); diff --git a/tests/unit/rpc/handlers/LedgerDataTests.cpp b/tests/unit/rpc/handlers/LedgerDataTests.cpp index c3d44bc03..d0f95b194 100644 --- a/tests/unit/rpc/handlers/LedgerDataTests.cpp +++ b/tests/unit/rpc/handlers/LedgerDataTests.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/unit/rpc/handlers/LedgerEntryTests.cpp b/tests/unit/rpc/handlers/LedgerEntryTests.cpp index b75ba417b..46dbe60aa 100644 --- a/tests/unit/rpc/handlers/LedgerEntryTests.cpp +++ b/tests/unit/rpc/handlers/LedgerEntryTests.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/unit/rpc/handlers/LedgerTests.cpp b/tests/unit/rpc/handlers/LedgerTests.cpp index 36fb9b1a8..c91433246 100644 --- a/tests/unit/rpc/handlers/LedgerTests.cpp +++ b/tests/unit/rpc/handlers/LedgerTests.cpp @@ -2,6 +2,7 @@ #include "rpc/Errors.hpp" #include "rpc/JS.hpp" #include "rpc/common/AnyHandler.hpp" +#include "rpc/common/SpecBackend.hpp" #include "rpc/common/Types.hpp" #include "rpc/handlers/Ledger.hpp" #include "util/HandlerBaseTestFixture.hpp" @@ -15,8 +16,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -1431,7 +1431,7 @@ struct RPCLedgerHandlerSpecCheckTestBundle { struct RPCLedgerHandlerSpecCheckTest : ::testing::TestWithParam { - rpc::spec::RpcSpecView spec = LedgerHandler::spec(2); + rpc::SpecView spec = LedgerHandler::spec(2); }; INSTANTIATE_TEST_SUITE_P( diff --git a/tests/unit/rpc/handlers/SubscribeTests.cpp b/tests/unit/rpc/handlers/SubscribeTests.cpp index 0f83a3b0d..218b806c7 100644 --- a/tests/unit/rpc/handlers/SubscribeTests.cpp +++ b/tests/unit/rpc/handlers/SubscribeTests.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/unit/rpc/handlers/TestHandlerTests.cpp b/tests/unit/rpc/handlers/TestHandlerTests.cpp index 3d3c9bd9c..949179286 100644 --- a/tests/unit/rpc/handlers/TestHandlerTests.cpp +++ b/tests/unit/rpc/handlers/TestHandlerTests.cpp @@ -58,7 +58,7 @@ TEST_F(RPCTestHandlerTest, HandlerErrorHandling) auto const err = rpc::makeError(output.result.error()); EXPECT_EQ(err.at("error").as_string(), "invalidParams"); - EXPECT_EQ(err.at("error_code").as_uint64(), rpc::RippledError::RpcInvalidParams); + EXPECT_EQ(err.at("error_code").as_uint64(), rpc::XrpldError::RpcInvalidParams); EXPECT_EQ(err.at("error_message").as_string(), "Invalid parameters."); }); } diff --git a/tests/unit/rpc/handlers/TxTests.cpp b/tests/unit/rpc/handlers/TxTests.cpp index 06611e3af..3fa377d3f 100644 --- a/tests/unit/rpc/handlers/TxTests.cpp +++ b/tests/unit/rpc/handlers/TxTests.cpp @@ -910,7 +910,7 @@ TEST_F(RPCTxTest, CTIDNotMatch) auto const err = rpc::makeError(output.result.error()); EXPECT_EQ(err.at("error").as_string(), "wrongNetwork"); - EXPECT_EQ(err.at("error_code").as_uint64(), rpc::RippledError::RpcWrongNetwork); + EXPECT_EQ(err.at("error_code").as_uint64(), rpc::XrpldError::RpcWrongNetwork); EXPECT_EQ( err.at("error_message").as_string(), "Wrong network. You should submit this request to a node running on NetworkID: 2" diff --git a/tests/unit/rpc/handlers/UnsubscribeTests.cpp b/tests/unit/rpc/handlers/UnsubscribeTests.cpp index 9d471f689..08c84676a 100644 --- a/tests/unit/rpc/handlers/UnsubscribeTests.cpp +++ b/tests/unit/rpc/handlers/UnsubscribeTests.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/unit/rpc/handlers/VaultInfoTests.cpp b/tests/unit/rpc/handlers/VaultInfoTests.cpp index ef4f94bdb..cb7595e02 100644 --- a/tests/unit/rpc/handlers/VaultInfoTests.cpp +++ b/tests/unit/rpc/handlers/VaultInfoTests.cpp @@ -210,7 +210,7 @@ TEST_F(RPCVaultInfoHandlerTest, InputHasOwnerButNotFoundResultsInError) ASSERT_FALSE(output); auto const err = rpc::makeError(output.result.error()); EXPECT_EQ(err.at("error").as_string(), "entryNotFound"); - EXPECT_EQ(err.at("error_code").as_uint64(), rpc::RippledError::RpcEntryNotFound); + EXPECT_EQ(err.at("error_code").as_uint64(), rpc::XrpldError::RpcEntryNotFound); EXPECT_EQ(err.at("error_message").as_string(), "Entry not found."); }); } @@ -242,7 +242,7 @@ TEST_F(RPCVaultInfoHandlerTest, VaultIDFailsVaultDeserializationReturnsEntryNotF ASSERT_FALSE(output); auto const err = rpc::makeError(output.result.error()); EXPECT_EQ(err.at("error").as_string(), "entryNotFound"); - EXPECT_EQ(err.at("error_code").as_uint64(), rpc::RippledError::RpcEntryNotFound); + EXPECT_EQ(err.at("error_code").as_uint64(), rpc::XrpldError::RpcEntryNotFound); EXPECT_EQ(err.at("error_message").as_string(), "vault object not found."); }); } @@ -293,7 +293,7 @@ TEST_F(RPCVaultInfoHandlerTest, MissingIssuanceObject) ASSERT_FALSE(output); auto const err = rpc::makeError(output.result.error()); EXPECT_EQ(err.at("error").as_string(), "entryNotFound"); - EXPECT_EQ(err.at("error_code").as_uint64(), rpc::RippledError::RpcEntryNotFound); + EXPECT_EQ(err.at("error_code").as_uint64(), rpc::XrpldError::RpcEntryNotFound); EXPECT_EQ(err.at("error_message").as_string(), "issuance object not found."); }); } diff --git a/tests/unit/web/RPCServerHandlerTests.cpp b/tests/unit/web/RPCServerHandlerTests.cpp index fb9879654..dcb84f80c 100644 --- a/tests/unit/web/RPCServerHandlerTests.cpp +++ b/tests/unit/web/RPCServerHandlerTests.cpp @@ -478,9 +478,7 @@ TEST_F(WebRPCServerHandlerTest, HTTPErrorPath) EXPECT_CALL(*rpcEngine, buildResponse(testing::_)) .WillOnce( testing::Return( - rpc::Result{ - rpc::Status{rpc::RippledError::RpcInvalidParams, "ledgerIndexMalformed"} - } + rpc::Result{rpc::Status{rpc::XrpldError::RpcInvalidParams, "ledgerIndexMalformed"}} ) ); @@ -533,9 +531,7 @@ TEST_F(WebRPCServerHandlerTest, WsErrorPath) EXPECT_CALL(*rpcEngine, buildResponse(testing::_)) .WillOnce( testing::Return( - rpc::Result{ - rpc::Status{rpc::RippledError::RpcInvalidParams, "ledgerIndexMalformed"} - } + rpc::Result{rpc::Status{rpc::XrpldError::RpcInvalidParams, "ledgerIndexMalformed"}} ) ); diff --git a/tests/unit/web/impl/ErrorHandlingTests.cpp b/tests/unit/web/impl/ErrorHandlingTests.cpp index a89d6f12d..9a93298d9 100644 --- a/tests/unit/web/impl/ErrorHandlingTests.cpp +++ b/tests/unit/web/impl/ErrorHandlingTests.cpp @@ -46,7 +46,7 @@ TEST_P(ErrorHandlingComposeErrorTest, composeError) { connection_->upgraded = GetParam().connectionUpgraded; ErrorHelper const errorHelper{connection_, GetParam().request}; - auto const result = errorHelper.composeError(rpc::RippledError::RpcNotReady); + auto const result = errorHelper.composeError(rpc::XrpldError::RpcNotReady); EXPECT_EQ(boost::json::serialize(result), boost::json::serialize(GetParam().expectedResult)); } @@ -135,7 +135,7 @@ INSTANTIATE_TEST_CASE_P( ErrorHandlingSendErrorTestBundle{ "UpgradedConnection", true, - rpc::Status{rpc::RippledError::RpcTooBusy}, + rpc::Status{rpc::XrpldError::RpcTooBusy}, R"JSON({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})JSON", boost::beast::http::status::ok }, @@ -177,7 +177,7 @@ INSTANTIATE_TEST_CASE_P( ErrorHandlingSendErrorTestBundle{ "NotUpgradedConnection_RippledError", false, - rpc::Status{rpc::RippledError::RpcTooBusy}, + rpc::Status{rpc::XrpldError::RpcTooBusy}, R"JSON({"result":{"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"}})JSON", boost::beast::http::status::bad_request }, diff --git a/tests/unit/web/ng/RPCServerHandlerTests.cpp b/tests/unit/web/ng/RPCServerHandlerTests.cpp index cda529f6e..88978b088 100644 --- a/tests/unit/web/ng/RPCServerHandlerTests.cpp +++ b/tests/unit/web/ng/RPCServerHandlerTests.cpp @@ -92,7 +92,7 @@ TEST_F(NgRpcServerHandlerTest, DosguardRejectedHttpRequest) EXPECT_EQ(responseHttp.result(), http::status::service_unavailable); auto const responseJson = boost::json::parse(responseHttp.body()).as_object(); - EXPECT_EQ(responseJson.at("error_code").as_int64(), rpc::RippledError::RpcSlowDown); + EXPECT_EQ(responseJson.at("error_code").as_int64(), rpc::XrpldError::RpcSlowDown); }); } @@ -108,7 +108,7 @@ TEST_F(NgRpcServerHandlerTest, DosguardRejectedWsRequest) auto const responseWs = boost::beast::buffers_to_string(response.asWsResponse()); auto const responseJson = boost::json::parse(responseWs).as_object(); - EXPECT_EQ(responseJson.at("error_code").as_int64(), rpc::RippledError::RpcSlowDown); + EXPECT_EQ(responseJson.at("error_code").as_int64(), rpc::XrpldError::RpcSlowDown); EXPECT_EQ(responseJson.at("request").as_string(), requestStr); }); } @@ -125,7 +125,7 @@ TEST_F(NgRpcServerHandlerTest, DosguardRejectedWsJsonRequest) auto const responseWs = boost::beast::buffers_to_string(response.asWsResponse()); auto const responseJson = boost::json::parse(responseWs).as_object(); - EXPECT_EQ(responseJson.at("error_code").as_int64(), rpc::RippledError::RpcSlowDown); + EXPECT_EQ(responseJson.at("error_code").as_int64(), rpc::XrpldError::RpcSlowDown); EXPECT_EQ(responseJson.at("request").as_string(), requestStr); EXPECT_EQ(responseJson.at("id").as_string(), "some id"); }); @@ -263,7 +263,7 @@ TEST_F(NgRpcServerHandlerTest, DosguardRejectedParsedRequest) EXPECT_EQ(responseHttp.result(), http::status::service_unavailable); auto const responseJson = boost::json::parse(responseHttp.body()).as_object(); - EXPECT_EQ(responseJson.at("error_code").as_int64(), rpc::RippledError::RpcSlowDown); + EXPECT_EQ(responseJson.at("error_code").as_int64(), rpc::XrpldError::RpcSlowDown); }); } @@ -287,7 +287,7 @@ TEST_F(NgRpcServerHandlerTest, DosguardAddsLoadWarning) EXPECT_EQ(responseHttp.result(), http::status::service_unavailable); auto const responseJson = boost::json::parse(responseHttp.body()).as_object(); - EXPECT_EQ(responseJson.at("error_code").as_int64(), rpc::RippledError::RpcSlowDown); + EXPECT_EQ(responseJson.at("error_code").as_int64(), rpc::XrpldError::RpcSlowDown); EXPECT_EQ(responseJson.at("warning").as_string(), "load"); EXPECT_EQ( diff --git a/tests/unit/web/ng/impl/ErrorHandlingTests.cpp b/tests/unit/web/ng/impl/ErrorHandlingTests.cpp index 2e16147e1..23a0b771e 100644 --- a/tests/unit/web/ng/impl/ErrorHandlingTests.cpp +++ b/tests/unit/web/ng/impl/ErrorHandlingTests.cpp @@ -60,7 +60,7 @@ TEST_P(NgErrorHandlingMakeErrorTest, MakeError) EXPECT_EQ(httpResponse.result(), GetParam().expectedStatus); std::string expectedContentType = "text/html"; - if (std::holds_alternative(GetParam().status.code)) + if (std::holds_alternative(GetParam().status.code)) expectedContentType = "application/json"; EXPECT_EQ(httpResponse.at(http::field::content_type), expectedContentType); @@ -74,7 +74,7 @@ INSTANTIATE_TEST_CASE_P( NgErrorHandlingMakeErrorTestBundle{ "WsRequest", false, - rpc::Status{rpc::RippledError::RpcTooBusy}, + rpc::Status{rpc::XrpldError::RpcTooBusy}, R"JSON({"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"})JSON", boost::beast::http::status::ok }, @@ -116,7 +116,7 @@ INSTANTIATE_TEST_CASE_P( NgErrorHandlingMakeErrorTestBundle{ "HttpRequest_RippledError", true, - rpc::Status{rpc::RippledError::RpcTooBusy}, + rpc::Status{rpc::XrpldError::RpcTooBusy}, R"JSON({"result":{"error":"tooBusy","error_code":9,"error_message":"The server is too busy to help you now.","status":"error","type":"response"}})JSON", boost::beast::http::status::bad_request }, @@ -300,7 +300,7 @@ TEST_P(NgErrorHandlingComposeErrorTest, ComposeError) { auto const request = makeRequest(GetParam().isHttp); ErrorHelper const errorHelper{request, GetParam().request}; - auto const response = errorHelper.composeError(rpc::Status{rpc::RippledError::RpcInternal}); + auto const response = errorHelper.composeError(rpc::Status{rpc::XrpldError::RpcInternal}); EXPECT_EQ(boost::json::serialize(response), GetParam().expectedMessage); }