From abff3a1685e98842c22edfc3d0b84ce85be8e391 Mon Sep 17 00:00:00 2001 From: Anton Yemelyanov Date: Sat, 18 Nov 2023 02:49:38 +0200 Subject: [PATCH] wip - renaming interop to runtime 2/2 --- core/src/adaptor.rs | 10 ++-- core/src/app.rs | 30 ++++++------ core/src/core.rs | 40 ++++++++-------- core/src/imports.rs | 6 +-- core/src/lib.rs | 2 +- core/src/modules/about.rs | 6 +-- core/src/modules/account_create.rs | 19 ++++---- core/src/modules/account_manager.rs | 18 ++++---- core/src/modules/changelog.rs | 6 +-- core/src/modules/deposit.rs | 6 +-- core/src/modules/export.rs | 8 ++-- core/src/modules/import.rs | 8 ++-- core/src/modules/logs.rs | 8 ++-- core/src/modules/metrics.rs | 12 ++--- core/src/modules/node.rs | 8 ++-- core/src/modules/overview.rs | 10 ++-- core/src/modules/request.rs | 6 +-- core/src/modules/send.rs | 6 +-- core/src/modules/settings.rs | 10 ++-- core/src/modules/testing.rs | 8 ++-- core/src/modules/tools/check_balance.rs | 8 ++-- core/src/modules/transactions.rs | 6 +-- core/src/modules/wallet_create.rs | 8 ++-- core/src/modules/wallet_open.rs | 8 ++-- core/src/modules/welcome.rs | 8 ++-- core/src/{interop => runtime}/mod.rs | 46 +++++++++---------- core/src/{interop => runtime}/panic.rs | 2 +- core/src/{interop => runtime}/payload.rs | 0 .../services/kaspa/config.rs | 0 .../services/kaspa/daemon.rs | 2 +- .../services/kaspa/inproc.rs | 2 +- .../services/kaspa/logs.rs | 0 .../services/kaspa/mod.rs | 21 ++++----- .../{interop => runtime}/services/metrics.rs | 2 +- core/src/{interop => runtime}/services/mod.rs | 0 .../{interop => runtime}/services/peers.rs | 0 core/src/{interop => runtime}/signals.rs | 14 +++--- extensions/chrome/src/ipc.rs | 4 +- extensions/chrome/src/server.rs | 2 +- macros/src/register.rs | 4 +- 40 files changed, 182 insertions(+), 182 deletions(-) rename core/src/{interop => runtime}/mod.rs (89%) rename core/src/{interop => runtime}/panic.rs (84%) rename core/src/{interop => runtime}/payload.rs (100%) rename core/src/{interop => runtime}/services/kaspa/config.rs (100%) rename core/src/{interop => runtime}/services/kaspa/daemon.rs (98%) rename core/src/{interop => runtime}/services/kaspa/inproc.rs (98%) rename core/src/{interop => runtime}/services/kaspa/logs.rs (100%) rename core/src/{interop => runtime}/services/kaspa/mod.rs (97%) rename core/src/{interop => runtime}/services/metrics.rs (99%) rename core/src/{interop => runtime}/services/mod.rs (100%) rename core/src/{interop => runtime}/services/peers.rs (100%) rename core/src/{interop => runtime}/signals.rs (80%) diff --git a/core/src/adaptor.rs b/core/src/adaptor.rs index 61ebdd9..9ca6952 100644 --- a/core/src/adaptor.rs +++ b/core/src/adaptor.rs @@ -5,12 +5,12 @@ use wasm_bindgen::prelude::*; struct Inner { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, } impl Inner { - pub fn new(interop: Interop) -> Self { - Self { interop } + pub fn new(runtime: Runtime) -> Self { + Self { runtime } } } @@ -21,9 +21,9 @@ pub struct Adaptor { } impl Adaptor { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - inner: Arc::new(Inner::new(interop.clone())), + inner: Arc::new(Inner::new(runtime.clone())), } } } diff --git a/core/src/app.rs b/core/src/app.rs index 12219f7..c3235e2 100644 --- a/core/src/app.rs +++ b/core/src/app.rs @@ -1,6 +1,6 @@ use crate::result::Result; use cfg_if::cfg_if; -use kaspa_ng_core::interop; +use kaspa_ng_core::runtime; use kaspa_ng_core::settings::Settings; use kaspa_wallet_core::api::WalletApi; use std::sync::Arc; @@ -124,7 +124,7 @@ cfg_if! { use std::sync::Mutex; - interop::panic::init_panic_handler(); + runtime::panic::init_panic_handler(); match parse_args() { Args::Cli => { @@ -213,8 +213,8 @@ cfg_if! { settings.node.node_kind = kaspa_ng_core::settings::KaspadNodeKind::Disable; } - let interop: Arc>> = Arc::new(Mutex::new(None)); - let delegate = interop.clone(); + let runtime: Arc>> = Arc::new(Mutex::new(None)); + let delegate = runtime.clone(); // println!("spawn done"); let native_options = eframe::NativeOptions { icon_data : IconData::try_from_png_bytes(KASPA_NG_ICON_256X256).ok(), @@ -227,17 +227,17 @@ cfg_if! { "Kaspa NG", native_options, Box::new(move |cc| { - let interop = interop::Interop::new(&cc.egui_ctx, &settings); - delegate.lock().unwrap().replace(interop.clone()); - interop::signals::Signals::bind(&interop); - interop.start(); + let runtime = runtime::Runtime::new(&cc.egui_ctx, &settings); + delegate.lock().unwrap().replace(runtime.clone()); + runtime::signals::Signals::bind(&runtime); + runtime.start(); - Box::new(kaspa_ng_core::Core::new(cc, interop, settings)) + Box::new(kaspa_ng_core::Core::new(cc, runtime, settings)) }), )?; - let interop = interop.lock().unwrap().take().unwrap(); - interop.shutdown().await; + let runtime = runtime.lock().unwrap().take().unwrap(); + runtime.shutdown().await; } } @@ -288,10 +288,10 @@ cfg_if! { "kaspa-ng", web_options, Box::new(move |cc| { - let interop = interop::Interop::new(&cc.egui_ctx, &settings); - interop.start(); + let runtime = runtime::Runtime::new(&cc.egui_ctx, &settings); + runtime.start(); - let adaptor = kaspa_ng_core::adaptor::Adaptor::new(interop.clone()); + let adaptor = kaspa_ng_core::adaptor::Adaptor::new(runtime.clone()); let window = web_sys::window().expect("no global `window` exists"); js_sys::Reflect::set( &window, @@ -299,7 +299,7 @@ cfg_if! { &JsValue::from(adaptor), ).expect("failed to set adaptor"); - Box::new(kaspa_ng_core::Core::new(cc, interop, settings)) + Box::new(kaspa_ng_core::Core::new(cc, runtime, settings)) }), ) .await diff --git a/core/src/core.rs b/core/src/core.rs index 7095723..dd6a7ff 100644 --- a/core/src/core.rs +++ b/core/src/core.rs @@ -1,5 +1,5 @@ use crate::imports::*; -use crate::interop::Interop; +use crate::runtime::Runtime; use crate::sync::SyncStatus; use egui_notify::Toasts; use kaspa_metrics::MetricsSnapshot; @@ -76,7 +76,7 @@ impl State { } pub struct Core { - interop: Interop, + runtime: Runtime, wallet: Arc, channel: ApplicationEventsChannel, module: Module, @@ -102,7 +102,7 @@ impl Core { /// Core initialization pub fn new( cc: &eframe::CreationContext<'_>, - interop: crate::interop::Interop, + runtime: crate::runtime::Runtime, mut settings: Settings, ) -> Self { let mut fonts = egui::FontDefinitions::default(); @@ -253,11 +253,11 @@ impl Core { let modules: HashMap = { cfg_if! { if #[cfg(not(target_arch = "wasm32"))] { - crate::modules::register_generic_modules(&interop).into_iter().chain( - crate::modules::register_native_modules(&interop) + crate::modules::register_generic_modules(&runtime).into_iter().chain( + crate::modules::register_native_modules(&runtime) ).collect() } else { - crate::modules::register_generic_modules(&interop) + crate::modules::register_generic_modules(&runtime) } } }; @@ -284,11 +284,11 @@ impl Core { .clone(); } - let channel = interop.application_events().clone(); - let wallet = interop.wallet().clone(); + let channel = runtime.application_events().clone(); + let wallet = runtime.wallet().clone(); let mut this = Self { - interop, + runtime, wallet, channel, module, @@ -340,7 +340,7 @@ impl Core { { let type_id = self.module.type_id(); - crate::interop::services::kaspa::update_logs_flag() + crate::runtime::services::kaspa::update_logs_flag() .store(type_id == TypeId::of::(), Ordering::Relaxed); // crate::runtime::kaspa::update_metrics_flag().store( // type_id == TypeId::of::() @@ -419,7 +419,7 @@ impl eframe::App for Core { #[cfg(not(target_arch = "wasm32"))] fn on_exit(&mut self, _gl: Option<&eframe::glow::Context>) { - crate::interop::halt(); + crate::runtime::halt(); } /// Called each time the UI needs repainting, which may be many times per second. @@ -428,7 +428,7 @@ impl eframe::App for Core { // println!("update..."); for event in self.channel.iter() { if let Err(err) = self.handle_events(event.clone(), ctx, frame) { - log_error!("error processing wallet interop event: {}", err); + log_error!("error processing wallet runtime event: {}", err); } } @@ -777,9 +777,9 @@ impl Core { if !self.state().is_connected() { self.render_connected_state(ui, Status::Disconnected); } else { - // let metrics = self.interop.kaspa_service().metrics(); + // let metrics = self.runtime.kaspa_service().metrics(); let peers = self - .interop + .runtime .peer_monitor_service() .peer_info() .map(|peers| peers.len()); @@ -1195,10 +1195,10 @@ impl Core { } pub fn wallet_update_list(&self) { - let interop = self.interop.clone(); + let runtime = self.runtime.clone(); spawn(async move { - let wallet_list = interop.wallet().wallet_enumerate().await?; - interop + let wallet_list = runtime.wallet().wallet_enumerate().await?; + runtime .send(Events::WalletList { wallet_list: Arc::new(wallet_list), }) @@ -1219,7 +1219,7 @@ impl Core { self.account_collection = Some(account_list.clone().into()); - let interop = self.interop.clone(); + let runtime = self.runtime.clone(); spawn(async move { let account_ids = account_list .iter() @@ -1234,7 +1234,7 @@ impl Core { let futures = account_ids .into_iter() .map(|account_id| { - interop + runtime .wallet() .transaction_data_get_range(account_id, network_id, 0..128) }) @@ -1263,7 +1263,7 @@ impl Core { } }); - interop.wallet().accounts_activate(None).await?; + runtime.wallet().accounts_activate(None).await?; Ok(()) }); diff --git a/core/src/imports.rs b/core/src/imports.rs index d17690c..aa9e7ea 100644 --- a/core/src/imports.rs +++ b/core/src/imports.rs @@ -9,7 +9,7 @@ pub use kaspa_wallet_core::api; pub use kaspa_wallet_core::api::WalletApi; pub use kaspa_wallet_core::events::SyncState; pub use kaspa_wallet_core::rpc::DynRpcApi; -pub use kaspa_wallet_core::runtime; +pub use kaspa_wallet_core::runtime::{Account as KaspaAccount, Wallet as KaspaWallet}; pub use kaspa_wallet_core::runtime::{AccountDescriptor, AccountId, Balance}; pub use kaspa_wallet_core::secret::Secret; pub use kaspa_wallet_core::storage::{ @@ -68,8 +68,6 @@ pub use crate::events::{ApplicationEventsChannel, Events}; // pub use crate::channel::Channel; pub use crate::collection::Collection; pub use crate::core::Core; -pub use crate::interop; -pub use crate::interop::{spawn, spawn_with_result, Interop, Payload, Service}; pub use crate::modules; pub use crate::modules::{Module, ModuleCaps, ModuleStyle, ModuleT}; pub use crate::network::Network; @@ -78,6 +76,8 @@ pub use crate::panel::Panel; pub use crate::primitives::{Account, AccountCollection, Transaction, TransactionCollection}; pub use crate::prompt::{cascade, with_secret}; pub use crate::result::Result; +pub use crate::runtime; +pub use crate::runtime::{spawn, spawn_with_result, Payload, Runtime, Service}; pub use crate::settings::{ KaspadNodeKind, NetworkInterfaceConfig, NetworkInterfaceKind, NodeSettings, RpcConfig, Settings, UxSettings, diff --git a/core/src/lib.rs b/core/src/lib.rs index a2aa25c..9dcf950 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -13,7 +13,6 @@ pub mod egui; pub mod error; pub mod events; pub mod imports; -pub mod interop; pub mod modules; pub mod network; pub mod notifications; @@ -21,6 +20,7 @@ pub mod panel; pub mod primitives; pub mod prompt; pub mod result; +pub mod runtime; pub mod settings; pub mod sync; pub mod utils; diff --git a/core/src/modules/about.rs b/core/src/modules/about.rs index 4af0522..36c8b59 100644 --- a/core/src/modules/about.rs +++ b/core/src/modules/about.rs @@ -2,12 +2,12 @@ use crate::imports::*; pub struct About { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, } impl About { - pub fn new(interop: Interop) -> Self { - Self { interop } + pub fn new(runtime: Runtime) -> Self { + Self { runtime } } } diff --git a/core/src/modules/account_create.rs b/core/src/modules/account_create.rs index 5127957..248590a 100644 --- a/core/src/modules/account_create.rs +++ b/core/src/modules/account_create.rs @@ -6,6 +6,7 @@ use kaspa_wallet_core::runtime::{AccountCreateArgs, PrvKeyDataCreateArgs, Wallet use kaspa_wallet_core::storage::interface::AccessContext; use kaspa_wallet_core::storage::{AccessContextT, AccountKind}; + #[derive(Clone)] pub enum State { Start, @@ -17,26 +18,26 @@ pub enum State { AccountError(Arc), PresentMnemonic(Arc), ConfirmMnemonic(Arc), - Finish(Arc), + Finish(Arc), } pub enum CreationData { Bip32 { mnemonic: Option, - account: Arc, + account: Arc, }, Keypair { private_key: Secret, - account: Arc, + account: Arc, }, MultiSig { mnemonics: Vec, - account: Arc, + account: Arc, }, } impl CreationData { - pub fn account(&self) -> Arc { + pub fn account(&self) -> Arc { match self { Self::Bip32 { account, .. } => account.clone(), Self::Keypair { account, .. } => account.clone(), @@ -58,16 +59,16 @@ struct Context { pub struct AccountCreate { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, // secret: String, args: Context, pub state: State, } impl AccountCreate { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - interop, + runtime, // secret: String::new(), state: State::Start, args: Default::default(), @@ -226,7 +227,7 @@ impl ModuleT for AccountCreate { if !wallet_create_result.is_pending() { // TODO CREATE WALLET ! - let _wallet = self.interop.wallet().clone(); + let _wallet = self.runtime.wallet().clone(); spawn_with_result(&wallet_create_result, async move { if args.enable_payment_secret && args.payment_secret.is_empty() { diff --git a/core/src/modules/account_manager.rs b/core/src/modules/account_manager.rs index 1a3c912..d508706 100644 --- a/core/src/modules/account_manager.rs +++ b/core/src/modules/account_manager.rs @@ -40,7 +40,7 @@ enum Estimate { pub struct AccountManager { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, selected: Option, state: State, @@ -56,9 +56,9 @@ pub struct AccountManager { } impl AccountManager { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - interop, + runtime, selected: None, state: State::Select, send_address : String::new(), @@ -346,7 +346,7 @@ impl AccountManager { // - TODO - let address = Address::try_from("kaspatest:qqz22l98sf8jun72rwh5rqe2tm8lhwtdxdmynrz4ypwak427qed5juktjt7ju").expect("Invalid address"); // let address = Address::try_from(context.address()).expect("Invalid address"); - let interop = self.interop.clone(); + let runtime = self.runtime.clone(); let account_id = account.id(); let payment_output = PaymentOutput { address, @@ -364,7 +364,7 @@ impl AccountManager { payload: None, }; - match interop.wallet().accounts_estimate_call(request).await { + match runtime.wallet().accounts_estimate_call(request).await { Ok(response) => { *estimate.lock().unwrap() = Estimate::GeneratorSummary(response.generator_summary); } @@ -373,7 +373,7 @@ impl AccountManager { } } - interop.egui_ctx().request_repaint(); + runtime.egui_ctx().request_repaint(); Ok(()) }); @@ -458,7 +458,7 @@ impl AccountManager { // let address = Address::try_from(context.address()).expect("Invalid address"); let address = Address::try_from("kaspatest:qqz22l98sf8jun72rwh5rqe2tm8lhwtdxdmynrz4ypwak427qed5juktjt7ju").expect("Invalid address"); - let interop = self.interop.clone(); + let runtime = self.runtime.clone(); let account_id = account.id(); let payment_output = PaymentOutput { address, @@ -478,7 +478,7 @@ impl AccountManager { payload: None, }; - match interop.wallet().accounts_send_call(request).await { + match runtime.wallet().accounts_send_call(request).await { Ok(response) => { println!("****** RESPONSE: {:?}", response); // *estimate.lock().unwrap() = Estimate::GeneratorSummary(response.generator_summary); @@ -489,7 +489,7 @@ impl AccountManager { } } - interop.egui_ctx().request_repaint(); + runtime.egui_ctx().request_repaint(); Ok(()) }); diff --git a/core/src/modules/changelog.rs b/core/src/modules/changelog.rs index e6965c3..7051ec0 100644 --- a/core/src/modules/changelog.rs +++ b/core/src/modules/changelog.rs @@ -2,15 +2,15 @@ use crate::imports::*; use crate::egui::easy_mark::easy_mark; pub struct Changelog { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, changelog : &'static str, } impl Changelog { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - interop, + runtime, changelog : include_str!("../../../CHANGELOG.md") } } diff --git a/core/src/modules/deposit.rs b/core/src/modules/deposit.rs index 3a309db..8540980 100644 --- a/core/src/modules/deposit.rs +++ b/core/src/modules/deposit.rs @@ -2,12 +2,12 @@ use crate::imports::*; pub struct Deposit { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, } impl Deposit { - pub fn new(interop: Interop) -> Self { - Self { interop } + pub fn new(runtime: Runtime) -> Self { + Self { runtime } } } diff --git a/core/src/modules/export.rs b/core/src/modules/export.rs index 4afce0b..e539cc2 100644 --- a/core/src/modules/export.rs +++ b/core/src/modules/export.rs @@ -9,7 +9,7 @@ pub enum State { pub struct Export { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, secret: String, pub state: State, pub message: Option, @@ -18,9 +18,9 @@ pub struct Export { } impl Export { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - interop, + runtime, secret: String::new(), state: State::Select, message: None, @@ -115,7 +115,7 @@ impl ModuleT for Export { self.secret.as_bytes().to_vec(), ); self.secret.zeroize(); - let wallet = self.interop.wallet();//.clone(); + let wallet = self.runtime.wallet();//.clone(); let wallet_name = self.selected_wallet.clone(); //.expect("Wallet name not set"); spawn_with_result(&unlock_result, async move { diff --git a/core/src/modules/import.rs b/core/src/modules/import.rs index 30500bd..6c032dd 100644 --- a/core/src/modules/import.rs +++ b/core/src/modules/import.rs @@ -11,7 +11,7 @@ pub enum State { pub struct Import { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, wallet_secret: String, word : String, @@ -24,9 +24,9 @@ pub struct Import { } impl Import { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - interop, + runtime, wallet_secret: String::new(), word : String::new(), @@ -185,7 +185,7 @@ impl ModuleT for Import { self.wallet_secret.as_bytes().to_vec() ); self.wallet_secret.zeroize(); - let wallet = self.interop.wallet().clone(); + let wallet = self.runtime.wallet().clone(); let wallet_name = self.selected_wallet.clone(); //.expect("Wallet name not set"); spawn_with_result(&unlock_result, async move { diff --git a/core/src/modules/logs.rs b/core/src/modules/logs.rs index 68efec1..6b6dcb2 100644 --- a/core/src/modules/logs.rs +++ b/core/src/modules/logs.rs @@ -2,13 +2,13 @@ use crate::imports::*; pub struct Logs { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, } impl Logs { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - interop, + runtime, } } } @@ -34,7 +34,7 @@ impl ModuleT for Logs { .stick_to_bottom(true) .show(_ui, |ui| { - for log in self.interop.kaspa_service().logs().iter() { + for log in self.runtime.kaspa_service().logs().iter() { ui.label(RichText::from(log)); } }); diff --git a/core/src/modules/metrics.rs b/core/src/modules/metrics.rs index 4937293..6472df7 100644 --- a/core/src/modules/metrics.rs +++ b/core/src/modules/metrics.rs @@ -1,5 +1,5 @@ use crate::imports::*; -use crate::interop::services::metrics::MAX_METRICS_SAMPLES; +use crate::runtime::services::metrics::MAX_METRICS_SAMPLES; use egui_extras::{StripBuilder, Size}; use kaspa_metrics::{Metric,MetricGroup, MetricsSnapshot}; use chrono::DateTime; @@ -13,12 +13,12 @@ use egui_plot::{ pub struct Metrics { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, } impl Metrics { - pub fn new(interop: Interop) -> Self { - Self { interop } + pub fn new(runtime: Runtime) -> Self { + Self { runtime } } } @@ -77,7 +77,7 @@ impl ModuleT for Metrics { core.settings.ux.metrics.graph_columns = graph_columns; core.settings.ux.metrics.graph_height = graph_height; core.settings.ux.metrics.graph_duration = graph_duration; - // TODO - post an application loop to relay to interop + // TODO - post an application loop to relay to runtime // so that we can combine multiple saves into one core.settings.store_sync().ok(); } @@ -154,7 +154,7 @@ impl Metrics { // --- let graph_data = { - let metrics_data = self.interop.metrics_service().metrics_data(); + let metrics_data = self.runtime.metrics_service().metrics_data(); let data = metrics_data.get(&metric).unwrap(); let samples = if data.len() < duration { data.len() } else { duration }; data[data.len()-samples..].to_vec() diff --git a/core/src/modules/node.rs b/core/src/modules/node.rs index 1a58e67..307dab9 100644 --- a/core/src/modules/node.rs +++ b/core/src/modules/node.rs @@ -5,12 +5,12 @@ use crate::utils::format_duration; pub struct Node { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, } impl Node { - pub fn new(interop: Interop) -> Self { - Self { interop } + pub fn new(runtime: Runtime) -> Self { + Self { runtime } } } @@ -48,7 +48,7 @@ impl ModuleT for Node { ui.vertical(|ui| { - if let Some(peers) = self.interop.peer_monitor_service().peer_info() { + if let Some(peers) = self.runtime.peer_monitor_service().peer_info() { let (inbound, outbound) : (Vec<_>,Vec<_>) = peers.iter().partition(|peer| peer.is_outbound); CollapsingHeader::new(i18n("Inbound")) diff --git a/core/src/modules/overview.rs b/core/src/modules/overview.rs index fdafdfc..d2e5292 100644 --- a/core/src/modules/overview.rs +++ b/core/src/modules/overview.rs @@ -11,12 +11,12 @@ use crate::imports::*; pub struct Overview { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, } impl Overview { - pub fn new(interop: Interop) -> Self { - Self { interop } + pub fn new(runtime: Runtime) -> Self { + Self { runtime } } } @@ -119,10 +119,10 @@ impl Overview { }; let graph_data = { - let metrics_data = self.interop.metrics_service().metrics_data(); + let metrics_data = self.runtime.metrics_service().metrics_data(); let data = metrics_data.get(&metric).unwrap(); let mut duration = 2 * 60; - let uptime = self.interop.uptime().as_secs() as usize; + let uptime = self.runtime.uptime().as_secs() as usize; if uptime < duration { duration = uptime; } diff --git a/core/src/modules/request.rs b/core/src/modules/request.rs index 97fd711..982a2fd 100644 --- a/core/src/modules/request.rs +++ b/core/src/modules/request.rs @@ -2,12 +2,12 @@ use crate::imports::*; pub struct Request { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, } impl Request { - pub fn new(interop: Interop) -> Self { - Self { interop } + pub fn new(runtime: Runtime) -> Self { + Self { runtime } } } diff --git a/core/src/modules/send.rs b/core/src/modules/send.rs index 27bc13f..b970cfe 100644 --- a/core/src/modules/send.rs +++ b/core/src/modules/send.rs @@ -2,12 +2,12 @@ use crate::imports::*; pub struct Send { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, } impl Send { - pub fn new(interop: Interop) -> Self { - Self { interop } + pub fn new(runtime: Runtime) -> Self { + Self { runtime } } } diff --git a/core/src/modules/settings.rs b/core/src/modules/settings.rs index 27e8e89..60d8f81 100644 --- a/core/src/modules/settings.rs +++ b/core/src/modules/settings.rs @@ -7,7 +7,7 @@ use crate::imports::*; pub struct Settings { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, settings : crate::settings::Settings, // pub kaspad: KaspadNodeKind, grpc_network_interface : NetworkInterfaceEditor, //::try_from(&self.settings.node.grpc_network_interface).unwrap(); @@ -16,8 +16,8 @@ pub struct Settings { } impl Settings { - pub fn new(interop: Interop) -> Self { - Self { interop, settings : crate::settings::Settings::default(), + pub fn new(runtime: Runtime) -> Self { + Self { runtime, settings : crate::settings::Settings::default(), grpc_network_interface : NetworkInterfaceEditor::default(), } } @@ -191,7 +191,7 @@ impl ModuleT for Settings { core.settings.store_sync().unwrap(); if restart { println!("NODE INTERFACE UPDATE: {:?}", self.settings.node); - self.interop.kaspa_service().update_services(&self.settings.node); + self.runtime.kaspa_service().update_services(&self.settings.node); // println!("TODO - restart"); } }, @@ -207,7 +207,7 @@ impl ModuleT for Settings { }); if ui.button("Test Toast").clicked() { - self.interop.try_send(Events::Notify { + self.runtime.try_send(Events::Notify { notification : Notification::info("Test Toast") }).unwrap(); } diff --git a/core/src/modules/testing.rs b/core/src/modules/testing.rs index 1997418..c855d63 100644 --- a/core/src/modules/testing.rs +++ b/core/src/modules/testing.rs @@ -12,7 +12,7 @@ pub enum State { pub struct Testing { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, // pub state: State, // pub message: Option, @@ -21,7 +21,7 @@ pub struct Testing { } impl Testing { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { let now = workflow_core::time::unixtime_as_millis_f64(); let graph_data = vec![ PlotPoint::new(now + 1000.0, 1.5), @@ -32,7 +32,7 @@ impl Testing { PlotPoint::new(now + 20000.0, 5.0), ]; Self { - interop, + runtime, // state: State::Select, // message: None, graph_data, @@ -248,7 +248,7 @@ impl ModuleT for Testing { ctx.wallet_secret.as_bytes().to_vec(), ); ctx.wallet_secret.zeroize(); - let wallet = ctx.interop.wallet().clone(); + let wallet = ctx.runtime.wallet().clone(); let wallet_name = ctx.selected_wallet.clone(); //.expect("Wallet name not set"); spawn_with_result(&unlock_result, async move { diff --git a/core/src/modules/tools/check_balance.rs b/core/src/modules/tools/check_balance.rs index 1f073ce..8e30983 100644 --- a/core/src/modules/tools/check_balance.rs +++ b/core/src/modules/tools/check_balance.rs @@ -9,16 +9,16 @@ pub enum State { pub struct Tools { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, state: State, address_string: String, address: Option
, } impl Tools { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - interop, + runtime, state: State::Select, address_string: Default::default(), address: None, @@ -94,7 +94,7 @@ impl ModuleT for Tools { let address_balance_result = Payload::>::new("tools_check_balance_result"); if !address_balance_result.is_pending() { - let _wallet = this.interop.wallet().clone(); + let _wallet = this.runtime.wallet().clone(); spawn_with_result(&address_balance_result, async move { todo!("CheckBalanceProcess") }); diff --git a/core/src/modules/transactions.rs b/core/src/modules/transactions.rs index e1f4a4b..9cb6ce2 100644 --- a/core/src/modules/transactions.rs +++ b/core/src/modules/transactions.rs @@ -2,12 +2,12 @@ use crate::imports::*; pub struct Transactions { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, } impl Transactions { - pub fn new(interop: Interop) -> Self { - Self { interop } + pub fn new(runtime: Runtime) -> Self { + Self { runtime } } } diff --git a/core/src/modules/wallet_create.rs b/core/src/modules/wallet_create.rs index 68f062e..2448fd1 100644 --- a/core/src/modules/wallet_create.rs +++ b/core/src/modules/wallet_create.rs @@ -65,7 +65,7 @@ struct Context { pub struct WalletCreate { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, // secret: String, args: Context, pub state: State, @@ -73,9 +73,9 @@ pub struct WalletCreate { } impl WalletCreate { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - interop, + runtime, // secret: String::new(), state: State::Start, args: Default::default(), @@ -391,7 +391,7 @@ impl ModuleT for WalletCreate { if !wallet_create_result.is_pending() { // TODO CREATE WALLET ! - let wallet = self.interop.wallet().clone(); + let wallet = self.runtime.wallet().clone(); spawn_with_result(&wallet_create_result, async move { println!("### A"); diff --git a/core/src/modules/wallet_open.rs b/core/src/modules/wallet_open.rs index 0ea4b27..ca34855 100644 --- a/core/src/modules/wallet_open.rs +++ b/core/src/modules/wallet_open.rs @@ -11,7 +11,7 @@ pub enum State { pub struct WalletOpen { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, wallet_secret: String, pub state: State, pub message: Option, @@ -19,9 +19,9 @@ pub struct WalletOpen { } impl WalletOpen { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - interop, + runtime, wallet_secret: String::new(), state: State::Select, message: None, @@ -152,7 +152,7 @@ impl ModuleT for WalletOpen { ctx.wallet_secret.as_bytes().to_vec(), ); ctx.wallet_secret.zeroize(); - let wallet = ctx.interop.wallet().clone(); + let wallet = ctx.runtime.wallet().clone(); let wallet_name = ctx.selected_wallet.clone(); //.expect("Wallet name not set"); spawn_with_result(&unlock_result, async move { diff --git a/core/src/modules/welcome.rs b/core/src/modules/welcome.rs index e84cc7f..c8c10b4 100644 --- a/core/src/modules/welcome.rs +++ b/core/src/modules/welcome.rs @@ -2,14 +2,14 @@ use crate::imports::*; pub struct Welcome { #[allow(dead_code)] - interop: Interop, + runtime: Runtime, settings : Settings, } impl Welcome { - pub fn new(interop: Interop) -> Self { + pub fn new(runtime: Runtime) -> Self { Self { - interop, + runtime, settings : Settings::default(), } } @@ -115,7 +115,7 @@ impl ModuleT for Welcome { settings.initialized = true; settings.version.clear(); // triggers changelog settings.store_sync().expect("Unable to store settings"); - self.interop.kaspa_service().update_services(&self.settings.node); + self.runtime.kaspa_service().update_services(&self.settings.node); core.settings = settings.clone(); core.get_mut::().load(settings); core.select::(); diff --git a/core/src/interop/mod.rs b/core/src/runtime/mod.rs similarity index 89% rename from core/src/interop/mod.rs rename to core/src/runtime/mod.rs index 560bb01..57e9c36 100644 --- a/core/src/interop/mod.rs +++ b/core/src/runtime/mod.rs @@ -41,15 +41,15 @@ pub struct Inner { start_time: std::time::Instant, } -/// Interop is a core component of the Kaspa NG application responsible for +/// Runtime is a core component of the Kaspa NG application responsible for /// running application services and communication between these services /// and the application UI. #[derive(Clone)] -pub struct Interop { +pub struct Runtime { inner: Arc, } -impl Interop { +impl Runtime { pub fn new(egui_ctx: &egui::Context, settings: &Settings) -> Self { let application_events = ApplicationEventsChannel::unbounded(Some(egui_ctx.clone())); let kaspa = Arc::new(KaspaService::new(application_events.clone(), settings)); @@ -66,7 +66,7 @@ impl Interop { metrics_service.clone(), ]); - let interop = Self { + let runtime = Self { inner: Arc::new(Inner { services, application_events, @@ -79,9 +79,9 @@ impl Interop { }), }; - register_global(Some(interop.clone())); + register_global(Some(runtime.clone())); - interop + runtime } pub fn uptime(&self) -> Duration { @@ -118,13 +118,13 @@ impl Interop { register_global(None); } - // / Start the interop runtime. + // / Start the runtime runtime. pub fn start(&self) { self.inner.is_running.store(true, Ordering::SeqCst); self.start_services(); } - /// Shutdown interop runtime. + /// Shutdown runtime runtime. pub async fn shutdown(&self) { if self.inner.is_running.load(Ordering::SeqCst) { self.inner.is_running.store(false, Ordering::SeqCst); @@ -211,25 +211,25 @@ impl Interop { } } -static mut INTEROP: Option = None; +static mut RUNTIME: Option = None; -fn interop() -> &'static Interop { +fn runtime() -> &'static Runtime { unsafe { - if let Some(interop) = &INTEROP { - interop + if let Some(runtime) = &RUNTIME { + runtime } else { - panic!("interop not initialized") + panic!("runtime not initialized") } } } -fn try_interop() -> Option<&'static Interop> { - unsafe { INTEROP.as_ref() } +fn try_runtime() -> Option<&'static Runtime> { + unsafe { RUNTIME.as_ref() } } -fn register_global(interop: Option) { +fn register_global(runtime: Option) { unsafe { - INTEROP = interop; + RUNTIME = runtime; } } @@ -239,7 +239,7 @@ pub fn spawn(task: F) where F: Future> + Send + 'static, { - interop().spawn_task(task); + runtime().spawn_task(task); } /// Spawn an async task that will result in @@ -251,15 +251,15 @@ where R: Clone + Send + 'static, F: Future> + Send + 'static, { - interop().spawn_task_with_result(payload, task); + runtime().spawn_task_with_result(payload, task); } -/// Gracefully halt the interop runtime. This is used +/// Gracefully halt the runtime runtime. This is used /// to shutdown kaspad when the kaspa-ng process exit /// is an inevitable eventuality. pub fn halt() { - if try_interop().is_some() { - let handle = tokio::spawn(async move { interop().shutdown().await }); + if try_runtime().is_some() { + let handle = tokio::spawn(async move { runtime().shutdown().await }); while !handle.is_finished() { std::thread::sleep(std::time::Duration::from_millis(50)); @@ -267,7 +267,7 @@ pub fn halt() { } } -/// Attempt to halt the interop runtime but exit the process +/// Attempt to halt the runtime runtime but exit the process /// if it takes too long. This is used in attempt to shutdown /// kaspad if the kaspa-ng process panics, which can result /// in a still functioning zombie child process on unix systems. diff --git a/core/src/interop/panic.rs b/core/src/runtime/panic.rs similarity index 84% rename from core/src/interop/panic.rs rename to core/src/runtime/panic.rs index c06c945..66c07f3 100644 --- a/core/src/interop/panic.rs +++ b/core/src/runtime/panic.rs @@ -4,6 +4,6 @@ pub fn init_panic_handler() { let default_hook = panic::take_hook(); panic::set_hook(Box::new(move |panic_info| { default_hook(panic_info); - crate::interop::abort(); + crate::runtime::abort(); })); } diff --git a/core/src/interop/payload.rs b/core/src/runtime/payload.rs similarity index 100% rename from core/src/interop/payload.rs rename to core/src/runtime/payload.rs diff --git a/core/src/interop/services/kaspa/config.rs b/core/src/runtime/services/kaspa/config.rs similarity index 100% rename from core/src/interop/services/kaspa/config.rs rename to core/src/runtime/services/kaspa/config.rs diff --git a/core/src/interop/services/kaspa/daemon.rs b/core/src/runtime/services/kaspa/daemon.rs similarity index 98% rename from core/src/interop/services/kaspa/daemon.rs rename to core/src/runtime/services/kaspa/daemon.rs index 2f0fcb7..b0c995f 100644 --- a/core/src/interop/services/kaspa/daemon.rs +++ b/core/src/runtime/services/kaspa/daemon.rs @@ -1,5 +1,5 @@ use crate::imports::*; -use crate::interop::services::kaspa::{Config, KaspadServiceEvents}; +use crate::runtime::services::kaspa::{Config, KaspadServiceEvents}; use std::process::Stdio; use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::process::Command; diff --git a/core/src/interop/services/kaspa/inproc.rs b/core/src/runtime/services/kaspa/inproc.rs similarity index 98% rename from core/src/interop/services/kaspa/inproc.rs rename to core/src/runtime/services/kaspa/inproc.rs index b3235d1..0ab8438 100644 --- a/core/src/interop/services/kaspa/inproc.rs +++ b/core/src/runtime/services/kaspa/inproc.rs @@ -1,5 +1,5 @@ use crate::imports::*; -use crate::interop::services::kaspa::Config; +use crate::runtime::services::kaspa::Config; use kaspa_core::core::Core; use kaspa_core::signals::Shutdown; use kaspa_utils::fd_budget; diff --git a/core/src/interop/services/kaspa/logs.rs b/core/src/runtime/services/kaspa/logs.rs similarity index 100% rename from core/src/interop/services/kaspa/logs.rs rename to core/src/runtime/services/kaspa/logs.rs diff --git a/core/src/interop/services/kaspa/mod.rs b/core/src/runtime/services/kaspa/mod.rs similarity index 97% rename from core/src/interop/services/kaspa/mod.rs rename to core/src/runtime/services/kaspa/mod.rs index 3430c87..6185d4b 100644 --- a/core/src/interop/services/kaspa/mod.rs +++ b/core/src/runtime/services/kaspa/mod.rs @@ -1,7 +1,7 @@ use std::time::Duration; use crate::imports::*; -use crate::interop::Service; +use crate::runtime::Service; pub use futures::{future::FutureExt, select, Future}; // use kaspa_metrics::{Metric, Metrics, MetricsSnapshot}; #[allow(unused_imports)] @@ -76,7 +76,7 @@ pub struct KaspaService { pub service_events: Channel, pub task_ctl: Channel<()>, pub network: Mutex, - pub wallet: Arc, + pub wallet: Arc, // pub metrics: Arc, // pub metrics_data: Mutex>>, #[cfg(not(target_arch = "wasm32"))] @@ -90,15 +90,14 @@ impl KaspaService { pub fn new(application_events: ApplicationEventsChannel, settings: &Settings) -> Self { // -- // create wallet instance - let storage = runtime::Wallet::local_store().unwrap_or_else(|e| { + let storage = KaspaWallet::local_store().unwrap_or_else(|e| { panic!("Failed to open local store: {}", e); }); - let wallet = - runtime::Wallet::try_with_rpc(None, storage, Some(settings.node.network.into())) - .unwrap_or_else(|e| { - panic!("Failed to create wallet instance: {}", e); - }); + let wallet = KaspaWallet::try_with_rpc(None, storage, Some(settings.node.network.into())) + .unwrap_or_else(|e| { + panic!("Failed to create wallet instance: {}", e); + }); // create service event channel let service_events = Channel::unbounded(); @@ -203,7 +202,7 @@ impl KaspaService { Ok(()) } - pub fn wallet(&self) -> Arc { + pub fn wallet(&self) -> Arc { self.wallet.clone() } @@ -238,7 +237,7 @@ impl KaspaService { return Ok(()); } - for service in crate::interop::interop().services().into_iter() { + for service in crate::runtime::runtime().services().into_iter() { service.detach_rpc().await?; } @@ -302,7 +301,7 @@ impl KaspaService { // self.metrics.start_task().await?; // self.metrics.set_rpc(Some(rpc_api.clone())); - for service in crate::interop::interop().services().into_iter() { + for service in crate::runtime::runtime().services().into_iter() { service.attach_rpc(rpc_api.clone()).await?; } diff --git a/core/src/interop/services/metrics.rs b/core/src/runtime/services/metrics.rs similarity index 99% rename from core/src/interop/services/metrics.rs rename to core/src/runtime/services/metrics.rs index 4af7378..54407b6 100644 --- a/core/src/interop/services/metrics.rs +++ b/core/src/runtime/services/metrics.rs @@ -1,7 +1,7 @@ // use std::time::Duration; use crate::imports::*; -use crate::interop::Service; +use crate::runtime::Service; pub use futures::{future::FutureExt, select, Future}; use kaspa_metrics::{Metric, Metrics, MetricsSnapshot}; #[allow(unused_imports)] diff --git a/core/src/interop/services/mod.rs b/core/src/runtime/services/mod.rs similarity index 100% rename from core/src/interop/services/mod.rs rename to core/src/runtime/services/mod.rs diff --git a/core/src/interop/services/peers.rs b/core/src/runtime/services/peers.rs similarity index 100% rename from core/src/interop/services/peers.rs rename to core/src/runtime/services/peers.rs diff --git a/core/src/interop/signals.rs b/core/src/runtime/signals.rs similarity index 80% rename from core/src/interop/signals.rs rename to core/src/runtime/signals.rs index 6d2a871..055b463 100644 --- a/core/src/interop/signals.rs +++ b/core/src/runtime/signals.rs @@ -1,17 +1,17 @@ use crate::events::Events; -use crate::interop::Interop; +use crate::runtime::Runtime; use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::Arc; pub struct Signals { - interop: Interop, + runtime: Runtime, iterations: AtomicU64, } impl Signals { - pub fn bind(interop: &Interop) { + pub fn bind(runtime: &Runtime) { let signals = Arc::new(Signals { - interop: interop.clone(), + runtime: runtime.clone(), iterations: AtomicU64::new(0), }); @@ -22,16 +22,16 @@ impl Signals { 0 => { // post a graceful exit event to the main event loop println!("^SIGTERM - shutting down..."); - signals.interop.try_send(Events::Exit).unwrap_or_else(|e| { + signals.runtime.try_send(Events::Exit).unwrap_or_else(|e| { println!("Error sending exit event: {:?}", e); }); } 1 => { - // start interop abort sequence + // start runtime abort sequence // (attempt to gracefully shutdown kaspad if running) // this will execute process::exit(1) after 5 seconds println!("^SIGTERM - aborting..."); - crate::interop::abort(); + crate::runtime::abort(); } _ => { // exit the process immediately diff --git a/extensions/chrome/src/ipc.rs b/extensions/chrome/src/ipc.rs index d31bc9d..eb3bc7f 100644 --- a/extensions/chrome/src/ipc.rs +++ b/extensions/chrome/src/ipc.rs @@ -13,7 +13,7 @@ use wasm_bindgen::prelude::*; #[repr(u8)] pub enum Target { Wallet = 0, - Interop = 1, + Runtime = 1, } impl TryFrom for Target { @@ -22,7 +22,7 @@ impl TryFrom for Target { fn try_from(value: u8) -> Result { match value { 0 => Ok(Target::Wallet), - 1 => Ok(Target::Interop), + 1 => Ok(Target::Runtime), _ => Err(Error::custom("invalid message target")), } } diff --git a/extensions/chrome/src/server.rs b/extensions/chrome/src/server.rs index f27f7ad..3a6528b 100644 --- a/extensions/chrome/src/server.rs +++ b/extensions/chrome/src/server.rs @@ -142,7 +142,7 @@ impl Server { } }); } - Target::Interop => { + Target::Runtime => { todo!() } } diff --git a/macros/src/register.rs b/macros/src/register.rs index b44deeb..4ae73c7 100644 --- a/macros/src/register.rs +++ b/macros/src/register.rs @@ -96,7 +96,7 @@ fn render(modules: Modules) -> TokenStream { let module_name = module.clone(); let type_name = Ident::new(&last.to_case(Case::UpperCamel), Span::call_site()); targets.push(quote! { - modules.insert_typeid(#module_name::#type_name::new(interop.clone())); + modules.insert_typeid(#module_name::#type_name::new(runtime.clone())); }); pub_mod.insert(first.clone()); @@ -119,7 +119,7 @@ fn render(modules: Modules) -> TokenStream { #(#use_mod)* - pub fn #function_name (interop : &Interop) -> HashMap:: { + pub fn #function_name (runtime : &Runtime) -> HashMap:: { let mut modules = HashMap::::new(); #(#targets)*