From cad7935d69f433e45d190902e58b1c996b35adfa Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:59:40 +0200 Subject: [PATCH] Improve FilterChanges implementation (#610) --- crates/rpc-types/src/eth/filter.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/rpc-types/src/eth/filter.rs b/crates/rpc-types/src/eth/filter.rs index 208878723dd..941032c7ee9 100644 --- a/crates/rpc-types/src/eth/filter.rs +++ b/crates/rpc-types/src/eth/filter.rs @@ -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 { /// Empty result. #[serde(with = "empty_array")] + #[default] Empty, /// New logs. Logs(Vec), @@ -861,6 +862,24 @@ pub enum FilterChanges { Transactions(Vec), } +impl From> for FilterChanges { + fn from(logs: Vec) -> Self { + FilterChanges::Logs(logs) + } +} + +impl From> for FilterChanges { + fn from(hashes: Vec) -> Self { + FilterChanges::Hashes(hashes) + } +} + +impl From> for FilterChanges { + fn from(transactions: Vec) -> Self { + FilterChanges::Transactions(transactions) + } +} + mod empty_array { use serde::{Serialize, Serializer};