|
1 | 1 | //! Shim and utilities for signet-sdk to reth conversions. |
2 | 2 |
|
3 | 3 | use alloy::consensus::Block; |
4 | | -use reth::providers::Chain; |
5 | | -use signet_extract::{BlockAndReceipts, Extractable, HasTxns}; |
| 4 | +use signet_extract::HasTxns; |
6 | 5 | use signet_types::primitives::TransactionSigned; |
7 | 6 |
|
8 | 7 | /// A type alias for Reth's recovered block with a signed transaction. |
9 | 8 | type RethRecovered = reth::primitives::RecoveredBlock<Block<TransactionSigned>>; |
10 | 9 |
|
11 | | -/// A shim around Reth's [`Chain`]. |
12 | | -#[derive(Debug)] |
13 | | -#[repr(transparent)] |
14 | | -pub struct ExtractableChainShim<'a> { |
15 | | - /// The underlying Reth chain. |
16 | | - chain: &'a Chain, |
17 | | -} |
18 | | - |
19 | | -impl<'a> ExtractableChainShim<'a> { |
20 | | - /// Create a new shim around the given Reth chain. |
21 | | - pub const fn new(chain: &'a Chain) -> Self { |
22 | | - Self { chain } |
23 | | - } |
24 | | - |
25 | | - /// Get a reference to the underlying Reth chain. |
26 | | - pub const fn chain(&self) -> &'a Chain { |
27 | | - self.chain |
28 | | - } |
29 | | -} |
30 | | - |
31 | | -impl<'a> Extractable for ExtractableChainShim<'a> { |
32 | | - type Block = RecoveredBlockShim; |
33 | | - type Receipt = reth::primitives::Receipt; |
34 | | - |
35 | | - fn blocks_and_receipts( |
36 | | - &self, |
37 | | - ) -> impl Iterator<Item = BlockAndReceipts<'_, Self::Block, Self::Receipt>> { |
38 | | - self.chain.blocks_and_receipts().map(|(block, receipts)| { |
39 | | - // SAFETY: `RecoveredBlockShim` is `#[repr(transparent)]` over a |
40 | | - // single `RethRecovered` field, guaranteeing identical memory |
41 | | - // layout. This makes the reference transmute sound. |
42 | | - let block = |
43 | | - unsafe { std::mem::transmute::<&'a RethRecovered, &RecoveredBlockShim>(block) }; |
44 | | - BlockAndReceipts { block, receipts } |
45 | | - }) |
46 | | - } |
47 | | -} |
48 | | - |
49 | 10 | /// A shim for Reth's [`reth::primitives::RecoveredBlock`]. |
50 | 11 | #[derive(Debug)] |
51 | 12 | #[repr(transparent)] |
|
0 commit comments