File tree Expand file tree Collapse file tree 5 files changed +30
-8
lines changed Expand file tree Collapse file tree 5 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " hermes"
3- version = " 0.4.2 "
3+ version = " 0.4.3 "
44description = " Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
55edition = " 2021"
66
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ pub use {
3333} ;
3434
3535pub enum RestError {
36+ BenchmarkPriceNotUnique ,
3637 UpdateDataNotFound ,
3738 CcipUpdateDataNotFound ,
3839 InvalidCCIPInput ,
@@ -42,6 +43,9 @@ pub enum RestError {
4243impl IntoResponse for RestError {
4344 fn into_response ( self ) -> Response {
4445 match self {
46+ RestError :: BenchmarkPriceNotUnique => {
47+ ( StatusCode :: NOT_FOUND , "Benchmark price is not unique" ) . into_response ( )
48+ }
4549 RestError :: UpdateDataNotFound => {
4650 ( StatusCode :: NOT_FOUND , "Update data not found" ) . into_response ( )
4751 }
Original file line number Diff line number Diff line change @@ -89,6 +89,15 @@ pub async fn get_price_feed(
8989 . next ( )
9090 . ok_or ( RestError :: UpdateDataNotFound ) ?;
9191
92+ // Currently Benchmarks API doesn't support returning the previous publish time. So we
93+ // are assuming that it is doing the same filter as us and returns not found if the
94+ // price update is not unique.
95+ if let Some ( prev_publish_time) = price_feed. prev_publish_time {
96+ if prev_publish_time == price_feed. price_feed . get_price_unchecked ( ) . publish_time {
97+ return Err ( RestError :: BenchmarkPriceNotUnique ) ;
98+ }
99+ }
100+
92101 // Note: This is a hack to get around the fact that Benchmark doesn't give per price feed
93102 // update data. Since we request only for a single feed then the whole prices update data
94103 // is this price feed update data.
Original file line number Diff line number Diff line change @@ -97,13 +97,22 @@ pub async fn get_vaa(
9797 . map ( |bytes| base64_standard_engine. encode ( bytes) )
9898 . ok_or ( RestError :: UpdateDataNotFound ) ?;
9999
100- let publish_time = price_feeds_with_update_data
100+ let price_feed = price_feeds_with_update_data
101101 . price_feeds
102- . get ( 0 )
103- . ok_or ( RestError :: UpdateDataNotFound ) ?
104- . price_feed
105- . get_price_unchecked ( )
106- . publish_time ;
102+ . into_iter ( )
103+ . next ( )
104+ . ok_or ( RestError :: UpdateDataNotFound ) ?;
105+
106+ let publish_time = price_feed. price_feed . get_price_unchecked ( ) . publish_time ;
107+
108+ // Currently Benchmarks API doesn't support returning the previous publish time. So we
109+ // are assuming that it is doing the same filter as us and returns not found if the
110+ // price update is not unique.
111+ if let Some ( prev_publish_time) = price_feed. prev_publish_time {
112+ if prev_publish_time == price_feed. price_feed . get_price_unchecked ( ) . publish_time {
113+ return Err ( RestError :: BenchmarkPriceNotUnique ) ;
114+ }
115+ }
107116
108117 Ok ( Json ( GetVaaResponse { vaa, publish_time } ) )
109118}
You can’t perform that action at this time.
0 commit comments