lib.rs
1 // Copyright (c) 2025 ADnet Contributors 2 // This file is part of the AlphaOS library. 3 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at: 7 8 // http://www.apache.org/licenses/LICENSE-2.0 9 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 // See https://github.com/ProvableHQ/snarkVM/issues/2775 17 #![forbid(unsafe_code)] 18 19 #[macro_use] 20 extern crate async_trait; 21 22 #[cfg(feature = "metrics")] 23 extern crate alphaos_node_metrics as metrics; 24 25 #[cfg(feature = "ledger")] 26 pub mod ledger; 27 #[cfg(feature = "ledger")] 28 pub use ledger::*; 29 30 #[cfg(feature = "mock")] 31 pub mod mock; 32 #[cfg(feature = "mock")] 33 pub use mock::*; 34 35 #[cfg(feature = "prover")] 36 pub mod prover; 37 #[cfg(feature = "prover")] 38 pub use prover::*; 39 40 #[cfg(feature = "translucent")] 41 pub mod translucent; 42 #[cfg(feature = "translucent")] 43 pub use translucent::*; 44 45 pub mod traits; 46 pub use traits::*; 47 48 /// Formats an ID into a truncated identifier (for logging purposes). 49 pub fn fmt_id(id: impl ToString) -> String { 50 let id = id.to_string(); 51 let mut formatted_id = id.chars().take(16).collect::<String>(); 52 if id.chars().count() > 16 { 53 formatted_id.push_str(".."); 54 } 55 formatted_id 56 } 57 58 /// A helper macro to spawn a blocking task. 59 #[macro_export] 60 macro_rules! spawn_blocking { 61 ($expr:expr) => { 62 match tokio::task::spawn_blocking(move || $expr).await { 63 Ok(value) => value, 64 Err(error) => Err(alphavm::prelude::anyhow!("[tokio::spawn_blocking] {error}")), 65 } 66 }; 67 }