#![deny(missing_docs)]
#![allow(async_fn_in_trait)]
use std::fmt;
#[doc(hidden)]
pub use async_trait::async_trait;
#[cfg(all(not(target_arch = "wasm32"), unix))]
use tokio::signal::unix;
#[cfg(not(target_arch = "wasm32"))]
use {::tracing::debug, tokio_util::sync::CancellationToken};
pub mod abi;
#[cfg(not(target_arch = "wasm32"))]
pub mod command;
pub mod crypto;
pub mod data_types;
pub mod dyn_convert;
mod graphql;
pub mod hashed;
pub mod http;
pub mod identifiers;
mod limited_writer;
pub mod ownership;
#[cfg(not(target_arch = "wasm32"))]
pub mod port;
#[cfg(with_metrics)]
pub mod prometheus_util;
#[cfg(not(chain))]
pub mod task;
#[cfg(not(chain))]
pub use task::Task;
pub mod task_processor;
pub mod time;
#[cfg_attr(web, path = "tracing_web.rs")]
pub mod tracing;
#[cfg(not(target_arch = "wasm32"))]
pub mod tracing_opentelemetry;
#[cfg(test)]
mod unit_tests;
pub mod util;
pub mod vm;
pub use graphql::BcsHexParseError;
#[doc(hidden)]
pub use {async_graphql, bcs, hex};
#[macro_export]
macro_rules! ensure {
($cond:expr, $e:expr) => {
if !($cond) {
return Err($e.into());
}
};
}
pub fn hex_debug<T: AsRef<[u8]>>(bytes: &T, f: &mut fmt::Formatter) -> fmt::Result {
const ELIDE_AFTER: usize = 16;
let bytes = bytes.as_ref();
if bytes.len() <= 2 * ELIDE_AFTER {
write!(f, "{}", hex::encode(bytes))?;
} else {
write!(
f,
"{}..{}",
hex::encode(&bytes[..ELIDE_AFTER]),
hex::encode(&bytes[(bytes.len() - ELIDE_AFTER)..])
)?;
}
Ok(())
}
#[expect(clippy::ptr_arg)] pub fn hex_vec_debug(list: &Vec<Vec<u8>>, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[")?;
for (i, bytes) in list.iter().enumerate() {
if i != 0 {
write!(f, ", ")?;
}
hex_debug(bytes, f)?;
}
write!(f, "]")
}
pub fn visit_allocative_simple<T>(_: &T, visitor: &mut allocative::Visitor<'_>) {
visitor.visit_simple_sized::<T>();
}
#[cfg(not(target_arch = "wasm32"))]
pub async fn listen_for_shutdown_signals(shutdown_sender: CancellationToken) {
let _shutdown_guard = shutdown_sender.drop_guard();
#[cfg(unix)]
{
let mut sigint =
unix::signal(unix::SignalKind::interrupt()).expect("Failed to set up SIGINT handler");
let mut sigterm =
unix::signal(unix::SignalKind::terminate()).expect("Failed to set up SIGTERM handler");
let mut sighup =
unix::signal(unix::SignalKind::hangup()).expect("Failed to set up SIGHUP handler");
tokio::select! {
_ = sigint.recv() => debug!("Received SIGINT"),
_ = sigterm.recv() => debug!("Received SIGTERM"),
_ = sighup.recv() => debug!("Received SIGHUP"),
}
}
#[cfg(windows)]
{
tokio::signal::ctrl_c()
.await
.expect("Failed to set up Ctrl+C handler");
debug!("Received Ctrl+C");
}
}