From 6370e4a9b301979b2ff9995f115d682c425f04d3 Mon Sep 17 00:00:00 2001 From: renancloudwalk Date: Tue, 28 May 2024 21:24:28 -0300 Subject: [PATCH] chore: actually pass the block header --- src/eth/consensus.rs | 24 ++---------------------- src/eth/primitives/block_header.rs | 26 ++++++++++++++++++++++++++ src/eth/primitives/unix_time.rs | 4 ++++ 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/eth/consensus.rs b/src/eth/consensus.rs index fda870c2a..b9fac4893 100644 --- a/src/eth/consensus.rs +++ b/src/eth/consensus.rs @@ -254,28 +254,8 @@ impl Consensus { } #[tracing::instrument(skip_all)] - pub async fn append_block_commit_to_followers(_data: Block, followers: Vec) -> Result<(), anyhow::Error> { - let header = BlockHeader { - number: 0, - hash: "hash".to_string(), - transactions_root: "root".to_string(), - gas_used: "0".to_string(), - gas_limit: "0".to_string(), - bloom: "bloom".to_string(), - timestamp: 0, - parent_hash: "parent_hash".to_string(), - author: "author".to_string(), - extra_data: vec![], - miner: "miner".to_string(), - difficulty: "difficulty".to_string(), - receipts_root: "receipts_root".to_string(), - uncle_hash: "uncle_hash".to_string(), - size: 0, - state_root: "state_root".to_string(), - total_difficulty: "total_difficulty".to_string(), - nonce: "nonce".to_string(), - }; - + pub async fn append_block_commit_to_followers(block: Block, followers: Vec) -> Result<(), anyhow::Error> { + let header: BlockHeader = (&block.header).into(); let transaction_hashes = vec!["hash1".to_string(), "hash2".to_string()]; // Replace with actual transaction hashes let term = 0; // Populate with actual term diff --git a/src/eth/primitives/block_header.rs b/src/eth/primitives/block_header.rs index 8125cc5e2..7a3df2f49 100644 --- a/src/eth/primitives/block_header.rs +++ b/src/eth/primitives/block_header.rs @@ -16,6 +16,7 @@ use fake::Faker; use hex_literal::hex; use jsonrpsee::SubscriptionMessage; +use crate::eth::consensus::append_entry; use crate::eth::primitives::logs_bloom::LogsBloom; use crate::eth::primitives::Address; use crate::eth::primitives::BlockNumber; @@ -163,6 +164,31 @@ where } } +impl From<&BlockHeader> for append_entry::BlockHeader { + fn from(block_header: &BlockHeader) -> Self { + append_entry::BlockHeader { + number: block_header.number.into(), + hash: block_header.hash.to_string(), + transactions_root: block_header.transactions_root.to_string(), + gas_used: block_header.gas_used.to_string(), + gas_limit: block_header.gas_limit.to_string(), + bloom: block_header.bloom.to_string(), + timestamp: block_header.timestamp.as_u64(), + parent_hash: block_header.parent_hash.to_string(), + author: block_header.author.to_string(), + extra_data: block_header.extra_data.clone().0, + miner: block_header.miner.to_string(), + difficulty: block_header.difficulty.to_string(), + receipts_root: block_header.receipts_root.to_string(), + uncle_hash: block_header.uncle_hash.to_string(), + size: block_header.size.into(), + state_root: block_header.state_root.to_string(), + total_difficulty: block_header.total_difficulty.to_string(), + nonce: block_header.nonce.to_string(), + } + } +} + // ----------------------------------------------------------------------------- // Conversions: Other -> Self // ----------------------------------------------------------------------------- diff --git a/src/eth/primitives/unix_time.rs b/src/eth/primitives/unix_time.rs index 84ea5454f..1ef8661a6 100644 --- a/src/eth/primitives/unix_time.rs +++ b/src/eth/primitives/unix_time.rs @@ -43,6 +43,10 @@ impl UnixTime { pub fn to_i64(&self) -> i64 { self.0.try_into().expect("UNIX time is unrealistically high") } + + pub fn as_u64(&self) -> u64 { + self.0 + } } impl FromStr for UnixTime {