make remote-ext work with ws and safe RPCs (#8889)

* make remote-ext work with ws and safe RPCs

* Update docs.

* Update utils/frame/remote-externalities/Cargo.toml

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Fix test

* Update lock file

* Update utils/frame/remote-externalities/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Fix build again.

* revert lifetime stuff

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Kian Paimani
2021-05-25 20:00:50 +02:00
committed by GitHub
parent 53e28b98e9
commit ec409615a3
4 changed files with 231 additions and 81 deletions
@@ -86,7 +86,7 @@ pub enum State {
modules: Option<Vec<String>>,
/// The url to connect to.
#[structopt(default_value = "http://localhost:9933", parse(try_from_str = parse_url))]
#[structopt(default_value = "ws://localhost:9944", parse(try_from_str = parse_url))]
url: String,
},
}
@@ -109,11 +109,11 @@ fn parse_hash(block_number: &str) -> Result<String, String> {
}
fn parse_url(s: &str) -> Result<String, &'static str> {
if s.starts_with("http://") {
if s.starts_with("ws://") || s.starts_with("wss://") {
// could use Url crate as well, but lets keep it simple for now.
Ok(s.to_string())
} else {
Err("not a valid HTTP url: must start with 'http://'")
Err("not a valid WS(S) url: must start with 'ws://' or 'wss://'")
}
}
@@ -166,9 +166,9 @@ impl TryRuntimeCmd {
block_at,
modules
} => Builder::<B>::new().mode(Mode::Online(OnlineConfig {
uri: url.into(),
transport: url.to_owned().into(),
state_snapshot: snapshot_path.as_ref().map(SnapshotConfig::new),
modules: modules.clone().unwrap_or_default(),
modules: modules.to_owned().unwrap_or_default(),
at: block_at.as_ref()
.map(|b| b.parse().map_err(|e| format!("Could not parse hash: {:?}", e))).transpose()?,
..Default::default()