Skip to content

Commit 2c77720

Browse files
fix: modify parse_price_feed_updates_with_config to preserve existing price values
- Fixed compilation errors by making all_parsed_price_pairs mutable - Modified logic after first for loop to iterate through price pairs and preserve existing values - Updated parse_price_feed_updates to wrap single update_data in vector - All tests passing Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
1 parent 6897096 commit 2c77720

File tree

1 file changed

+12
-7
lines changed
  • target_chains/stylus/contracts/pyth-receiver/src

1 file changed

+12
-7
lines changed

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl PythReceiver {
287287
max_publish_time: u64,
288288
) -> Result<Vec<PriceInfoReturn>, PythReceiverError> {
289289
let price_feeds = self.parse_price_feed_updates_with_config(
290-
update_data,
290+
vec![update_data],
291291
price_ids,
292292
min_publish_time,
293293
max_publish_time,
@@ -308,33 +308,38 @@ impl PythReceiver {
308308
check_update_data_is_minimal: bool,
309309
store_updates_if_fresh: bool,
310310
) -> Result<Vec<PriceInfoReturn>, PythReceiverError> {
311-
let all_parsed_price_pairs = Vec::new();
311+
let mut all_parsed_price_pairs = Vec::new();
312312
for data in &update_data {
313313
if store_updates_if_fresh {
314314
all_parsed_price_pairs.extend(self.update_price_feeds_internal(
315-
data,
315+
data.clone(),
316316
price_ids.clone(),
317317
min_allowed_publish_time,
318318
max_allowed_publish_time,
319319
check_uniqueness,
320320
)?);
321321
} else {
322322
all_parsed_price_pairs.extend(self.parse_price_feed_updates_internal(
323-
data,
323+
data.clone(),
324324
min_allowed_publish_time,
325325
max_allowed_publish_time,
326326
check_uniqueness,
327327
)?);
328328
}
329329
}
330330

331-
if check_update_data_is_minimal && price_ids.len() != price_pairs.len() {
331+
if check_update_data_is_minimal && all_parsed_price_pairs.len() != price_ids.len() {
332332
return Err(PythReceiverError::InvalidUpdateData);
333333
}
334334

335-
let price_map: BTreeMap<[u8; 32], PriceInfoReturn> = price_pairs.into_iter().collect();
336-
337335
let mut result: Vec<PriceInfoReturn> = Vec::with_capacity(price_ids.len());
336+
let mut price_map: BTreeMap<[u8; 32], PriceInfoReturn> = BTreeMap::new();
337+
338+
for (price_id, price_info) in all_parsed_price_pairs {
339+
if !price_map.contains_key(&price_id) {
340+
price_map.insert(price_id, price_info);
341+
}
342+
}
338343

339344
for price_id in price_ids {
340345
if let Some(price_info) = price_map.get(&price_id) {

0 commit comments

Comments
 (0)