patches for daemon proxy request

This commit is contained in:
creating2morrow 2023-06-29 09:59:51 -04:00
parent c5bd5c407f
commit b1800617d8
3 changed files with 32 additions and 37 deletions

View file

@ -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<reqres::XmrDaemonGetInfoResponse, Box<dyn Er
let host = utils::get_i2p_http_proxy();
let proxy = reqwest::Proxy::http(&host)?;
let client = reqwest::Client::builder().proxy(proxy).build();
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(),
@ -1206,8 +1205,7 @@ pub async fn p_get_info() -> Result<reqres::XmrDaemonGetInfoResponse, Box<dyn Er
pub async fn get_height() -> 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<reqres::XmrDaemonGetHeightResponse, Box<dy
let host = utils::get_i2p_http_proxy();
let proxy = reqwest::Proxy::http(&host)?;
let client = reqwest::Client::builder().proxy(proxy).build();
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) => {
@ -1248,7 +1245,7 @@ pub async fn p_get_height() -> Result<reqres::XmrDaemonGetHeightResponse, Box<dy
pub async fn get_block(height: u64) -> 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<reqres::XmrDaemonGetBlockRespons
let host = utils::get_i2p_http_proxy();
let proxy = reqwest::Proxy::http(&host)?;
let client = reqwest::Client::builder().proxy(proxy).build();
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(),
@ -1300,9 +1297,8 @@ pub async fn p_get_block(height: u64) -> Result<reqres::XmrDaemonGetBlockRespons
pub async fn get_transactions(txs_hashes: Vec<String>) -> 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<String>) -> Result<reqres::XmrDa
let host = utils::get_i2p_http_proxy();
let proxy = reqwest::Proxy::http(&host)?;
let client = reqwest::Client::builder().proxy(proxy).build();
let args = args::Args::parse();
let daemon = String::from(args.monero_rpc_daemon);
let daemon = get_rpc_daemon();
let url = format!("{}/{}", daemon, DaemonFields::GetTransactions.value());
let req = reqres::XmrDaemonGetTransactionsRequest {
txs_hashes,

View file

@ -740,12 +740,7 @@ pub async fn estimate_fee() -> u128 {
let mut height: u64 = 0;
let mut count: u64 = 1;
let mut v_fee: Vec<u128> = 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);

View file

@ -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<reqres::XmrDaemonGetInfoResponse>, 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();
});
}