mod v1;
pub use v1::SignetHeaderV1;
#[cfg(feature = "experimental")]
mod v2;
#[cfg(feature = "experimental")]
#[allow(deprecated)]
pub use v2::SignetHeaderV2;
use alloy::consensus::{constants::EMPTY_ROOT_HASH, BlockHeader, Header};
use std::sync::LazyLock;
static DEFAULT_HEADER: LazyLock<Header> = LazyLock::new(Header::default);
#[derive(Debug, thiserror::Error)]
#[error("invalid signet header: expected default: {must_be_default:?}, expected non-default: {must_not_be_default:?}")]
pub struct SignetHeaderError {
pub must_be_default: Vec<&'static str>,
pub must_not_be_default: Vec<&'static str>,
}
pub(crate) fn check_shared_defaults(header: &Header) -> Vec<&'static str> {
let d = &*DEFAULT_HEADER;
let mut bad = Vec::new();
if header.ommers_hash() != d.ommers_hash() {
bad.push("ommers_hash");
}
if header.state_root() != d.state_root() {
bad.push("state_root");
}
if header.withdrawals_root() != d.withdrawals_root() {
bad.push("withdrawals_root");
}
if header.blob_gas_used() != d.blob_gas_used() {
bad.push("blob_gas_used");
}
if header.excess_blob_gas() != d.excess_blob_gas() {
bad.push("excess_blob_gas");
}
if header.requests_hash() != d.requests_hash() {
bad.push("requests_hash");
}
if header.extra_data() != d.extra_data() {
bad.push("extra_data");
}
bad
}
pub(crate) fn check_roots_empty(header: &Header) -> Vec<&'static str> {
let mut bad = Vec::new();
if header.transactions_root() != EMPTY_ROOT_HASH {
bad.push("transactions_root");
}
if header.receipts_root() != EMPTY_ROOT_HASH {
bad.push("receipts_root");
}
bad
}
#[cfg(feature = "experimental")]
pub(crate) fn check_roots_non_empty(header: &Header) -> Vec<&'static str> {
let mut bad = Vec::new();
if header.transactions_root() == EMPTY_ROOT_HASH {
bad.push("transactions_root");
}
if header.receipts_root() == EMPTY_ROOT_HASH {
bad.push("receipts_root");
}
bad
}