diff --git a/swap/src/api.rs b/swap/src/api.rs index 3643014a..46af21ae 100644 --- a/swap/src/api.rs +++ b/swap/src/api.rs @@ -11,10 +11,10 @@ use anyhow::{Context as AnyContext, Result}; use std::fmt; use std::net::SocketAddr; use std::path::PathBuf; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc}; use url::Url; use std::sync::Once; -use tokio::sync::broadcast; +use tokio::sync::{broadcast, Mutex}; static START: Once = Once::new(); @@ -30,11 +30,14 @@ pub struct Config { pub is_testnet: bool, } +// workaround for warning over monero_rpc_process which we must own but not read +#[allow(dead_code)] pub struct Context { pub db: Arc, bitcoin_wallet: Option>, monero_wallet: Option>, monero_rpc_process: Option, + running_swap: Arc>, pub config: Config, pub shutdown: Arc>, } @@ -117,6 +120,7 @@ impl Context { is_testnet, }, shutdown: Arc::new(shutdown), + running_swap: Arc::new(Mutex::new(false)), }; Ok(init) @@ -209,7 +213,6 @@ fn env_config_from(testnet: bool) -> EnvConfig { } #[cfg(test)] pub mod api_test { - use super::*; use crate::tor::DEFAULT_SOCKS5_PORT; use std::str::FromStr; use uuid::Uuid; @@ -315,6 +318,3 @@ pub mod api_test { } } } -mod tests { - use super::*; -} diff --git a/swap/src/api/request.rs b/swap/src/api/request.rs index 6e0d3486..63818713 100644 --- a/swap/src/api/request.rs +++ b/swap/src/api/request.rs @@ -285,7 +285,7 @@ impl Request { json!({ "signed_tx": signed_tx, - "amount": amount.as_sat(), + "amount": amount.to_sat(), "txid": signed_tx.txid(), }) } @@ -297,7 +297,7 @@ impl Request { loop { tokio::select! { _ = self.shutdown.recv() => { - server_handle.stop(); + server_handle.stop()?; return Ok(json!({ "result": [] })) @@ -316,7 +316,7 @@ impl Request { ); json!({ - "balance": bitcoin_balance.as_sat() + "balance": bitcoin_balance.to_sat() }) } Method::Resume => { diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index da8954a1..29ce0fae 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -21,7 +21,7 @@ use tokio::sync::broadcast; #[tokio::main] async fn main() -> Result<()> { - let (tx, mut rx1) = broadcast::channel(1); + let (tx, _) = broadcast::channel(1); let (context, mut request) = match parse_args_and_apply_defaults(env::args_os(), tx).await? { ParseResult::Context(context, request) => (context, request), ParseResult::PrintAndExitZero { message } => { diff --git a/swap/src/rpc/methods.rs b/swap/src/rpc/methods.rs index 1769fdef..b41d884b 100644 --- a/swap/src/rpc/methods.rs +++ b/swap/src/rpc/methods.rs @@ -9,7 +9,6 @@ use std::collections::HashMap; use std::str::FromStr; use std::sync::Arc; use uuid::Uuid; -use crate::rpc::Error; pub fn register_modules(context: Arc) -> RpcModule> { let mut module = RpcModule::new(context); diff --git a/swap/tests/rpc.rs b/swap/tests/rpc.rs index 59f2b3d9..6148df2b 100644 --- a/swap/tests/rpc.rs +++ b/swap/tests/rpc.rs @@ -24,10 +24,10 @@ use sequential_test::sequential; // to be replaced with actual "real" testing values // need to create some kind of swap database and bitcoin environment with some funds const SERVER_ADDRESS: &str = "127.0.0.1:1234"; -const BITCOIN_ADDR: &str = "valid_address"; -const MONERO_ADDR: &str = "valid_address"; -const SELLER: &str = "some_seller"; -const SWAP_ID: &str = "valid_swap_id"; +const BITCOIN_ADDR: &str = "tb1qr3em6k3gfnyl8r7q0v7t4tlnyxzgxma3lressv"; +const MONERO_ADDR: &str = "53gEuGZUhP9JMEBZoGaFNzhwEgiG7hwQdMCqFxiyiTeFPmkbt1mAoNybEUvYBKHcnrSgxnVWgZsTvRBaHBNXPa8tHiCU51a"; +const SELLER: &str = "/ip4/127.0.0.1/tcp/9939/p2p/12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi"; +const SWAP_ID: &str = "ea030832-3be9-454f-bb98-5ea9a788406b"; pub async fn initialize_context() -> (Arc, Request) { let (is_testnet, debug, json) = (true, false, false);