-
Notifications
You must be signed in to change notification settings - Fork 252
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: network-parameterized block responses #1106
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
use alloy_primitives::{Address, BlockHash, Bytes, TxHash, U256}; | ||
use alloy_serde::WithOtherFields; | ||
|
||
use crate::BlockTransactions; | ||
|
||
/// Receipt JSON-RPC response. | ||
pub trait ReceiptResponse { | ||
/// Address of the created contract, or `None` if the transaction was not a deployment. | ||
|
@@ -46,6 +48,44 @@ pub trait TransactionResponse { | |
fn input(&self) -> &Bytes; | ||
} | ||
|
||
/// Header JSON-RPC response. | ||
pub trait HeaderResponse { | ||
/// Hash of the block | ||
fn hash(&self) -> Option<BlockHash>; | ||
|
||
/// Block number | ||
fn number(&self) -> Option<u64>; | ||
|
||
/// Block timestamp | ||
fn timestamp(&self) -> Option<u64>; | ||
|
||
/// Extra data | ||
fn extra_data(&self) -> &Bytes; | ||
|
||
/// Base fee per unit of gas (If EIP-1559 is supported) | ||
fn base_fee_per_gas(&self) -> Option<u128>; | ||
|
||
/// Blob fee for the next block (if EIP-4844 is supported) | ||
fn next_block_blob_fee(&self) -> Option<u128>; | ||
Comment on lines
+62
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a good start, we can add more functions based on the spec: https://ethereum.github.io/execution-apis/api-documentation/ |
||
} | ||
|
||
/// Block JSON-RPC response. | ||
pub trait BlockResponse { | ||
/// Header type | ||
type Header; | ||
/// Transaction type | ||
type Transaction; | ||
|
||
/// Block header | ||
fn header(&self) -> &Self::Header; | ||
|
||
/// Block transactions | ||
fn transactions(&self) -> &BlockTransactions<Self::Transaction>; | ||
|
||
/// Mutable reference to block transactions | ||
fn transactions_mut(&mut self) -> &mut BlockTransactions<Self::Transaction>; | ||
} | ||
|
||
impl<T: TransactionResponse> TransactionResponse for WithOtherFields<T> { | ||
fn tx_hash(&self) -> TxHash { | ||
self.inner.tx_hash() | ||
|
@@ -89,3 +129,46 @@ impl<T: ReceiptResponse> ReceiptResponse for WithOtherFields<T> { | |
self.inner.block_number() | ||
} | ||
} | ||
|
||
impl<T: BlockResponse> BlockResponse for WithOtherFields<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we do the same for HeaderResponse, in case the header is |
||
type Header = T::Header; | ||
type Transaction = T::Transaction; | ||
|
||
fn header(&self) -> &Self::Header { | ||
self.inner.header() | ||
} | ||
|
||
fn transactions(&self) -> &BlockTransactions<Self::Transaction> { | ||
self.inner.transactions() | ||
} | ||
|
||
fn transactions_mut(&mut self) -> &mut BlockTransactions<Self::Transaction> { | ||
self.inner.transactions_mut() | ||
} | ||
} | ||
|
||
impl<T: HeaderResponse> HeaderResponse for WithOtherFields<T> { | ||
fn hash(&self) -> Option<BlockHash> { | ||
self.inner.hash() | ||
} | ||
|
||
fn number(&self) -> Option<u64> { | ||
self.inner.number() | ||
} | ||
|
||
fn timestamp(&self) -> Option<u64> { | ||
self.inner.timestamp() | ||
} | ||
|
||
fn extra_data(&self) -> &Bytes { | ||
self.inner.extra_data() | ||
} | ||
|
||
fn base_fee_per_gas(&self) -> Option<u128> { | ||
self.inner.base_fee_per_gas() | ||
} | ||
|
||
fn next_block_blob_fee(&self) -> Option<u128> { | ||
self.inner.next_block_blob_fee() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use crate::Network; | ||
use alloy_consensus::TxType; | ||
use alloy_eips::eip2718::Eip2718Error; | ||
use alloy_rpc_types_eth::{AnyTransactionReceipt, Header, Transaction, TransactionRequest}; | ||
use alloy_rpc_types_eth::{AnyTransactionReceipt, Block, Header, Transaction, TransactionRequest}; | ||
use alloy_serde::WithOtherFields; | ||
use core::fmt; | ||
|
||
|
@@ -73,5 +73,7 @@ impl Network for AnyNetwork { | |
|
||
type ReceiptResponse = AnyTransactionReceipt; | ||
|
||
type HeaderResponse = WithOtherFields<Header>; | ||
type HeaderResponse = Header; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this remain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Header is getting flattened into block in RPC, so if block has additional fields those will get consumed by header's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, that makes sense |
||
|
||
type BlockResponse = WithOtherFields<Block<Self::TransactionResponse>>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it would be reasonable to expect these to exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have them as options due to pending blocks missing some of the fields? though looks like we have issues with deserializing them anyway:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meh, this complicates things a lot because for pending, there's a ton missing
this was for alchemy
so looks like we can't easily embed the header here anyway...