|
| 1 | +// Module contains lightened versions of the entities. |
| 2 | + |
| 3 | +use super::*; |
| 4 | + |
| 5 | +#[derive(Debug, Clone, Decode, Encode, Deserialize, tree_hash_derive::TreeHash)] |
| 6 | +pub struct ExecutionPayload { |
| 7 | + pub parent_hash: Bytes32, |
| 8 | + pub fee_recipient: Address, |
| 9 | + pub state_root: Bytes32, |
| 10 | + pub receipts_root: Bytes32, |
| 11 | + pub logs_bloom: H256, |
| 12 | + pub prev_randao: Bytes32, |
| 13 | + #[serde(deserialize_with = "utils::deserialize_u64")] |
| 14 | + pub block_number: u64, |
| 15 | + #[serde(deserialize_with = "utils::deserialize_u64")] |
| 16 | + pub gas_limit: u64, |
| 17 | + #[serde(deserialize_with = "utils::deserialize_u64")] |
| 18 | + pub gas_used: u64, |
| 19 | + #[serde(deserialize_with = "utils::deserialize_u64")] |
| 20 | + pub timestamp: u64, |
| 21 | + pub extra_data: base_types::ByteList<32>, |
| 22 | + #[serde(deserialize_with = "utils::deserialize_u256")] |
| 23 | + pub base_fee_per_gas: U256, |
| 24 | + pub block_hash: Bytes32, |
| 25 | + pub transactions: H256, |
| 26 | + pub withdrawals: H256, |
| 27 | + #[serde(deserialize_with = "utils::deserialize_u64")] |
| 28 | + pub blob_gas_used: u64, |
| 29 | + #[serde(deserialize_with = "utils::deserialize_u64")] |
| 30 | + pub excess_blob_gas: u64, |
| 31 | +} |
| 32 | + |
| 33 | +impl From<super::ExecutionPayload> for ExecutionPayload { |
| 34 | + fn from(value: super::ExecutionPayload) -> Self { |
| 35 | + Self { |
| 36 | + parent_hash: value.parent_hash, |
| 37 | + fee_recipient: value.fee_recipient, |
| 38 | + state_root: value.state_root, |
| 39 | + receipts_root: value.receipts_root, |
| 40 | + logs_bloom: value.logs_bloom.tree_hash_root(), |
| 41 | + prev_randao: value.prev_randao, |
| 42 | + block_number: value.block_number, |
| 43 | + gas_limit: value.gas_limit, |
| 44 | + gas_used: value.gas_used, |
| 45 | + timestamp: value.timestamp, |
| 46 | + extra_data: value.extra_data, |
| 47 | + base_fee_per_gas: value.base_fee_per_gas, |
| 48 | + block_hash: value.block_hash, |
| 49 | + transactions: value.transactions.tree_hash_root(), |
| 50 | + withdrawals: value.withdrawals.tree_hash_root(), |
| 51 | + blob_gas_used: value.blob_gas_used, |
| 52 | + excess_blob_gas: value.excess_blob_gas, |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +#[derive(Debug, Clone, Decode, Encode, tree_hash_derive::TreeHash, Deserialize)] |
| 58 | +pub struct BlockBody { |
| 59 | + pub randao_reveal: H256, |
| 60 | + pub eth1_data: H256, |
| 61 | + pub graffiti: Bytes32, |
| 62 | + pub proposer_slashings: H256, |
| 63 | + pub attester_slashings: H256, |
| 64 | + pub attestations: H256, |
| 65 | + pub deposits: H256, |
| 66 | + pub voluntary_exits: H256, |
| 67 | + pub sync_aggregate: H256, |
| 68 | + pub execution_payload: ExecutionPayload, |
| 69 | + pub bls_to_execution_changes: H256, |
| 70 | + pub blob_kzg_commitments: H256, |
| 71 | +} |
| 72 | + |
| 73 | +impl From<super::BlockBody> for BlockBody { |
| 74 | + fn from(value: super::BlockBody) -> Self { |
| 75 | + Self { |
| 76 | + randao_reveal: value.randao_reveal.tree_hash_root(), |
| 77 | + eth1_data: value.eth1_data.tree_hash_root(), |
| 78 | + graffiti: value.graffiti, |
| 79 | + proposer_slashings: value.proposer_slashings.tree_hash_root(), |
| 80 | + attester_slashings: value.attester_slashings.tree_hash_root(), |
| 81 | + attestations: value.attestations.tree_hash_root(), |
| 82 | + deposits: value.deposits.tree_hash_root(), |
| 83 | + voluntary_exits: value.voluntary_exits.tree_hash_root(), |
| 84 | + sync_aggregate: value.sync_aggregate.tree_hash_root(), |
| 85 | + execution_payload: value.execution_payload.into(), |
| 86 | + bls_to_execution_changes: value.bls_to_execution_changes.tree_hash_root(), |
| 87 | + blob_kzg_commitments: value.blob_kzg_commitments.tree_hash_root(), |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +#[derive(Debug, Clone, tree_hash_derive::TreeHash, Decode, Encode, Deserialize)] |
| 93 | +pub struct Block { |
| 94 | + #[serde(deserialize_with = "utils::deserialize_u64")] |
| 95 | + pub slot: u64, |
| 96 | + #[serde(deserialize_with = "utils::deserialize_u64")] |
| 97 | + pub proposer_index: u64, |
| 98 | + pub parent_root: Hash256, |
| 99 | + pub state_root: Hash256, |
| 100 | + pub body: BlockBody, |
| 101 | +} |
| 102 | + |
| 103 | +impl From<super::Block> for Block { |
| 104 | + fn from(value: super::Block) -> Self { |
| 105 | + Self { |
| 106 | + slot: value.slot, |
| 107 | + proposer_index: value.proposer_index, |
| 108 | + parent_root: value.parent_root, |
| 109 | + state_root: value.state_root, |
| 110 | + body: value.body.into(), |
| 111 | + } |
| 112 | + } |
| 113 | +} |
0 commit comments