diff --git a/swap/src/api.rs b/swap/src/api.rs index 365d8354..2362d766 100644 --- a/swap/src/api.rs +++ b/swap/src/api.rs @@ -120,6 +120,12 @@ impl SwapLock { } } +impl Default for SwapLock { + fn default() -> Self { + Self::new() + } +} + // workaround for warning over monero_rpc_process which we must own but not read #[allow(dead_code)] pub struct Context { @@ -131,6 +137,7 @@ pub struct Context { pub config: Config, } +#[allow(clippy::too_many_arguments)] impl Context { pub async fn build( bitcoin: Option, @@ -219,7 +226,7 @@ impl Context { bitcoin_wallet: Some(bob_bitcoin_wallet), monero_wallet: Some(bob_monero_wallet), config, - db: open_db(db_path).await.unwrap(), + db: open_db(db_path).await.expect("Could not open sqlite database"), monero_rpc_process: None, swap_lock: Arc::new(SwapLock::new()), } @@ -310,7 +317,7 @@ fn env_config_from(testnet: bool) -> EnvConfig { impl Config { pub fn for_harness(seed: Seed, env_config: EnvConfig) -> Self { - let data_dir = data::data_dir_from(None, false).unwrap(); + let data_dir = data::data_dir_from(None, false).expect("Could not find data directory"); Self { tor_socks5_port: None, diff --git a/swap/src/rpc.rs b/swap/src/rpc.rs index 252e6e9a..6e759057 100644 --- a/swap/src/rpc.rs +++ b/swap/src/rpc.rs @@ -20,7 +20,7 @@ pub async fn run_server( let mut modules = RpcModule::new(()); { modules - .merge(methods::register_modules(Arc::clone(&context))) + .merge(methods::register_modules(Arc::clone(&context))?) .expect("Could not register RPC modules") } diff --git a/swap/src/rpc/methods.rs b/swap/src/rpc/methods.rs index 6cdada40..6425aae0 100644 --- a/swap/src/rpc/methods.rs +++ b/swap/src/rpc/methods.rs @@ -12,14 +12,13 @@ use std::str::FromStr; use std::sync::Arc; use uuid::Uuid; -pub fn register_modules(context: Arc) -> RpcModule> { +pub fn register_modules(context: Arc) -> Result>> { let mut module = RpcModule::new(context); module .register_async_method("suspend_current_swap", |params, context| async move { execute_request(params, Method::SuspendCurrentSwap, &context).await - }) - .unwrap(); + })?; module .register_async_method("get_swap_info", |params_raw, context| async move { @@ -35,26 +34,22 @@ pub fn register_modules(context: Arc) -> RpcModule> { &context, ) .await - }) - .unwrap(); + })?; module .register_async_method("get_bitcoin_balance", |params, context| async move { execute_request(params, Method::Balance, &context).await - }) - .unwrap(); + })?; module .register_async_method("get_history", |params, context| async move { execute_request(params, Method::History, &context).await - }) - .unwrap(); + })?; module .register_async_method("get_raw_states", |params, context| async move { execute_request(params, Method::GetRawStates, &context).await - }) - .unwrap(); + })?; module .register_async_method("resume_swap", |params_raw, context| async move { @@ -65,8 +60,7 @@ pub fn register_modules(context: Arc) -> RpcModule> { })?; execute_request(params_raw, Method::Resume { swap_id: *swap_id }, &context).await - }) - .unwrap(); + })?; module .register_async_method("cancel_refund_swap", |params_raw, context| async move { @@ -82,8 +76,7 @@ pub fn register_modules(context: Arc) -> RpcModule> { &context, ) .await - }) - .unwrap(); + })?; module .register_async_method( @@ -101,9 +94,7 @@ pub fn register_modules(context: Arc) -> RpcModule> { &context, ) .await - }, - ) - .unwrap(); + })?; module .register_async_method("withdraw_btc", |params_raw, context| async move { @@ -139,8 +130,7 @@ pub fn register_modules(context: Arc) -> RpcModule> { &context, ) .await - }) - .unwrap(); + })?; module .register_async_method("buy_xmr", |params_raw, context| async move { @@ -190,8 +180,7 @@ pub fn register_modules(context: Arc) -> RpcModule> { &context, ) .await - }) - .unwrap(); + })?; module .register_async_method("list_sellers", |params_raw, context| async move { @@ -208,16 +197,14 @@ pub fn register_modules(context: Arc) -> RpcModule> { &context, ) .await - }) - .unwrap(); + })?; module .register_async_method("get_current_swap", |params, context| async move { execute_request(params, Method::GetCurrentSwap, &context).await - }) - .unwrap(); + })?; - module + Ok(module) } async fn execute_request(