Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix owner API scan #591

Merged
merged 2 commits into from
Mar 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions impls/src/node_clients/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -241,15 +242,22 @@ impl NodeClient for HTTPNodeClient {
tasks.push(client.post_async::<Request, Response>(
url.as_str(),
req,
self.node_api_secret(),
api_secret.clone(),
));
}

let task: FuturesUnordered<_> = tasks.into_iter().collect();
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 {
Ok(resps) => {
Expand Down