@@ -189,9 +189,28 @@ impl PythReceiver {
189
189
190
190
match msg {
191
191
Message :: PriceFeedMessage ( price_feed_message) => {
192
- // if self.update_price_feed_if_new(price_feed_message.feed_id,PriceInfoStorage::from(&price_feed_message)) {
193
- // count_updates += 1;
194
- // }
192
+ let price_id_fb : FixedBytes < 32 > = FixedBytes :: from ( price_feed_message. feed_id ) ;
193
+ let mut recent_price_info = self . latest_price_info . get ( price_id_fb) ;
194
+
195
+ let stored_price_info = PriceInfo {
196
+ price : recent_price_info. price . get ( ) ,
197
+ conf : recent_price_info. conf . get ( ) ,
198
+ expo : recent_price_info. expo . get ( ) ,
199
+ publish_time : recent_price_info. publish_time . get ( ) ,
200
+ ema_price : recent_price_info. ema_price . get ( ) ,
201
+ ema_conf : recent_price_info. ema_conf . get ( ) ,
202
+ } ;
203
+
204
+ if recent_price_info. publish_time . get ( ) < U64 :: from ( price_feed_message. publish_time )
205
+ || recent_price_info. price . get ( ) == I64 :: ZERO {
206
+ recent_price_info. publish_time . set ( U64 :: from ( price_feed_message. publish_time ) ) ;
207
+ recent_price_info. price . set ( I64 :: from_le_bytes ( price_feed_message. price . to_le_bytes ( ) ) ) ;
208
+ recent_price_info. conf . set ( U64 :: from ( price_feed_message. conf ) ) ;
209
+ recent_price_info. expo . set ( I32 :: from_le_bytes ( price_feed_message. exponent . to_le_bytes ( ) ) ) ;
210
+ recent_price_info. ema_price . set ( I64 :: from_le_bytes ( price_feed_message. ema_price . to_le_bytes ( ) ) ) ;
211
+ recent_price_info. ema_conf . set ( U64 :: from ( price_feed_message. ema_conf ) ) ;
212
+ }
213
+
195
214
196
215
} ,
197
216
Message :: TwapMessage ( _) => {
@@ -275,19 +294,8 @@ impl PythReceiver {
275
294
// Updates the Price Feed only if it is newer than the current one. This function never fails
276
295
// and will either update in-place or not update at all. The return value indicates whether
277
296
// the update was performed or not.
278
- // fn update_price_feed_if_new(&mut self, price_id: [u8; 32], price_feed: PriceInfo) -> bool {
279
- // match self.latest_price_info.get(&price_id) {
280
- // Some(stored_price_feed) => {
281
- // let update = price_feed.price.publish_time > stored_price_feed.price.publish_time;
282
- // update.then(|| self.prices.insert(&price_feed.id, &price_feed));
283
- // update
284
- // }
285
-
286
- // None => {
287
- // self.prices.insert(&price_feed.id, &price_feed);
288
- // true
289
- // }
290
- // }
297
+ // fn update_price_feed_if_new(&self, price_id: [u8; 32], price_feed: PriceInfo) -> bool {
298
+
291
299
// }
292
300
293
301
0 commit comments