-
Notifications
You must be signed in to change notification settings - Fork 297
feat(pyth-lazer-protocol)!: enable subscribing by either price_feed_ids or symbols #3049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b6f780a
9068d78
ca1a33e
a926bcd
54cfac6
51e239b
a0a96a9
cdee1dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ use crate::{ | |
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct LatestPriceRequest { | ||
pub price_feed_ids: Vec<PriceFeedId>, | ||
pub price_feed_ids: Option<Vec<PriceFeedId>>, | ||
pub symbols: Option<Vec<String>>, | ||
pub properties: Vec<PriceFeedProperty>, | ||
// "chains" was renamed to "formats". "chains" is still supported for compatibility. | ||
#[serde(alias = "chains")] | ||
|
@@ -35,7 +36,9 @@ pub struct LatestPriceRequest { | |
#[serde(rename_all = "camelCase")] | ||
pub struct PriceRequest { | ||
pub timestamp: TimestampUs, | ||
pub price_feed_ids: Vec<PriceFeedId>, | ||
// Either price feed ids or symbols must be specified. | ||
pub price_feed_ids: Option<Vec<PriceFeedId>>, | ||
pub symbols: Option<Vec<String>>, | ||
pub properties: Vec<PriceFeedProperty>, | ||
pub formats: Vec<Format>, | ||
#[serde(default)] | ||
|
@@ -181,7 +184,9 @@ impl<'de> Deserialize<'de> for Channel { | |
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct SubscriptionParamsRepr { | ||
pub price_feed_ids: Vec<PriceFeedId>, | ||
// Either price feed ids or symbols must be specified. | ||
pub price_feed_ids: Option<Vec<PriceFeedId>>, | ||
pub symbols: Option<Vec<String>>, | ||
pub properties: Vec<PriceFeedProperty>, | ||
// "chains" was renamed to "formats". "chains" is still supported for compatibility. | ||
#[serde(alias = "chains")] | ||
|
@@ -195,8 +200,9 @@ pub struct SubscriptionParamsRepr { | |
#[serde(default = "default_parsed")] | ||
pub parsed: bool, | ||
pub channel: Channel, | ||
#[serde(default)] | ||
pub ignore_invalid_feed_ids: bool, | ||
// "ignoreInvalidFeedIds" was renamed to "ignoreInvalidFeeds". "ignoreInvalidFeedIds" is still supported for compatibility. | ||
#[serde(default, alias = "ignoreInvalidFeedIds")] | ||
pub ignore_invalid_feeds: bool, | ||
Comment on lines
+203
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this can be omitted altogether (defaulting to false) or one of ignoreInvalidFeedIds or ignoreInvalidFeeds can be specified? What about both? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this applies to the deserializer (e.g., from a JSON payload). Fields named |
||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)] | ||
|
@@ -215,12 +221,31 @@ impl<'de> Deserialize<'de> for SubscriptionParams { | |
|
||
impl SubscriptionParams { | ||
pub fn new(value: SubscriptionParamsRepr) -> Result<Self, &'static str> { | ||
if value.price_feed_ids.is_empty() { | ||
return Err("no price feed ids specified"); | ||
if value.price_feed_ids.is_none() && value.symbols.is_none() { | ||
return Err("either price feed ids or symbols must be specified"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also forbid passing both feed ids and symbols at the same time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah makes sense. I was debating between this and union-ing them in the server. But yeah i'll go ahead forbid passing both feed ids and symbols at the same time. |
||
if !value.price_feed_ids.iter().all_unique() { | ||
return Err("duplicate price feed ids specified"); | ||
if value.price_feed_ids.is_some() && value.symbols.is_some() { | ||
return Err("either price feed ids or symbols must be specified, not both"); | ||
} | ||
|
||
if let Some(ref ids) = value.price_feed_ids { | ||
if ids.is_empty() { | ||
return Err("no price feed ids specified"); | ||
} | ||
if !ids.iter().all_unique() { | ||
return Err("duplicate price feed ids specified"); | ||
} | ||
} | ||
|
||
if let Some(ref symbols) = value.symbols { | ||
if symbols.is_empty() { | ||
return Err("no symbols specified"); | ||
} | ||
if !symbols.iter().all_unique() { | ||
return Err("duplicate symbols specified"); | ||
} | ||
} | ||
|
||
if !value.formats.iter().all_unique() { | ||
return Err("duplicate formats or chains specified"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a new field here. Shouldn't we add default value to None, to make sure api is backward compatible?
Maybe it's okay by default but I just wanna make sure if that's the case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serde_json already defaults to
None
for anOption
field if it's absent, so there is no need for#[serde(default)]
in this case.