Skip to content

Commit

Permalink
feat(rpc-types-engine): add forkchoice state zero helpers (#1231)
Browse files Browse the repository at this point in the history
feat: add forkchoice state zero helpers
  • Loading branch information
Rjected authored Sep 3, 2024
1 parent 06e0ae9 commit 6806537
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions crates/rpc-types-engine/src/forkchoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,41 @@ pub struct ForkchoiceState {
pub finalized_block_hash: B256,
}

impl ForkchoiceState {
/// Returns the `head_block_hash`, only if it is not [`B256::ZERO`], otherwise this returns
/// [`None`].
#[inline]
pub fn state_head_hash(&self) -> Option<B256> {
if self.head_block_hash.is_zero() {
None
} else {
Some(self.head_block_hash)
}
}

/// Returns the `safe_block_hash`, only if it is not [`B256::ZERO`], otherwise this returns
/// [`None`].
#[inline]
pub fn state_safe_hash(&self) -> Option<B256> {
if self.safe_block_hash.is_zero() {
None
} else {
Some(self.safe_block_hash)
}
}

/// Returns the `finalized_block_hash`, only if it is not [`B256::ZERO`], otherwise this
/// returns [`None`].
#[inline]
pub fn state_finalized_hash(&self) -> Option<B256> {
if self.finalized_block_hash.is_zero() {
None
} else {
Some(self.finalized_block_hash)
}
}
}

/// A standalone forkchoice update errors for RPC.
///
/// These are considered hard RPC errors and are _not_ returned as [PayloadStatus] or
Expand Down

0 comments on commit 6806537

Please sign in to comment.