@@ -333,50 +333,43 @@ abstract contract Pyth is
333333 uint64 [] memory slots
334334 )
335335 {
336- {
337- uint requiredFee = getUpdateFee (updateData);
338- if (msg .value < requiredFee) revert PythErrors.InsufficientFee ();
339- }
336+ if (msg .value < getUpdateFee (updateData)) revert PythErrors.InsufficientFee ();
340337
341338 // 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+ });
350348
351349 // Track total updates for minimal update data check
352350 uint64 totalUpdatesAcrossBlobs = 0 ;
353351
354352 unchecked {
355353 // Process each update, passing the context struct
356354 // 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 ) {
358356 totalUpdatesAcrossBlobs += _processSingleUpdateDataBlob (
359357 updateData[i],
360358 context
361359 );
362360 }
363361
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+ }));
380373 }
381374 }
382375 }
@@ -390,7 +383,7 @@ abstract contract Pyth is
390383 }
391384
392385 // Check all price feeds were found
393- for (uint k = 0 ; k < priceIds.length ; k ++ ) {
386+ for (uint k = 0 ; k < priceIds.length ; ++ k ) {
394387 if (context.priceFeeds[k].id == 0 ) {
395388 revert PythErrors.PriceFeedNotFoundWithinRange ();
396389 }
@@ -399,6 +392,7 @@ abstract contract Pyth is
399392 // Return results
400393 return (context.priceFeeds, context.slots);
401394 }
395+
402396 function parsePriceFeedUpdates (
403397 bytes [] calldata updateData ,
404398 bytes32 [] calldata priceIds ,
0 commit comments