@@ -179,34 +179,13 @@ abstract contract Pyth is
179179 if (price.publishTime == 0 ) revert PythErrors.PriceFeedNotFound ();
180180 }
181181
182- /// Internal struct to hold parameters for update processing
183- /// @dev Storing these variable in a struct rather than local variables
184- /// helps reduce stack depth.
185- struct UpdateProcessingContext {
186- bytes32 [] priceIds;
187- uint64 minPublishTime;
188- uint64 maxPublishTime;
189- bool checkUniqueness;
190- PythStructs.PriceFeed[] priceFeeds;
191- uint64 [] slots;
192- }
193-
194- /// The initial Merkle header data in an updateData. The encoded bytes
195- /// are kept in calldata for gas efficiency.
196- /// @dev Storing these variable in a struct rather than local variables
197- /// helps reduce stack depth.
198- struct MerkleData {
199- bytes20 digest;
200- uint8 numUpdates;
201- uint64 slot;
202- }
203-
204- /// @dev Helper function to process a single price update within a Merkle proof.
205- function _processSingleMerkleUpdate (
206- MerkleData memory merkleData ,
182+ /// @dev Helper function to parse a single price update within a Merkle proof.
183+ /// Parsed price feeds will be stored in the context.
184+ function _parseSingleMerkleUpdate (
185+ PythInternalStructs.MerkleData memory merkleData ,
207186 bytes calldata encoded ,
208187 uint offset ,
209- UpdateProcessingContext memory context
188+ PythInternalStructs.UpdateParseContext memory context
210189 ) internal pure returns (uint newOffset ) {
211190 PythInternalStructs.PriceInfo memory priceInfo;
212191 bytes32 priceId;
@@ -230,10 +209,10 @@ abstract contract Pyth is
230209 if (k < context.priceIds.length && context.priceFeeds[k].id == 0 ) {
231210 uint publishTime = uint (priceInfo.publishTime);
232211 if (
233- publishTime >= context.minPublishTime &&
234- publishTime <= context.maxPublishTime &&
235- (! context.checkUniqueness ||
236- context.minPublishTime > prevPublishTime)
212+ publishTime >= context.config. minPublishTime &&
213+ publishTime <= context.config. maxPublishTime &&
214+ (! context.config. checkUniqueness ||
215+ context.config. minPublishTime > prevPublishTime)
237216 ) {
238217 context.priceFeeds[k].id = priceId;
239218 context.priceFeeds[k].price.price = priceInfo.price;
@@ -252,7 +231,7 @@ abstract contract Pyth is
252231 /// @dev Processes a single entry from the updateData array.
253232 function _processSingleUpdateDataBlob (
254233 bytes calldata singleUpdateData ,
255- UpdateProcessingContext memory context
234+ PythInternalStructs.UpdateParseContext memory context
256235 ) internal view {
257236 // Check magic number and length first
258237 if (
@@ -276,7 +255,7 @@ abstract contract Pyth is
276255 }
277256
278257 // Extract Merkle data
279- MerkleData memory merkleData;
258+ PythInternalStructs. MerkleData memory merkleData;
280259 bytes calldata encoded;
281260 (
282261 offset,
@@ -291,7 +270,7 @@ abstract contract Pyth is
291270
292271 // Process each update within the Merkle proof
293272 for (uint j = 0 ; j < merkleData.numUpdates; j++ ) {
294- offset = _processSingleMerkleUpdate (
273+ offset = _parseSingleMerkleUpdate (
295274 merkleData,
296275 encoded,
297276 offset,
@@ -322,16 +301,15 @@ abstract contract Pyth is
322301 }
323302
324303 // Create the context struct that holds all shared parameters
325- UpdateProcessingContext memory context;
304+ PythInternalStructs.UpdateParseContext memory context;
326305 context.priceIds = priceIds;
327- context.minPublishTime = config.minPublishTime;
328- context.maxPublishTime = config.maxPublishTime;
329- context.checkUniqueness = config.checkUniqueness;
306+ context.config = config;
330307 context.priceFeeds = new PythStructs.PriceFeed [](priceIds.length );
331308 context.slots = new uint64 [](priceIds.length );
332309
333310 unchecked {
334311 // Process each update, passing the context struct
312+ // Parsed results will be filled in context.priceFeeds and context.slots
335313 for (uint i = 0 ; i < updateData.length ; i++ ) {
336314 _processSingleUpdateDataBlob (updateData[i], context);
337315 }
@@ -369,8 +347,6 @@ abstract contract Pyth is
369347 );
370348 }
371349
372- /// @dev Same as `parsePriceFeedUpdates`, but also returns the Pythnet slot
373- /// associated with each price update.
374350 function parsePriceFeedUpdatesWithSlots (
375351 bytes [] calldata updateData ,
376352 bytes32 [] calldata priceIds ,
0 commit comments