@@ -151,6 +151,8 @@ enum ClientMessage {
151151 binary : bool ,
152152 #[ serde( default ) ]
153153 allow_out_of_order : bool ,
154+ #[ serde( default ) ]
155+ ignore_invalid_price_ids : bool ,
154156 } ,
155157 #[ serde( rename = "unsubscribe" ) ]
156158 Unsubscribe { ids : Vec < PriceIdInput > } ,
@@ -530,18 +532,22 @@ where
530532 verbose,
531533 binary,
532534 allow_out_of_order,
535+ ignore_invalid_price_ids,
533536 } ) => {
534537 let price_ids: Vec < PriceIdentifier > = ids. into_iter ( ) . map ( |id| id. into ( ) ) . collect ( ) ;
535538 let available_price_ids = Aggregates :: get_price_feed_ids ( & * self . state ) . await ;
536539
537- let not_found_price_ids: Vec < & PriceIdentifier > = price_ids
540+ let ( found_price_ids, not_found_price_ids) : (
541+ Vec < & PriceIdentifier > ,
542+ Vec < & PriceIdentifier > ,
543+ ) = price_ids
538544 . iter ( )
539- . filter ( |price_id| !available_price_ids. contains ( price_id) )
540- . collect ( ) ;
545+ . partition ( |price_id| available_price_ids. contains ( price_id) ) ;
541546
542547 // If there is a single price id that is not found, we don't subscribe to any of the
543- // asked correct price feed ids and return an error to be more explicit and clear.
544- if !not_found_price_ids. is_empty ( ) {
548+ // asked correct price feed ids and return an error to be more explicit and clear,
549+ // unless the client explicitly asked to ignore invalid ids
550+ if !not_found_price_ids. is_empty ( ) && !ignore_invalid_price_ids {
545551 self . sender
546552 . send (
547553 serde_json:: to_string ( & ServerMessage :: Response (
@@ -556,10 +562,22 @@ where
556562 )
557563 . await ?;
558564 return Ok ( ( ) ) ;
565+ } else if found_price_ids. is_empty ( ) {
566+ self . sender
567+ . send (
568+ serde_json:: to_string ( & ServerMessage :: Response (
569+ ServerResponseMessage :: Err {
570+ error : "No price feeds available" . to_string ( ) ,
571+ } ,
572+ ) ) ?
573+ . into ( ) ,
574+ )
575+ . await ?;
576+ return Ok ( ( ) ) ;
559577 } else {
560- for price_id in price_ids {
578+ for price_id in found_price_ids {
561579 self . price_feeds_with_config . insert (
562- price_id,
580+ * price_id,
563581 PriceFeedClientConfig {
564582 verbose,
565583 binary,
0 commit comments