1pub mod block;
2pub mod crypto;
3pub mod header;
4pub mod transaction;
5pub mod types;
6pub mod utils;
7
8pub use types::*;
10pub use utils::codec::{Decode, Encode};
11
12pub type PrimitiveResult<T> = Result<T, PrimitiveError>;
14
15#[derive(Debug, Clone, PartialEq, Eq)]
17pub enum PrimitiveError {
18 InvalidFormat,
20 ValidationFailed(String),
22 CodecError(String),
24 CryptoError(String),
26 InvalidBlock(String),
28 SizeLimit(String),
30 InvalidTransaction(String),
32 InvalidHeader(String),
34}
35
36impl std::fmt::Display for PrimitiveError {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 match self {
39 PrimitiveError::InvalidFormat => write!(f, "Invalid data format"),
40 PrimitiveError::ValidationFailed(msg) => write!(f, "Validation failed: {}", msg),
41 PrimitiveError::CodecError(msg) => write!(f, "Codec error: {}", msg),
42 PrimitiveError::CryptoError(msg) => write!(f, "Crypto error: {}", msg),
43 PrimitiveError::InvalidBlock(msg) => write!(f, "Invalid block: {}", msg),
44 PrimitiveError::SizeLimit(msg) => write!(f, "Size limit exceeded: {}", msg),
45 PrimitiveError::InvalidTransaction(msg) => write!(f, "Invalid transaction: {}", msg),
46 PrimitiveError::InvalidHeader(msg) => write!(f, "Invalid header: {}", msg),
47 }
48 }
49}
50
51impl std::error::Error for PrimitiveError {}
52
53pub trait Hashable {
55 fn hash(&self) -> Hash;
56}
57
58pub trait Validate {
60 fn validate(&self) -> PrimitiveResult<()>;
61}
62
63pub mod constants {
65 pub const MAX_BLOCK_SIZE: u32 = 4 * 1024 * 1024; pub const MAX_CORES: u32 = 1023;
70
71 pub const MAX_ACCUMULATION_SIZE: u32 = 1024 * 1024; }
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 #[test]
80 fn test_primitive_error_display() {
81 let err = PrimitiveError::ValidationFailed("test error".to_string());
82 assert_eq!(format!("{}", err), "Validation failed: test error");
83 }
84}