Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add missing helpers to BlockTransactions #159

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion crates/rpc-types/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,17 @@ impl BlockTransactions {
self
}

/// Check if the enum variant is used for an uncle response.
/// Check if the enum variant is used for hashes.
pub const fn is_hashes(&self) -> bool {
matches!(self, Self::Hashes(_))
}

/// Returns true if the enum variant is used for full transactions.
pub const fn is_full(&self) -> bool {
matches!(self, Self::Full(_))
}

/// Returns true if the enum variant is used for an uncle response.
pub const fn is_uncle(&self) -> bool {
matches!(self, Self::Uncle)
}
Expand Down Expand Up @@ -167,6 +177,24 @@ impl BlockTransactions {
pub const fn uncle() -> Self {
Self::Uncle
}

/// Returns the number of transactions.
pub fn len(&self) -> usize {
match self {
BlockTransactions::Hashes(hashes) => hashes.len(),
BlockTransactions::Full(txs) => txs.len(),
BlockTransactions::Uncle => 0,
}
}

/// Whether the block has no transactions.
pub fn is_empty(&self) -> bool {
match self {
BlockTransactions::Hashes(hashes) => hashes.is_empty(),
BlockTransactions::Full(txs) => txs.is_empty(),
BlockTransactions::Uncle => true,
}
}
}

/// An iterator over the transaction hashes of a block.
Expand Down
Loading