Skip to main content

amareleo_node_bft_ledger_service/
lib.rs

1// Copyright 2024 Aleo Network Foundation
2// This file is part of the snarkOS 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#![forbid(unsafe_code)]
17
18#[cfg(feature = "tracing")]
19#[macro_use]
20extern crate tracing;
21
22#[cfg(feature = "tracing")]
23#[macro_use]
24extern crate amareleo_chain_tracing;
25
26#[macro_use]
27extern crate async_trait;
28
29#[cfg(feature = "ledger")]
30pub mod ledger;
31#[cfg(feature = "ledger")]
32pub use ledger::*;
33
34#[cfg(feature = "mock")]
35pub mod mock;
36#[cfg(feature = "mock")]
37pub use mock::*;
38
39pub mod traits;
40pub use traits::*;
41
42/// Formats an ID into a truncated identifier (for logging purposes).
43pub fn fmt_id(id: impl ToString) -> String {
44    let id = id.to_string();
45    let mut formatted_id = id.chars().take(16).collect::<String>();
46    if id.chars().count() > 16 {
47        formatted_id.push_str("..");
48    }
49    formatted_id
50}
51
52/// A helper macro to spawn a blocking task.
53#[macro_export]
54macro_rules! spawn_blocking {
55    ($expr:expr) => {
56        match tokio::task::spawn_blocking(move || $expr).await {
57            Ok(value) => value,
58            Err(error) => Err(snarkvm::prelude::anyhow!("[tokio::spawn_blocking] {error}")),
59        }
60    };
61}