mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: reuse alloy proof fns (#13091)
This commit is contained in:
@ -1,26 +1,22 @@
|
||||
//! Helper function for calculating Merkle proofs and hashes.
|
||||
|
||||
use crate::{Receipt, ReceiptWithBloom, ReceiptWithBloomRef};
|
||||
use alloc::{borrow::Borrow, vec::Vec};
|
||||
use alloy_consensus::{Header, EMPTY_OMMER_ROOT_HASH};
|
||||
use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawal};
|
||||
use alloy_primitives::{keccak256, B256};
|
||||
use alloy_trie::root::{ordered_trie_root, ordered_trie_root_with_encoder};
|
||||
use alloy_primitives::B256;
|
||||
use alloy_trie::root::ordered_trie_root_with_encoder;
|
||||
|
||||
/// Calculate a transaction root.
|
||||
///
|
||||
/// `(rlp(index), encoded(tx))` pairs.
|
||||
pub fn calculate_transaction_root<T>(transactions: &[T]) -> B256
|
||||
where
|
||||
T: Encodable2718,
|
||||
{
|
||||
ordered_trie_root_with_encoder(transactions, |tx, buf| tx.borrow().encode_2718(buf))
|
||||
}
|
||||
#[doc(inline)]
|
||||
pub use alloy_consensus::proofs::calculate_transaction_root;
|
||||
|
||||
/// Calculates the root hash of the withdrawals.
|
||||
pub fn calculate_withdrawals_root(withdrawals: &[Withdrawal]) -> B256 {
|
||||
ordered_trie_root(withdrawals)
|
||||
}
|
||||
#[doc(inline)]
|
||||
pub use alloy_consensus::proofs::calculate_withdrawals_root;
|
||||
|
||||
/// Calculates the root hash for ommer/uncle headers.
|
||||
#[doc(inline)]
|
||||
pub use alloy_consensus::proofs::calculate_ommers_root;
|
||||
|
||||
/// Calculates the receipt root for a header.
|
||||
pub fn calculate_receipt_root(receipts: &[ReceiptWithBloom]) -> B256 {
|
||||
@ -41,18 +37,6 @@ pub fn calculate_receipt_root_no_memo(receipts: &[&Receipt]) -> B256 {
|
||||
})
|
||||
}
|
||||
|
||||
/// Calculates the root hash for ommer/uncle headers.
|
||||
pub fn calculate_ommers_root(ommers: &[Header]) -> B256 {
|
||||
// Check if `ommers` list is empty
|
||||
if ommers.is_empty() {
|
||||
return EMPTY_OMMER_ROOT_HASH
|
||||
}
|
||||
// RLP Encode
|
||||
let mut ommers_rlp = Vec::new();
|
||||
alloy_rlp::encode_list(ommers, &mut ommers_rlp);
|
||||
keccak256(ommers_rlp)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user