#![allow(clippy::too_many_arguments)]
use super::*;
impl<N: Network> Header<N> {
pub fn verify(
&self,
expected_previous_state_root: N::StateRoot,
expected_transactions_root: Field<N>,
expected_finalize_root: Field<N>,
expected_ratifications_root: Field<N>,
expected_solutions_root: Field<N>,
expected_subdag_root: Field<N>,
expected_round: u64,
expected_height: u32,
expected_cumulative_weight: u128,
expected_cumulative_proof_target: u128,
expected_coinbase_target: u64,
expected_proof_target: u64,
expected_last_coinbase_target: u64,
expected_last_coinbase_timestamp: i64,
expected_timestamp: i64,
current_timestamp: i64,
) -> Result<()> {
ensure!(self.is_valid(), "Header is malformed in block {expected_height}");
ensure!(
self.previous_state_root == expected_previous_state_root,
"Previous state root is incorrect in block {expected_height} (found '{}', expected '{}')",
self.previous_state_root,
expected_previous_state_root
);
ensure!(
self.transactions_root == expected_transactions_root,
"Transactions root is incorrect in block {expected_height} (found '{}', expected '{}')",
self.transactions_root,
expected_transactions_root
);
ensure!(
self.finalize_root == expected_finalize_root,
"Finalize root is incorrect in block {expected_height} (found '{}', expected '{}')",
self.finalize_root,
expected_finalize_root
);
ensure!(
self.ratifications_root == expected_ratifications_root,
"Ratifications root is incorrect in block {expected_height} (found '{}', expected '{}')",
self.ratifications_root,
expected_ratifications_root
);
ensure!(
self.solutions_root == expected_solutions_root,
"Solutions root is incorrect in block {expected_height} (found '{}', expected '{}')",
self.solutions_root,
expected_solutions_root
);
ensure!(
self.subdag_root == expected_subdag_root,
"Subdag root is incorrect in block {expected_height} (found '{}', expected '{}')",
self.subdag_root,
expected_subdag_root
);
self.metadata.verify(
expected_round,
expected_height,
expected_cumulative_weight,
expected_cumulative_proof_target,
expected_coinbase_target,
expected_proof_target,
expected_last_coinbase_target,
expected_last_coinbase_timestamp,
expected_timestamp,
current_timestamp,
)
}
}