From 41399ab015f7b39b66cecd0f31020d2f4edb6d48 Mon Sep 17 00:00:00 2001 From: Lorenzo Tucci Date: Fri, 4 Aug 2023 21:49:05 +0200 Subject: [PATCH] set server listen address manually and return file locations in JSON on Config --- swap/src/api.rs | 4 ++-- swap/src/api/request.rs | 18 +++++++++++++++--- swap/src/bin/swap.rs | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/swap/src/api.rs b/swap/src/api.rs index bc7f5385..9e19f89a 100644 --- a/swap/src/api.rs +++ b/swap/src/api.rs @@ -96,7 +96,7 @@ impl Context { let _ = cli::tracing::init(debug, json, data_dir.join("logs"), None); }); - let init = Context { + let context = Context { db: open_db(data_dir.join("sqlite")).await?, bitcoin_wallet, monero_wallet, @@ -116,7 +116,7 @@ impl Context { running_swap: Arc::new(Mutex::new(false)), }; - Ok(init) + Ok(context) } } diff --git a/swap/src/api/request.rs b/swap/src/api/request.rs index 936e9e35..ebc0f111 100644 --- a/swap/src/api/request.rs +++ b/swap/src/api/request.rs @@ -17,6 +17,7 @@ use std::convert::TryInto; use std::future::Future; use std::sync::Arc; use std::time::Duration; +use std::net::SocketAddr; use tokio::sync::broadcast; use uuid::Uuid; @@ -77,6 +78,7 @@ pub struct Params { pub rendezvous_point: Option, pub swap_id: Option, pub amount: Option, + pub server_address: Option, pub address: Option, } @@ -274,7 +276,11 @@ impl Request { tracing::info!(path=%format!("{}/wallet", data_dir_display), "Internal bitcoin wallet directory"); json!({ - "result": [] + "log_files": format!("{}/logs", data_dir_display), + "sqlite": format!("{}/sqlite", data_dir_display), + "seed": format!("{}/seed.pem", data_dir_display), + "monero-wallet-rpc": format!("{}/monero", data_dir_display), + "bitcoin_wallet": format!("{}/wallet", data_dir_display), }) } Method::WithdrawBtc => { @@ -313,9 +319,15 @@ impl Request { }) } Method::StartDaemon => { - let addr2 = "127.0.0.1:1234".parse()?; + let server_address = match self.params.server_address { + Some(address) => address, + None => { + "127.0.0.1:3456".parse()? + } + }; - let (_, server_handle) = rpc::run_server(addr2, Arc::clone(&context)).await?; + + let (_, server_handle) = rpc::run_server(server_address, Arc::clone(&context)).await?; loop { tokio::select! { diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index 54714495..e86cf75a 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -33,7 +33,7 @@ async fn main() -> Result<()> { if let Err(e) = check_latest_version(env!("CARGO_PKG_VERSION")).await { eprintln!("{}", e); } - let result = request.call(Arc::clone(&context)).await?; + let _result = request.call(Arc::clone(&context)).await?; Ok(()) }