1cfg_if::cfg_if! {
2// Used in external `tests/`.
3if #[cfg(test)] {
4use proptest as _;
5use proptest_derive as _;
6use tokio as _;
7 }
8}
910use std::time::{SystemTime, UNIX_EPOCH};
1112pub mod batch_verifier;
13pub mod blocks;
14mod decomposed_amount;
15pub mod genesis;
16pub mod hard_forks;
17pub mod miner_tx;
18pub mod transactions;
1920pub use decomposed_amount::is_decomposed_amount;
21pub use hard_forks::{check_block_version_vote, HFVotes, HFsInfo, HardFork};
22pub use transactions::TxVersion;
2324#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
25pub enum ConsensusError {
26#[error("Block error: {0}")]
27Block(#[from] blocks::BlockError),
28#[error("Transaction error: {0}")]
29Transaction(#[from] transactions::TransactionError),
30}
3132/// Checks that a point is canonically encoded.
33///
34/// <https://github.com/dalek-cryptography/curve25519-dalek/issues/380>
35fn check_point_canonically_encoded(point: &curve25519_dalek::edwards::CompressedEdwardsY) -> bool {
36let bytes = point.as_bytes();
3738 point
39 .decompress()
40// Ban points which are either unreduced or -0
41.filter(|point| point.compress().as_bytes() == bytes)
42 .is_some()
43}
4445/// Returns the current UNIX timestamp.
46pub fn current_unix_timestamp() -> u64 {
47 SystemTime::now()
48 .duration_since(UNIX_EPOCH)
49 .unwrap()
50 .as_secs()
51}
5253/// An internal function that returns an iterator or a parallel iterator if the
54/// `rayon` feature is enabled.
55#[cfg(feature = "rayon")]
56fn try_par_iter<T>(t: T) -> T::Iter
57where
58T: rayon::iter::IntoParallelIterator,
59{
60 t.into_par_iter()
61}
6263/// An internal function that returns an iterator or a parallel iterator if the
64/// `rayon` feature is enabled.
65#[cfg(not(feature = "rayon"))]
66fn try_par_iter<T>(t: T) -> impl Iterator<Item = T::Item>
67where
68T: IntoIterator,
69{
70 t.into_iter()
71}