mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 05:45:40 +00:00
default Tor socks port to 9050, Cargo fmt
This commit is contained in:
parent
09d9ca10e2
commit
167aef8ef5
@ -22,7 +22,7 @@ static START: Once = Once::new();
|
|||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
tor_socks5_port: Option<u16>,
|
tor_socks5_port: u16,
|
||||||
namespace: XmrBtcNamespace,
|
namespace: XmrBtcNamespace,
|
||||||
server_address: Option<SocketAddr>,
|
server_address: Option<SocketAddr>,
|
||||||
pub env_config: EnvConfig,
|
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(|| {
|
START.call_once(|| {
|
||||||
let _ = cli::tracing::init(debug, json, data_dir.join("logs"));
|
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");
|
let data_dir = data::data_dir_from(None, false).expect("Could not find data directory");
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
tor_socks5_port: None,
|
tor_socks5_port: 9050,
|
||||||
namespace: XmrBtcNamespace::from_is_testnet(false),
|
namespace: XmrBtcNamespace::from_is_testnet(false),
|
||||||
server_address: None,
|
server_address: None,
|
||||||
env_config,
|
env_config,
|
||||||
@ -399,7 +399,7 @@ pub mod api_test {
|
|||||||
|
|
||||||
let env_config = env_config_from(is_testnet);
|
let env_config = env_config_from(is_testnet);
|
||||||
Self {
|
Self {
|
||||||
tor_socks5_port: Some(9050),
|
tor_socks5_port: 9050,
|
||||||
namespace: XmrBtcNamespace::from_is_testnet(is_testnet),
|
namespace: XmrBtcNamespace::from_is_testnet(is_testnet),
|
||||||
server_address: None,
|
server_address: None,
|
||||||
env_config,
|
env_config,
|
||||||
|
@ -351,10 +351,7 @@ impl Request {
|
|||||||
);
|
);
|
||||||
let mut swarm = swarm::cli(
|
let mut swarm = swarm::cli(
|
||||||
seed.derive_libp2p_identity(),
|
seed.derive_libp2p_identity(),
|
||||||
context
|
context.config.tor_socks5_port,
|
||||||
.config
|
|
||||||
.tor_socks5_port
|
|
||||||
.context("Could not get Tor SOCKS5 port")?,
|
|
||||||
behaviour,
|
behaviour,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@ -512,15 +509,8 @@ impl Request {
|
|||||||
),
|
),
|
||||||
(seed.clone(), context.config.namespace),
|
(seed.clone(), context.config.namespace),
|
||||||
);
|
);
|
||||||
let mut swarm = swarm::cli(
|
let mut swarm =
|
||||||
seed.clone(),
|
swarm::cli(seed.clone(), context.config.tor_socks5_port, behaviour).await?;
|
||||||
context
|
|
||||||
.config
|
|
||||||
.tor_socks5_port
|
|
||||||
.context("Could not get Tor SOCKS5 port")?,
|
|
||||||
behaviour,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let our_peer_id = swarm.local_peer_id();
|
let our_peer_id = swarm.local_peer_id();
|
||||||
|
|
||||||
tracing::debug!(peer_id = %our_peer_id, "Network layer initialized");
|
tracing::debug!(peer_id = %our_peer_id, "Network layer initialized");
|
||||||
@ -748,10 +738,7 @@ impl Request {
|
|||||||
rendezvous_node_peer_id,
|
rendezvous_node_peer_id,
|
||||||
rendezvous_point,
|
rendezvous_point,
|
||||||
context.config.namespace,
|
context.config.namespace,
|
||||||
context
|
context.config.tor_socks5_port,
|
||||||
.config
|
|
||||||
.tor_socks5_port
|
|
||||||
.context("Could not get Tor SOCKS5 port")?,
|
|
||||||
identity,
|
identity,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -26,32 +26,26 @@ pub fn register_modules(context: Arc<Context>) -> Result<RpcModule<Arc<Context>>
|
|||||||
.get("swap_id")
|
.get("swap_id")
|
||||||
.ok_or_else(|| jsonrpsee_core::Error::Custom("Does not contain swap_id".to_string()))?;
|
.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(
|
execute_request(params_raw, Method::GetSwapInfo { swap_id }, &context).await
|
||||||
params_raw,
|
|
||||||
Method::GetSwapInfo { swap_id },
|
|
||||||
&context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
module.register_async_method("get_bitcoin_balance", |params_raw, context| async move {
|
module.register_async_method("get_bitcoin_balance", |params_raw, context| async move {
|
||||||
|
|
||||||
let params: HashMap<String, serde_json::Value> = params_raw.parse()?;
|
let params: HashMap<String, serde_json::Value> = params_raw.parse()?;
|
||||||
|
|
||||||
let force_refresh = params.get("force_refresh")
|
let force_refresh = params
|
||||||
.ok_or_else(|| { jsonrpsee_core::Error::Custom("Does not contain force_refresh".to_string())})?
|
.get("force_refresh")
|
||||||
|
.ok_or_else(|| {
|
||||||
|
jsonrpsee_core::Error::Custom("Does not contain force_refresh".to_string())
|
||||||
|
})?
|
||||||
.as_bool()
|
.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 {
|
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")
|
.get("swap_id")
|
||||||
.ok_or_else(|| jsonrpsee_core::Error::Custom("Does not contain swap_id".to_string()))?;
|
.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
|
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")
|
.get("swap_id")
|
||||||
.ok_or_else(|| jsonrpsee_core::Error::Custom("Does not contain swap_id".to_string()))?;
|
.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(
|
execute_request(params_raw, Method::CancelAndRefund { swap_id }, &context).await
|
||||||
params_raw,
|
|
||||||
Method::CancelAndRefund { swap_id },
|
|
||||||
&context,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
module.register_async_method(
|
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())
|
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(
|
execute_request(params_raw, Method::MoneroRecovery { swap_id }, &context).await
|
||||||
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
|
let rendezvous_point = rendezvous_point
|
||||||
.as_str()
|
.as_str()
|
||||||
.and_then(|addr_str| Multiaddr::from_str(addr_str).ok())
|
.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(
|
execute_request(
|
||||||
params_raw,
|
params_raw,
|
||||||
|
@ -18,13 +18,13 @@ mod test {
|
|||||||
use swap::api::request::{Method, Request};
|
use swap::api::request::{Method, Request};
|
||||||
use swap::api::Context;
|
use swap::api::Context;
|
||||||
|
|
||||||
use tracing_subscriber::filter::LevelFilter;
|
|
||||||
use crate::harness::alice_run_until::is_xmr_lock_transaction_sent;
|
use crate::harness::alice_run_until::is_xmr_lock_transaction_sent;
|
||||||
use crate::harness::bob_run_until::is_btc_locked;
|
use crate::harness::bob_run_until::is_btc_locked;
|
||||||
use crate::harness::{setup_test, SlowCancelConfig, TestContext};
|
use crate::harness::{setup_test, SlowCancelConfig, TestContext};
|
||||||
use swap::asb::FixedRate;
|
use swap::asb::FixedRate;
|
||||||
use swap::protocol::{alice, bob};
|
use swap::protocol::{alice, bob};
|
||||||
use swap::tracing_ext::{capture_logs, MakeCapturingWriter};
|
use swap::tracing_ext::{capture_logs, MakeCapturingWriter};
|
||||||
|
use tracing_subscriber::filter::LevelFilter;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
const SERVER_ADDRESS: &str = "127.0.0.1:1234";
|
const SERVER_ADDRESS: &str = "127.0.0.1:1234";
|
||||||
@ -85,7 +85,6 @@ mod test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
pub async fn get_swap_info() {
|
pub async fn get_swap_info() {
|
||||||
@ -419,7 +418,8 @@ mod test {
|
|||||||
HashMap::from([("swapId".to_string(), SWAP_ID.to_string())])
|
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())
|
.acquire_swap_lock(Uuid::parse_str(SWAP_ID).unwrap())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -433,5 +433,4 @@ mod test {
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user