From f572dc7a359903826f9a93c0237fae7251239490 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Fri, 14 Jun 2024 15:29:43 +0200 Subject: [PATCH 1/2] feat: add getter methods for FilterChanges --- crates/rpc-types-eth/src/filter.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/rpc-types-eth/src/filter.rs b/crates/rpc-types-eth/src/filter.rs index 23fa26a79cb..acbdca340f9 100644 --- a/crates/rpc-types-eth/src/filter.rs +++ b/crates/rpc-types-eth/src/filter.rs @@ -894,6 +894,35 @@ impl From> for FilterChanges { } } +impl FilterChanges { + /// Get the hashes if present. + pub fn hashes(&self) -> Option<&[B256]> { + if let Self::Hashes(hashes) = self { + Some(hashes) + } else { + None + } + } + + /// Get the logs if present. + pub fn logs(&self) -> Option<&[RpcLog]> { + if let Self::Logs(logs) = self { + Some(logs) + } else { + None + } + } + + /// Get the transactions if present. + pub fn transactions(&self) -> Option<&[T]> { + if let Self::Transactions(transactions) = self { + Some(transactions) + } else { + None + } + } +} + mod empty_array { use serde::{Serialize, Serializer}; From 5dfac6916bbd5b409cabaf5703e180c2ca61c572 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Fri, 14 Jun 2024 15:35:43 +0200 Subject: [PATCH 2/2] fix comments --- crates/rpc-types-eth/src/filter.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rpc-types-eth/src/filter.rs b/crates/rpc-types-eth/src/filter.rs index acbdca340f9..d1d62775563 100644 --- a/crates/rpc-types-eth/src/filter.rs +++ b/crates/rpc-types-eth/src/filter.rs @@ -896,7 +896,7 @@ impl From> for FilterChanges { impl FilterChanges { /// Get the hashes if present. - pub fn hashes(&self) -> Option<&[B256]> { + pub fn as_hashes(&self) -> Option<&[B256]> { if let Self::Hashes(hashes) = self { Some(hashes) } else { @@ -905,7 +905,7 @@ impl FilterChanges { } /// Get the logs if present. - pub fn logs(&self) -> Option<&[RpcLog]> { + pub fn as_logs(&self) -> Option<&[RpcLog]> { if let Self::Logs(logs) = self { Some(logs) } else { @@ -914,7 +914,7 @@ impl FilterChanges { } /// Get the transactions if present. - pub fn transactions(&self) -> Option<&[T]> { + pub fn as_transactions(&self) -> Option<&[T]> { if let Self::Transactions(transactions) = self { Some(transactions) } else {