Skip to content

Commit

Permalink
chore: actually pass the block header
Browse files Browse the repository at this point in the history
  • Loading branch information
renancloudwalk committed May 29, 2024
1 parent 5efea25 commit 6370e4a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
24 changes: 2 additions & 22 deletions src/eth/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,28 +254,8 @@ impl Consensus {
}

#[tracing::instrument(skip_all)]
pub async fn append_block_commit_to_followers(_data: Block, followers: Vec<Peer>) -> 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<Peer>) -> 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
Expand Down
26 changes: 26 additions & 0 deletions src/eth/primitives/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
// -----------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/eth/primitives/unix_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6370e4a

Please sign in to comment.