From 687118541d45f86c9999f9e493feff1910c14466 Mon Sep 17 00:00:00 2001 From: Quentin Le Sceller Date: Fri, 5 Mar 2021 13:30:13 -0500 Subject: [PATCH] Fix owner API scan (#591) Co-authored-by: jaspervdm --- impls/src/node_clients/http.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/impls/src/node_clients/http.rs b/impls/src/node_clients/http.rs index 6618c8642..1f380cd43 100644 --- a/impls/src/node_clients/http.rs +++ b/impls/src/node_clients/http.rs @@ -21,6 +21,7 @@ use futures::stream::FuturesUnordered; use futures::TryStreamExt; use std::collections::HashMap; use std::env; +use tokio::runtime::Handle; use crate::client_utils::{Client, RUNTIME}; use crate::libwallet; @@ -222,7 +223,7 @@ impl NodeClient for HTTPNodeClient { trace!("Output query chunk size is: {}", chunk_size); let url = format!("{}{}", self.node_url(), ENDPOINT); - + let api_secret = self.node_api_secret(); let task = async move { let client = Client::new(); @@ -241,7 +242,7 @@ impl NodeClient for HTTPNodeClient { tasks.push(client.post_async::( url.as_str(), req, - self.node_api_secret(), + api_secret.clone(), )); } @@ -249,7 +250,14 @@ impl NodeClient for HTTPNodeClient { task.try_collect().await }; - let res: Result, _> = RUNTIME.lock().unwrap().block_on(task); + let res: Result, _> = if Handle::try_current().is_ok() { + let rt = RUNTIME.clone(); + std::thread::spawn(move || rt.lock().unwrap().block_on(task)) + .join() + .unwrap() + } else { + RUNTIME.lock().unwrap().block_on(task) + }; let results: Vec = match res { Ok(resps) => {