Skip to content

Commit

Permalink
feat: add getter methods for FilterChanges (#899)
Browse files Browse the repository at this point in the history
* feat: add getter methods for FilterChanges

* fix comments
  • Loading branch information
tcoratger authored Jun 14, 2024
1 parent b79257c commit 5c21232
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions crates/rpc-types-eth/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,35 @@ impl From<Vec<Transaction>> for FilterChanges {
}
}

impl<T> FilterChanges<T> {
/// Get the hashes if present.
pub fn as_hashes(&self) -> Option<&[B256]> {
if let Self::Hashes(hashes) = self {
Some(hashes)
} else {
None
}
}

/// Get the logs if present.
pub fn as_logs(&self) -> Option<&[RpcLog]> {
if let Self::Logs(logs) = self {
Some(logs)
} else {
None
}
}

/// Get the transactions if present.
pub fn as_transactions(&self) -> Option<&[T]> {
if let Self::Transactions(transactions) = self {
Some(transactions)
} else {
None
}
}
}

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

Expand Down

0 comments on commit 5c21232

Please sign in to comment.