|
| 1 | +use crate::primitives::CustomTransaction; |
| 2 | +use alloy_consensus::{crypto::RecoveryError, transaction::Recovered}; |
| 3 | +use alloy_eips::{eip2718::WithEncoded, eip4895::Withdrawals}; |
| 4 | +use alloy_primitives::{Bloom, Bytes, B256}; |
| 5 | +use alloy_rpc_types_engine::PayloadId; |
| 6 | +use reth_optimism_flashblocks::{FlashblockDiff, FlashblockPayload, FlashblockPayloadBase}; |
| 7 | +use serde::{Deserialize, Deserializer}; |
| 8 | + |
| 9 | +#[derive(Debug, Clone, Default)] |
| 10 | +pub struct CustomFlashblockPayloadBase { |
| 11 | + pub parent_hash: B256, |
| 12 | + pub block_number: u64, |
| 13 | + pub timestamp: u64, |
| 14 | +} |
| 15 | + |
| 16 | +impl FlashblockPayloadBase for CustomFlashblockPayloadBase { |
| 17 | + fn parent_hash(&self) -> B256 { |
| 18 | + self.parent_hash |
| 19 | + } |
| 20 | + |
| 21 | + fn block_number(&self) -> u64 { |
| 22 | + self.block_number |
| 23 | + } |
| 24 | + |
| 25 | + fn timestamp(&self) -> u64 { |
| 26 | + self.timestamp |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +#[derive(Debug, Clone, Default)] |
| 31 | +pub struct CustomFlashblockPayloadDiff { |
| 32 | + pub block_hash: B256, |
| 33 | + pub state_root: B256, |
| 34 | + pub gas_used: u64, |
| 35 | + pub logs_bloom: Bloom, |
| 36 | + pub receipts_root: B256, |
| 37 | + pub transactions: Vec<Bytes>, |
| 38 | +} |
| 39 | + |
| 40 | +impl FlashblockDiff for CustomFlashblockPayloadDiff { |
| 41 | + fn block_hash(&self) -> B256 { |
| 42 | + self.block_hash |
| 43 | + } |
| 44 | + |
| 45 | + fn state_root(&self) -> B256 { |
| 46 | + self.state_root |
| 47 | + } |
| 48 | + |
| 49 | + fn gas_used(&self) -> u64 { |
| 50 | + self.gas_used |
| 51 | + } |
| 52 | + |
| 53 | + fn logs_bloom(&self) -> &Bloom { |
| 54 | + &self.logs_bloom |
| 55 | + } |
| 56 | + |
| 57 | + fn receipts_root(&self) -> B256 { |
| 58 | + self.receipts_root |
| 59 | + } |
| 60 | + |
| 61 | + fn transactions_raw(&self) -> &[Bytes] { |
| 62 | + &self.transactions |
| 63 | + } |
| 64 | + |
| 65 | + fn withdrawals(&self) -> Option<&Withdrawals> { |
| 66 | + None |
| 67 | + } |
| 68 | + |
| 69 | + fn withdrawals_root(&self) -> Option<B256> { |
| 70 | + None |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +#[derive(Debug, Clone)] |
| 75 | +pub struct CustomFlashblockPayload { |
| 76 | + pub index: u64, |
| 77 | + pub payload_id: PayloadId, |
| 78 | + pub base: Option<CustomFlashblockPayloadBase>, |
| 79 | + pub diff: CustomFlashblockPayloadDiff, |
| 80 | +} |
| 81 | + |
| 82 | +impl<'de> Deserialize<'de> for CustomFlashblockPayload { |
| 83 | + fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error> |
| 84 | + where |
| 85 | + D: Deserializer<'de>, |
| 86 | + { |
| 87 | + todo!("implement deserialization") |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +impl FlashblockPayload for CustomFlashblockPayload { |
| 92 | + type Base = CustomFlashblockPayloadBase; |
| 93 | + type Diff = CustomFlashblockPayloadDiff; |
| 94 | + type SignedTx = CustomTransaction; |
| 95 | + |
| 96 | + fn index(&self) -> u64 { |
| 97 | + self.index |
| 98 | + } |
| 99 | + |
| 100 | + fn payload_id(&self) -> PayloadId { |
| 101 | + self.payload_id |
| 102 | + } |
| 103 | + |
| 104 | + fn base(&self) -> Option<Self::Base> { |
| 105 | + self.base.clone() |
| 106 | + } |
| 107 | + |
| 108 | + fn diff(&self) -> &Self::Diff { |
| 109 | + &self.diff |
| 110 | + } |
| 111 | + |
| 112 | + fn block_number(&self) -> u64 { |
| 113 | + self.base.as_ref().map(|b| b.block_number()).unwrap_or(0) |
| 114 | + } |
| 115 | + |
| 116 | + fn recover_transactions( |
| 117 | + &self, |
| 118 | + ) -> impl Iterator<Item = Result<WithEncoded<Recovered<Self::SignedTx>>, RecoveryError>> { |
| 119 | + std::iter::from_fn(|| todo!("implement transaction recovery")) |
| 120 | + } |
| 121 | +} |
0 commit comments