snarkos_node_bft_ledger_service/
lib.rs

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