#![warn(missing_docs)]
use std::sync::Arc;
use fedimint_core::fedimint_build_code_version_env;
use fedimint_core::util::handle_version_hash_command;
use fedimint_gateway_server::Gateway;
use fedimint_logging::{LOG_GATEWAY, TracingSetup};
#[cfg(not(any(target_env = "msvc", target_os = "ios", target_os = "android")))]
use tikv_jemallocator::Jemalloc;
use tracing::info;
#[cfg(not(any(target_env = "msvc", target_os = "ios", target_os = "android")))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
fn main() -> Result<(), anyhow::Error> {
let runtime = Arc::new(tokio::runtime::Runtime::new()?);
runtime.block_on(async {
handle_version_hash_command(fedimint_build_code_version_env!());
TracingSetup::default().init()?;
let (mnemonic_sender, mnemonic_receiver) = tokio::sync::broadcast::channel::<()>(4);
let gatewayd = Gateway::new_with_default_modules(mnemonic_sender).await?;
let shutdown_receiver = gatewayd
.clone()
.run(runtime.clone(), mnemonic_receiver)
.await?;
shutdown_receiver.await;
gatewayd.unannounce_from_all_federations().await;
info!(target: LOG_GATEWAY, "Gatewayd exiting...");
Ok(())
})
}