Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix nftData unique bug
  • Loading branch information
cindyyan317 committed Jul 25, 2024
commit ccdc5aa236321e4fb8f6e0e6dcee17faed81e42a
2 changes: 1 addition & 1 deletion src/data/BackendInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ BackendInterface::fetchLedgerObjectSeq(
) const
{
auto seq = doFetchLedgerObjectSeq(key, sequence, yield);
if (!seq)
if (!seq)
LOG(gLog.trace()) << "Missed in db";
return seq;
}
Expand Down
3 changes: 2 additions & 1 deletion src/data/BackendInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ class BackendInterface {
* @return The sequence in unit32_t on success; nullopt otherwise
*/
virtual std::optional<std::uint32_t>
doFetchLedgerObjectSeq(ripple::uint256 const& key, std::uint32_t sequence, boost::asio::yield_context yield) const = 0;
doFetchLedgerObjectSeq(ripple::uint256 const& key, std::uint32_t sequence, boost::asio::yield_context yield)
const = 0;

/**
* @brief The database-specific implementation for fetching ledger objects.
Expand Down
9 changes: 5 additions & 4 deletions src/data/CassandraBackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,12 @@ class BasicCassandraBackend : public BackendInterface {
{
LOG(log_.debug()) << "Fetching ledger object for seq " << sequence << ", key = " << ripple::to_string(key);
if (auto const res = executor_.read(yield, schema_->selectObject, key, sequence); res) {
if (auto const result = res->template get<Blob, std::uint32_t>(); result) {
auto [_ ,seq] = result.value();
if (auto const result = res->template get<Blob, std::uint32_t>(); result) {
auto [_, seq] = result.value();
return seq;
} LOG(log_.debug()) << "Could not fetch ledger object sequence - no rows";

}
LOG(log_.debug()) << "Could not fetch ledger object sequence - no rows";

} else {
LOG(log_.error()) << "Could not fetch ledger object sequence: " << res.error();
}
Expand Down
2 changes: 1 addition & 1 deletion src/etl/impl/LedgerLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class LedgerLoader {
// Remove all but the last NFTsData for each id. unique removes all but the first of a group, so we want to
// reverse sort by transaction index
std::sort(result.nfTokensData.begin(), result.nfTokensData.end(), [](NFTsData const& a, NFTsData const& b) {
return a.tokenID > b.tokenID && a.transactionIndex > b.transactionIndex;
return a.tokenID == b.tokenID ? a.transactionIndex > b.transactionIndex : a.tokenID > b.tokenID;
});

// Now we can unique the NFTs by tokenID.
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/handlers/LedgerEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ LedgerEntryHandler::process(LedgerEntryHandler::Input input, Context const& ctx)
auto ledgerObject = sharedPtrBackend_->fetchLedgerObject(key, lgrInfo.seq, ctx.yield);

if (!ledgerObject || ledgerObject->empty()) {
if (not input.includeDeleted)
if (not input.includeDeleted)
return Error{Status{"entryNotFound"}};
auto const deletedSeq = sharedPtrBackend_->fetchLedgerObjectSeq(key, lgrInfo.seq, ctx.yield);
if (!deletedSeq)
if (!deletedSeq)
return Error{Status{"entryNotFound"}};
ledgerObject = sharedPtrBackend_->fetchLedgerObject(key, deletedSeq.value() - 1, ctx.yield);
if (!ledgerObject || ledgerObject->empty())
if (!ledgerObject || ledgerObject->empty())
return Error{Status{"entryNotFound"}};
output.deletedLedgerIndex = deletedSeq;
}
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/rpc/handlers/LedgerEntryTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2847,7 +2847,7 @@ TEST_F(RPCLedgerEntryTest, ObjectUpdateIncludeDelete)
.WillRepeatedly(Return(line1.getSerializer().peekData()));
EXPECT_CALL(*backend, doFetchLedgerObject(ripple::uint256{INDEX1}, RANGEMAX - 1, _))
.WillRepeatedly(Return(line2.getSerializer().peekData()));

runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{LedgerEntryHandler{backend}};
auto const req = json::parse(fmt::format(
Expand Down Expand Up @@ -2920,8 +2920,7 @@ TEST_F(RPCLedgerEntryTest, ObjectSeqNotExist)
EXPECT_CALL(*backend, fetchLedgerBySequence(RANGEMAX, _)).WillRepeatedly(Return(ledgerinfo));
EXPECT_CALL(*backend, doFetchLedgerObject(ripple::uint256{INDEX1}, RANGEMAX, _))
.WillOnce(Return(std::optional<Blob>{}));
EXPECT_CALL(*backend, doFetchLedgerObjectSeq(ripple::uint256{INDEX1}, RANGEMAX, _))
.WillOnce(Return(std::nullopt));
EXPECT_CALL(*backend, doFetchLedgerObjectSeq(ripple::uint256{INDEX1}, RANGEMAX, _)).WillOnce(Return(std::nullopt));

runSpawn([&, this](auto yield) {
auto const handler = AnyHandler{LedgerEntryHandler{backend}};
Expand All @@ -2939,4 +2938,3 @@ TEST_F(RPCLedgerEntryTest, ObjectSeqNotExist)
EXPECT_EQ(myerr, "entryNotFound");
});
}