#![allow(clippy::too_many_arguments)]
use super::*;
impl<N: Network> Metadata<N> {
pub fn verify(
&self,
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(), "Metadata is malformed in block {expected_height}");
ensure!(
self.round == expected_round,
"Round is incorrect in block {expected_height} (found '{}', expected '{}')",
self.round,
expected_round
);
ensure!(
self.height == expected_height,
"Height is incorrect in block {expected_height} (found '{}', expected '{}')",
self.height,
expected_height
);
ensure!(
self.cumulative_weight == expected_cumulative_weight,
"Cumulative weight is incorrect in block {expected_height} (found '{}', expected '{}')",
self.cumulative_weight,
expected_cumulative_weight
);
ensure!(
self.cumulative_proof_target == expected_cumulative_proof_target,
"Cumulative proof target is incorrect in block {expected_height} (found '{}', expected '{}')",
self.cumulative_proof_target,
expected_cumulative_proof_target
);
ensure!(
self.coinbase_target == expected_coinbase_target,
"Coinbase target is incorrect in block {expected_height} (found '{}', expected '{}')",
self.coinbase_target,
expected_coinbase_target
);
ensure!(
self.proof_target == expected_proof_target,
"Proof target is incorrect in block {expected_height} (found '{}', expected '{}')",
self.proof_target,
expected_proof_target
);
ensure!(
self.last_coinbase_target == expected_last_coinbase_target,
"Last coinbase target is incorrect in block {expected_height} (found '{}', expected '{}')",
self.last_coinbase_target,
expected_last_coinbase_target
);
ensure!(
self.last_coinbase_timestamp == expected_last_coinbase_timestamp,
"Last coinbase timestamp is incorrect in block {expected_height} (found '{}', expected '{}')",
self.last_coinbase_timestamp,
expected_last_coinbase_timestamp
);
ensure!(
self.timestamp == expected_timestamp,
"Timestamp is incorrect in block {expected_height} (found '{}', expected '{}')",
self.timestamp,
expected_timestamp
);
ensure!(
self.timestamp <= current_timestamp,
"Timestamp is in the future in block {expected_height} (found '{}', expected before '{}')",
self.timestamp,
current_timestamp
);
Ok(())
}
}