diff --git a/wallet-ffi/src/lib.rs b/wallet-ffi/src/lib.rs index 093c2f21..d4fa4051 100644 --- a/wallet-ffi/src/lib.rs +++ b/wallet-ffi/src/lib.rs @@ -28,9 +28,7 @@ pub mod transfer; pub mod types; pub mod wallet; -use once_cell::sync::OnceCell; -use std::sync::Arc; -use tokio::runtime::Runtime; +use tokio::runtime::{Handle}; use crate::error::{print_error, WalletFfiError}; @@ -38,15 +36,9 @@ use crate::error::{print_error, WalletFfiError}; pub use error::WalletFfiError as FfiError; pub use types::*; -// Global Tokio runtime - initialized once -static RUNTIME: OnceCell> = OnceCell::new(); - /// Get a reference to the global runtime. -pub(crate) fn get_runtime() -> Result<&'static Arc, WalletFfiError> { - RUNTIME.get().ok_or_else(|| { - print_error("Runtime not initialized. Call wallet_ffi_init_runtime() first."); - WalletFfiError::RuntimeError - }) +pub(crate) fn get_runtime() -> Result { + Handle::try_current().map_err(|_| WalletFfiError::RuntimeError) } /// Run an async future on the global runtime, blocking until completion. @@ -65,12 +57,9 @@ pub(crate) fn block_on(future: F) -> Result WalletFfiError { - let result = RUNTIME.get_or_try_init(|| { - tokio::runtime::Builder::new_multi_thread() - .enable_all() - .build() - .map(Arc::new) - }); + let result = tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build(); match result { Ok(_) => WalletFfiError::Success, @@ -80,13 +69,3 @@ pub extern "C" fn wallet_ffi_init_runtime() -> WalletFfiError { } } } - -/// Check if the runtime is initialized. -/// -/// # Returns -/// - `true` if the runtime is ready -/// - `false` if `wallet_ffi_init_runtime()` hasn't been called yet -#[no_mangle] -pub extern "C" fn wallet_ffi_runtime_initialized() -> bool { - RUNTIME.get().is_some() -} diff --git a/wallet-ffi/wallet_ffi.h b/wallet-ffi/wallet_ffi.h index 7ae524ba..4158110b 100644 --- a/wallet-ffi/wallet_ffi.h +++ b/wallet-ffi/wallet_ffi.h @@ -218,15 +218,6 @@ typedef struct FfiTransferResult { */ enum WalletFfiError wallet_ffi_init_runtime(void); -/** - * Check if the runtime is initialized. - * - * # Returns - * - `true` if the runtime is ready - * - `false` if `wallet_ffi_init_runtime()` hasn't been called yet - */ -bool wallet_ffi_runtime_initialized(void); - /** * Create a new public account. *