Fix owner API scan (#591)

Co-authored-by: jaspervdm <j@sper.dev>
This commit is contained in:
Quentin Le Sceller 2021-03-05 13:30:13 -05:00 committed by GitHub
parent 594f4cc8ba
commit 687118541d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,7 @@ use futures::stream::FuturesUnordered;
use futures::TryStreamExt; use futures::TryStreamExt;
use std::collections::HashMap; use std::collections::HashMap;
use std::env; use std::env;
use tokio::runtime::Handle;
use crate::client_utils::{Client, RUNTIME}; use crate::client_utils::{Client, RUNTIME};
use crate::libwallet; use crate::libwallet;
@ -222,7 +223,7 @@ impl NodeClient for HTTPNodeClient {
trace!("Output query chunk size is: {}", chunk_size); trace!("Output query chunk size is: {}", chunk_size);
let url = format!("{}{}", self.node_url(), ENDPOINT); let url = format!("{}{}", self.node_url(), ENDPOINT);
let api_secret = self.node_api_secret();
let task = async move { let task = async move {
let client = Client::new(); let client = Client::new();
@ -241,7 +242,7 @@ impl NodeClient for HTTPNodeClient {
tasks.push(client.post_async::<Request, Response>( tasks.push(client.post_async::<Request, Response>(
url.as_str(), url.as_str(),
req, req,
self.node_api_secret(), api_secret.clone(),
)); ));
} }
@ -249,7 +250,14 @@ impl NodeClient for HTTPNodeClient {
task.try_collect().await task.try_collect().await
}; };
let res: Result<Vec<Response>, _> = RUNTIME.lock().unwrap().block_on(task); let res: Result<Vec<Response>, _> = 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<OutputPrintable> = match res { let results: Vec<OutputPrintable> = match res {
Ok(resps) => { Ok(resps) => {