Skip to content

Commit

Permalink
wip - renaming interop to runtime 2/2
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Nov 18, 2023
1 parent b738d08 commit abff3a1
Show file tree
Hide file tree
Showing 40 changed files with 182 additions and 182 deletions.
10 changes: 5 additions & 5 deletions core/src/adaptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand All @@ -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())),
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions core/src/app.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -213,8 +213,8 @@ cfg_if! {
settings.node.node_kind = kaspa_ng_core::settings::KaspadNodeKind::Disable;
}

let interop: Arc<Mutex<Option<interop::Interop>>> = Arc::new(Mutex::new(None));
let delegate = interop.clone();
let runtime: Arc<Mutex<Option<runtime::Runtime>>> = 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(),
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -288,18 +288,18 @@ 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,
&JsValue::from_str("adaptor"),
&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
Expand Down
40 changes: 20 additions & 20 deletions core/src/core.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -76,7 +76,7 @@ impl State {
}

pub struct Core {
interop: Interop,
runtime: Runtime,
wallet: Arc<dyn WalletApi>,
channel: ApplicationEventsChannel,
module: Module,
Expand All @@ -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();
Expand Down Expand Up @@ -253,11 +253,11 @@ impl Core {
let modules: HashMap<TypeId, Module> = {
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)
}
}
};
Expand All @@ -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,
Expand Down Expand Up @@ -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::<modules::Logs>(), Ordering::Relaxed);
// crate::runtime::kaspa::update_metrics_flag().store(
// type_id == TypeId::of::<modules::Overview>()
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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),
})
Expand All @@ -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()
Expand All @@ -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)
})
Expand Down Expand Up @@ -1263,7 +1263,7 @@ impl Core {
}
});

interop.wallet().accounts_activate(None).await?;
runtime.wallet().accounts_activate(None).await?;

Ok(())
});
Expand Down
6 changes: 3 additions & 3 deletions core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ pub mod egui;
pub mod error;
pub mod events;
pub mod imports;
pub mod interop;
pub mod modules;
pub mod network;
pub mod notifications;
pub mod panel;
pub mod primitives;
pub mod prompt;
pub mod result;
pub mod runtime;
pub mod settings;
pub mod sync;
pub mod utils;
6 changes: 3 additions & 3 deletions core/src/modules/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

}
Expand Down
19 changes: 10 additions & 9 deletions core/src/modules/account_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,26 +18,26 @@ pub enum State {
AccountError(Arc<Error>),
PresentMnemonic(Arc<CreationData>),
ConfirmMnemonic(Arc<CreationData>),
Finish(Arc<dyn runtime::Account>),
Finish(Arc<dyn KaspaAccount>),
}

pub enum CreationData {
Bip32 {
mnemonic: Option<Mnemonic>,
account: Arc<dyn runtime::Account>,
account: Arc<dyn KaspaAccount>,
},
Keypair {
private_key: Secret,
account: Arc<dyn runtime::Account>,
account: Arc<dyn KaspaAccount>,
},
MultiSig {
mnemonics: Vec<Mnemonic>,
account: Arc<dyn runtime::Account>,
account: Arc<dyn KaspaAccount>,
},
}

impl CreationData {
pub fn account(&self) -> Arc<dyn runtime::Account> {
pub fn account(&self) -> Arc<dyn KaspaAccount> {
match self {
Self::Bip32 { account, .. } => account.clone(),
Self::Keypair { account, .. } => account.clone(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit abff3a1

Please sign in to comment.