Update exit-future and make sc-cli compile on wasm (#4289)

* updated exit-future (github repo)

* Switch to broadcast crate

* Migrate client/cli

* Switch exit-future to modernize branch

* Small changes

* Switch to cargo version and fix fg tests

* Revert "Small changes"

This reverts commit a488106805d220cb4aee9e46a71481424c6d87d5.
This commit is contained in:
Ashley
2019-12-04 18:35:33 +01:00
committed by GitHub
parent c071276187
commit a58e8a6e45
11 changed files with 105 additions and 76 deletions
+31 -24
View File
@@ -43,7 +43,7 @@ use primitives::H256;
use std::{
io::{Write, Read, Seek, Cursor, stdin, stdout, ErrorKind}, iter, fs::{self, File},
net::{Ipv4Addr, SocketAddr}, path::{Path, PathBuf}, str::FromStr,
net::{Ipv4Addr, SocketAddr}, path::{Path, PathBuf}, str::FromStr, pin::Pin, task::Poll
};
use names::{Generator, Name};
@@ -61,8 +61,7 @@ pub use traits::{GetLogFilter, AugmentClap};
use app_dirs::{AppInfo, AppDataType};
use log::info;
use lazy_static::lazy_static;
use futures::{Future, FutureExt, TryFutureExt};
use futures01::{Async, Future as _};
use futures::{Future, compat::Future01CompatExt, executor::block_on};
use sc_telemetry::TelemetryEndpoints;
use sp_runtime::generic::BlockId;
use sp_runtime::traits::Block as BlockT;
@@ -396,23 +395,23 @@ impl<'a> ParseAndPrepareExport<'a> {
// Note: while we would like the user to handle the exit themselves, we handle it here
// for backwards compatibility reasons.
let (exit_send, exit_recv) = std::sync::mpsc::channel();
let exit = exit.into_exit()
.map(|_| Ok::<_, ()>(()))
.compat();
let exit = exit.into_exit();
std::thread::spawn(move || {
let _ = exit.wait();
block_on(exit);
let _ = exit_send.send(());
});
let mut export_fut = builder(config)?.export_blocks(file, from.into(), to.map(Into::into), json);
let fut = futures01::future::poll_fn(|| {
let mut export_fut = builder(config)?
.export_blocks(file, from.into(), to.map(Into::into), json)
.compat();
let fut = futures::future::poll_fn(|cx| {
if exit_recv.try_recv().is_ok() {
return Ok(Async::Ready(()));
return Poll::Ready(Ok(()));
}
export_fut.poll()
Pin::new(&mut export_fut).poll(cx)
});
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
let mut runtime = tokio::runtime::Runtime::new().unwrap();
runtime.block_on(fut)?;
Ok(())
}
@@ -455,23 +454,23 @@ impl<'a> ParseAndPrepareImport<'a> {
// Note: while we would like the user to handle the exit themselves, we handle it here
// for backwards compatibility reasons.
let (exit_send, exit_recv) = std::sync::mpsc::channel();
let exit = exit.into_exit()
.map(|_| Ok::<_, ()>(()))
.compat();
let exit = exit.into_exit();
std::thread::spawn(move || {
let _ = exit.wait();
block_on(exit);
let _ = exit_send.send(());
});
let mut import_fut = builder(config)?.import_blocks(file, false);
let fut = futures01::future::poll_fn(|| {
let mut import_fut = builder(config)?
.import_blocks(file, false)
.compat();
let fut = futures::future::poll_fn(|cx| {
if exit_recv.try_recv().is_ok() {
return Ok(Async::Ready(()));
return Poll::Ready(Ok(()));
}
import_fut.poll()
Pin::new(&mut import_fut).poll(cx)
});
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
let mut runtime = tokio::runtime::Runtime::new().unwrap();
runtime.block_on(fut)?;
Ok(())
}
@@ -513,8 +512,10 @@ impl<'a> CheckBlock<'a> {
};
let start = std::time::Instant::now();
let check = builder(config)?.check_block(block_id);
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
let check = builder(config)?
.check_block(block_id)
.compat();
let mut runtime = tokio::runtime::Runtime::new().unwrap();
runtime.block_on(check)?;
println!("Completed in {} ms.", start.elapsed().as_millis());
Ok(())
@@ -719,6 +720,7 @@ fn fill_network_configuration(
Ok(())
}
#[cfg(not(target_os = "unknown"))]
fn input_keystore_password() -> Result<String, String> {
rpassword::read_password_from_tty(Some("Keystore password: "))
.map_err(|e| format!("{:?}", e))
@@ -730,7 +732,12 @@ fn fill_config_keystore_password<C, G, E>(
cli: &RunCmd,
) -> Result<(), String> {
config.keystore_password = if cli.password_interactive {
Some(input_keystore_password()?.into())
#[cfg(not(target_os = "unknown"))]
{
Some(input_keystore_password()?.into())
}
#[cfg(target_os = "unknown")]
None
} else if let Some(ref file) = cli.password_filename {
Some(fs::read_to_string(file).map_err(|e| format!("{}", e))?.into())
} else if let Some(ref password) = cli.password {