fix: treat bool params as invalid in logs subscription (#3716)

This commit is contained in:
Matthias Seitz
2023-07-11 17:13:06 +02:00
committed by GitHub
parent 94129631cb
commit fbdea30375
2 changed files with 31 additions and 1 deletions

View File

@@ -96,7 +96,7 @@ pub enum SubscriptionKind {
Syncing,
}
/// Subscription kind.
/// Any additional parameters for a subscription.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub enum Params {
/// No parameters passed.
@@ -108,6 +108,20 @@ pub enum Params {
Bool(bool),
}
impl Params {
/// Returns true if it's a bool parameter.
#[inline]
pub fn is_bool(&self) -> bool {
matches!(self, Params::Bool(_))
}
/// Returns true if it's a log parameter.
#[inline]
pub fn is_logs(&self) -> bool {
matches!(self, Params::Logs(_))
}
}
impl Serialize for Params {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -141,3 +155,16 @@ impl<'a> Deserialize<'a> for Params {
.map_err(|e| D::Error::custom(format!("Invalid Pub-Sub parameters: {e}")))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn params_serde() {
let s: Params = serde_json::from_str("true").unwrap();
assert_eq!(s, Params::Bool(true));
let s: Params = serde_json::from_str("null").unwrap();
assert_eq!(s, Params::None);
}
}

View File

@@ -115,6 +115,9 @@ where
// if no params are provided, used default filter params
let filter = match params {
Some(Params::Logs(filter)) => FilteredParams::new(Some(*filter)),
Some(Params::Bool(_)) => {
return Err(invalid_params_rpc_err("Invalid params for logs").into())
}
_ => FilteredParams::default(),
};
let stream =