Skip to content

Commit

Permalink
Improve FilterChanges implementation (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Apr 23, 2024
1 parent c4e77b4 commit cad7935
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion crates/rpc-types/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,12 @@ impl FilteredParams {
}

/// Response of the `eth_getFilterChanges` RPC.
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[derive(Default, Clone, Debug, PartialEq, Eq, Serialize)]
#[serde(untagged)]
pub enum FilterChanges<T = Transaction> {
/// Empty result.
#[serde(with = "empty_array")]
#[default]
Empty,
/// New logs.
Logs(Vec<RpcLog>),
Expand All @@ -861,6 +862,24 @@ pub enum FilterChanges<T = Transaction> {
Transactions(Vec<T>),
}

impl From<Vec<RpcLog>> for FilterChanges {
fn from(logs: Vec<RpcLog>) -> Self {
FilterChanges::Logs(logs)
}
}

impl From<Vec<B256>> for FilterChanges {
fn from(hashes: Vec<B256>) -> Self {
FilterChanges::Hashes(hashes)
}
}

impl From<Vec<Transaction>> for FilterChanges {
fn from(transactions: Vec<Transaction>) -> Self {
FilterChanges::Transactions(transactions)
}
}

mod empty_array {
use serde::{Serialize, Serializer};

Expand Down

0 comments on commit cad7935

Please sign in to comment.