@@ -333,50 +333,43 @@ abstract contract Pyth is
333
333
uint64 [] memory slots
334
334
)
335
335
{
336
- {
337
- uint requiredFee = getUpdateFee (updateData);
338
- if (msg .value < requiredFee) revert PythErrors.InsufficientFee ();
339
- }
336
+ if (msg .value < getUpdateFee (updateData)) revert PythErrors.InsufficientFee ();
340
337
341
338
// Create the context struct that holds all shared parameters
342
- PythInternalStructs.UpdateParseContext memory context;
343
- context.priceIds = priceIds;
344
- context.minAllowedPublishTime = minAllowedPublishTime;
345
- context.maxAllowedPublishTime = maxAllowedPublishTime;
346
- context.checkUniqueness = checkUniqueness;
347
- context.checkUpdateDataIsMinimal = checkUpdateDataIsMinimal;
348
- context.priceFeeds = new PythStructs.PriceFeed [](priceIds.length );
349
- context.slots = new uint64 [](priceIds.length );
339
+ PythInternalStructs.UpdateParseContext memory context = PythInternalStructs.UpdateParseContext ({
340
+ priceIds: priceIds,
341
+ minAllowedPublishTime: minAllowedPublishTime,
342
+ maxAllowedPublishTime: maxAllowedPublishTime,
343
+ checkUniqueness: checkUniqueness,
344
+ checkUpdateDataIsMinimal: checkUpdateDataIsMinimal,
345
+ priceFeeds: new PythStructs.PriceFeed [](priceIds.length ),
346
+ slots: new uint64 [](priceIds.length )
347
+ });
350
348
351
349
// Track total updates for minimal update data check
352
350
uint64 totalUpdatesAcrossBlobs = 0 ;
353
351
354
352
unchecked {
355
353
// Process each update, passing the context struct
356
354
// Parsed results will be filled in context.priceFeeds and context.slots
357
- for (uint i = 0 ; i < updateData.length ; i ++ ) {
355
+ for (uint i = 0 ; i < updateData.length ; ++ i ) {
358
356
totalUpdatesAcrossBlobs += _processSingleUpdateDataBlob (
359
357
updateData[i],
360
358
context
361
359
);
362
360
}
363
361
364
- if (storeUpdatesIfFresh) {
365
- for (uint j = 0 ; j < priceIds.length ; j++ ) {
366
- bytes32 curPriceId = priceIds[j];
367
- if (context.priceFeeds[j].id != 0 ) {
368
- // Create a new PriceInfo memory object from the context.priceFeeds data
369
- PythInternalStructs.PriceInfo memory newInfo;
370
- newInfo.publishTime = uint64 (context.priceFeeds[j].price.publishTime);
371
- newInfo.expo = context.priceFeeds[j].price.expo;
372
- newInfo.price = context.priceFeeds[j].price.price;
373
- newInfo.conf = context.priceFeeds[j].price.conf;
374
- newInfo.emaPrice = context.priceFeeds[j].emaPrice.price;
375
- newInfo.emaConf = context.priceFeeds[j].emaPrice.conf;
376
-
377
- // Pass the new memory object to update storage
378
- updateLatestPriceIfNecessary (curPriceId, newInfo);
379
- }
362
+ for (uint j = 0 ; j < priceIds.length ; ++ j) {
363
+ PythStructs.PriceFeed memory pf = context.priceFeeds[j];
364
+ if (storeUpdatesIfFresh && pf.id != 0 ) {
365
+ updateLatestPriceIfNecessary (priceIds[j], PythInternalStructs.PriceInfo ({
366
+ publishTime: uint64 (pf.price.publishTime),
367
+ expo: pf.price.expo,
368
+ price: pf.price.price,
369
+ conf: pf.price.conf,
370
+ emaPrice: pf.emaPrice.price,
371
+ emaConf: pf.emaPrice.conf
372
+ }));
380
373
}
381
374
}
382
375
}
@@ -390,7 +383,7 @@ abstract contract Pyth is
390
383
}
391
384
392
385
// Check all price feeds were found
393
- for (uint k = 0 ; k < priceIds.length ; k ++ ) {
386
+ for (uint k = 0 ; k < priceIds.length ; ++ k ) {
394
387
if (context.priceFeeds[k].id == 0 ) {
395
388
revert PythErrors.PriceFeedNotFoundWithinRange ();
396
389
}
@@ -399,6 +392,7 @@ abstract contract Pyth is
399
392
// Return results
400
393
return (context.priceFeeds, context.slots);
401
394
}
395
+
402
396
function parsePriceFeedUpdates (
403
397
bytes [] calldata updateData ,
404
398
bytes32 [] calldata priceIds ,
0 commit comments