diff --git a/mm2src/coins/utxo.rs b/mm2src/coins/utxo.rs index 19d78dd018..e69530b6bb 100644 --- a/mm2src/coins/utxo.rs +++ b/mm2src/coins/utxo.rs @@ -692,14 +692,15 @@ pub async fn utxo_fields_from_conf_and_request( let client = Arc::new(client); - let weak_client = Arc::downgrade(&client); - spawn_electrum_ping_loop(weak_client, servers); - let weak_client = Arc::downgrade(&client); let client_name = format!("{} GUI/MM2 {}", ctx.gui().unwrap_or("UNKNOWN"), MM_VERSION); spawn_electrum_version_loop(weak_client, on_connect_rx, client_name); try_s!(wait_for_protocol_version_checked(&client).await); + + let weak_client = Arc::downgrade(&client); + spawn_electrum_ping_loop(weak_client, servers); + UtxoRpcClientEnum::Electrum(ElectrumClient(client)) }, _ => return ERR!("utxo_arc_from_conf_and_request should be called only by enable or electrum requests"), diff --git a/mm2src/coins/utxo/rpc_clients.rs b/mm2src/coins/utxo/rpc_clients.rs index 74c7d85bd7..99bc372c13 100644 --- a/mm2src/coins/utxo/rpc_clients.rs +++ b/mm2src/coins/utxo/rpc_clients.rs @@ -1050,21 +1050,23 @@ async fn electrum_request_to( request: JsonRpcRequest, to_addr: String, ) -> Result<(JsonRpcRemoteAddr, JsonRpcResponse), String> { - let connections = client.connections.lock().await; - let connection = connections - .iter() - .find(|c| c.addr == to_addr) - .ok_or(ERRL!("Unknown destination address {}", to_addr))?; - - let response = match &*connection.tx.lock().await { - Some(tx) => try_s!( - electrum_request(request.clone(), tx.clone(), connection.responses.clone()) - .compat() - .await - ), - None => return ERR!("Connection {} is not established yet", to_addr), + let (tx, responses) = { + let connections = client.connections.lock().await; + let connection = connections + .iter() + .find(|c| c.addr == to_addr) + .ok_or(ERRL!("Unknown destination address {}", to_addr))?; + let responses = connection.responses.clone(); + let tx = { + match &*connection.tx.lock().await { + Some(tx) => tx.clone(), + None => return ERR!("Connection {} is not established yet", to_addr), + } + }; + (tx, responses) }; + let response = try_s!(electrum_request(request.clone(), tx, responses).compat().await); Ok((JsonRpcRemoteAddr(to_addr.to_owned()), response)) }