Skip to content

Commit

Permalink
fix: check if value is bool (paradigmxyz#3708)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 11, 2023
1 parent 2bc5e19 commit 467f6f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions crates/rpc/rpc-types/src/eth/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ pub enum Params {
None,
/// Log parameters.
Logs(Box<Filter>),
/// New pending transaction parameters.
NewPendingTransactions(bool),
/// Boolean parameter for new pending transactions.
Bool(bool),
}

impl Serialize for Params {
Expand All @@ -116,7 +116,7 @@ impl Serialize for Params {
match self {
Params::None => (&[] as &[serde_json::Value]).serialize(serializer),
Params::Logs(logs) => logs.serialize(serializer),
Params::NewPendingTransactions(full) => full.serialize(serializer),
Params::Bool(full) => full.serialize(serializer),
}
}
}
Expand All @@ -132,6 +132,10 @@ impl<'a> Deserialize<'a> for Params {
return Ok(Params::None)
}

if let Some(val) = v.as_bool() {
return Ok(Params::Bool(val))
}

serde_json::from_value(v)
.map(|f| Params::Logs(Box::new(f)))
.map_err(|e| D::Error::custom(format!("Invalid Pub-Sub parameters: {e}")))
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc/src/eth/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ where
SubscriptionKind::NewPendingTransactions => {
if let Some(params) = params {
match params {
Params::NewPendingTransactions(true) => {
Params::Bool(true) => {
// full transaction objects requested
let stream = pubsub.full_pending_transaction_stream().map(|tx| {
EthSubscriptionResult::FullTransaction(Box::new(
Expand All @@ -135,7 +135,7 @@ where
});
return pipe_from_stream(accepted_sink, stream).await
}
Params::NewPendingTransactions(false) | Params::None => {
Params::Bool(false) | Params::None => {
// only hashes requested
}
Params::Logs(_) => {
Expand Down

0 comments on commit 467f6f9

Please sign in to comment.