default Tor socks port to 9050, Cargo fmt

This commit is contained in:
Lorenzo Tucci 2024-02-12 09:19:10 +02:00
parent 09d9ca10e2
commit 167aef8ef5
No known key found for this signature in database
GPG Key ID: D98C4FA2CDF590A0
4 changed files with 35 additions and 59 deletions

View File

@ -22,7 +22,7 @@ static START: Once = Once::new();
#[derive(Clone, PartialEq, Debug)]
pub struct Config {
tor_socks5_port: Option<u16>,
tor_socks5_port: u16,
namespace: XmrBtcNamespace,
server_address: Option<SocketAddr>,
pub env_config: EnvConfig,
@ -217,7 +217,7 @@ impl Context {
}
};
let tor_socks5_port = tor.map(|tor| tor.tor_socks5_port);
let tor_socks5_port = tor.map_or(9050, |tor| tor.tor_socks5_port);
START.call_once(|| {
let _ = cli::tracing::init(debug, json, data_dir.join("logs"));
@ -356,7 +356,7 @@ impl Config {
let data_dir = data::data_dir_from(None, false).expect("Could not find data directory");
Self {
tor_socks5_port: None,
tor_socks5_port: 9050,
namespace: XmrBtcNamespace::from_is_testnet(false),
server_address: None,
env_config,
@ -399,7 +399,7 @@ pub mod api_test {
let env_config = env_config_from(is_testnet);
Self {
tor_socks5_port: Some(9050),
tor_socks5_port: 9050,
namespace: XmrBtcNamespace::from_is_testnet(is_testnet),
server_address: None,
env_config,

View File

@ -351,10 +351,7 @@ impl Request {
);
let mut swarm = swarm::cli(
seed.derive_libp2p_identity(),
context
.config
.tor_socks5_port
.context("Could not get Tor SOCKS5 port")?,
context.config.tor_socks5_port,
behaviour,
)
.await?;
@ -512,15 +509,8 @@ impl Request {
),
(seed.clone(), context.config.namespace),
);
let mut swarm = swarm::cli(
seed.clone(),
context
.config
.tor_socks5_port
.context("Could not get Tor SOCKS5 port")?,
behaviour,
)
.await?;
let mut swarm =
swarm::cli(seed.clone(), context.config.tor_socks5_port, behaviour).await?;
let our_peer_id = swarm.local_peer_id();
tracing::debug!(peer_id = %our_peer_id, "Network layer initialized");
@ -748,10 +738,7 @@ impl Request {
rendezvous_node_peer_id,
rendezvous_point,
context.config.namespace,
context
.config
.tor_socks5_port
.context("Could not get Tor SOCKS5 port")?,
context.config.tor_socks5_port,
identity,
)
.await?;

View File

@ -26,32 +26,26 @@ pub fn register_modules(context: Arc<Context>) -> Result<RpcModule<Arc<Context>>
.get("swap_id")
.ok_or_else(|| jsonrpsee_core::Error::Custom("Does not contain swap_id".to_string()))?;
let swap_id = as_uuid(swap_id).ok_or_else( || jsonrpsee_core::Error::Custom("Could not parse swap_id".to_string()))?;
let swap_id = as_uuid(swap_id)
.ok_or_else(|| jsonrpsee_core::Error::Custom("Could not parse swap_id".to_string()))?;
execute_request(
params_raw,
Method::GetSwapInfo { swap_id },
&context,
)
.await
execute_request(params_raw, Method::GetSwapInfo { swap_id }, &context).await
})?;
module.register_async_method("get_bitcoin_balance", |params_raw, context| async move {
let params: HashMap<String, serde_json::Value> = params_raw.parse()?;
let force_refresh = params.get("force_refresh")
.ok_or_else(|| { jsonrpsee_core::Error::Custom("Does not contain force_refresh".to_string())})?
let force_refresh = params
.get("force_refresh")
.ok_or_else(|| {
jsonrpsee_core::Error::Custom("Does not contain force_refresh".to_string())
})?
.as_bool()
.ok_or_else(|| { jsonrpsee_core::Error::Custom("force_refesh is not a boolean".to_string())})?;
.ok_or_else(|| {
jsonrpsee_core::Error::Custom("force_refesh is not a boolean".to_string())
})?;
execute_request(
params_raw,
Method::Balance { force_refresh },
&context
)
.await
execute_request(params_raw, Method::Balance { force_refresh }, &context).await
})?;
module.register_async_method("get_history", |params, context| async move {
@ -69,7 +63,8 @@ pub fn register_modules(context: Arc<Context>) -> Result<RpcModule<Arc<Context>>
.get("swap_id")
.ok_or_else(|| jsonrpsee_core::Error::Custom("Does not contain swap_id".to_string()))?;
let swap_id = as_uuid(swap_id).ok_or_else( || jsonrpsee_core::Error::Custom("Could not parse swap_id".to_string()))?;
let swap_id = as_uuid(swap_id)
.ok_or_else(|| jsonrpsee_core::Error::Custom("Could not parse swap_id".to_string()))?;
execute_request(params_raw, Method::Resume { swap_id }, &context).await
})?;
@ -81,14 +76,10 @@ pub fn register_modules(context: Arc<Context>) -> Result<RpcModule<Arc<Context>>
.get("swap_id")
.ok_or_else(|| jsonrpsee_core::Error::Custom("Does not contain swap_id".to_string()))?;
let swap_id = as_uuid(swap_id).ok_or_else( || jsonrpsee_core::Error::Custom("Could not parse swap_id".to_string()))?;
let swap_id = as_uuid(swap_id)
.ok_or_else(|| jsonrpsee_core::Error::Custom("Could not parse swap_id".to_string()))?;
execute_request(
params_raw,
Method::CancelAndRefund { swap_id },
&context,
)
.await
execute_request(params_raw, Method::CancelAndRefund { swap_id }, &context).await
})?;
module.register_async_method(
@ -100,14 +91,11 @@ pub fn register_modules(context: Arc<Context>) -> Result<RpcModule<Arc<Context>>
jsonrpsee_core::Error::Custom("Does not contain swap_id".to_string())
})?;
let swap_id = as_uuid(swap_id).ok_or_else( || jsonrpsee_core::Error::Custom("Could not parse swap_id".to_string()))?;
let swap_id = as_uuid(swap_id).ok_or_else(|| {
jsonrpsee_core::Error::Custom("Could not parse swap_id".to_string())
})?;
execute_request(
params_raw,
Method::MoneroRecovery { swap_id },
&context,
)
.await
execute_request(params_raw, Method::MoneroRecovery { swap_id }, &context).await
},
)?;
@ -198,7 +186,9 @@ pub fn register_modules(context: Arc<Context>) -> Result<RpcModule<Arc<Context>>
let rendezvous_point = rendezvous_point
.as_str()
.and_then(|addr_str| Multiaddr::from_str(addr_str).ok())
.ok_or_else(|| jsonrpsee_core::Error::Custom("Could not parse valid multiaddr".to_string()))?;
.ok_or_else(|| {
jsonrpsee_core::Error::Custom("Could not parse valid multiaddr".to_string())
})?;
execute_request(
params_raw,

View File

@ -18,13 +18,13 @@ mod test {
use swap::api::request::{Method, Request};
use swap::api::Context;
use tracing_subscriber::filter::LevelFilter;
use crate::harness::alice_run_until::is_xmr_lock_transaction_sent;
use crate::harness::bob_run_until::is_btc_locked;
use crate::harness::{setup_test, SlowCancelConfig, TestContext};
use swap::asb::FixedRate;
use swap::protocol::{alice, bob};
use swap::tracing_ext::{capture_logs, MakeCapturingWriter};
use tracing_subscriber::filter::LevelFilter;
use uuid::Uuid;
const SERVER_ADDRESS: &str = "127.0.0.1:1234";
@ -85,7 +85,6 @@ mod test {
}
}
#[tokio::test]
#[serial]
pub async fn get_swap_info() {
@ -419,7 +418,8 @@ mod test {
HashMap::from([("swapId".to_string(), SWAP_ID.to_string())])
);
cloned_ctx.swap_lock
cloned_ctx
.swap_lock
.acquire_swap_lock(Uuid::parse_str(SWAP_ID).unwrap())
.await
.unwrap();
@ -433,5 +433,4 @@ mod test {
})
.await;
}
}