From d619d1ec91dbe509ba11cf2909b94b16e96c29f0 Mon Sep 17 00:00:00 2001 From: Alex Kremer Date: Thu, 1 Oct 2026 17:49:54 +0100 Subject: [PATCH] chore: Conform to rpc-spec 0.1.21 (#3238) --- conan.lock | 2 +- conanfile.py | 2 +- src/rpc/Errors.hpp | 5 ----- src/rpc/handlers/LedgerEntry.cpp | 14 ++++++++++---- src/rpc/handlers/TransactionEntry.cpp | 6 +++++- tests/unit/rpc/ErrorTests.cpp | 4 ++-- tests/unit/rpc/handlers/LedgerEntryTests.cpp | 6 +++--- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/conan.lock b/conan.lock index ff828c988..924e442c0 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.19#870b2d3abcfbbf13b61c2d3c69495060%1790348286.187549", + "xrpl-rpc-spec/0.1.21#d536f87a2ae7d313452746cfa3ac4404%1790869005.122975", "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 7a0887db3..8db0b9dda 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.19", + "xrpl-rpc-spec/0.1.21", "xrpl/3.4.0", ] diff --git a/src/rpc/Errors.hpp b/src/rpc/Errors.hpp index 44d2e1618..63a86e157 100644 --- a/src/rpc/Errors.hpp +++ b/src/rpc/Errors.hpp @@ -18,11 +18,6 @@ struct ClioErrorInfo { std::string_view const message; }; -/** - * @brief A globally available rpc::Status that represents a successful state. - */ -static Status gOk; - /** * @brief Get the error info object from an clio-specific error code. * diff --git a/src/rpc/handlers/LedgerEntry.cpp b/src/rpc/handlers/LedgerEntry.cpp index fdf72d829..1a54e1b6c 100644 --- a/src/rpc/handlers/LedgerEntry.cpp +++ b/src/rpc/handlers/LedgerEntry.cpp @@ -256,10 +256,16 @@ resolveLocator(Input const& input, uint32_t apiVersion) } if (input.rippleStateAccount.has_value()) { - auto const& state = *input.rippleStateAccount; - return Locator{ - .key = xrpl::keylet::trustLine(state.accounts[0], state.accounts[1], state.currency).key - }; + return locatorFrom( + *input.rippleStateAccount, xrpl::ltRIPPLE_STATE, [](le::RippleStateEntry const& entry) { + return LocatorOrStatus{Locator{ + .key = xrpl::keylet::trustLine( + entry.accounts[0], entry.accounts[1], entry.currency + ) + .key + }}; + } + ); } if (input.escrow.has_value()) { diff --git a/src/rpc/handlers/TransactionEntry.cpp b/src/rpc/handlers/TransactionEntry.cpp index 895c0b015..3eb081b72 100644 --- a/src/rpc/handlers/TransactionEntry.cpp +++ b/src/rpc/handlers/TransactionEntry.cpp @@ -40,7 +40,11 @@ TransactionEntryHandler::process( output.apiVersion = ctx.apiVersion; output.ledgerHeader = *expectedLgrInfo; - auto const dbRet = sharedPtrBackend_->fetchTransaction(input.txHash, ctx.yield); + + // The spec rejects a missing or malformed tx_hash, so the hash is always present here + ASSERT(input.txHash.has_value(), "TransactionEntry's tx_hash must be validated by the spec"); + auto const dbRet = sharedPtrBackend_->fetchTransaction(*input.txHash, ctx.yield); + // Note: transaction_entry is meant to only search a specified ledger for // the specified transaction. tx searches the entire range of history. For // rippled, having two separate commands made sense, as tx would use SQLite diff --git a/tests/unit/rpc/ErrorTests.cpp b/tests/unit/rpc/ErrorTests.cpp index eff670a21..c32c6b94b 100644 --- a/tests/unit/rpc/ErrorTests.cpp +++ b/tests/unit/rpc/ErrorTests.cpp @@ -51,7 +51,7 @@ check( TEST(RPCErrorsTest, StatusAsBool) { // Only RpcSuccess status should return false - EXPECT_FALSE(Status{XrpldError::RpcSuccess}); + EXPECT_FALSE(Status{Status::kOK}); // true should be returned for any error state, we just test a few CombinedError const errors[]{ @@ -77,7 +77,7 @@ TEST(RPCErrorsTest, StatusEquals) TEST(RPCErrorsTest, SuccessToJSON) { - auto const status = Status{XrpldError::RpcSuccess}; + auto const status = Status{Status::kOK}; check(makeError(status), "unknown", XrpldError::RpcSuccess, "An unknown error code."); } diff --git a/tests/unit/rpc/handlers/LedgerEntryTests.cpp b/tests/unit/rpc/handlers/LedgerEntryTests.cpp index 46dbe60aa..fe9ead426 100644 --- a/tests/unit/rpc/handlers/LedgerEntryTests.cpp +++ b/tests/unit/rpc/handlers/LedgerEntryTests.cpp @@ -661,12 +661,12 @@ generateTestValuesForParametersTest() }, ParamTestCaseBundle{ - .testName = "InvalidRippleStateType", + .testName = "InvalidRippleStateIndex", .testJson = R"JSON({ "ripple_state": "123" })JSON", - .expectedError = "invalidParams", - .expectedErrorMessage = "Invalid parameters." + .expectedError = "malformedRequest", + .expectedErrorMessage = "Malformed request." }, ParamTestCaseBundle{