Compare commits

...

4 Commits

Author SHA1 Message Date
Mayukha Vadari
67daf923c7 Update comments for threshold logic in GetAggregatePrice
Clarified comments regarding the threshold logic for erasing outdated prices.
2026-03-18 16:10:21 -04:00
Mayukha Vadari
dd008b98a4 Change adjustReserve type from int32 to int8 2026-03-17 18:18:28 -04:00
Mayukha Vadari
ead4e49dd2 Implement ledger retrieval in GetAggregatePrice
Added ledger lookup to GetAggregatePrice handler.
2026-03-17 18:13:26 -04:00
Mayukha Vadari
3758152499 Change adjustReserve type from uint32 to int32 2026-03-17 18:10:48 -04:00
2 changed files with 9 additions and 8 deletions

View File

@@ -92,7 +92,7 @@ SetOracle::preclaim(PreclaimContext const& ctx)
return !v || *v == (*sle)[field];
};
std::uint32_t adjustReserve = 0;
std::int8_t adjustReserve = 0;
if (sle)
{
// update

View File

@@ -218,6 +218,12 @@ doGetAggregatePrice(RPC::JsonContext& context)
return result;
}
// Get the ledger
std::shared_ptr<ReadView const> ledger;
result = RPC::lookupLedger(ledger, context);
if (!ledger)
return result; // LCOV_EXCL_LINE
// Collect the dataset into bimap keyed by lastUpdateTime and
// STAmount (Number is int64 and price is uint64)
Prices prices;
@@ -238,11 +244,6 @@ doGetAggregatePrice(RPC::JsonContext& context)
return result;
}
std::shared_ptr<ReadView const> ledger;
result = RPC::lookupLedger(ledger, context);
if (!ledger)
return result; // LCOV_EXCL_LINE
auto const sle = ledger->read(keylet::oracle(*account, *documentID));
iteratePriceData(context, sle, [&](STObject const& node) {
auto const& series = node.getFieldArray(sfPriceDataSeries);
@@ -284,8 +285,8 @@ doGetAggregatePrice(RPC::JsonContext& context)
if (auto const threshold = std::get<std::uint32_t>(timeThreshold))
{
// threshold defines an acceptable range {max,min} of lastUpdateTime as
// {latestTime, latestTime - threshold}, the prices with lastUpdateTime
// greater than (latestTime - threshold) are erased.
// {latestTime, latestTime - threshold}. Prices with lastUpdateTime
// less than (latestTime - threshold) are erased (outdated prices).
auto const oldestTime = prices.left.rbegin()->first;
auto const upperBound = latestTime > threshold ? (latestTime - threshold) : oldestTime;
if (upperBound > oldestTime)