cuprate_consensus_rules/
lib.rs1cfg_if::cfg_if! {
2 if #[cfg(test)] {
4 use proptest as _;
5 use proptest_derive as _;
6 use tokio as _;
7 }
8}
9
10use std::time::{SystemTime, UNIX_EPOCH};
11
12pub mod batch_verifier;
13pub mod blocks;
14mod decomposed_amount;
15pub mod genesis;
16pub mod hard_forks;
17pub mod miner_tx;
18pub mod transactions;
19
20pub use decomposed_amount::is_decomposed_amount;
21pub use hard_forks::{check_block_version_vote, HFVotes, HFsInfo, HardFork};
22pub use transactions::TxVersion;
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
25pub enum ConsensusError {
26 #[error("Block error: {0}")]
27 Block(#[from] blocks::BlockError),
28 #[error("Transaction error: {0}")]
29 Transaction(#[from] transactions::TransactionError),
30}
31
32fn check_point_canonically_encoded(point: &curve25519_dalek::edwards::CompressedEdwardsY) -> bool {
36 let bytes = point.as_bytes();
37
38 point
39 .decompress()
40 .filter(|point| point.compress().as_bytes() == bytes)
42 .is_some()
43}
44
45pub fn current_unix_timestamp() -> u64 {
47 SystemTime::now()
48 .duration_since(UNIX_EPOCH)
49 .unwrap()
50 .as_secs()
51}
52
53#[cfg(feature = "rayon")]
56fn try_par_iter<T>(t: T) -> T::Iter
57where
58 T: rayon::iter::IntoParallelIterator,
59{
60 t.into_par_iter()
61}
62
63#[cfg(not(feature = "rayon"))]
66fn try_par_iter<T>(t: T) -> impl Iterator<Item = T::Item>
67where
68 T: IntoIterator,
69{
70 t.into_iter()
71}