@@ -193,11 +193,30 @@ impl PythReceiver {
193
193
194
194
pub fn update_price_feeds_if_necessary (
195
195
& mut self ,
196
- _update_data : Vec < Vec < u8 > > ,
197
- _price_ids : Vec < [ u8 ; 32 ] > ,
198
- _publish_times : Vec < u64 > ,
199
- ) {
200
- // dummy implementation
196
+ update_data : Vec < Vec < u8 > > ,
197
+ price_ids : Vec < [ u8 ; 32 ] > ,
198
+ publish_times : Vec < u64 > ,
199
+ ) -> Result < ( ) , PythReceiverError > {
200
+ if ( price_ids. len ( ) != publish_times. len ( ) )
201
+ || ( price_ids. is_empty ( ) && publish_times. is_empty ( ) )
202
+ {
203
+ return Err ( PythReceiverError :: InvalidUpdateData ) ;
204
+ }
205
+
206
+ for i in 0 ..price_ids. len ( ) {
207
+ if ( self . latest_price_info_publish_time ( price_ids[ i] ) < publish_times[ i] ) {
208
+ self . update_price_feeds ( update_data. clone ( ) ) ?;
209
+ return Ok ( ( ) ) ;
210
+ }
211
+ }
212
+
213
+ return Err ( PythReceiverError :: NoFreshUpdate ) ;
214
+ }
215
+
216
+ fn latest_price_info_publish_time ( & self , price_id : [ u8 ; 32 ] ) -> u64 {
217
+ let price_id_fb: FixedBytes < 32 > = FixedBytes :: from ( price_id) ;
218
+ let recent_price_info = self . latest_price_info . get ( price_id_fb) ;
219
+ recent_price_info. publish_time . get ( ) . to :: < u64 > ( )
201
220
}
202
221
203
222
fn update_price_feeds_internal (
@@ -449,12 +468,21 @@ impl PythReceiver {
449
468
450
469
pub fn parse_price_feed_updates_unique (
451
470
& mut self ,
452
- _update_data : Vec < Vec < u8 > > ,
453
- _price_ids : Vec < [ u8 ; 32 ] > ,
454
- _min_publish_time : u64 ,
455
- _max_publish_time : u64 ,
456
- ) -> Vec < PriceInfoReturn > {
457
- Vec :: new ( )
471
+ update_data : Vec < Vec < u8 > > ,
472
+ price_ids : Vec < [ u8 ; 32 ] > ,
473
+ min_publish_time : u64 ,
474
+ max_publish_time : u64 ,
475
+ ) -> Result < Vec < PriceInfoReturn > , PythReceiverError > {
476
+ let price_feeds = self . parse_price_feed_updates_with_config (
477
+ update_data,
478
+ price_ids,
479
+ min_publish_time,
480
+ max_publish_time,
481
+ true ,
482
+ false ,
483
+ false ,
484
+ ) ;
485
+ price_feeds
458
486
}
459
487
460
488
fn is_no_older_than ( & self , publish_time : U64 , max_age : u64 ) -> bool {
0 commit comments