From b1800617d8d6fd961c8c9b0a57d5500d9cedd760 Mon Sep 17 00:00:00 2001 From: creating2morrow Date: Thu, 29 Jun 2023 09:59:51 -0400 Subject: [PATCH] patches for daemon proxy request --- neveko-core/src/monero.rs | 27 +++++++++++---------------- neveko-core/src/utils.rs | 14 +++++++------- neveko-gui/src/apps/home.rs | 28 ++++++++++++++-------------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/neveko-core/src/monero.rs b/neveko-core/src/monero.rs index e0e1e72..9dfd3c7 100644 --- a/neveko-core/src/monero.rs +++ b/neveko-core/src/monero.rs @@ -334,12 +334,11 @@ fn get_rpc_creds() -> RpcLogin { fn get_rpc_daemon() -> String { let args = args::Args::parse(); let gui_host = std::env::var(crate::MONERO_DAEMON_HOST).unwrap_or(utils::empty_string()); - let daemon = if gui_host == utils::empty_string() { + if gui_host == utils::empty_string() { String::from(args.monero_rpc_daemon) } else { gui_host - }; - format!("{}/json_rpc", daemon) + } } /// Performs rpc 'get_version' method @@ -1158,7 +1157,7 @@ pub async fn create_address() -> reqres::XmrRpcCreateAddressResponse { pub async fn get_info() -> reqres::XmrDaemonGetInfoResponse { info!("fetching daemon info"); let client = reqwest::Client::new(); - let host = get_rpc_daemon(); + let host = format!("{}/json_rpc", get_rpc_daemon()); let req = reqres::XmrRpcRequest { jsonrpc: DaemonFields::Version.value(), id: DaemonFields::Id.value(), @@ -1183,7 +1182,7 @@ pub async fn p_get_info() -> Result Result reqres::XmrDaemonGetHeightResponse { info!("fetching daemon height"); let client = reqwest::Client::new(); - let args = args::Args::parse(); - let daemon = String::from(args.monero_rpc_daemon); + let daemon = get_rpc_daemon(); let req = format!("{}/{}", daemon, DaemonFields::GetHeight.value()); match client.post(req).send().await { Ok(response) => { @@ -1228,8 +1226,7 @@ pub async fn p_get_height() -> Result { @@ -1248,7 +1245,7 @@ pub async fn p_get_height() -> Result reqres::XmrDaemonGetBlockResponse { info!("fetching block at height: {}", height); let client = reqwest::Client::new(); - let host = get_rpc_daemon(); + let host = format!("{}/json_rpc", get_rpc_daemon()); let params: reqres::XmrDaemonGetBlockParams = reqres::XmrDaemonGetBlockParams { height }; let req = reqres::XmrDaemonGetBlockRequest { jsonrpc: DaemonFields::Version.value(), @@ -1275,7 +1272,7 @@ pub async fn p_get_block(height: u64) -> Result Result) -> reqres::XmrDaemonGetTransactionsResponse { info!("fetching {} transactions", txs_hashes.len()); let client = reqwest::Client::new(); - let args = args::Args::parse(); - let daemon = String::from(args.monero_rpc_daemon); - let url = format!("{}/{}", daemon, DaemonFields::GetTransactions.value()); + let host = get_rpc_daemon(); + let url = format!("{}/{}", host, DaemonFields::GetTransactions.value()); let req = reqres::XmrDaemonGetTransactionsRequest { txs_hashes, decode_as_json: true, @@ -1328,8 +1324,7 @@ pub async fn p_get_transactions(txs_hashes: Vec) -> Result u128 { let mut height: u64 = 0; let mut count: u64 = 1; let mut v_fee: Vec = Vec::new(); - loop { - debug!("current height: {}", height); - if v_fee.len() >= 30 { - break; - } - let mut r_height: reqres::XmrDaemonGetHeightResponse = Default::default(); + let mut r_height: reqres::XmrDaemonGetHeightResponse = Default::default(); let remote_var = std::env::var(crate::GUI_REMOTE_NODE).unwrap_or(utils::empty_string()); if remote_var == String::from(crate::GUI_SET_REMOTE_NODE) { let p_height = monero::p_get_height().await; @@ -757,6 +752,11 @@ pub async fn estimate_fee() -> u128 { error!("error fetching height"); return ESTIMATE_FEE_FAILURE; } + loop { + debug!("current height: {}", height); + if v_fee.len() >= 30 { + break; + } height = r_height.height - count; let mut block: reqres::XmrDaemonGetBlockResponse = Default::default(); if remote_var == String::from(crate::GUI_SET_REMOTE_NODE) { @@ -804,7 +804,7 @@ pub async fn can_transfer(invoice: u128) -> bool { monero::close_wallet(&wallet_name, &wallet_password).await; let fee = estimate_fee().await; if fee == ESTIMATE_FEE_FAILURE { - false; + return false; } debug!("fee estimated to: {}", fee); debug!("balance: {}", balance.result.unlocked_balance); diff --git a/neveko-gui/src/apps/home.rs b/neveko-gui/src/apps/home.rs index 3f4e496..b885241 100644 --- a/neveko-gui/src/apps/home.rs +++ b/neveko-gui/src/apps/home.rs @@ -273,6 +273,11 @@ impl eframe::App for HomeApp { ui.text_edit_singleline(&mut self.connections.i2p_proxy_host) .labelled_by(cm_i2p_proxy_label.id); }); + ui.horizontal(|ui| { + let cm_i2p_socks_label = ui.label("i2p socks host: \t"); + ui.text_edit_singleline(&mut self.connections.i2p_socks_host) + .labelled_by(cm_i2p_socks_label.id); + }); ui.horizontal(|ui| { let cm_i2p_tunnels_label = ui.label("tunnels.json dir: "); ui.text_edit_singleline(&mut self.connections.i2p_tunnels_json) @@ -301,18 +306,6 @@ impl eframe::App for HomeApp { self.is_editing_connections = false; utils::kill_child_processes(true); utils::start_core(&self.connections); - if self.connections.is_i2p_advanced { - // set the i2p proxy host for advanced user re-use - std::env::set_var( - neveko_core::NEVEKO_I2P_PROXY_HOST, - self.connections.i2p_proxy_host.clone(), - ); - std::env::set_var( - neveko_core::NEVEKO_I2P_TUNNELS_JSON, - self.connections.i2p_tunnels_json.clone(), - ); - std::env::set_var(neveko_core::NEVEKO_I2P_ADVANCED_MODE, String::from("1")); - } self.is_loading = true; start_core_timeout(self.core_timeout_tx.clone(), ctx.clone()); } @@ -444,8 +437,15 @@ impl eframe::App for HomeApp { //------------------------------------------------------------------------------------------------- fn send_xmrd_get_info_req(tx: Sender, ctx: egui::Context) { tokio::spawn(async move { - let info: reqres::XmrDaemonGetInfoResponse = monero::get_info().await; - let _ = tx.send(info); + let remote_var = std::env::var(neveko_core::GUI_REMOTE_NODE).unwrap_or(utils::empty_string()); + if remote_var == String::from(neveko_core::GUI_SET_REMOTE_NODE) { + let p_info = monero::p_get_info().await; + let info = p_info.unwrap_or(Default::default()); + let _ = tx.send(info); + } else { + let info = monero::get_info().await; + let _ = tx.send(info); + } ctx.request_repaint(); }); }