From 29c0827f9b3dfe8f870dbabdc595331c9220d65a Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 27 Apr 2022 16:29:24 +0200 Subject: [PATCH 1/2] feat: add full to sparse block conversion --- ethers-core/src/types/block.rs | 103 ++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/ethers-core/src/types/block.rs b/ethers-core/src/types/block.rs index cfe9d1799..33ebc1172 100644 --- a/ethers-core/src/types/block.rs +++ b/ethers-core/src/types/block.rs @@ -1,5 +1,5 @@ // Taken from -use crate::types::{Address, Bloom, Bytes, H256, U256, U64}; +use crate::types::{Address, Bloom, Bytes, Transaction, TxHash, H256, U256, U64}; #[cfg(not(feature = "celo"))] use core::cmp::Ordering; use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer}; @@ -137,6 +137,107 @@ impl Block { } } +impl From> for Block { + fn from(full: Block) -> Self { + #[cfg(not(feature = "celo"))] + { + let Block { + hash, + parent_hash, + uncles_hash, + author, + state_root, + transactions_root, + receipts_root, + number, + gas_used, + gas_limit, + extra_data, + logs_bloom, + timestamp, + difficulty, + total_difficulty, + seal_fields, + uncles, + transactions, + size, + mix_hash, + nonce, + base_fee_per_gas, + } = full; + Block { + hash, + parent_hash, + uncles_hash, + author, + state_root, + transactions_root, + receipts_root, + number, + gas_used, + gas_limit, + extra_data, + logs_bloom, + timestamp, + difficulty, + total_difficulty, + seal_fields, + uncles, + size, + mix_hash, + nonce, + base_fee_per_gas, + transactions: transactions.iter().map(|tx| tx.hash).collect(), + } + } + + #[cfg(feature = "celo")] + { + let Block { + hash, + parent_hash, + author, + state_root, + transactions_root, + receipts_root, + number, + gas_used, + extra_data, + logs_bloom, + timestamp, + total_difficulty, + seal_fields, + transactions, + size, + base_fee_per_gas, + randomness, + epoch_snark_data, + } = full; + + Block { + hash, + parent_hash, + author, + state_root, + transactions_root, + receipts_root, + number, + gas_used, + extra_data, + logs_bloom, + timestamp, + total_difficulty, + seal_fields, + size, + base_fee_per_gas, + randomness, + epoch_snark_data, + transactions: transactions.iter().map(|tx| tx.hash).collect(), + } + } + } +} + #[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)] #[cfg(feature = "celo")] /// Commit-reveal data for generating randomness in the From 855e93647949aff5babd770170986bd21794876c Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 27 Apr 2022 16:33:13 +0200 Subject: [PATCH 2/2] feat: add sparse to full block conversion --- ethers-core/src/types/block.rs | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/ethers-core/src/types/block.rs b/ethers-core/src/types/block.rs index 33ebc1172..c3038dc84 100644 --- a/ethers-core/src/types/block.rs +++ b/ethers-core/src/types/block.rs @@ -137,6 +137,108 @@ impl Block { } } +impl Block { + /// Converts this block that only holds transaction hashes into a full block with `Transaction` + pub fn into_full_block(self, transactions: Vec) -> Block { + #[cfg(not(feature = "celo"))] + { + let Block { + hash, + parent_hash, + uncles_hash, + author, + state_root, + transactions_root, + receipts_root, + number, + gas_used, + gas_limit, + extra_data, + logs_bloom, + timestamp, + difficulty, + total_difficulty, + seal_fields, + uncles, + size, + mix_hash, + nonce, + base_fee_per_gas, + .. + } = self; + Block { + hash, + parent_hash, + uncles_hash, + author, + state_root, + transactions_root, + receipts_root, + number, + gas_used, + gas_limit, + extra_data, + logs_bloom, + timestamp, + difficulty, + total_difficulty, + seal_fields, + uncles, + size, + mix_hash, + nonce, + base_fee_per_gas, + transactions, + } + } + + #[cfg(feature = "celo")] + { + let Block { + hash, + parent_hash, + author, + state_root, + transactions_root, + receipts_root, + number, + gas_used, + extra_data, + logs_bloom, + timestamp, + total_difficulty, + seal_fields, + size, + base_fee_per_gas, + randomness, + epoch_snark_data, + .. + } = self; + + Block { + hash, + parent_hash, + author, + state_root, + transactions_root, + receipts_root, + number, + gas_used, + extra_data, + logs_bloom, + timestamp, + total_difficulty, + seal_fields, + size, + base_fee_per_gas, + randomness, + epoch_snark_data, + transactions, + } + } + } +} + impl From> for Block { fn from(full: Block) -> Self { #[cfg(not(feature = "celo"))]