mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-01 18:44:58 -05:00
fix: treat bool params as invalid in logs subscription (#3716)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user