From c8b42a7f4839b5b8c41df7ab3373fa1b5fc50da8 Mon Sep 17 00:00:00 2001 From: Sergey Kuznetsov Date: Wed, 13 May 2026 15:33:49 +0100 Subject: [PATCH] refactor: Improve RPC variable naming and handling (#7103) --- .../rpc/handlers/account/AccountObjects.cpp | 80 +++++++++---------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/src/xrpld/rpc/handlers/account/AccountObjects.cpp b/src/xrpld/rpc/handlers/account/AccountObjects.cpp index e17543b339..c544a6ff1a 100644 --- a/src/xrpld/rpc/handlers/account/AccountObjects.cpp +++ b/src/xrpld/rpc/handlers/account/AccountObjects.cpp @@ -59,12 +59,12 @@ getAccountObjects( // iterate NFT pages if the filter says so AND dirIndex == 0 bool iterateNFTPages = (!typeFilter.has_value() || typeMatchesFilter(typeFilter.value(), ltNFTOKEN_PAGE)) && - dirIndex == beast::kZERO; + dirIndex.isZero(); Keylet const firstNFTPage = keylet::nftpageMin(account); // we need to check the marker to see if it is an NFTTokenPage index. - if (iterateNFTPages && entryIndex != beast::kZERO) + if (iterateNFTPages && entryIndex.isNonZero()) { // if it is we will try to iterate the pages up to the limit // and then change over to the owner directory @@ -77,49 +77,44 @@ getAccountObjects( // this is a mutable version of limit, used to seamlessly switch // to iterating directory entries when nftokenpages are exhausted - uint32_t mlimit = limit; + uint32_t limitLeft = limit; // iterate NFTokenPages preferentially if (iterateNFTPages) { Keylet const first = - entryIndex == beast::kZERO ? firstNFTPage : Keylet{ltNFTOKEN_PAGE, entryIndex}; + entryIndex.isZero() ? firstNFTPage : Keylet{ltNFTOKEN_PAGE, entryIndex}; Keylet const last = keylet::nftpageMax(account); - // current key - uint256 ck = ledger.succ(first.key, last.key.next()).value_or(last.key); + auto currentKey = ledger.succ(first.key, last.key.next()).value_or(last.key); - // current page - auto cp = ledger.read(Keylet{ltNFTOKEN_PAGE, ck}); + auto currentPage = ledger.read(Keylet{ltNFTOKEN_PAGE, currentKey}); - while (cp) + while (currentPage) { - jvObjects.append(cp->getJson(JsonOptions::Values::None)); - auto const npm = (*cp)[~sfNextPageMin]; + jvObjects.append(currentPage->getJson(JsonOptions::Values::None)); + auto const npm = (*currentPage)[~sfNextPageMin]; if (npm) { - cp = ledger.read(Keylet(ltNFTOKEN_PAGE, *npm)); + currentPage = ledger.read(Keylet(ltNFTOKEN_PAGE, *npm)); } else { - cp = nullptr; + currentPage = nullptr; } - if (--mlimit == 0) + if (--limitLeft == 0 && currentPage) { - if (cp) - { - jvResult[jss::limit] = limit; - jvResult[jss::marker] = std::string("0,") + to_string(ck); - return true; - } + jvResult[jss::limit] = limit; + jvResult[jss::marker] = std::string("0,") + to_string(currentKey); + return true; } if (!npm) break; - ck = *npm; + currentKey = *npm; } // if execution reaches here then we're about to transition @@ -130,12 +125,12 @@ getAccountObjects( } auto const root = keylet::ownerDir(account); - auto found = false; + auto startEntryFound = false; if (dirIndex.isZero()) { dirIndex = root.key; - found = true; + startEntryFound = true; } auto dir = ledger.read({ltDIR_NODE, dirIndex}); @@ -144,7 +139,7 @@ getAccountObjects( // it's possible the user had nftoken pages but no // directory entries. If there's no nftoken page, we will // give empty array for account_objects. - if (mlimit >= limit) + if (limitLeft >= limit) jvResult[jss::account_objects] = json::ValueType::Array; // non-zero dirIndex validity was checked in the beginning of this @@ -156,33 +151,33 @@ getAccountObjects( return true; } - std::uint32_t i = 0; + std::uint32_t itemsAdded = 0; for (;;) { - auto const& entries = dir->getFieldV256(sfIndexes); - auto iter = entries.begin(); + auto const& dirEntries = dir->getFieldV256(sfIndexes); + auto entryIter = dirEntries.begin(); - if (!found) + if (!startEntryFound) { - iter = std::find(iter, entries.end(), entryIndex); - if (iter == entries.end()) + entryIter = std::find(entryIter, dirEntries.end(), entryIndex); + if (entryIter == dirEntries.end()) return false; - found = true; + startEntryFound = true; } // it's possible that the returned NFTPages exactly filled the // response. Check for that condition. - if (i == mlimit && mlimit < limit) + if (itemsAdded == limitLeft && limitLeft < limit && entryIter != dirEntries.end()) { jvResult[jss::limit] = limit; - jvResult[jss::marker] = to_string(dirIndex) + ',' + to_string(*iter); + jvResult[jss::marker] = to_string(dirIndex) + ',' + to_string(*entryIter); return true; } - for (; iter != entries.end(); ++iter) + for (; entryIter != dirEntries.end(); ++entryIter) { - auto const sleNode = ledger.read(keylet::child(*iter)); + auto const sleNode = ledger.read(keylet::child(*entryIter)); if (!typeFilter.has_value() || typeMatchesFilter(typeFilter.value(), sleNode->getType())) @@ -190,12 +185,12 @@ getAccountObjects( jvObjects.append(sleNode->getJson(JsonOptions::Values::None)); } - if (++i == mlimit) + if (++itemsAdded == limitLeft) { - if (++iter != entries.end()) + if (++entryIter != dirEntries.end()) { jvResult[jss::limit] = limit; - jvResult[jss::marker] = to_string(dirIndex) + ',' + to_string(*iter); + jvResult[jss::marker] = to_string(dirIndex) + ',' + to_string(*entryIter); return true; } @@ -212,13 +207,14 @@ getAccountObjects( if (!dir) return true; - if (i == mlimit) + if (itemsAdded == limitLeft) { - auto const& e = dir->getFieldV256(sfIndexes); - if (!e.empty()) + auto const& currentDirEntries = dir->getFieldV256(sfIndexes); + if (!currentDirEntries.empty()) { jvResult[jss::limit] = limit; - jvResult[jss::marker] = to_string(dirIndex) + ',' + to_string(*e.begin()); + jvResult[jss::marker] = + to_string(dirIndex) + ',' + to_string(*currentDirEntries.begin()); } return true;