@@ -15,7 +15,7 @@ mod test_data;
15
15
#[ cfg( test) ]
16
16
use mock_instant:: global:: MockClock ;
17
17
18
- use alloc:: { collections :: BTreeMap , vec:: Vec } ;
18
+ use alloc:: vec:: Vec ;
19
19
use stylus_sdk:: {
20
20
alloy_primitives:: { Address , FixedBytes , I32 , I64 , U16 , U256 , U32 , U64 } ,
21
21
call:: Call ,
@@ -111,6 +111,26 @@ impl PythReceiver {
111
111
}
112
112
}
113
113
114
+ pub fn query_price_feed ( & self , id : [ u8 ; 32 ] ) -> Result < PriceFeedReturn , PythReceiverError > {
115
+ let id_fb = FixedBytes :: < 32 > :: from ( id) ;
116
+
117
+ let price_info = self . latest_price_info . get ( id_fb) ;
118
+
119
+ if price_info. publish_time . get ( ) == U64 :: ZERO {
120
+ return Err ( PythReceiverError :: PriceUnavailable ) ;
121
+ }
122
+
123
+ Ok ( (
124
+ id_fb,
125
+ price_info. publish_time . get ( ) ,
126
+ price_info. expo . get ( ) ,
127
+ price_info. price . get ( ) ,
128
+ price_info. conf . get ( ) ,
129
+ price_info. ema_price . get ( ) ,
130
+ price_info. ema_conf . get ( ) ,
131
+ ) )
132
+ }
133
+
114
134
pub fn get_price_unsafe ( & self , id : [ u8 ; 32 ] ) -> Result < PriceReturn , PythReceiverError > {
115
135
let id_fb = FixedBytes :: < 32 > :: from ( id) ;
116
136
@@ -370,7 +390,7 @@ impl PythReceiver {
370
390
let accumulator_update = AccumulatorUpdateData :: try_from_slice ( & update_data_array)
371
391
. map_err ( |_| PythReceiverError :: InvalidAccumulatorMessage ) ?;
372
392
373
- let mut price_feeds: BTreeMap < [ u8 ; 32 ] , PriceFeedReturn > = BTreeMap :: new ( ) ;
393
+ let mut price_feeds = Vec :: new ( ) ;
374
394
375
395
match accumulator_update. proof {
376
396
Proof :: WormholeMerkle { vaa, updates } => {
@@ -424,9 +444,10 @@ impl PythReceiver {
424
444
return Err ( PythReceiverError :: PriceFeedNotFoundWithinRange ) ;
425
445
}
426
446
447
+ let price_id_fb =
448
+ FixedBytes :: < 32 > :: from ( price_feed_message. feed_id ) ;
449
+
427
450
if check_uniqueness {
428
- let price_id_fb =
429
- FixedBytes :: < 32 > :: from ( price_feed_message. feed_id ) ;
430
451
let prev_price_info = self . latest_price_info . get ( price_id_fb) ;
431
452
let prev_publish_time =
432
453
prev_price_info. publish_time . get ( ) . to :: < u64 > ( ) ;
@@ -439,7 +460,7 @@ impl PythReceiver {
439
460
}
440
461
441
462
let price_info_return = (
442
- price_feed_message . feed_id ,
463
+ price_id_fb ,
443
464
U64 :: from ( publish_time) ,
444
465
I32 :: from_be_bytes ( price_feed_message. exponent . to_be_bytes ( ) ) ,
445
466
I64 :: from_be_bytes ( price_feed_message. price . to_be_bytes ( ) ) ,
@@ -448,7 +469,7 @@ impl PythReceiver {
448
469
U64 :: from ( price_feed_message. ema_conf ) ,
449
470
) ;
450
471
451
- price_feeds. insert ( price_feed_message . feed_id , price_info_return) ;
472
+ price_feeds. push ( price_info_return) ;
452
473
}
453
474
_ => {
454
475
return Err ( PythReceiverError :: InvalidAccumulatorMessageType ) ;
@@ -458,10 +479,7 @@ impl PythReceiver {
458
479
}
459
480
} ;
460
481
461
- Ok ( price_feeds
462
- . into_iter ( )
463
- . map ( |( _, price_info) | price_info)
464
- . collect ( ) )
482
+ Ok ( price_feeds)
465
483
}
466
484
467
485
pub fn parse_twap_price_feed_updates (
0 commit comments