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

feat: add block num hash helper #1304

Merged
merged 1 commit into from
Sep 18, 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
14 changes: 13 additions & 1 deletion crates/rpc-types-engine/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloc::{
use alloy_consensus::{Blob, Bytes48};
use alloy_eips::{
eip4844::BlobTransactionSidecar, eip4895::Withdrawal, eip6110::DepositRequest,
eip7002::WithdrawalRequest, eip7251::ConsolidationRequest,
eip7002::WithdrawalRequest, eip7251::ConsolidationRequest, BlockNumHash,
};
use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256};
use core::iter::{FromIterator, IntoIterator};
Expand Down Expand Up @@ -192,6 +192,13 @@ pub struct ExecutionPayloadV1 {
pub transactions: Vec<Bytes>,
}

impl ExecutionPayloadV1 {
/// Returns the block number and hash as a [`BlockNumHash`].
pub const fn block_num_hash(&self) -> BlockNumHash {
BlockNumHash::new(self.block_number, self.block_hash)
}
}

/// This structure maps on the ExecutionPayloadV2 structure of the beacon chain spec.
///
/// See also: <https://github.com/ethereum/execution-apis/blob/6709c2a795b707202e93c4f2867fa0bf2640a84f/src/engine/shanghai.md#executionpayloadv2>
Expand Down Expand Up @@ -843,6 +850,11 @@ impl ExecutionPayload {
self.as_v1().block_number
}

/// Returns the block number for this payload.
pub const fn block_num_hash(&self) -> BlockNumHash {
self.as_v1().block_num_hash()
}

/// Returns the prev randao for this payload.
pub const fn prev_randao(&self) -> B256 {
self.as_v1().prev_randao
Expand Down