pub mod icrc21;
use crate::{ids::EndpointCall, perf};
use std::future::Future;
#[cfg_attr(not(target_arch = "wasm32"), expect(clippy::missing_const_for_fn))]
fn ensure_memory_bootstrap() {
#[cfg(target_arch = "wasm32")]
{
if let Err(err) = crate::ops::runtime::memory::MemoryRegistryOps::ensure_bootstrap() {
panic!("runtime memory bootstrap failed before endpoint dispatch: {err}");
}
}
}
fn enter_endpoint() {
ensure_memory_bootstrap();
perf::enter_endpoint();
}
pub fn preflight_endpoint(call: EndpointCall) {
ensure_memory_bootstrap();
enforce_fleet_activation_fence(call);
}
#[cfg_attr(not(target_arch = "wasm32"), expect(clippy::missing_const_for_fn))]
fn enforce_fleet_activation_fence(call: EndpointCall) {
#[cfg(target_arch = "wasm32")]
if let Err(error) =
crate::workflow::runtime::fleet_activation::FleetActivationWorkflow::require_endpoint_allowed(
call,
)
{
panic!(
"Fleet activation fence rejected endpoint {}: {error}",
call.endpoint.name
);
}
#[cfg(not(target_arch = "wasm32"))]
{
let _ = call;
let _ = crate::workflow::runtime::fleet_activation::FleetActivationWorkflow::require_endpoint_allowed;
}
}
pub fn dispatch_query<R>(call: EndpointCall, f: impl FnOnce() -> R) -> R {
enter_endpoint();
let res = f();
perf::exit_endpoint(call);
res
}
pub async fn dispatch_query_async<R, F>(call: EndpointCall, f: impl FnOnce() -> F) -> R
where
F: Future<Output = R>,
{
enter_endpoint();
let res = f().await;
perf::exit_endpoint(call);
res
}
pub fn dispatch_update<R>(call: EndpointCall, f: impl FnOnce() -> R) -> R {
enter_endpoint();
let res = f();
perf::exit_endpoint(call);
res
}
pub async fn dispatch_update_async<R, F>(call: EndpointCall, f: impl FnOnce() -> F) -> R
where
F: Future<Output = R>,
{
enter_endpoint();
let res = f().await;
perf::exit_endpoint(call);
res
}